|
|
|
@ -596,8 +596,10 @@ public class AzureTtsHelper: NSObject, ITtsService, AVAudioPlayerDelegate { |
|
|
|
|
|
|
|
synthesizer?.addSynthesisCompletedEventHandler { [weak self] _, _ in |
|
|
|
guard let self = self else { return } |
|
|
|
self.speaking = false |
|
|
|
if self.suppressStreamPlayback { return } |
|
|
|
if !self.isUsingPushStreamCapture { |
|
|
|
self.speaking = false |
|
|
|
} |
|
|
|
// 将当前合成的音频加入播放队列 |
|
|
|
if !self.currentSynthesisBuffer.isEmpty { |
|
|
|
os_log("调用链: 合成完成 入队播放 数据长度=%{public}dB session=%{public}@", log: self.log, type: .info, self.currentSynthesisBuffer.count, self.sessionid) |
|
|
|
@ -621,11 +623,13 @@ public class AzureTtsHelper: NSObject, ITtsService, AVAudioPlayerDelegate { |
|
|
|
|
|
|
|
synthesizer?.addSynthesisCanceledEventHandler { [weak self] _, event in |
|
|
|
guard let self = self else { return } |
|
|
|
self.speaking = false |
|
|
|
|
|
|
|
// 减少待处理文本计数 |
|
|
|
self.pendingTextCount = max(0, self.pendingTextCount - 1) |
|
|
|
if self.suppressStreamPlayback { return } |
|
|
|
if !self.isUsingPushStreamCapture { |
|
|
|
self.speaking = false |
|
|
|
} |
|
|
|
|
|
|
|
if self.isUsingPushStreamCapture { |
|
|
|
self.audioPlaybackQueue.async { |
|
|
|
@ -664,11 +668,11 @@ public class AzureTtsHelper: NSObject, ITtsService, AVAudioPlayerDelegate { |
|
|
|
*/ |
|
|
|
private func handleSynthesizedAudioChunk(_ data: Data) { |
|
|
|
if suppressStreamPlayback { return } |
|
|
|
if !speaking { return } |
|
|
|
if sessionid.isEmpty { return } |
|
|
|
notifyAudioData(data) |
|
|
|
guard isUsingPushStreamCapture else { return } |
|
|
|
audioPlaybackQueue.async { |
|
|
|
if !self.speaking { return } |
|
|
|
if self.sessionid.isEmpty { return } |
|
|
|
let pcm = self.stripWavHeaderIfNeeded(data) |
|
|
|
if !pcm.isEmpty { |
|
|
|
self.pcmPendingData.append(pcm) |
|
|
|
@ -767,6 +771,7 @@ public class AzureTtsHelper: NSObject, ITtsService, AVAudioPlayerDelegate { |
|
|
|
*/ |
|
|
|
private func checkStreamPlaybackCompletedIfNeeded() { |
|
|
|
if activeStreamSynthesisCount == 0, pcmPendingData.isEmpty, scheduledBufferCount == 0 { |
|
|
|
speaking = false |
|
|
|
hasNotifiedPlaybackStartedForStream = false |
|
|
|
os_log("调用链: 流式播放完成 session=%{public}@", log: log, type: .info, sessionid) |
|
|
|
notifyEvent(eventType: .playbackCompleted) |
|
|
|
|