From ffa065c402ec7b92901686914a5c23f2f5fce427 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 15 Oct 2021 19:27:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/AppPattern.kt | 2 ++ .../main/java/io/legado/app/service/HttpReadAloudService.kt | 4 ++-- .../main/java/io/legado/app/service/TTSReadAloudService.kt | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/AppPattern.kt b/app/src/main/java/io/legado/app/constant/AppPattern.kt index fc3d127ea..d2e041b7a 100644 --- a/app/src/main/java/io/legado/app/constant/AppPattern.kt +++ b/app/src/main/java/io/legado/app/constant/AppPattern.kt @@ -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})+\$") } diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index fbc27b742..fd5349ee9 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 4efb4e8d1..24db5db4d 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -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) } }