Browse Source

修复录音完后,播放外放问题。修复录音从耳机录音问题

newdev_shunjiawei
fdp 1 year ago
parent
commit
9b42e9f400
  1. 26
      local_plugins/azure_speech/ios/azure_speech/Sources/tools/MicrophoneCapture.swift
  2. 16
      local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift

26
local_plugins/azure_speech/ios/azure_speech/Sources/tools/MicrophoneCapture.swift

@ -444,6 +444,32 @@ public class MicrophoneCapture: NSObject {
// 安全地处理音频会话
guard let audioSession = audioSession else { return }
do {
try audioSession.setActive(false)
if self.hasBluetoothDevices {
print("耳机")
// 设置音频会话参数
try audioSession.setCategory(.playback,
mode: .videoChat,
options: [
.allowBluetoothA2DP,
.allowBluetooth
]) // 添加音频优先级控制
} else {
print("手机")
try audioSession.setCategory(.playback,
mode: .videoChat,
options: [
.mixWithOthers,
.defaultToSpeaker])
}
try audioSession.overrideOutputAudioPort(.none)
try audioSession.setActive(true)
} catch {
print("音频会话配置失败: \(error.localizedDescription)")
}
}

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

@ -192,15 +192,13 @@ public class SimpleAudioReceiver: NSObject {
do {
// 确保正在写入状态
guard self._isWriting else { return }
// 设置音频会话参数
try audioSession.setCategory(.playAndRecord,
mode: .voiceChat,
options: [.defaultToSpeaker,
.mixWithOthers,
.defaultToSpeaker,
.allowBluetoothA2DP,
.allowBluetooth])
try audioSession.overrideOutputAudioPort(.none)
// 设置音频会话参数
try audioSession.setCategory(.playAndRecord,
mode: .videoChat,
options: [.allowBluetoothA2DP, // 允许蓝牙耳机,不占用hfp链路
.mixWithOthers,
.defaultToSpeaker]) // 添加音频优先级控制
try audioSession.setActive(true)
try micCapture.startCapture()
try micCapture.audioDataHandler = { data in

Loading…
Cancel
Save