我正在尝试使用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());
问题是当我退出播放音频的activity时,音频一直在播放,而我想让它停止。
如果使用android.speech.tts.TextToSpeech
,我可以轻松地使用TextToSpeech.Stop()
,但是如何使用IBM Watson文本到语音?
当我问这个问题时,这个功能还不存在,所以我创建了github问题https://github.com/watson-developer-cloud/android-sdk/issues/21,他们创建了一个拉请求来解决这个问题。现在我们可以用
streamPlayer.interrupt();
停止StreamPlayer