Files
archived-orca/mobile/src/platform/dictation-capture-contract.ts
Kelvin Amoaba 64d811bde0 feat(mobile): send phone dictation audio every 150 ms with at most four chunks in flight (#39341)
Each chunk RPC holds one of the page bridge's 60 desktop request slots until
the host answers, through a reconnect too, so the page drained the microphone
only every 500 ms. Cap chunk sends at four per dictation and merge audio
captured meanwhile into the next request, then drain every 150 ms.
2026-11-07 07:25:10 +00:00

33 lines
1.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Share raw PCM chunks so both hosts reserve budgets before wire encoding.
export type DictationCaptureChunk = {
readonly data: Uint8Array
// Zero for direct native events; page ring overflow reports lost bytes so it reaches the same connection-slow state as budget refusal.
readonly droppedBytes: number
}
// Permission/unavailable are device outcomes; bridge refusal rejects with its reason.
export type DictationCaptureOpen =
| { readonly ok: true }
| { readonly ok: false; readonly reason: 'permission-denied' | 'unavailable' }
export type DictationCaptureSubscription = { readonly remove: () => void }
export type DictationCapture = {
readonly open: () => Promise<DictationCaptureOpen>
readonly begin: () => boolean
// End only after delivering the stop reply’s final ring audio; native events already delivered theirs. Never reject from exit cleanup.
readonly end: () => Promise<void>
readonly release: () => void
readonly onChunk: (
handler: (chunk: DictationCaptureChunk) => void
) => DictationCaptureSubscription
// Notify loss without a reason argument because callers treat every source alike: native began/blocked, page equivalents, or refused reads.
readonly onInterruption: (handler: () => void) => DictationCaptureSubscription
}
// 1024-byte 16 kHz/16-bit events arrive every 32 ms; forwarding each would consume almost all 64 request slots on a two-second link.
export const DICTATION_NATIVE_EVENT_INTERVAL_MS = 32
// Short batches bring the host's live text sooner; the chunk send window, not this interval, bounds the bridge slots a slow link holds.
export const DICTATION_CAPTURE_DRAIN_INTERVAL_MS = 150