pull/1395/head
gedoor 4 years ago
parent 60f84c7119
commit ffa065c402
  1. 2
      app/src/main/java/io/legado/app/constant/AppPattern.kt
  2. 4
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  3. 4
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt

@ -18,4 +18,6 @@ object AppPattern {
val bdRegex = Regex("(\\p{P})+") val bdRegex = Regex("(\\p{P})+")
val rnRegex = Regex("[\\r\\n]") val rnRegex = Regex("[\\r\\n]")
val notReadAloudRegex = Regex("^(\\s|\\p{C}|\\p{P}|\\p{Z}|\\p{S})+\$")
} }

@ -4,6 +4,7 @@ import android.app.PendingIntent
import android.media.MediaPlayer import android.media.MediaPlayer
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppLog import io.legado.app.constant.AppLog
import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -26,7 +27,6 @@ class HttpReadAloudService : BaseReadAloudService(),
MediaPlayer.OnErrorListener, MediaPlayer.OnErrorListener,
MediaPlayer.OnCompletionListener { MediaPlayer.OnCompletionListener {
private val bdRegex = "^(\\s|\\p{P})+$".toRegex()
private val mediaPlayer = MediaPlayer() private val mediaPlayer = MediaPlayer()
private val ttsFolderPath: String by lazy { private val ttsFolderPath: String by lazy {
externalCacheDir!!.absolutePath + File.separator + "httpTTS" + File.separator externalCacheDir!!.absolutePath + File.separator + "httpTTS" + File.separator
@ -96,7 +96,7 @@ class HttpReadAloudService : BaseReadAloudService(),
ReadAloud.httpTTS?.let { httpTts -> ReadAloud.httpTTS?.let { httpTts ->
contentList.forEachIndexed { index, item -> contentList.forEachIndexed { index, item ->
if (isActive) { if (isActive) {
val speakText = item.replace(bdRegex, "") val speakText = item.replace(AppPattern.notReadAloudRegex, "")
val fileName = val fileName =
md5SpeakFileName( md5SpeakFileName(
httpTts.url, httpTts.url,

@ -5,6 +5,7 @@ import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener import android.speech.tts.UtteranceProgressListener
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
@ -15,7 +16,6 @@ import java.util.*
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener {
private val bdRegex = "^(\\s|\\p{P})+$".toRegex()
private var textToSpeech: TextToSpeech? = null private var textToSpeech: TextToSpeech? = null
private var ttsInitFinish = false private var ttsInitFinish = false
private val ttsUtteranceListener = TTSUtteranceListener() private val ttsUtteranceListener = TTSUtteranceListener()
@ -73,7 +73,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
textToSpeech?.let { textToSpeech?.let {
it.speak("", TextToSpeech.QUEUE_FLUSH, null, null) it.speak("", TextToSpeech.QUEUE_FLUSH, null, null)
for (i in nowSpeak until contentList.size) { for (i in nowSpeak until contentList.size) {
val text = contentList[i].replace(bdRegex, "") val text = contentList[i].replace(AppPattern.notReadAloudRegex, "")
it.speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i) it.speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i)
} }
} }

Loading…
Cancel
Save