From 4e82bb13f6c75204f29bdd13b7129fac55a49d19 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 17 Jan 2026 14:23:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=9F=B3=E9=A2=91=E5=A4=84=E7=90=86):?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E9=9F=B3=E9=A2=91=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=92=8C=E8=AF=AD=E9=9F=B3=E8=AF=86=E5=88=AB=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将AzureAsrHelper的performAudioStart方法改为public以便外部调用 在AgentServiceImpl中增加音频会话检查和设置逻辑 调整MusicService中音频会话设置的注释 缩短AgentServiceImpl的空闲检测时间至5秒 --- .../Sources/agent_service/AgentServiceImpl.swift | 10 +++++++++- .../Sources/azure_speech/AzureAsrHelper.swift | 2 +- .../Sources/music_service/MusicService.swift | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) 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 b5abb3e9f..4755617ff 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 @@ -100,7 +100,7 @@ class AgentServiceImpl: NSObject { private let timerQueue = DispatchQueue(label: "com.example.idleTimer.queue") private var idleTimer: DispatchSourceTimer? - private let maxIdleSeconds: TimeInterval = 10 + private let maxIdleSeconds: TimeInterval = 5 var micCapture: MicrophoneCapture! // 语音识别模式 public var currentRecognitionMode: String = "normal" @@ -311,6 +311,9 @@ class AgentServiceImpl: NSObject { LocationService.shared.getCurrentLocation() { location in // self.locationInfo = location } + + checkAdnSetAudioSession() + return isInitialized } @@ -387,6 +390,11 @@ class AgentServiceImpl: NSObject { return true } + private func checkAdnSetAudioSession() { + let audioSourceType: AzureAsrHelper.AudioSourceType = BleService.shared.isConnected() ? .external : .microphone + azureAsrHelper?.performAudioStart(audioSourceType: audioSourceType, audioDataCallback: nil) + } + private func startIdleCheckForMode(mode: String) { stopIdleCheck() guard isRecognizing else { return } 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 9658a20af..3ea1fb6a0 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 @@ -338,7 +338,7 @@ public class AzureAsrHelper: NSObject { /** * 执行音频启动操作 */ - private func performAudioStart( + public func performAudioStart( audioSourceType: AudioSourceType, audioDataCallback: SimpleAudioReceiver.AudioDataCallback? ) -> Bool { diff --git a/local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift b/local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift index c13217297..0eb558514 100644 --- a/local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift +++ b/local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift @@ -41,10 +41,10 @@ public class MusicService: NSObject { private override init() { super.init() setupRemoteCommandCenter() - setupAudioSession() + // setupAudioSession() setupNotificationObservers() // 监听通话状态(需主线程队列) -// callObserver.setDelegate(self, queue: DispatchQueue.main) + //callObserver.setDelegate(self, queue: DispatchQueue.main) } public func initialize(serviceUrl: String, userToken: String) {