@voiceinput/core 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,179 @@
1
+ import { VoiceInputError, VoiceInputError as VoiceInputError$1, VoiceInputErrorCode, VoiceInputErrorOptions, VoiceInputProviderV1, VoiceTranscriptionOptions } from "@voiceinput/provider";
2
+ //#region src/text-engine/types.d.ts
3
+ type VoiceInputTextTarget = HTMLInputElement | HTMLTextAreaElement;
4
+ type VoiceInputInterimBehavior = "inline" | "expose";
5
+ type VoiceInputTextSpanState = "provisional" | "finalized" | "frozen" | "transformed";
6
+ interface VoiceInputTextSelection {
7
+ readonly start: number;
8
+ readonly end: number;
9
+ readonly direction: "forward" | "backward" | "none";
10
+ }
11
+ interface VoiceInputTextSpan {
12
+ readonly id: number;
13
+ readonly start: number;
14
+ readonly end: number;
15
+ readonly text: string;
16
+ readonly state: VoiceInputTextSpanState;
17
+ }
18
+ interface VoiceInputTextEngineSnapshot {
19
+ readonly value: string;
20
+ readonly selection: VoiceInputTextSelection | null;
21
+ readonly interimTranscript: string;
22
+ readonly spans: readonly VoiceInputTextSpan[];
23
+ }
24
+ /**
25
+ * Connects the engine's immediate shadow value to controlled application state.
26
+ *
27
+ * `getValue` supplies the value when a target is attached. `onValueChange`
28
+ * requests an application update but is not expected to commit synchronously.
29
+ * Pass each value committed by the application to
30
+ * `reconcileControlledValue` on the text engine.
31
+ */
32
+ interface VoiceInputControlledTextBinding {
33
+ getValue(): string;
34
+ onValueChange(value: string): void;
35
+ /** Notify through a native input event instead of the binding callback. */
36
+ dispatchInput?: boolean;
37
+ }
38
+ type VoiceInputTransformTranscript = (text: string) => PromiseLike<string> | string;
39
+ interface VoiceInputTextLimit {
40
+ readonly type: "text-limit";
41
+ readonly maxLength: number;
42
+ readonly text: string;
43
+ readonly insertedText: string;
44
+ readonly source: "interim" | "final" | "transform";
45
+ }
46
+ type VoiceInputTextEngineEvent = VoiceInputTextLimit | {
47
+ type: "target-unavailable" | "reset";
48
+ };
49
+ interface CreateVoiceInputTextEngineOptions {
50
+ interimBehavior?: VoiceInputInterimBehavior;
51
+ controlled?: VoiceInputControlledTextBinding;
52
+ transformTranscript?: VoiceInputTransformTranscript;
53
+ transformTimeoutMs?: number;
54
+ }
55
+ interface VoiceInputTextCompletion {
56
+ readonly processing: boolean;
57
+ readonly result: Promise<readonly VoiceInputError$1[]>;
58
+ }
59
+ interface VoiceInputTextEngine {
60
+ getSnapshot(): VoiceInputTextEngineSnapshot;
61
+ setTarget(target: VoiceInputTextTarget | null): void;
62
+ captureSelection(): VoiceInputTextSelection | null;
63
+ reconcileControlledValue(value: string): void;
64
+ updateOptions(options: Omit<CreateVoiceInputTextEngineOptions, "controlled">): void;
65
+ begin(): void;
66
+ applyInterim(text: string, segmentId?: string): void;
67
+ applyFinal(text: string, segmentId?: string): void;
68
+ complete(): VoiceInputTextCompletion;
69
+ cancel(): void;
70
+ undo(): void;
71
+ redo(): void;
72
+ isWritable(): boolean;
73
+ subscribe(listener: (event: VoiceInputTextEngineEvent) => void): () => void;
74
+ destroy(): void;
75
+ }
76
+ //#endregion
77
+ //#region src/text-engine.d.ts
78
+ declare function createVoiceInputTextEngine(options?: CreateVoiceInputTextEngineOptions): VoiceInputTextEngine;
79
+ //#endregion
80
+ //#region src/session.d.ts
81
+ type VoiceInputStatus = "idle" | "requesting-permission" | "connecting" | "listening" | "stopping" | "processing" | "error";
82
+ type VoiceInputStopReason = "user" | "max-duration" | "replaced" | "max-length" | "target-unavailable" | "backgrounded";
83
+ interface VoiceInputSnapshot {
84
+ readonly status: VoiceInputStatus;
85
+ readonly transcript: string;
86
+ readonly interimTranscript: string;
87
+ readonly finalTranscript: string;
88
+ readonly error: VoiceInputError | null;
89
+ }
90
+ type VoiceInputSessionEvent = VoiceInputTextLimit | {
91
+ type: "status-change";
92
+ previousStatus: VoiceInputStatus;
93
+ status: VoiceInputStatus;
94
+ } | {
95
+ type: "interim";
96
+ text: string;
97
+ segmentId: string;
98
+ transcript: string;
99
+ transcriptChanged: boolean;
100
+ } | {
101
+ type: "final";
102
+ text: string;
103
+ segmentId: string;
104
+ transcript: string;
105
+ transcriptChanged: boolean;
106
+ finalTranscriptChanged: boolean;
107
+ } | {
108
+ type: "duration-warning";
109
+ remainingMs: number;
110
+ maxDurationMs: number;
111
+ } | {
112
+ type: "stop";
113
+ reason: VoiceInputStopReason;
114
+ } | {
115
+ type: "cancel";
116
+ } | {
117
+ type: "speech-start";
118
+ } | {
119
+ type: "speech-end";
120
+ } | {
121
+ type: "error";
122
+ error: VoiceInputError;
123
+ };
124
+ interface VoiceAudioSourcePrepareOptions {
125
+ sampleRate: number;
126
+ abortSignal: AbortSignal;
127
+ onAcquired?(): void;
128
+ }
129
+ interface PreparedVoiceAudioSource {
130
+ readonly stream: ReadableStream<Int16Array>;
131
+ start(): PromiseLike<void> | void;
132
+ stop(): PromiseLike<void> | void;
133
+ abort(reason?: unknown): void;
134
+ }
135
+ interface VoiceAudioSource {
136
+ prepare(options: VoiceAudioSourcePrepareOptions): PromiseLike<PreparedVoiceAudioSource>;
137
+ }
138
+ interface CreateVoiceInputSessionOptions extends VoiceTranscriptionOptions {
139
+ provider: VoiceInputProviderV1;
140
+ audioSource: VoiceAudioSource;
141
+ textEngine?: VoiceInputTextEngine;
142
+ maxDurationMs?: number;
143
+ connectionTimeoutMs?: number;
144
+ }
145
+ interface VoiceInputSession {
146
+ getSnapshot(): VoiceInputSnapshot;
147
+ subscribe(listener: (event: VoiceInputSessionEvent) => void): () => void;
148
+ /** Applies to the next recording; a running session keeps its configuration. */
149
+ updateOptions(options: Omit<CreateVoiceInputSessionOptions, "textEngine">): void;
150
+ start(): Promise<void>;
151
+ stop(reason?: VoiceInputStopReason): Promise<void>;
152
+ cancel(): Promise<void>;
153
+ toggle(): Promise<void>;
154
+ }
155
+ declare function createVoiceInputSession(options: CreateVoiceInputSessionOptions): VoiceInputSession;
156
+ //#endregion
157
+ //#region src/browser-audio.d.ts
158
+ type BrowserVoiceInputCapability = "secure-context" | "media-devices" | "get-user-media" | "audio-context" | "audio-worklet";
159
+ interface BrowserVoiceInputSupport {
160
+ readonly isSupported: boolean;
161
+ readonly missingCapabilities: readonly BrowserVoiceInputCapability[];
162
+ }
163
+ interface CreateBrowserAudioSourceOptions {
164
+ /** Additional microphone constraints. VoiceInput always requests mono audio. */
165
+ constraints?: MediaTrackConstraints;
166
+ /** Duration of each emitted PCM16 frame. Defaults to 20 milliseconds. */
167
+ frameDurationMs?: number;
168
+ /** Self-hosted AudioWorklet module URL. The Blob-backed module is used by default. */
169
+ workletModuleUrl?: string | URL;
170
+ }
171
+ declare function getBrowserVoiceInputSupport(): BrowserVoiceInputSupport;
172
+ declare function createBrowserAudioSource(options?: CreateBrowserAudioSourceOptions): VoiceAudioSource;
173
+ declare function normalizeBrowserAudioError(error: unknown): VoiceInputError$1;
174
+ //#endregion
175
+ //#region src/audio-worklet-source.d.ts
176
+ declare const AUDIO_WORKLET_SOURCE: string;
177
+ //#endregion
178
+ export { type BrowserVoiceInputCapability, type BrowserVoiceInputSupport, type CreateBrowserAudioSourceOptions, type CreateVoiceInputSessionOptions, type CreateVoiceInputTextEngineOptions, type PreparedVoiceAudioSource, AUDIO_WORKLET_SOURCE as VOICE_INPUT_AUDIO_WORKLET_SOURCE, type VoiceAudioSource, type VoiceAudioSourcePrepareOptions, type VoiceInputControlledTextBinding, VoiceInputError, type VoiceInputErrorCode, type VoiceInputErrorOptions, type VoiceInputInterimBehavior, type VoiceInputSession, type VoiceInputSessionEvent, type VoiceInputSnapshot, type VoiceInputStatus, type VoiceInputStopReason, type VoiceInputTextCompletion, type VoiceInputTextEngine, type VoiceInputTextEngineEvent, type VoiceInputTextEngineSnapshot, type VoiceInputTextLimit, type VoiceInputTextSelection, type VoiceInputTextSpan, type VoiceInputTextSpanState, type VoiceInputTextTarget, type VoiceInputTransformTranscript, createBrowserAudioSource, createVoiceInputSession, createVoiceInputTextEngine, getBrowserVoiceInputSupport, normalizeBrowserAudioError };
179
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/text-engine/types.ts","../src/text-engine.ts","../src/session.ts","../src/browser-audio.ts","../src/audio-worklet-source.ts"],"mappings":";;KAEY,uBAAuB,mBAAmB;KAC1C;KACA;UAGK;WACN;WACA;WACA;;UAGM;WACN;WACA;WACA;WACA;WACA,OAAO;;UAGD;WACN;WACA,WAAW;WACX;WACA,gBAAgB;;;;;;;;;;UAWV;EACf;EACA,cAAc;;EAEd;;KAGU,iCACV,iBACG;UAEY;WACN;WACA;WACA;WACA;WACA;;KAGC,4BACV;EAAwB;;UAET;EACf,kBAAkB;EAClB,aAAa;EACb,sBAAsB;EACtB;;UAGe;WACN;WACA,QAAQ,iBAAiB;;UAGnB;EACf,eAAe;EACf,UAAU,QAAQ;EAClB,oBAAoB;EACpB,yBAAyB;EACzB,cACE,SAAS,KAAK;EAEhB;EACA,aAAa,cAAc;EAC3B,WAAW,cAAc;EACzB,YAAY;EACZ;EACA;EACA;EACA;EACA,UAAU,WAAW,OAAO;EAC5B;;;;iBC7Dc,2BACd,UAAS,oCACR;;;KCDS;KASA;UAQK;WACN,QAAQ;WACR;WACA;WACA;WACA,OAAO;;KAGN,yBACR;EAEE;EACA,gBAAgB;EAChB,QAAQ;;EAGR;EACA;EACA;EACA;EACA;;EAGA;EACA;EACA;EACA;EACA;EACA;;EAGA;EACA;EACA;;EAEA;EAAc,QAAQ;;EACtB;;EACA;;EACA;;EACA;EAAe,OAAO;;UAEX;EACf;EACA,aAAa;EACb;;UAGe;WACN,QAAQ,eAAe;EAChC,SAAS;EACT,QAAQ;EACR,MAAM;;UAGS;EACf,QACE,SAAS,iCACR,YAAY;;UAGA,uCAAuC;EACtD,UAAU;EACV,aAAa;EACb,aAAa;EACb;EACA;;UAGe;EACf,eAAe;EACf,UAAU,WAAW,OAAO;;EAE5B,cACE,SAAS,KAAK;EAEhB,SAAS;EACT,KAAK,SAAS,uBAAuB;EACrC,UAAU;EACV,UAAU;;iBA0BI,wBACd,SAAS,iCACR;;;KCvIS;UAOK;WACN;WACA,8BAA8B;;UAGxB;;EAEf,cAAc;;EAEd;;EAEA,4BAA4B;;iBAGd,+BAA+B;iBAyC/B,yBACd,UAAS,kCACR;iBAqSa,2BAA2B,iBAAiB;;;cCpL/C"}