diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt index 1fdaea5df..a1921b405 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt @@ -316,6 +316,8 @@ object AgentService : CoroutineScope { _isTtsSpeaking.set(true) restartIdleCheck() sendEvent("tts_started", mapOf("status" to "started")) + // 停止气泡音,避免与TTS同时播放 + audioPlayer?.stopAudio() } TtsEventType.SYNTHESIS_COMPLETED -> { @@ -328,11 +330,15 @@ object AgentService : CoroutineScope { _isTtsSpeaking.set(false) restartIdleCheck() sendEvent("tts_canceled", mapOf("status" to "canceled")) + // TTS取消时停止气泡音 + audioPlayer?.stopAudio() } TtsEventType.PLAYBACK_STARTED -> { //开始AI播报内容 restartIdleCheck() sendEvent("playback_started", mapOf("status" to "playback_started")) + // 确保气泡音已停止,避免与TTS播放重叠 + audioPlayer?.stopAudio() // 发送AI说话开始广播 val intent = Intent("com.yunqiinnovation.music_service.AI_SAY_START").apply { @@ -355,6 +361,8 @@ object AgentService : CoroutineScope { TtsEventType.ERROR -> { _isTtsSpeaking.set(false) restartIdleCheck() + // TTS错误时停止气泡音 + audioPlayer?.stopAudio() val params = event.params val code = params["errorCode"] as? String ?: "UNKNOWN_ERROR" val message = params["errorMessage"] as? String ?: "未知错误" @@ -663,6 +671,8 @@ object AgentService : CoroutineScope { // 并行执行停止操作,加快响应速度 stopTts() stopAiStream() + // 停止气泡音,避免在打断后继续播放 + audioPlayer?.stopAudio() // 记录打断耗时 @@ -888,7 +898,8 @@ object AgentService : CoroutineScope { responseBuilder.append(token) if (speakResponse && reply && broadcast) { ttsService?.speakStream(token) - // audioPlayer?.stopAudio() + // 在开始流式TTS时立即停止气泡音 + audioPlayer?.stopAudio() } if (reply && token.isNotEmpty()) { // 发送流式回复token diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift index bfac028cd..684616bc8 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift @@ -996,7 +996,8 @@ class ChatApiStreamCallback: StreamCallback { if speakResponse && reply && broadcast{ try agentService.azureTtsHelper?.speakStream(token) -// try agentService.audioPlayer?.stopAwaitSound() + // 在开始流式TTS时立即停止气泡音 + try agentService.audioPlayer?.stopAwaitSound() } if (reply && token != "") { try agentService.sendEvent(name: "assistant_token", data: ["token": token])