|
|
@ -174,8 +174,9 @@ public final class SonioxLiveSession { |
|
|
lock.unlock() |
|
|
lock.unlock() |
|
|
|
|
|
|
|
|
print("SonioxLiveSession: Sending finalize packet...") |
|
|
print("SonioxLiveSession: Sending finalize packet...") |
|
|
// 1. Send trailing 120ms silence frame so acoustic model cleanly resolves trailing syllables |
|
|
|
|
|
let silenceChunk = Data(count: 3840) |
|
|
|
|
|
|
|
|
// 1. Send trailing 300ms (9600 bytes at 16kHz 16-bit PCM) silence frame |
|
|
|
|
|
// so acoustic CTC model cleanly flushes and resolves trailing fast speech syllables |
|
|
|
|
|
let silenceChunk = Data(count: 9600) |
|
|
let silenceMsg = URLSessionWebSocketTask.Message.data(silenceChunk) |
|
|
let silenceMsg = URLSessionWebSocketTask.Message.data(silenceChunk) |
|
|
task.send(silenceMsg) { _ in } |
|
|
task.send(silenceMsg) { _ in } |
|
|
|
|
|
|
|
|
@ -191,14 +192,14 @@ public final class SonioxLiveSession { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Fast safety timeout fallback: finalize must complete within 1.0s |
|
|
|
|
|
DispatchQueue.global().asyncAfter(deadline: .now() + 1.0) { [weak self] in |
|
|
|
|
|
|
|
|
// Safety timeout fallback: allow up to 4.5s for STT inference & network transit |
|
|
|
|
|
DispatchQueue.global().asyncAfter(deadline: .now() + 4.5) { [weak self] in |
|
|
guard let self = self else { return } |
|
|
guard let self = self else { return } |
|
|
self.lock.lock() |
|
|
self.lock.lock() |
|
|
let stillOpen = !self.isClosed |
|
|
let stillOpen = !self.isClosed |
|
|
self.lock.unlock() |
|
|
self.lock.unlock() |
|
|
if stillOpen { |
|
|
if stillOpen { |
|
|
print("SonioxLiveSession: Finalize timeout (1.0s) reached — completing.") |
|
|
|
|
|
|
|
|
print("SonioxLiveSession: Finalize timeout (4.5s) reached — completing.") |
|
|
self.completeWithCurrentText() |
|
|
self.completeWithCurrentText() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|