|
|
|
@ -1701,7 +1701,7 @@ class ChatApiStreamCallback: StreamCallback { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if (responseBuilder.isEmpty) { //关闭声音 |
|
|
|
if (token != "" && responseBuilder.isEmpty) { //关闭声音 |
|
|
|
try agentService.audioPlayer?.stopAwaitSound() |
|
|
|
} |
|
|
|
|
|
|
|
@ -1975,6 +1975,7 @@ class AudioPlayer { |
|
|
|
private var callingPlayer: AVAudioPlayer? |
|
|
|
private var awaitPlayer: AVAudioPlayer? // 新增:等待音效播放器 |
|
|
|
private var awaitTimer: DispatchSourceTimer? // 新增:等待音效超时定时器 |
|
|
|
private var isAwaitSoundActive: Bool = false // 等待音效播放状态开关 |
|
|
|
private let logger = OSLog(subsystem: "com.yunqiinnovation.agent_service", category: "AudioPlayer") |
|
|
|
private let audioQueue = DispatchQueue(label: "agent.audio.player", qos: .userInitiated) |
|
|
|
|
|
|
|
@ -2012,8 +2013,8 @@ class AudioPlayer { |
|
|
|
} |
|
|
|
|
|
|
|
func playAwaitSound() { |
|
|
|
//先停止之前的等待音效和定时器 |
|
|
|
stopAwaitSound() |
|
|
|
// 若已处于等待音效播放状态,则直接返回,避免频繁启停 |
|
|
|
if isAwaitSoundActive { return } |
|
|
|
|
|
|
|
// 修复:通过 agentService 引用访问 currentRecognitionMode |
|
|
|
if agentService?.currentRecognitionMode == "phone_call" {//电话模式不要嘟嘟嘟。影响回音消除功能 |
|
|
|
@ -2022,6 +2023,7 @@ class AudioPlayer { |
|
|
|
|
|
|
|
// 播放等待音效 |
|
|
|
playLoopSound(named: "await", fileType: "mp3", player: &awaitPlayer,volume:0.2) |
|
|
|
isAwaitSoundActive = true |
|
|
|
|
|
|
|
// 启动超时定时器 |
|
|
|
startAwaitTimeout() |
|
|
|
@ -2041,10 +2043,20 @@ class AudioPlayer { |
|
|
|
} |
|
|
|
|
|
|
|
func stopAwaitSound() { |
|
|
|
if !self.isAwaitSoundActive { return } |
|
|
|
self.isAwaitSoundActive = false |
|
|
|
// 确保在主线程执行音频停止操作 |
|
|
|
DispatchQueue.main.async { [weak self] in |
|
|
|
guard let self = self else { return } |
|
|
|
|
|
|
|
// 若未处于等待音效播放状态,直接返回,避免高频空调用 |
|
|
|
let wasPlaying = self.awaitPlayer?.isPlaying ?? false |
|
|
|
let hadTimer = self.awaitTimer != nil |
|
|
|
// 幂等短路:若既未播放也无定时器,直接返回,避免高频空调用带来的开销 |
|
|
|
if !wasPlaying && !hadTimer { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 停止音频播放 |
|
|
|
if let player = self.awaitPlayer { |
|
|
|
if player.isPlaying { |
|
|
|
@ -2054,8 +2066,9 @@ class AudioPlayer { |
|
|
|
} |
|
|
|
|
|
|
|
// 停止超时定时器 |
|
|
|
if hadTimer { |
|
|
|
self.stopAwaitTimeout() |
|
|
|
|
|
|
|
} |
|
|
|
os_log("停止等待音效播放", log: self.logger, type: .debug) |
|
|
|
} |
|
|
|
} |
|
|
|
|