How to pause android.speech.tts.TextToSpeech?

前端 未结 10 950
不知归路
不知归路 2020-12-01 03:47

I\'m playing text with android TTS - android.speech.tts.TextToSpeech

I use: TextToSpeech.speak to speak and .stop to stop. Is

相关标签:
10条回答
  • 2020-12-01 04:30

    Also, an escaped quote (\") seems to have it pause somewhat as well - at least, if you put it around a word it adds space around the word.

    0 讨论(0)
  • 2020-12-01 04:33

    I used splitting of string and used playsilence() like below:

    public void speakSpeech(String speech) {
    
        HashMap<String, String> myHash = new HashMap<String, String>();
    
        myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "done");
    
        String[] splitspeech = speech.split("\\.");
    
        for (int i = 0; i < splitspeech.length; i++) {
    
            if (i == 0) { // Use for the first splited text to flush on audio stream
    
                textToSpeech.speak(splitspeech[i].toString().trim(),TextToSpeech.QUEUE_FLUSH, myHash);
    
            } else { // add the new test on previous then play the TTS
    
                textToSpeech.speak(splitspeech[i].toString().trim(), TextToSpeech.QUEUE_ADD,myHash);
            }
    
            textToSpeech.playSilence(750, TextToSpeech.QUEUE_ADD, null);
        }
    }
    
    0 讨论(0)
  • 2020-12-01 04:33

    divide the messages into parts and listen for last utterance by using onutteranceprogress listener

     tts.playSilence(1250, TextToSpeech.QUEUE_ADD, null);
    
    0 讨论(0)
  • 2020-12-01 04:39

    I haven't yet tried this, but I need to do the same thing. My thinking is to first split your speech text into an array of words.

    Then create a recursive function that plays the next word after the current word is finished, while keeping a counter of the current word.

    0 讨论(0)
提交回复
热议问题