简体   繁体   中英

How to stop StreamPlayer of IBM Watson text-to-speech

I am trying to use IBM Watson text-to-speech to convert text to audio output on my Android application. Here is my dependencies

compile 'com.ibm.watson.developer_cloud:java-sdk:3.5.3'
compile 'com.ibm.watson.developer_cloud:android-sdk:0.2.1'

Here where i convert string to audio

new StreamPlayer().playStream(textToSpeechService.synthesize(params[0], Voice.EN_LISA).execute());

The problem is when i quit the activity where i play the audio, the audio keeps playing on while i want it to be stopped.

If use android.speech.tts.TextToSpeech i can easily use TextToSpeech.stop() but how to do it with IBM Watson text-to-speech?

When i asked this question, the functionality doesn't exist yet, so i created github issue https://github.com/watson-developer-cloud/android-sdk/issues/21 and they created a pull request to solve the problem. Now we can use

streamPlayer.interrupt();

to stop StreamPlayer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM