pull/1118/head
gedoor 3 years ago
parent f7170d9c2c
commit b446d59c40
  1. 3
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt

@ -13,7 +13,6 @@ import io.legado.app.service.help.ReadBook
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.launch
import java.util.* import java.util.*
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener {
@ -56,11 +55,9 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
play() play()
} }
} else { } else {
launch {
toastOnUi(R.string.tts_init_failed) toastOnUi(R.string.tts_init_failed)
} }
} }
}
@Synchronized @Synchronized
override fun play() { override fun play() {

@ -167,17 +167,22 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
} }
if (!ttsInitFinish) return if (!ttsInitFinish) return
if (text == "") return if (text == "") return
if (textToSpeech?.isSpeaking == true) if (textToSpeech?.isSpeaking == true) {
textToSpeech?.stop() textToSpeech?.stop()
}
textToSpeech?.speak(text, TextToSpeech.QUEUE_ADD, null, "select_text") textToSpeech?.speak(text, TextToSpeech.QUEUE_ADD, null, "select_text")
lastText = "" lastText = ""
} }
@Synchronized @Synchronized
override fun onInit(status: Int) { override fun onInit(status: Int) {
if (status == TextToSpeech.SUCCESS) {
textToSpeech?.language = Locale.CHINA textToSpeech?.language = Locale.CHINA
ttsInitFinish = true ttsInitFinish = true
readAloud(lastText) readAloud(lastText)
} else {
context.toastOnUi(R.string.tts_init_failed)
}
} }
@RequiresApi(Build.VERSION_CODES.M) @RequiresApi(Build.VERSION_CODES.M)

Loading…
Cancel
Save