forked from Blendman974/faceclaw
Add cloud voice model support for iOS
This commit is contained in:
1 parent
5df873e5b1
commit
920cce6a26
24 files changed
+518
-176
No files matched your search
+14
-3
@@ -1,9 +1,20 @@
|
||||
import { toJavaBytes } from './cloud-stt'
|
||||
|
||||
declare const com: any
|
||||
export type SocketListener = { onOpen(): void; onTextMessage(message: string): void; onClosed(code: number, reason: string): void; onFailure(message: string): void }
|
||||
export function openSocket(url: string, listener: SocketListener): { sendText(text: string): void; close(code: number, reason: string): void } {
|
||||
/** One extra handshake header, e.g. an API key. */
|
||||
export type SocketHeader = { name: string; value: string }
|
||||
export type SocketConnection = {
|
||||
/** False when the frame was refused outright; later failures arrive via onFailure. */
|
||||
sendText(text: string): boolean
|
||||
sendBinary(bytes: Uint8Array): boolean
|
||||
close(code: number, reason: string): void
|
||||
}
|
||||
export function openSocket(url: string, listener: SocketListener, header?: SocketHeader): SocketConnection {
|
||||
const proxy = new com.faceclaw.app.FaceclawWebSocketListener(listener)
|
||||
const native = new com.faceclaw.app.FaceclawWebSocket(url, proxy, null, null)
|
||||
const connection = { listenerProxy: proxy, sendText: (text: string) => native.sendText(text),
|
||||
const native = new com.faceclaw.app.FaceclawWebSocket(url, proxy, header?.name ?? null, header?.value ?? null)
|
||||
const connection = { listenerProxy: proxy, sendText: (text: string) => native.sendText(text) !== false,
|
||||
sendBinary: (bytes: Uint8Array) => native.sendBinary(toJavaBytes(bytes)) !== false,
|
||||
close: (code: number, reason: string) => native.close(code, reason) }
|
||||
return connection
|
||||
}
|
||||
Reference in new issue
Block a user