android - TextToSpeech.OnInitListener.onInit(int) 被连续调用

标签 android text-to-speech

我收到报告称,在某些(不是全部)HTC Desire HD(FRF91、2.2)和 HTC EVO 4G(PC36100|3.29.651.5、2.2)上,TextToSpeech.OnInitListener.onInit(int) 在同一个对象上被重复调用(在几秒钟内超过 1500 次)。我的任何其他用户(或其他 Desire HD 用户)AFAICT 都不会发生这种行为。

代码是:

TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
    private int mCallCount = 0; // trying to investigate potential infinite loops

    @Override
    public void onInit(int status) {
        if ((mCallCount % 100) == 1) {
            // report this
        }
        mCallCount++;
    }
});

有人有什么想法吗?

编辑:我也尝试调用 shutdown() 方法(第一次检测到多个监听器调用)但这似乎没有帮助。

最佳答案

也许你应该用你自己的中介方法来解决它,例如:

private long lastCall = 0;
private long deepBreath = 5*1000; //5 seconds
private boolean hasRested;

TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() { 
    @Override 
    public void onInit(int status) { 
        long thisCall = Calendar.getInstance().getTimeInMillis();
        intermediaryMethod(status, thisCall);
    } 
}); 

//new method
public void intermediaryMethod(int status, long thisCall) {
    hasRested = (thisCall-lastCall)>=deepBreath;
    if (hasRested) {
        lastCall = thisCall;
        //do something about 'status'
    }
}

关于android - TextToSpeech.OnInitListener.onInit(int) 被连续调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4819330/

相关文章:

python - Ubuntu 和 Python : Time based scripting of multiple texts to speech

android - TextToSpeech.isSpeaking() 在什么情况下返回 true?

android - 在发生特定事件时重复文本到语音

android - Android 和 iOS 的 Unity 命令行参数

java - 旋转 ImageView 以面对给定的纬度和经度位置

android - 找不到 EGLConfig

java - 使用 SQLite (android) 存储数据的问题

android - 如何在 Android 中为 action.VIEW 添加异常 url

安卓 TextToSpeech : getting the audio time length

javascript - 如何使用 JavaScript 创建语音?