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 65f63bf07..0643f2510 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 @@ -319,19 +319,24 @@ class AgentServiceImpl: NSObject { // 根据模式决定空闲检测策略 switch mode { case "phone_call": + azureAsrHelper?.restoreOriginalAudioState() // 通话模式:禁用空闲检测,保持持续激活 os_log("通话模式:禁用空闲检测", log: logger, type: .info) return case "ble_wakeup": + azureAsrHelper?.disableBluetoothAudio() // BLE唤醒模式:使用默认的空闲检测 startIdleCheck(idleSeconds: maxIdleSeconds) case "push_to_talk": + azureAsrHelper?.disableBluetoothAudio() // 按住说话模式:使用默认的空闲检测 startIdleCheck(idleSeconds: maxIdleSeconds) case "normal": + azureAsrHelper?.disableBluetoothAudio() // 普通模式:使用默认的空闲检测 startIdleCheck(idleSeconds: maxIdleSeconds) default: + azureAsrHelper?.disableBluetoothAudio() // 未知模式:使用默认的空闲检测 os_log("未知识别模式: %{public}@,使用默认空闲检测", log: logger, type: .error, mode) startIdleCheck(idleSeconds: maxIdleSeconds) diff --git a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift index 9f60f9218..1046f1979 100644 --- a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift +++ b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift @@ -55,7 +55,7 @@ public class AzureAsrHelper: NSObject { private var isAutoDetectLanguage = false private var subscriptionKey = "" private var region = "" - + // 音频源配置 public enum AudioSourceType { /** 使用设备麦克风 */ @@ -838,25 +838,25 @@ public class AzureAsrHelper: NSObject { /** - * 禁用蓝牙音频功能,切换回正常音频模式 + * 禁用耳机进行拾音 */ public func disableBluetoothAudio() { do { - print("禁用蓝牙音频功能,切换回正常音频模式") - audioStream?.disableBluetoothAudio() + print("禁用耳机进行拾音") + audioStream?.isHeadphones = true } catch { print("disableBluetoothAudio") } } /** - * 恢复原始音频设备状态(通常是重新启用蓝牙) + * 恢复耳机进行拾音 */ - public func restoreOriginalAudioState() { + public func restoreOriginalAudioState() { do { - print("恢复原始音频设备状态(通常是重新启用蓝牙)") - audioStream?.restoreOriginalAudioState() + print("恢复耳机进行拾音") + audioStream?.isHeadphones = false } catch { print("restoreOriginalAudioState") } diff --git a/local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift b/local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift index e5d8b79c6..6aebfac1a 100644 --- a/local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift +++ b/local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift @@ -54,7 +54,7 @@ public class SimpleAudioReceiver: NSObject { private var currentRoute: AudioOutputRoute? //public var onAudioData: ((Data) -> Void)? public var recordfile: RecordFile? - + public var isHeadphones = true /** * 初始化 @@ -261,11 +261,17 @@ public class SimpleAudioReceiver: NSObject { desiredMode = .voiceChat desiredOptions = [.allowBluetooth] } else { - // 非通话:保持原有逻辑,但使用 .allowBluetooth 以支持录音(而不是 A2DP) - desiredCategory = .playAndRecord - desiredMode = .videoChat - desiredOptions = [.allowBluetooth, .mixWithOthers, .defaultToSpeaker] - //desiredOptions = [.mixWithOthers, .defaultToSpeaker] + if(isHeadphones){ + // 非通话:保持原有逻辑,但使用 .allowBluetooth 以支持录音(而不是 A2DP) + desiredCategory = .playAndRecord + desiredMode = .videoChat + desiredOptions = [.allowBluetooth, .mixWithOthers, .defaultToSpeaker] + //desiredOptions = [.mixWithOthers, .defaultToSpeaker] + }else{ + desiredCategory = .playAndRecord + desiredMode = .videoChat + desiredOptions = [.mixWithOthers, .defaultToSpeaker] + } } // 仅在类别或模式变化时才调用 setCategory,避免触发不必要的 categoryChange