From 7bed598ba3a8aa7a985f054c882865026f29f785 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Fri, 17 Oct 2025 19:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent_service/AgentServiceImpl.swift | 30 ++++++++++++------- .../azure_speech/AzureSpeechPlugin.swift | 6 ++-- .../ble_service/OpusAudioManager.kt | 2 +- .../ble_service/SwiftOpusAudioProcessor.swift | 2 +- .../chat_api/SystemFunctionHandler.swift | 2 +- 5 files changed, 26 insertions(+), 16 deletions(-) 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 25e740417..a0561af62 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 @@ -182,6 +182,14 @@ class AgentServiceImpl: NSObject { self.callingTool = callingTool } + //加载 isInterrupt 状态 + loadIsInterruptFromCache() + if let isttsinterrupt = config["isttsinterrupt"] as? String { + if (isttsinterrupt == "true"){ + self.isInterrupt = true + } + } + if let serverurl = config["serverurl"] as? String { self.serverurl = serverurl } @@ -256,8 +264,7 @@ class AgentServiceImpl: NSObject { if isInitialized { loadChatHistory() - // 从 UserDefaults 加载 isInterrupt 状态 - loadIsInterruptFromCache() + } LocationService.shared.getCurrentLocation() { location in // self.locationInfo = location @@ -552,7 +559,7 @@ class AgentServiceImpl: NSObject { return false } guard let audioStream = azureAsrHelper?.audioStream else { - os_log("AI音频流未初始化", log: logger,type: .error) + // os_log("AI音频流未初始化", log: logger,type: .error) return false } audioStream.saveAudioDataTo(data: audioData) @@ -1787,10 +1794,10 @@ class ChatApiStreamCallback: StreamCallback { print("onFunctionCall=functionCall\(functionCall)") if (name == "exit_interaction") { - // 关闭编码器 (设备侧) - BleService.shared.closeCodec() - agentService.stopRecognition() - } + // 关闭编码器 (设备侧) + BleService.shared.closeCodec() + agentService.stopRecognition() + } try agentService.sendEvent(name: "function_call", data: [ "sessionid":sessionid, @@ -1870,7 +1877,7 @@ extension AgentServiceImpl: TtsEventListener { restartIdleCheck() sendEvent(name: "tts_started", data: ["status": "started"]) audioPlayer?.stopAwaitSound() - + case .synthesisCompleted: isSpeaking = false restartIdleCheck() @@ -1880,10 +1887,13 @@ extension AgentServiceImpl: TtsEventListener { restartIdleCheck() sendEvent(name: "playback_started", data: ["status": "playback_started"]) MusicService.shared.reduceVolume() + if(isInterrupt){ //播报开始。打断唤醒输入 + BleService.shared.closeCodec() + } case .playbackCompleted: restartIdleCheck() - if(isInterrupt){ - BleService.shared.openB1Encoder() + if(isInterrupt){//播报结束。打开解码器 + BleService.shared.openB1Encoder() } sendEvent(name: "playback_completed", data: ["status": "playback_completed"]) MusicService.shared.restoreVolume() diff --git a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift index 6bf1caab1..f63488d10 100644 --- a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift +++ b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift @@ -376,7 +376,7 @@ private func sendAstEvent(_ event: [String: Any]) { // 安全解包版本 guard let audioStream = azureAsrHelper.audioStream else { - os_log("音频流未初始化", type: .error) + // os_log("音频流未初始化", type: .error) return } print("liwei----------外部音频推送:\(audioBytes.data.count)") @@ -986,7 +986,7 @@ extension AzureSpeechPlugin: BleService.Callback { } // 安全解包版本 guard let audioStream = azureAsrHelper.audioStream else { - os_log("音频流未初始化", type: .error) + // os_log("音频流未初始化", type: .error) return } azureAsrHelper.audioStream?.saveAudioDataTo(data: data) @@ -1030,7 +1030,7 @@ extension AzureSpeechPlugin: BleService.Callback { // 安全解包版本 guard let audioStream = azureAsrHelper.audioStream else { - os_log("音频流未初始化", type: .error) + // os_log("音频流未初始化", type: .error) return } azureAsrHelper.audioStream?.saveAudioDataTo(data: rightBuffer) diff --git a/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/OpusAudioManager.kt b/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/OpusAudioManager.kt index ccba13367..110d502dc 100644 --- a/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/OpusAudioManager.kt +++ b/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/OpusAudioManager.kt @@ -241,7 +241,7 @@ class OpusAudioManager { if (channelCount >= 1) { callback?.onAudioDataDecoded(data, channelCount) } else { - Log.e(TAG, "Opus解码数据错误: ${data.size} bytes") + // Log.e(TAG, "Opus解码数据错误: ${data.size} bytes") } } } diff --git a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftOpusAudioProcessor.swift b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftOpusAudioProcessor.swift index 87367acd5..7e0898ec3 100644 --- a/local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftOpusAudioProcessor.swift +++ b/local_plugins/ble_service/ios/ble_service/Sources/ble_service/SwiftOpusAudioProcessor.swift @@ -282,7 +282,7 @@ class SwiftOpusAudioProcessor: NSObject { return } - print("Opus解码数据: \(data.count) bytes, 声道数: \(channels)") + // print("Opus解码数据: \(data.count) bytes, 声道数: \(channels)") DispatchQueue.main.async { [weak self] in self?.callback?.onAudioDataReceived(data: data, channel: self?.channels ?? 0) } diff --git a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift index 9dfda89a8..1b892350a 100644 --- a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift +++ b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift @@ -195,7 +195,7 @@ public class SystemFunctionHandler: NSObject { let handler = GetContactsHandler() _ = client.registerLocalFunction( name: "get_contacts", - description: "获取通讯录中的所有联系人", + description: "获取联系人列表,读取通讯录信息,联系人名称和电话", parameters: parameters, handler: handler )