Fix crash in Android tts engine demo. (#2029)

This commit is contained in:
Fangjun Kuang
2025-03-20 10:41:52 +08:00
committed by GitHub
parent a19e57604e
commit ee2b8d0a28

View File

@@ -177,8 +177,6 @@ class MainActivity : ComponentActivity() {
rtfText = "" rtfText = ""
Log.i(TAG, "Started with text $testText") Log.i(TAG, "Started with text $testText")
samplesChannel = Channel<FloatArray>()
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
for (samples in samplesChannel) { for (samples in samplesChannel) {
track.write( track.write(
@@ -191,6 +189,10 @@ class MainActivity : ComponentActivity() {
break break
} }
} }
for (s in samplesChannel) {
// drain the channel
}
} }
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
@@ -219,7 +221,6 @@ class MainActivity : ComponentActivity() {
audioDuration, audioDuration,
elapsed / audioDuration elapsed / audioDuration
) )
samplesChannel.close()
val filename = val filename =
application.filesDir.absolutePath + "/generated.wav" application.filesDir.absolutePath + "/generated.wav"