Browse Source

1

newdev_shunjiawei
fdp 1 year ago
parent
commit
35207e2dfb
  1. 5
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift
  2. 16
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift
  3. 18
      local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift

5
local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift

@ -319,19 +319,24 @@ class AgentServiceImpl: NSObject {
// 根据模式决定空闲检测策略 // 根据模式决定空闲检测策略
switch mode { switch mode {
case "phone_call": case "phone_call":
azureAsrHelper?.restoreOriginalAudioState()
// 通话模式:禁用空闲检测,保持持续激活 // 通话模式:禁用空闲检测,保持持续激活
os_log("通话模式:禁用空闲检测", log: logger, type: .info) os_log("通话模式:禁用空闲检测", log: logger, type: .info)
return return
case "ble_wakeup": case "ble_wakeup":
azureAsrHelper?.disableBluetoothAudio()
// BLE唤醒模式:使用默认的空闲检测 // BLE唤醒模式:使用默认的空闲检测
startIdleCheck(idleSeconds: maxIdleSeconds) startIdleCheck(idleSeconds: maxIdleSeconds)
case "push_to_talk": case "push_to_talk":
azureAsrHelper?.disableBluetoothAudio()
// 按住说话模式:使用默认的空闲检测 // 按住说话模式:使用默认的空闲检测
startIdleCheck(idleSeconds: maxIdleSeconds) startIdleCheck(idleSeconds: maxIdleSeconds)
case "normal": case "normal":
azureAsrHelper?.disableBluetoothAudio()
// 普通模式:使用默认的空闲检测 // 普通模式:使用默认的空闲检测
startIdleCheck(idleSeconds: maxIdleSeconds) startIdleCheck(idleSeconds: maxIdleSeconds)
default: default:
azureAsrHelper?.disableBluetoothAudio()
// 未知模式:使用默认的空闲检测 // 未知模式:使用默认的空闲检测
os_log("未知识别模式: %{public}@,使用默认空闲检测", log: logger, type: .error, mode) os_log("未知识别模式: %{public}@,使用默认空闲检测", log: logger, type: .error, mode)
startIdleCheck(idleSeconds: maxIdleSeconds) startIdleCheck(idleSeconds: maxIdleSeconds)

16
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 isAutoDetectLanguage = false
private var subscriptionKey = "" private var subscriptionKey = ""
private var region = "" private var region = ""
// 音频源配置 // 音频源配置
public enum AudioSourceType { public enum AudioSourceType {
/** 使用设备麦克风 */ /** 使用设备麦克风 */
@ -838,25 +838,25 @@ public class AzureAsrHelper: NSObject {
/** /**
* 禁用蓝牙音频功能,切换回正常音频模式 * 禁用耳机进行拾音
*/ */
public func disableBluetoothAudio() { public func disableBluetoothAudio() {
do { do {
print("禁用蓝牙音频功能,切换回正常音频模式") print("禁用耳机进行拾音")
audioStream?.disableBluetoothAudio() audioStream?.isHeadphones = true
} catch { } catch {
print("disableBluetoothAudio") print("disableBluetoothAudio")
} }
} }
/** /**
* 恢复原始音频设备状态(通常是重新启用蓝牙) * 恢复耳机进行拾音
*/ */
public func restoreOriginalAudioState() { public func restoreOriginalAudioState() {
do { do {
print("恢复原始音频设备状态(通常是重新启用蓝牙)") print("恢复耳机进行拾音")
audioStream?.restoreOriginalAudioState() audioStream?.isHeadphones = false
} catch { } catch {
print("restoreOriginalAudioState") print("restoreOriginalAudioState")
} }

18
local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift

@ -54,7 +54,7 @@ public class SimpleAudioReceiver: NSObject {
private var currentRoute: AudioOutputRoute? private var currentRoute: AudioOutputRoute?
//public var onAudioData: ((Data) -> Void)? //public var onAudioData: ((Data) -> Void)?
public var recordfile: RecordFile? public var recordfile: RecordFile?
public var isHeadphones = true
/** /**
* 初始化 * 初始化
@ -261,11 +261,17 @@ public class SimpleAudioReceiver: NSObject {
desiredMode = .voiceChat desiredMode = .voiceChat
desiredOptions = [.allowBluetooth] desiredOptions = [.allowBluetooth]
} else { } else {
// 非通话:保持原有逻辑,但使用 .allowBluetooth 以支持录音(而不是 A2DP) if(isHeadphones){
desiredCategory = .playAndRecord // 非通话:保持原有逻辑,但使用 .allowBluetooth 以支持录音(而不是 A2DP)
desiredMode = .videoChat desiredCategory = .playAndRecord
desiredOptions = [.allowBluetooth, .mixWithOthers, .defaultToSpeaker] desiredMode = .videoChat
//desiredOptions = [.mixWithOthers, .defaultToSpeaker] desiredOptions = [.allowBluetooth, .mixWithOthers, .defaultToSpeaker]
//desiredOptions = [.mixWithOthers, .defaultToSpeaker]
}else{
desiredCategory = .playAndRecord
desiredMode = .videoChat
desiredOptions = [.mixWithOthers, .defaultToSpeaker]
}
} }
// 仅在类别或模式变化时才调用 setCategory,避免触发不必要的 categoryChange // 仅在类别或模式变化时才调用 setCategory,避免触发不必要的 categoryChange

Loading…
Cancel
Save