Browse Source

refactor(音频处理): 修改音频会话和语音识别相关逻辑

将AzureAsrHelper的performAudioStart方法改为public以便外部调用
在AgentServiceImpl中增加音频会话检查和设置逻辑
调整MusicService中音频会话设置的注释
缩短AgentServiceImpl的空闲检测时间至5秒
weicu
liwei1dao 9 months ago
parent
commit
4e82bb13f6
  1. 10
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift
  2. 2
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift
  3. 4
      local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift

10
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 let timerQueue = DispatchQueue(label: "com.example.idleTimer.queue")
private var idleTimer: DispatchSourceTimer? private var idleTimer: DispatchSourceTimer?
private let maxIdleSeconds: TimeInterval = 10 private let maxIdleSeconds: TimeInterval = 5
var micCapture: MicrophoneCapture! var micCapture: MicrophoneCapture!
// 语音识别模式 // 语音识别模式
public var currentRecognitionMode: String = "normal" public var currentRecognitionMode: String = "normal"
@ -311,6 +311,9 @@ class AgentServiceImpl: NSObject {
LocationService.shared.getCurrentLocation() { location in LocationService.shared.getCurrentLocation() { location in
// self.locationInfo = location // self.locationInfo = location
} }
checkAdnSetAudioSession()
return isInitialized return isInitialized
} }
@ -387,6 +390,11 @@ class AgentServiceImpl: NSObject {
return true 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) { private func startIdleCheckForMode(mode: String) {
stopIdleCheck() stopIdleCheck()
guard isRecognizing else { return } guard isRecognizing else { return }

2
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, audioSourceType: AudioSourceType,
audioDataCallback: SimpleAudioReceiver.AudioDataCallback? audioDataCallback: SimpleAudioReceiver.AudioDataCallback?
) -> Bool { ) -> Bool {

4
local_plugins/music_service/ios/music_service/Sources/music_service/MusicService.swift

@ -41,10 +41,10 @@ public class MusicService: NSObject {
private override init() { private override init() {
super.init() super.init()
setupRemoteCommandCenter() setupRemoteCommandCenter()
setupAudioSession() // setupAudioSession()
setupNotificationObservers() setupNotificationObservers()
// 监听通话状态(需主线程队列) // 监听通话状态(需主线程队列)
// callObserver.setDelegate(self, queue: DispatchQueue.main) //callObserver.setDelegate(self, queue: DispatchQueue.main)
} }
public func initialize(serviceUrl: String, userToken: String) { public func initialize(serviceUrl: String, userToken: String) {

Loading…
Cancel
Save