在TTS完成后采取行动;请不要重叠执行TTS

时间:2018-01-20 22:45:51

标签: android text-to-speech delayed-execution

根据https://stackoverflow.com/a/22875621/9023855的建议,为什么我的代码没有按预期工作?我的计划是自动点击按钮。

private boolean threadDone = true;

public void setTimer(final boolean shown_answer, final TextToSpeech tts){

    final Handler h =new Handler();
    Runnable r = new Runnable() {
        public void run() {
            if (!tts.isSpeak() && threadDone) {
                onTtsFinished(shown_answer);
            }

            h.postDelayed(this, 1000);
        }
    };
    h.postDelayed(r, 1000);
}

public void onTtsFinished(boolean shown_answer) {
    threadDone = false;
    if(showAnswer && !shown_answer){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                button.performClick();
                threadDone = true;
            }
        }, showDelay);

    }

    if(nextQuestion && shown_answer){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                button.performClick();
                threadDone = true;
            }
        }, nextDelay);
    }
}

https://github.com/patarapolw/AndroidDuendecat/blob/052d228165277c655417e4f4fb586295b7e710c8/app/src/main/java/com/blogspot/fossipol/duendecat/MyTimer.java#L54

0 个答案:

没有答案