TTS play silence in a for-loop doesn`t work

眉间皱痕 提交于 2019-12-13 04:41:34

问题


I want to add a pause button to my TTS-app. I am trying to do this with a while-loop, which should playSIlence. It isn't working, but I can't find my mistake.

my boolean:

    boolean pausegedrückt;

for-loop:

    for (int i = 1; i < anzahl+1; i++) {
         while (pausegedrückt==true) {
            tts.playSilence(1000, TextToSpeech.QUEUE_ADD, null);
        }

            String str = String.valueOf(i);
            tts.speak(str, TextToSpeech.QUEUE_ADD, null);
            tts.playSilence(3000, TextToSpeech.QUEUE_ADD, null); 

        }

my onCheckedChanged

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
        l.setBackgroundColor(Color.BLUE);
        pausegedrückt=false;
    } else {
        l.setBackgroundColor(Color.BLACK);
        pausegedrückt=true;
    }

回答1:


I would suggest adding an OnUtteranceCompletedListener or an UtteranceProgressListener as utterances can fail on some devices without it.

Also, you are adding 1 second of silence to the queue for each loop. If it loops 10,000 times, you're going to end up with a lot of silence..... You need the loop inside the utterance listener (or at least another boolean parameter), so it will only add a further 1 second of silence once the previous silence finishes.

That said, I don't think this is the right approach to pausing the speech.



来源:https://stackoverflow.com/questions/22635249/tts-play-silence-in-a-for-loop-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!