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