From 21099d0860814ba4930f1ed5be1ebfd9d5341100 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 29 May 2025 09:55:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=92=AD=E6=94=BE=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E4=B8=8D=E6=92=AD=E6=8A=A5=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunqiinnovation/azure_speech/AzureTtsHelper.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureTtsHelper.kt b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureTtsHelper.kt index 70227503f..b08fb0d50 100644 --- a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureTtsHelper.kt +++ b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureTtsHelper.kt @@ -243,7 +243,15 @@ class AzureTtsHelper(private val context: Context) : ITtsService { )) } } - + //清洗播报语音内容 + fun cleanTextForTTS(text: String): String { + return text + .replace(Regex("https?://\\S+"), "") // 移除 URL + .replace(Regex("[\\p{Punct}]"), "") // 可选:移除标点符号(你可能不想全部移除) + .replace(Regex("[\uD83C-\uDBFF\uDC00-\uDFFF]+"), "") // 移除 emoji 表情 + .replace(Regex("\\s+"), " ") // 多个空格合并 + .trim() + } /** * 设置语音参数 */ @@ -372,8 +380,7 @@ class AzureTtsHelper(private val context: Context) : ITtsService { } lastSpeakTime = currentTime - val currentText = streamBuffer.toString() - + val currentText = cleanTextForTTS(streamBuffer.toString()) // 定义标点符号列表 val punctuationMarks = listOf('.', '。', '!', '!', '?', '?', ';', ';', ',', ',', ':', ':', '\n')