Skip to content

Commit ee2b8d0

Browse files
authored
Fix crash in Android tts engine demo. (#2029)
1 parent a19e576 commit ee2b8d0

File tree

1 file changed

+4
-3
lines changed
  • android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine

1 file changed

+4
-3
lines changed

android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine/MainActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ class MainActivity : ComponentActivity() {
177177
rtfText = ""
178178
Log.i(TAG, "Started with text $testText")
179179

180-
samplesChannel = Channel<FloatArray>()
181-
182180
CoroutineScope(Dispatchers.IO).launch {
183181
for (samples in samplesChannel) {
184182
track.write(
@@ -191,6 +189,10 @@ class MainActivity : ComponentActivity() {
191189
break
192190
}
193191
}
192+
193+
for (s in samplesChannel) {
194+
// drain the channel
195+
}
194196
}
195197

196198
CoroutineScope(Dispatchers.Default).launch {
@@ -219,7 +221,6 @@ class MainActivity : ComponentActivity() {
219221
audioDuration,
220222
elapsed / audioDuration
221223
)
222-
samplesChannel.close()
223224

224225
val filename =
225226
application.filesDir.absolutePath + "/generated.wav"

0 commit comments

Comments
 (0)