How to pause android.speech.tts.TextToSpeech?

前端 未结 10 989
不知归路
不知归路 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条回答
  •  萌比男神i
    2020-12-01 04:33

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

    public void speakSpeech(String speech) {
    
        HashMap myHash = new HashMap();
    
        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);
        }
    }
    

提交回复
热议问题