Skip to content

Commit 1a2b032

Browse files
Reef-7sanchitmonga22
authored andcommitted
Fix errors and restore rac_free error handling in voice agent bridge
1 parent 327cb50 commit 1a2b032

1 file changed

Lines changed: 30 additions & 21 deletions

File tree

sdk/runanywhere-flutter/packages/runanywhere/lib/native/dart_bridge_voice_agent.dart

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,16 @@ class DartBridgeVoiceAgent {
6565
return _handle!;
6666
}
6767

68-
try {
69-
// Use shared component handles (matches Swift approach)
70-
// This allows the voice agent to use already-loaded models from the
71-
// individual component bridges (STT, LLM, TTS, VAD)
72-
final llmHandle = DartBridgeLLM.shared.getHandle();
73-
final sttHandle = DartBridgeSTT.shared.getHandle();
74-
final ttsHandle = DartBridgeTTS.shared.getHandle();
75-
final vadHandle = DartBridgeVAD.shared.getHandle();
68+
// Use shared component handles (matches Swift approach)
69+
// This allows the voice agent to use already-loaded models from the
70+
// individual component bridges (STT, LLM, TTS, VAD)
71+
final llmHandle = DartBridgeLLM.shared.getHandle();
72+
final sttHandle = DartBridgeSTT.shared.getHandle();
73+
final ttsHandle = DartBridgeTTS.shared.getHandle();
74+
final vadHandle = DartBridgeVAD.shared.getHandle();
7675

77-
_logger.debug(
78-
'Creating voice agent with shared handles: LLM=$llmHandle, STT=$sttHandle, TTS=$ttsHandle, VAD=$vadHandle');
76+
_logger.debug(
77+
'Creating voice agent with shared handles: LLM=$llmHandle, STT=$sttHandle, TTS=$ttsHandle, VAD=$vadHandle');
7978

8079
try {
8180
final handlePtr = calloc<RacVoiceAgentHandle>();
@@ -127,7 +126,8 @@ class DartBridgeVoiceAgent {
127126
try {
128127
final loadedPtr = calloc<Int32>();
129128
try {
130-
final result = NativeFunctions.voiceAgentIsSTTLoaded(_handle!, loadedPtr);
129+
final result =
130+
NativeFunctions.voiceAgentIsSTTLoaded(_handle!, loadedPtr);
131131
return result == RAC_SUCCESS && loadedPtr.value == RAC_TRUE;
132132
} finally {
133133
calloc.free(loadedPtr);
@@ -144,7 +144,8 @@ class DartBridgeVoiceAgent {
144144
try {
145145
final loadedPtr = calloc<Int32>();
146146
try {
147-
final result = NativeFunctions.voiceAgentIsLLMLoaded(_handle!, loadedPtr);
147+
final result =
148+
NativeFunctions.voiceAgentIsLLMLoaded(_handle!, loadedPtr);
148149
return result == RAC_SUCCESS && loadedPtr.value == RAC_TRUE;
149150
} finally {
150151
calloc.free(loadedPtr);
@@ -161,7 +162,8 @@ class DartBridgeVoiceAgent {
161162
try {
162163
final loadedPtr = calloc<Int32>();
163164
try {
164-
final result = NativeFunctions.voiceAgentIsTTSLoaded(_handle!, loadedPtr);
165+
final result =
166+
NativeFunctions.voiceAgentIsTTSLoaded(_handle!, loadedPtr);
165167
return result == RAC_SUCCESS && loadedPtr.value == RAC_TRUE;
166168
} finally {
167169
calloc.free(loadedPtr);
@@ -181,7 +183,8 @@ class DartBridgeVoiceAgent {
181183
final idPtr = modelId.toNativeUtf8();
182184

183185
try {
184-
final result = NativeFunctions.voiceAgentLoadSTTModel(handle, pathPtr, idPtr);
186+
final result =
187+
NativeFunctions.voiceAgentLoadSTTModel(handle, pathPtr, idPtr);
185188

186189
if (result != RAC_SUCCESS) {
187190
throw StateError(
@@ -205,7 +208,8 @@ class DartBridgeVoiceAgent {
205208
final idPtr = modelId.toNativeUtf8();
206209

207210
try {
208-
final result = NativeFunctions.voiceAgentLoadLLMModel(handle, pathPtr, idPtr);
211+
final result =
212+
NativeFunctions.voiceAgentLoadLLMModel(handle, pathPtr, idPtr);
209213

210214
if (result != RAC_SUCCESS) {
211215
throw StateError(
@@ -229,7 +233,8 @@ class DartBridgeVoiceAgent {
229233
final idPtr = voiceId.toNativeUtf8();
230234

231235
try {
232-
final result = NativeFunctions.voiceAgentLoadTTSVoice(handle, pathPtr, idPtr);
236+
final result =
237+
NativeFunctions.voiceAgentLoadTTSVoice(handle, pathPtr, idPtr);
233238

234239
if (result != RAC_SUCCESS) {
235240
throw StateError(
@@ -254,7 +259,8 @@ class DartBridgeVoiceAgent {
254259
final handle = await getHandle();
255260

256261
try {
257-
final result = NativeFunctions.voiceAgentInitializeWithLoadedModels(handle);
262+
final result =
263+
NativeFunctions.voiceAgentInitializeWithLoadedModels(handle);
258264

259265
if (result != RAC_SUCCESS) {
260266
throw StateError(
@@ -288,8 +294,7 @@ class DartBridgeVoiceAgent {
288294
}
289295

290296
// Run the heavy C++ processing in a background isolate
291-
return Isolate.run(
292-
() => _processVoiceTurnInIsolate(handle, audioData));
297+
return Isolate.run(() => _processVoiceTurnInIsolate(handle, audioData));
293298
}
294299

295300
/// Static helper for processing voice turn in an isolate.
@@ -363,7 +368,9 @@ class DartBridgeVoiceAgent {
363368
Uint8List audioWavData;
364369
if (result.synthesizedAudioSize > 0 && result.synthesizedAudio != nullptr) {
365370
audioWavData = Uint8List.fromList(
366-
result.synthesizedAudio.cast<Uint8>().asTypedList(result.synthesizedAudioSize),
371+
result.synthesizedAudio
372+
.cast<Uint8>()
373+
.asTypedList(result.synthesizedAudioSize),
367374
);
368375
} else {
369376
audioWavData = Uint8List(0);
@@ -416,7 +423,8 @@ class DartBridgeVoiceAgent {
416423
final resultPtr = calloc<Pointer<Utf8>>();
417424

418425
try {
419-
final status = NativeFunctions.voiceAgentGenerateResponse(handle, promptPtr, resultPtr);
426+
final status = NativeFunctions.voiceAgentGenerateResponse(
427+
handle, promptPtr, resultPtr);
420428

421429
if (status != RAC_SUCCESS) {
422430
throw StateError(
@@ -514,6 +522,7 @@ class DartBridgeVoiceAgent {
514522
class VoiceTurnResult {
515523
final String transcription;
516524
final String response;
525+
517526
/// WAV-formatted audio data ready for playback
518527
final Uint8List audioWavData;
519528
final int sttDurationMs;

0 commit comments

Comments
 (0)