赞
踩
textToSpeech.speak(tts, TextToSpeech.QUEUE_FLUSH, null);
for (int i=0 ; i<5 ; i++){
textToSpeech.speak("简单播放tts,"+i, TextToSpeech.QUEUE_FLUSH, null);
}
for (int i=0 ; i<5 ; i++){
if (!textToSpeech.isSpeaking()){
textToSpeech.speak("简单播放tts,"+i, TextToSpeech.QUEUE_FLUSH, null);
}
}
for (int i=0 ; i<5 ; i++){
textToSpeech.speak("简单播放,"+i, TextToSpeech.QUEUE_ADD, null);
}
private final class OnCompleteListener extends UtteranceProgressListener { /** * 播放完成。这个是播报完毕的时候 每一次播报完毕都会走 */ @Override public void onDone(final String utteranceId) { } /** * 播放异常 */ @Override public void onError(final String utteranceId) { } /** * 播放开始。这个是开始的时候。是先发声之后才会走这里 */ @Override public void onStart(final String utteranceId) { } }
//指定文件地址
wavPath = Environment.getExternalStorageDirectory() + "/temp.wav";
//添加文本内容
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, content);
//使用指定的参数将给定的文本合成为文件。该方法是异步的,即该方法只是将请求添加到TTS请求队列中,然后返回。
//当此方法返回时,合成可能还没有完成(甚至还没有开始!)。
int r = mSpeech.synthesizeToFile(content, map, wavPath);
AudioPlayData data = new AudioPlayData.Builder(AudioTtsPriority.HIGH_PRIORITY)
.tts("我是一个混合的协议的语音播报")
.rawId(R.raw.timeout)
.tts("Hello TTS Service")
.url("https://asraudio.cdnjtzy.com/eb93cfd82d0044a1a9ce047c3aeafb8c.mp3")
.url("https://asraudio.cdnjtzy.com/52bdab34457e4d9ca14a5a7feee94a23.mp3")
.url("https://asraudio.cdnjtzy.com/eb93cfd82d0044a1a9ce047c3aeafb8c.mp3")
.build();
AudioService.getInstance().play(data);
java.lang.IllegalStateException: Player is accessed on the wrong thread. See https://exoplayer.dev/issues/player-accessed-on-wrong-thread
@Override
public void playTts(final String tts) {
if (null != this.mDelegate) {
if (DelegateTaskExecutor.getInstance().isMainThread()) {
this.mDelegate.playTts(tts);
} else {
DelegateTaskExecutor.getInstance().postToMainThread(() -> mDelegate.playTts(tts));
}
}
}
<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE"/>
</intent>
</queries>
public int speak(final CharSequence text,
final int queueMode,
final Bundle params,
final String utteranceId) {
return runAction((ITextToSpeechService service) -> {
Uri utteranceUri = mUtterances.get(text);
if (utteranceUri != null) {
return service.playAudio(getCallerIdentity(), utteranceUri, queueMode,
getParams(params), utteranceId);
} else {
return service.speak(getCallerIdentity(), text, queueMode, getParams(params),
utteranceId);
}
}, ERROR, "speak");
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。