import type { Blocker, Refusal, Side, Speech, State } from "./types.js"; export interface VoiceOptions { /** The running transcript, as it is heard. Show it in the composer. */ onPartial?: (text: string) => void; /** * One finished utterance. Send it through the composer's EXISTING submit * path — voice is a way of typing, not a second way of sending. */ onUtterance: (text: string) => void; /** The platform's speech services. Without them the browser stands in. */ speech?: Speech; /** Which side to try first. The platform's, unless the caller says otherwise. */ prefer?: Side; /** The platform refused, and the browser is standing in or cannot. Fires once * per conversation per service; also readable as `refusal` on the machine. */ onRefusal?: (refusal: Refusal) => void; /** BCP-47. Defaults to the browser's own language. */ language?: string; /** Silence, in ms, that ends an utterance. */ pause?: number; /** The reading voice, by `speechSynthesis` voice name. Browser leg only — * the platform's voice is the transport's, or the one `say` names. */ voice?: string; /** The live input level, 0..1, while the mic is open — for a meter or a * waveform. Fires many times a second; keep the handler cheap. */ onLevel?: (value: number) => void; } export interface Voice { state: State; /** True from the first click to the second. A conversation, not a keypress. */ open: boolean; /** The latest input level, 0..1, while the mic is open. Mutated in place — * sample it (rAF), never render from it. */ level: number; /** Why voice cannot run here, or `null`. */ blocked: Blocker | null; /** One sentence a person can act on, or `null`. */ reason: string | null; /** The platform's refusal in this conversation, or `null`. Render it: a * service that refused and a service that worked sound the same. */ refusal: Refusal | null; /** Start the conversation, or end it. */ toggle: () => void; /** Read a reply aloud, in `voice` — the speech service's voice id — where * given. A no-op unless the conversation is live. Resolves `true` when the * sentence played to its end, `false` when it was spoken over, hushed, * replaced or never read — so a reply read in parts stops where it was * interrupted instead of carrying on over the speaker. */ say: (text: string, voice?: string) => Promise; /** Stop mid-word. */ hush: () => void; } /** * A spoken conversation with the composer it is attached to. * * One click opens the microphone and it stays open: the transcript streams into * the composer as it is heard, each pause sends a turn through the composer's * own submit path, and the reply is read back. Speaking over the reply stops it * and starts the next turn. A second click — on ANY mic on the page — ends it. * * The conversation outlives the composer drawing it: sending the first turn is * exactly what makes a chat surface swap `/c/new` for `/c/`, which remounts * the composer, and a remount is not hanging up. In memory only — a fresh page * load starts closed, because nobody has asked for the microphone yet. * * The caller keeps the machine (it needs `say`); `` only draws it. */ export declare function useVoice(options: VoiceOptions): Voice; //# sourceMappingURL=voice.d.ts.map