|
|
@ -20,11 +20,13 @@ import java.util.* |
|
|
|
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { |
|
|
|
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
var textToSpeech: TextToSpeech? = null |
|
|
|
private var textToSpeech: TextToSpeech? = null |
|
|
|
|
|
|
|
|
|
|
|
fun clearTTS() { |
|
|
|
fun clearTTS() { |
|
|
|
textToSpeech?.stop() |
|
|
|
textToSpeech?.let { |
|
|
|
textToSpeech?.shutdown() |
|
|
|
it.stop() |
|
|
|
|
|
|
|
it.shutdown() |
|
|
|
|
|
|
|
} |
|
|
|
textToSpeech = null |
|
|
|
textToSpeech = null |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -45,9 +47,11 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener |
|
|
|
@Synchronized |
|
|
|
@Synchronized |
|
|
|
override fun onInit(status: Int) { |
|
|
|
override fun onInit(status: Int) { |
|
|
|
if (status == TextToSpeech.SUCCESS) { |
|
|
|
if (status == TextToSpeech.SUCCESS) { |
|
|
|
textToSpeech?.language = Locale.CHINA |
|
|
|
textToSpeech?.let { |
|
|
|
textToSpeech?.setOnUtteranceProgressListener(TTSUtteranceListener()) |
|
|
|
it.language = Locale.CHINA |
|
|
|
|
|
|
|
it.setOnUtteranceProgressListener(TTSUtteranceListener()) |
|
|
|
ttsInitFinish = true |
|
|
|
ttsInitFinish = true |
|
|
|
|
|
|
|
} |
|
|
|
play() |
|
|
|
play() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
launch { |
|
|
|
launch { |
|
|
|