import type { ClientVoiceInputConfig } from "@opengeni/contracts"; import type { OpenGeniClient } from "@opengeni/sdk"; import { OpenGeniRecordingsClient, type RecorderPlatform } from "@opengeni/sdk/recordings"; import type { VoiceRecordingStore } from "../voice-recording-store.js"; export type VoiceInputStatus = "idle" | "requesting-permission" | "recording" | "saving" | "transcribing" | "retrying" | "recovered" | "transcript-ready" | "error"; /** The recording calls dictation makes, as `OpenGeniRecordingsClient` provides them. */ export type VoiceInputRecordingsClient = Pick; export type UseVoiceInputOptions = { /** * The SDK client. Dictation records through its recordings API; a client * with only `transcribeAudio` records in memory and sends one request. */ client: VoiceInputClient | null; workspaceId: string; capability: ClientVoiceInputConfig | null; enabled: boolean; value: string; setValue: (value: string) => void; focusInput: () => void; disabled?: boolean | undefined; /** * The language spoken, as an ISO 639-1 or 639-3 code ("nb", "en"). Omitted * or null detects it. Each dictation keeps the language it was started in. */ language?: string | null | undefined; /** * Names and words to listen for, such as the person's vocabulary: at most * 100, each up to 50 characters. Each dictation keeps the ones it started with. */ keyterms?: readonly string[] | undefined; /** * The speech-to-text model to transcribe with, as the workspace's voice * input lists it (`capability.models`). Omitted or null: the workspace's * voice input model. Each dictation keeps the model it was started with. */ model?: { providerId: string; model: string; } | null | undefined; /** * Asked before each new dictation takes the microphone, such as a host's * consent prompt. Resolving false (or throwing) keeps the microphone off. */ beforeStart?: (() => boolean | Promise) | undefined; /** * Offer dictations an earlier page, tab or device left in this workspace * (default). Off for a host that dictates somewhere else, such as the * desktop app's dictation from anywhere: the composer offers them instead. */ recover?: boolean | undefined; /** * A copy of each dictation's speech once capture ends, for a host that keeps * it on the device (the desktop app's dictation history). When the person * cancels a dictation, its copy comes with `cancelled` set (again, when * capture had already ended): the dictation itself is deleted, so this copy * is all that is left of it. */ onAudio?: ((audio: VoiceInputAudio) => void) | undefined; /** A recordings client, such as a host proxy. Built from `client` otherwise. */ recordings?: Partial | undefined; /** How this device records; the browser's by default. */ platform?: RecorderPlatform | undefined; /** How often a dictation's transcript is checked. Default 1 second. */ pollIntervalMilliseconds?: number | undefined; now?: (() => Date) | undefined; /** @deprecated Dictations are kept by the shared recording store; ignored. */ createRecordingStore?: (() => VoiceRecordingStore) | undefined; /** @deprecated The recorder chooses the recording id; ignored. */ createRecordingId?: (() => string) | undefined; /** @deprecated Recordings are claimed with Web Locks; ignored. */ createOwnerId?: (() => string) | undefined; /** @deprecated The server retries transcription itself; ignored. */ automaticRetryDelayMilliseconds?: number | undefined; }; type VoiceInputClient = Pick & Partial>; /** A dictation's speech, as recorded. */ export type VoiceInputAudio = { /** The dictation's recording; null for one sent in a single request. */ recordingId: string | null; audio: Blob; durationMilliseconds: number; /** * The person cancelled the dictation and it is deleted. Speech shorter than * a few seconds is taken for an accidental start and never comes; capture * cut short by Cancel may miss its last second. */ cancelled?: boolean; }; export type UseVoiceInputResult = { status: VoiceInputStatus; error: string | null; available: boolean; /** Live mic stream while recording; null once stopped/cancelled. */ stream: MediaStream | null; recordingId: string | null; durationSeconds: number; /** Wall-clock start of the current capture (epoch ms), or null when not recording. */ recordingStartedAt: number | null; /** Capture stops and transcribes automatically after this many seconds. */ maxRecordingSeconds: number | null; /** The speech is saved (on this device or the server) and isn't lost by a reload. */ locallySaved: boolean; hasRecoverableRecording: boolean; savedTranscript: string | null; /** The microphone's level from 0 to 1 while recording, when the recorder meters it. */ level: () => number | null; start: () => Promise; /** Stop capture, then transcribe into the draft. */ stop: () => void; /** Transcribe a saved dictation again, or keep waiting for one still being heard. */ retry: () => void; /** Insert a saved transcript into the draft. */ insertSavedTranscript: () => Promise; /** * The person's Cancel: delete the dictation under way, recording * or transcribing, so nothing offers it again. Its speech goes to `onAudio` * first, marked cancelled, for a host that keeps it. A saved dictation an * earlier page left only stops being retried and stays offered. */ cancel: () => void; /** * Stop without transcribing and keep the speech here, to insert, retry or * discard later: for something other than the person ending the dictation, * such as another chat opening or live voice taking over. A start of a few * seconds is deleted. */ setAside: () => void; /** Intentionally delete the current dictation. */ discard: () => Promise; /** * Let go of the current dictation without deleting it: a recording stops * and uploads, and a held one stays saved for the next composer to offer. */ release: () => void; /** * Transcribe speech this page already has (a dictation kept on the device) * as a new dictation, uploaded the way a recorded one is; its text arrives * as a recorded dictation's does. Resolves false when it can't start: not * idle, or no recordings client. */ transcribe: (audio: Blob, options?: { durationMilliseconds?: number; }) => Promise; }; export declare const VOICE_RECORDING_TIMESLICE_MILLISECONDS = 1000; /** @deprecated Dictations no longer use owner heartbeats. */ export declare const VOICE_RECORDING_OWNER_HEARTBEAT_MILLISECONDS = 5000; /** @deprecated Dictations no longer use owner heartbeats. */ export declare const VOICE_RECORDING_OWNER_STALE_MILLISECONDS = 30000; /** The longest one-shot dictation, recorded in memory and sent in one request. */ export declare const VOICE_RECORDING_CLIENT_MAX_DURATION_SECONDS = 600; /** The longest dictation recorded through the recordings API. */ export declare const VOICE_RECORDING_RESUMABLE_CLIENT_MAX_DURATION_SECONDS: number; /** * Dictation for a composer: record the microphone, transcribe it with the * workspace's voice input, and add the text to the draft without sending. * * Each dictation is a recording (purpose `dictation`): saved on the device * every second, uploaded as it is spoken, transcribed by the server, private * to its speaker and deleted a day after it is heard. Closing the tab, losing * the connection or a failed transcription loses nothing: the next composer * that opens in this workspace offers the saved text. Taking the text deletes * the dictation first, so two tabs never insert the same speech. */ export declare function useVoiceInput(options: UseVoiceInputOptions): UseVoiceInputResult; export {};