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')