TTS在for循环不`吨工作中发挥沉默 [英] TTS play silence in a for-loop doesn`t work

查看:177
本文介绍了TTS在for循环不`吨工作中发挥沉默的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想暂停按钮添加到我的TTS应用。我想用whil​​e循环,这应该playSIlence做到这一点。它不工作,但我找不到我的错误。

我的布尔值:

 布尔pausegedrückt;

有关循环:

 的for(int i = 1; I< anzahl + 1;我++){
         而(pausegedrückt==真){
            tts.playSilence(1000,TextToSpeech.QUEUE_ADD,NULL);
        }            字符串str =将String.valueOf(I)
            tts.speak(STR,TextToSpeech.QUEUE_ADD,NULL);
            tts.playSilence(3000,TextToSpeech.QUEUE_ADD,NULL);        }

我onCheckedChanged

  @覆盖
公共无效onCheckedChanged(CompoundButton buttonView,布尔器isChecked){
    如果(器isChecked){
        l.setBackgroundColor(Color.BLUE);
        pausegedrückt= FALSE;
    }其他{
        l.setBackgroundColor(Color.BLACK);
        pausegedrückt= TRUE;
    }


解决方案

我建议增加一个<一个href=\"http://developer.android.com/reference/android/speech/tts/TextToSpeech.OnUtteranceCompletedListener.html\"相对=nofollow> OnUtteranceCompletedListener 或 UtteranceProgressListener 因为话语可以在某些设备发生故障离不开它了。

另外,您要添加的沉默1秒队列为每个循环。如果循环10000次,你将有很多的沉默结束了.....你需要话语监听器里循环(或者至少另一个布尔参数),所以它只会增加的进一步1秒沉默一旦previous沉默结束。

这是说,我不认为这是暂停的讲话是正确的做法。

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;
    }

解决方案

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.

这篇关于TTS在for循环不`吨工作中发挥沉默的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆