android - 当同时使用两种语言时,TextToSpeech 队列性能不佳

标签 android performance text-to-speech

我需要在 Android 上使用 TTS 来同时说两种语言:一种是英语短语,另一种是德语短语。为此,我提供了两种不同的 TextToSpeech.OnInitListener 实现。到目前为止一切正常。然后我试着说出来,辅助功能:

// wait for speaker availability
public boolean isSpeakingWait(tts) {

    int N = 50;
    int i = 0;
    while( tts.isSpeaking() && i < N ) {
        i--;
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    return i == 50;
}

并呼吁发言:

isSpeakWait(ttsEN);
ttsEN.speak(strEN, TextToSpeech.QUEUE_FLUSH, null);
isSpeakWait(ttsDE);
ttsDE.speak(strDE, TextToSpeech.QUEUE_FLUSH, null);

看起来在插入队列后我可能会等待几秒钟才能发出声音,并且它发生在 en 和 de 调用中。

有时我会在 EN 和 DE 短语之间看到以下错误:

W/TextToSpeech﹕ isSpeaking failed: not bound to TTS engine
W/TextToSpeech﹕ speak failed: not bound to TTS engine

我想,问题在于更改 TTS 的语言(因为 EN 我发送到使用 en-us 初始化的 TTS,而 DE 发送到使用 de-de 初始化的 TTS)。对提高性能有什么建议吗?

更新 我注意到按德语单词和生成语音后的静音时间约为 8 秒,而英语单词约为 2 秒

最佳答案

来不及回答但是是的,TTS 就像一个单例。5-8 秒是延迟加载。因此,如果 1 个实例在每次讲话之前使用 tts.setLanguage(),那么 2 个 tts 实例是相同的。

关于android - 当同时使用两种语言时,TextToSpeech 队列性能不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27973311/

相关文章:

android - 找到重复的类 com.google.android.gms.location.places.zza

android - Safeargs 生成的说明不起作用 (Android)

linux - 比较多个性能报告

c++ - 参数已知时的性能比较?

android - 尝试在 setOnUtteranceProgressListener 中调用 Toaster 或自定义函数

android - Ionic项目的发布配置,类似于Android studio中的flavors

android - android 应用程序上的 twitter 集成

Java复制bufferedImage性能问题

.net - 使用 SpeechSynthesizer 使用 SpeechAudioFormatInfo 流式传输 TTS

java - 在 Text to Speech 中不总是调用 UtteranceProgressListener?