Skip to content

Commit b7fbfcc

Browse files
ZhaoChaoqunclaude
andcommitted
Fix trailing audio loss in Streaming Paraformer
- Move inputFinished() inside recognitionQueue to ensure all audio is submitted before signaling end of input - Add extra decode() call after the while loop to process any remaining frames that become decodable after inputFinished() Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 807295f commit b7fbfcc

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Sources/RecordingManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ class RecordingManager {
398398

399399
/// 停止 Streaming Paraformer 录音
400400
private func stopRecordingStreaming(completion: @escaping (String?) -> Void) {
401-
// 通知输入结束
402-
onlineRecognizer?.inputFinished()
403-
404401
// 处理剩余的解码
405402
recognitionQueue.async { [weak self] in
406403
guard let self = self,
@@ -409,11 +406,17 @@ class RecordingManager {
409406
return
410407
}
411408

409+
// 通知输入结束(必须在 recognitionQueue 中调用,确保之前的音频都已送入)
410+
recognizer.inputFinished()
411+
412412
// 继续解码直到完成
413413
while recognizer.isReady() {
414414
recognizer.decode()
415415
}
416416

417+
// 再次尝试解码(inputFinished 后可能产生新的可解码帧)
418+
recognizer.decode()
419+
417420
// 获取最终结果
418421
let text = recognizer.getResult()
419422

0 commit comments

Comments
 (0)