This commit is contained in:
gedoor 2021-10-15 19:27:16 +08:00
parent 60f84c7119
commit ffa065c402
3 changed files with 6 additions and 4 deletions

View File

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

View File

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

View File

@ -5,6 +5,7 @@ import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener
import io.legado.app.R
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig
import io.legado.app.help.MediaHelp
@ -15,7 +16,6 @@ import java.util.*
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener {
private val bdRegex = "^(\\s|\\p{P})+$".toRegex()
private var textToSpeech: TextToSpeech? = null
private var ttsInitFinish = false
private val ttsUtteranceListener = TTSUtteranceListener()
@ -73,7 +73,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
textToSpeech?.let {
it.speak("", TextToSpeech.QUEUE_FLUSH, null, null)
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)
}
}