|
|
|
@ -42,9 +42,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener |
|
|
|
|
|
|
|
|
|
private fun initTts() { |
|
|
|
|
ttsInitFinish = false |
|
|
|
|
textToSpeech = TextToSpeech(this, this).apply { |
|
|
|
|
setOnUtteranceProgressListener(ttsUtteranceListener) |
|
|
|
|
} |
|
|
|
|
textToSpeech = TextToSpeech(this, this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
@ -55,6 +53,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener |
|
|
|
|
override fun onInit(status: Int) { |
|
|
|
|
if (status == TextToSpeech.SUCCESS) { |
|
|
|
|
textToSpeech?.let { |
|
|
|
|
it.setOnUtteranceProgressListener(ttsUtteranceListener) |
|
|
|
|
it.language = Locale.CHINA |
|
|
|
|
ttsInitFinish = true |
|
|
|
|
play() |
|
|
|
@ -69,16 +68,20 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener |
|
|
|
|
@Synchronized |
|
|
|
|
override fun play() { |
|
|
|
|
if (contentList.isNotEmpty() && ttsInitFinish && requestFocus()) { |
|
|
|
|
MediaHelp.playSilentSound(this) |
|
|
|
|
super.play() |
|
|
|
|
textToSpeech?.stop() |
|
|
|
|
for (i in nowSpeak until contentList.size) { |
|
|
|
|
textToSpeech?.speak( |
|
|
|
|
contentList[i], |
|
|
|
|
TextToSpeech.QUEUE_ADD, |
|
|
|
|
null, |
|
|
|
|
AppConst.APP_TAG + i |
|
|
|
|
) |
|
|
|
|
execute { |
|
|
|
|
MediaHelp.playSilentSound(this@TTSReadAloudService) |
|
|
|
|
textToSpeech?.let { |
|
|
|
|
it.stop() |
|
|
|
|
for (i in nowSpeak until contentList.size) { |
|
|
|
|
it.speak( |
|
|
|
|
contentList[i], |
|
|
|
|
TextToSpeech.QUEUE_ADD, |
|
|
|
|
null, |
|
|
|
|
AppConst.APP_TAG + i |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|