|
|
|
@ -2,8 +2,8 @@ import Foundation |
|
|
|
import AppKit |
|
|
|
|
|
|
|
public final class SonioxLiveSession { |
|
|
|
public static let primaryWsBase = "wss://translate.compare.soniox.com/compare/api/compare-websocket" |
|
|
|
public static let fallbackWsBase = "wss://stt.compare.soniox.com/compare/api/compare-websocket" |
|
|
|
public static let primaryWsBase = "wss://stt.compare.soniox.com/compare/api/compare-websocket" |
|
|
|
public static let fallbackWsBase = "wss://translate.compare.soniox.com/compare/api/compare-websocket" |
|
|
|
private static let userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" |
|
|
|
public static func origin(for endpoint: String) -> String { |
|
|
|
return endpoint.contains("translate") ? "https://translate.compare.soniox.com" : "https://stt.compare.soniox.com" |
|
|
|
@ -240,8 +240,9 @@ public final class SonioxLiveSession { |
|
|
|
lock.unlock() |
|
|
|
|
|
|
|
print("SonioxLiveSession: Sending finalize packet...") |
|
|
|
// 1. Send trailing 300ms (9600 bytes at 16kHz 16-bit PCM) silence frame |
|
|
|
let silenceChunk = Data(count: 9600) |
|
|
|
// 1. Send trailing 600ms (19200 bytes at 16kHz 16-bit PCM) silence frame |
|
|
|
// so acoustic CTC model cleanly flushes and resolves trailing fast speech syllables |
|
|
|
let silenceChunk = Data(count: 19200) |
|
|
|
let silenceMsg = URLSessionWebSocketTask.Message.data(silenceChunk) |
|
|
|
task.send(silenceMsg) { _ in } |
|
|
|
|
|
|
|
@ -796,7 +797,7 @@ public final class SonioxLiveSession { |
|
|
|
if done || isCancelled() { return } |
|
|
|
|
|
|
|
if offset >= pcmData.count { |
|
|
|
let silence = Data(count: 6400) |
|
|
|
let silence = Data(count: 19200) |
|
|
|
task.send(.data(silence)) { _ in |
|
|
|
task.send(.string("{\"type\": \"finalize\"}")) { _ in |
|
|
|
task.send(.string("END")) { _ in } |
|
|
|
|