feat: 优化

pull/209/head
kunfei 5 years ago
parent d9c7f73764
commit a3ddf6a435
  1. 16
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt

@ -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
ttsInitFinish = true it.setOnUtteranceProgressListener(TTSUtteranceListener())
ttsInitFinish = true
}
play() play()
} else { } else {
launch { launch {

Loading…
Cancel
Save