From 09b377cb7eca714da6e9f77739b7a020b6f43565 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 26 Aug 2025 19:17:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=9D=83=E9=99=90=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E9=A2=84=E7=83=AD=E9=BA=A6=E5=85=8B=E9=A3=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/tools/SimpleAudioReceiver.swift | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) 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 d2cba5f9f..e7c8cc797 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 @@ -70,7 +70,9 @@ public class SimpleAudioReceiver: NSObject { print("音频录制组件已初始化,跳过重复初始化") return } - preConfigureAudioSession() + if audioSession.recordPermission == .granted { //判断权限成功 预热麦克风 + preConfigureAudioSession() + } // 预配置音频会话 audioFormat = getOptimalAudioFormat() @@ -229,7 +231,7 @@ public class SimpleAudioReceiver: NSObject { // 【新增】首先配置音频会话 try audioSession.setCategory( .playAndRecord, - mode: .videoChat, + mode: .default, options: [ .defaultToSpeaker, .allowBluetooth, @@ -239,13 +241,13 @@ public class SimpleAudioReceiver: NSObject { ) // 【新增】请求麦克风权限(如果尚未授权) -// if audioSession.recordPermission != .granted { -// audioSession.requestRecordPermission { granted in -// if !granted { -// print("麦克风权限被拒绝") -// } -// } -// } + if audioSession.recordPermission != .granted { + audioSession.requestRecordPermission { granted in + if !granted { + print("麦克风权限被拒绝") + } + } + } // 【新增】激活音频会话(在配置音频引擎之前) try audioSession.setActive(true) @@ -272,9 +274,9 @@ public class SimpleAudioReceiver: NSObject { let hardwareFormat = inputNode.inputFormat(forBus: 0) // iOS 13+ 启用语音处理 - if #available(iOS 13.0, *) { - try inputNode.setVoiceProcessingEnabled(true) - } +// if #available(iOS 13.0, *) { +// try inputNode.setVoiceProcessingEnabled(true) +// } // 检查目标音频格式和转换器是否可用 guard let targetFormat = audioFormat, // 外部定义的期望音频格式