Browse Source

恢复ios面对面翻译

weicu
fdp 1 year ago
parent
commit
f1b9509874
  1. 4
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift
  2. 8
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift
  3. 79
      local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift

4
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift

@ -639,7 +639,7 @@ public class AzureAsrHelper: NSObject {
do {
print("禁用蓝牙音频功能,切换回正常音频模式")
// audioStream?.disableBluetoothAudio()
audioStream?.disableBluetoothAudio()
} catch {
print("disableBluetoothAudio")
}
@ -651,7 +651,7 @@ public class AzureAsrHelper: NSObject {
do {
print("恢复原始音频设备状态(通常是重新启用蓝牙)")
//audioStream?.restoreOriginalAudioState()
audioStream?.restoreOriginalAudioState()
} catch {
print("restoreOriginalAudioState")
}

8
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift

@ -522,18 +522,16 @@ private func sendAstEvent(_ event: [String: Any]) {
if (type == 0) {
// 默认(如果有耳机选耳机,否则使用系统扬声器)
azureAsrHelper.restoreOriginalAudioState();
// azureTtsHelper.setAudioOutputDevice()
azureTtsHelper.setAudioOutputDevice()
} else if (type == 1) {
// 强制使用声器
azureAsrHelper.disableBluetoothAudio();
// azureTtsHelper.setAudioOutputDevice()
azureTtsHelper.setAudioOutputDevice()
} else if (type == 2) {
// 强制使用耳机
azureAsrHelper.restoreOriginalAudioState();
//azureTtsHelper.setAudioOutputDevice()
azureTtsHelper.setAudioOutputDevice()
}

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

@ -365,7 +365,82 @@ public class SimpleAudioReceiver: NSObject {
}
// MARK: - 协议定义
/**
* 禁用蓝牙音频功能,切换回正常音频模式
* 强制使用设备内置扬声器或听筒
*/
public func disableBluetoothAudio() {
do {
print("禁用蓝牙音频功能,切换回正常音频模式")
// 暂停当前音频引擎
if _isWriting {
audioEngine?.pause()
try audioSession.setActive(false)
}
// 设置音频会话为不允许蓝牙
try audioSession.setCategory(
.playAndRecord,
mode: .videoChat,
options: [.defaultToSpeaker, .mixWithOthers] // 移除 .allowBluetooth
)
// 强制使用扬声器
try audioSession.overrideOutputAudioPort(.speaker)
// 重新激活音频会话
if _isWriting {
try audioSession.setActive(true)
try audioEngine?.start()
}
// 更新当前路由状态
currentRoute = .speaker
} catch {
print("禁用蓝牙音频失败: \(error.localizedDescription)")
}
}
/**
* 恢复原始音频设备状态(重新启用蓝牙)
* 允许系统自动选择最佳音频设备
*/
public func restoreOriginalAudioState() {
do {
print("恢复原始音频设备状态(重新启用蓝牙)")
// 暂停当前音频引擎
if _isWriting {
audioEngine?.pause()
try audioSession.setActive(false)
}
// 恢复完整的蓝牙音频支持
try audioSession.setCategory(
.playAndRecord,
mode: .videoChat,
options: [.defaultToSpeaker, .allowBluetooth, .mixWithOthers]
)
// 取消音频端口覆盖,让系统自动选择
try audioSession.overrideOutputAudioPort(.none)
// 重新激活音频会话
if _isWriting {
try audioSession.setActive(true)
try audioEngine?.start()
}
// 重置路由状态,让系统自动选择
currentRoute = nil
} catch {
print("恢复原始音频状态失败: \(error.localizedDescription)")
}
}
public func stopMicrophoneCapture() {
@ -568,5 +643,5 @@ private class LinkedBlockingQueue<T> {
}
}
// MARK: - 协议定义

Loading…
Cancel
Save