我正在尝试使用IBM Watson文本到语音在Android应用程序上将文本转换为音频输出。
这是我的依赖
compile 'com.ibm.watson.developer_cloud:java-sdk:3.5.3'
compile 'com.ibm.watson.developer_cloud:android-sdk:0.2.1'
在这里我将字符串转换为音频
new StreamPlayer().playStream(textToSpeechService.synthesize(params[0], Voice.EN_LISA).execute());
问题是当我退出播放音频的活动时,音频会继续播放,而我希望停止播放。
如果使用
android.speech.tts.TextToSpeech
,我可以轻松使用TextToSpeech.stop()
,但是如何使用IBM Watson文本转语音功能呢? 最佳答案
当我问这个问题时,功能还不存在,所以我创建了github问题https://github.com/watson-developer-cloud/android-sdk/issues/21,他们创建了一个pull请求来解决该问题。现在我们可以使用
streamPlayer.interrupt();
停止StreamPlayer