@voiceinput/provider 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.
- package/LICENSE +21 -0
- package/README.md +187 -0
- package/dist/index.cjs +30 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +62 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/test.cjs +477 -0
- package/dist/test.cjs.map +1 -0
- package/dist/test.d.cts +72 -0
- package/dist/test.d.cts.map +1 -0
- package/dist/test.d.ts +72 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +474 -0
- package/dist/test.js.map +1 -0
- package/dist/transport.cjs +46 -0
- package/dist/transport.cjs.map +1 -0
- package/dist/transport.d.cts +9 -0
- package/dist/transport.d.cts.map +1 -0
- package/dist/transport.d.ts +9 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +45 -0
- package/dist/transport.js.map +1 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hirad Arshadiyarahmadi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# `@voiceinput/provider`
|
|
2
|
+
|
|
3
|
+
Versioned contracts and test utilities for VoiceInput adapters. Application
|
|
4
|
+
authors normally receive this package through `@voiceinput/react`; adapter
|
|
5
|
+
authors use it directly.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @voiceinput/provider@next
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Provider contract
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type { VoiceInputProviderV1 } from "@voiceinput/provider";
|
|
17
|
+
|
|
18
|
+
const provider: VoiceInputProviderV1 = {
|
|
19
|
+
specificationVersion: "v1",
|
|
20
|
+
provider: "acme",
|
|
21
|
+
modelId: "acme-realtime-1",
|
|
22
|
+
sampleRate: 16_000,
|
|
23
|
+
|
|
24
|
+
validateOptions(options) {
|
|
25
|
+
// Synchronously reject unsupported shared options before recording.
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
async doOpen(options) {
|
|
29
|
+
// Return a session that accepts mono PCM16 and emits normalized parts.
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`validateOptions` must be synchronous. `doOpen` receives the same transcription
|
|
35
|
+
options plus an `AbortSignal`. A session owns:
|
|
36
|
+
|
|
37
|
+
- `stream`: terminal `ReadableStream<VoiceInputProviderV1StreamPart>`
|
|
38
|
+
- `sendAudio(Int16Array)`: mono PCM16 at the declared sample rate
|
|
39
|
+
- `finish()`: graceful and idempotent
|
|
40
|
+
- `abort(reason?)`: immediate and idempotent
|
|
41
|
+
|
|
42
|
+
Normal stream completion is terminal. Provider failures should be emitted as a
|
|
43
|
+
normalized error part before closure.
|
|
44
|
+
|
|
45
|
+
## Portable transcription options
|
|
46
|
+
|
|
47
|
+
| Option | Meaning |
|
|
48
|
+
| ---------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
49
|
+
| `language?: string` | BCP 47 language hint; omission asks for provider auto-detection |
|
|
50
|
+
| `vocabulary?: readonly string[]` | Domain terms; adapters document their real provider mapping |
|
|
51
|
+
| `endpointing?: false \| { silenceMs: number }` | Provider default when omitted, manual/disabled when `false`, or a silence threshold |
|
|
52
|
+
|
|
53
|
+
An adapter must reject an unsupported option with `VoiceInputError`; it must not
|
|
54
|
+
silently ignore or approximate it.
|
|
55
|
+
|
|
56
|
+
## Normalized stream parts
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
type VoiceInputProviderV1StreamPart =
|
|
60
|
+
| { type: "interim"; text: string }
|
|
61
|
+
| { type: "final"; text: string }
|
|
62
|
+
| { type: "speech-start" }
|
|
63
|
+
| { type: "speech-end" }
|
|
64
|
+
| { type: "error"; error: VoiceInputError };
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Errors
|
|
68
|
+
|
|
69
|
+
`VoiceInputError` is safe to recognize across realms with
|
|
70
|
+
`VoiceInputError.isInstance(value)`. It preserves the original `cause` and
|
|
71
|
+
exposes:
|
|
72
|
+
|
|
73
|
+
- `code`: stable `VoiceInputErrorCode`
|
|
74
|
+
- `provider?: string`
|
|
75
|
+
- `retryable: boolean`
|
|
76
|
+
- `retryAfterMs?: number`
|
|
77
|
+
|
|
78
|
+
Error codes are `unsupported-browser`, `permission-denied`, `device-not-found`,
|
|
79
|
+
`device-busy`, `unauthorized`, `rate-limited`, `token-error`, `network-error`,
|
|
80
|
+
`provider-error`, `unsupported-feature`, `invalid-configuration`, `audio-error`,
|
|
81
|
+
and `transform-error`.
|
|
82
|
+
|
|
83
|
+
Branch on `code`, never on the message. `invalid-configuration` means the value
|
|
84
|
+
is malformed; `unsupported-feature` means the value is valid but the selected
|
|
85
|
+
provider or model cannot implement it faithfully. Adapters and core preserve an
|
|
86
|
+
existing `VoiceInputError`, including `provider`, `retryable`, `retryAfterMs`,
|
|
87
|
+
and safe causes, instead of recategorizing it.
|
|
88
|
+
|
|
89
|
+
## Test export
|
|
90
|
+
|
|
91
|
+
Import deterministic utilities from the separate test entry point:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import {
|
|
95
|
+
createFakeVoiceInputProvider,
|
|
96
|
+
createVoiceInputProviderV1ConformanceCases,
|
|
97
|
+
} from "@voiceinput/provider/test";
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The fake provider returns `{ provider, controller }`. The controller can wait
|
|
101
|
+
for sessions, resolve or reject opening, emit normalized parts, close, fail, or
|
|
102
|
+
time out a stream, and inspect immutable session snapshots.
|
|
103
|
+
|
|
104
|
+
The conformance runner is framework-independent:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { createVoiceInputSession } from "@voiceinput/core";
|
|
108
|
+
|
|
109
|
+
const cases = createVoiceInputProviderV1ConformanceCases({
|
|
110
|
+
createHarness: createMyDeterministicAdapterHarness,
|
|
111
|
+
createAccumulatorSession: (provider, audioSource) =>
|
|
112
|
+
createVoiceInputSession({ provider, audioSource }),
|
|
113
|
+
errorTaxonomy: {
|
|
114
|
+
createUnsupportedBrowserProvider: createMissingRuntimeAdapter,
|
|
115
|
+
invalidOptions: { language: "not a tag" },
|
|
116
|
+
malformedUnsupportedOptions: malformedUnavailableOptions,
|
|
117
|
+
unsupportedOptions: { vocabulary: ["valid-but-unavailable"] },
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
for (const testCase of cases) {
|
|
122
|
+
await testCase.run();
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The cases require ordered normalized output, multiple final chunks through the
|
|
127
|
+
shared core accumulator, delayed final drain after `finish()`, no
|
|
128
|
+
interim-to-final promotion, terminal timeout mapping, no output after completion
|
|
129
|
+
or abort, idempotent finish/abort cleanup, opening abort, PCM16 delivery, and
|
|
130
|
+
the shared error taxonomy. A harness's `timeout()` method must induce its
|
|
131
|
+
adapter's real timeout or equivalent terminal transport condition; the resulting
|
|
132
|
+
stream error must be a retryable `network-error`.
|
|
133
|
+
|
|
134
|
+
Your harness supplies the adapter under test and a controller for its fake
|
|
135
|
+
transport. See the
|
|
136
|
+
[custom-provider guide](https://github.com/VoiceInput/voiceinput/blob/main/docs/custom-provider.md).
|
|
137
|
+
|
|
138
|
+
## Public API
|
|
139
|
+
|
|
140
|
+
Main entry point:
|
|
141
|
+
|
|
142
|
+
- `VoiceInputError`
|
|
143
|
+
- `VoiceInputErrorCode`, `VoiceInputErrorOptions`
|
|
144
|
+
- `VoiceEndpointingOptions`, `VoiceTranscriptionOptions`
|
|
145
|
+
- `VoiceInputProviderV1`
|
|
146
|
+
- `VoiceInputProviderV1CallOptions`
|
|
147
|
+
- `VoiceInputProviderV1Session`
|
|
148
|
+
- `VoiceInputProviderV1StreamPart`
|
|
149
|
+
|
|
150
|
+
`@voiceinput/provider/test`:
|
|
151
|
+
|
|
152
|
+
- `createFakeVoiceInputProvider`
|
|
153
|
+
- `createVoiceInputProviderV1ConformanceCases`
|
|
154
|
+
- `VoiceInputProviderConformanceError`
|
|
155
|
+
- `FakeVoiceInputProvider`
|
|
156
|
+
- `FakeVoiceInputProviderOptions`
|
|
157
|
+
- `FakeVoiceInputProviderController`
|
|
158
|
+
- `FakeVoiceInputProviderSessionSnapshot`
|
|
159
|
+
- `VoiceInputProviderV1ConformanceHarness`
|
|
160
|
+
- `VoiceInputProviderV1ConformanceCase`
|
|
161
|
+
- `VoiceInputProviderV1ConformanceOptions`
|
|
162
|
+
|
|
163
|
+
## Security boundary
|
|
164
|
+
|
|
165
|
+
This package contains no credential handling. Official adapters expose browser
|
|
166
|
+
code from their root and token minting from a separate `/server` export. Custom
|
|
167
|
+
adapters should preserve the same boundary: long-lived credentials must never
|
|
168
|
+
enter browser code, payloads, or logs.
|
|
169
|
+
|
|
170
|
+
## Segment identity
|
|
171
|
+
|
|
172
|
+
Include `segmentId: string` on each `interim` and `final` stream part. Keep it
|
|
173
|
+
stable across revisions of one segment and unique within an open session. Emit
|
|
174
|
+
ordered segments; buffer out-of-order provider results in the adapter. Empty
|
|
175
|
+
finals close segments too. Speech-start/end notifications alone do not close a
|
|
176
|
+
transcription segment. Identical text in two segments is legitimate repetition.
|
|
177
|
+
|
|
178
|
+
Official adapters always provide identities. The optional field preserves older
|
|
179
|
+
strictly sequential custom providers; without it, each final advances an
|
|
180
|
+
implicit segment and duplicate finals cannot be identified reliably. New
|
|
181
|
+
adapters should always implement segment identity and use the published
|
|
182
|
+
conformance cases.
|
|
183
|
+
|
|
184
|
+
`sendAudio` may return a promise for backpressure. Bound transport queues and
|
|
185
|
+
honor abort while waiting; never silently drop audio. The official adapters use
|
|
186
|
+
the shared `@voiceinput/provider/transport` helper with a 1 MiB high-water mark
|
|
187
|
+
and a five-second congestion deadline.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
const voiceInputErrorMarker = Symbol.for("@voiceinput/provider/VoiceInputError");
|
|
4
|
+
var VoiceInputError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
provider;
|
|
7
|
+
retryable;
|
|
8
|
+
retryAfterMs;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options.message, { cause: options.cause });
|
|
11
|
+
this.name = "VoiceInputError";
|
|
12
|
+
this.code = options.code;
|
|
13
|
+
this.provider = options.provider;
|
|
14
|
+
this.retryable = options.retryable ?? false;
|
|
15
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
16
|
+
Object.defineProperty(this, voiceInputErrorMarker, {
|
|
17
|
+
configurable: false,
|
|
18
|
+
enumerable: false,
|
|
19
|
+
value: true,
|
|
20
|
+
writable: false
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
static isInstance(value) {
|
|
24
|
+
return typeof value === "object" && value !== null && voiceInputErrorMarker in value && value[voiceInputErrorMarker] === true;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.VoiceInputError = VoiceInputError;
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["const voiceInputErrorMarker = Symbol.for(\n \"@voiceinput/provider/VoiceInputError\",\n);\n\nexport type VoiceInputErrorCode =\n | \"unsupported-browser\"\n | \"permission-denied\"\n | \"device-not-found\"\n | \"device-busy\"\n | \"unauthorized\"\n | \"rate-limited\"\n | \"token-error\"\n | \"network-error\"\n | \"provider-error\"\n | \"unsupported-feature\"\n | \"invalid-configuration\"\n | \"audio-error\"\n | \"transform-error\";\n\nexport interface VoiceInputErrorOptions {\n code: VoiceInputErrorCode;\n message: string;\n provider?: string;\n retryable?: boolean;\n retryAfterMs?: number;\n cause?: unknown;\n}\n\nexport class VoiceInputError extends Error {\n readonly code: VoiceInputErrorCode;\n readonly provider: string | undefined;\n readonly retryable: boolean;\n readonly retryAfterMs: number | undefined;\n\n constructor(options: VoiceInputErrorOptions) {\n super(options.message, { cause: options.cause });\n this.name = \"VoiceInputError\";\n this.code = options.code;\n this.provider = options.provider;\n this.retryable = options.retryable ?? false;\n this.retryAfterMs = options.retryAfterMs;\n\n Object.defineProperty(this, voiceInputErrorMarker, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n });\n }\n\n static isInstance(value: unknown): value is VoiceInputError {\n return (\n typeof value === \"object\" &&\n value !== null &&\n voiceInputErrorMarker in value &&\n (value as Record<PropertyKey, unknown>)[voiceInputErrorMarker] === true\n );\n }\n}\n\nexport interface VoiceEndpointingOptions {\n silenceMs: number;\n}\n\nexport interface VoiceTranscriptionOptions {\n language?: string;\n vocabulary?: readonly string[];\n endpointing?: false | VoiceEndpointingOptions;\n}\n\nexport interface VoiceInputProviderV1CallOptions extends VoiceTranscriptionOptions {\n abortSignal: AbortSignal;\n}\n\nexport type VoiceInputProviderV1StreamPart =\n | { type: \"interim\"; text: string; segmentId?: string }\n | { type: \"final\"; text: string; segmentId?: string }\n | { type: \"speech-start\" }\n | { type: \"speech-end\" }\n | { type: \"error\"; error: VoiceInputError };\n\nexport interface VoiceInputProviderV1Session {\n readonly stream: ReadableStream<VoiceInputProviderV1StreamPart>;\n sendAudio(chunk: Int16Array): PromiseLike<void> | void;\n finish(): PromiseLike<void> | void;\n abort(reason?: unknown): void;\n}\n\nexport interface VoiceInputProviderV1 {\n readonly specificationVersion: \"v1\";\n readonly provider: string;\n readonly modelId: string;\n readonly sampleRate: number;\n validateOptions(options: VoiceTranscriptionOptions): void;\n doOpen(\n options: VoiceInputProviderV1CallOptions,\n ): PromiseLike<VoiceInputProviderV1Session>;\n}\n"],"mappings":";;AAAA,MAAM,wBAAwB,OAAO,IACnC,sCACF;AA0BA,IAAa,kBAAb,cAAqC,MAAM;CACzC;CACA;CACA;CACA;CAEA,YAAY,SAAiC;EAC3C,MAAM,QAAQ,SAAS,EAAE,OAAO,QAAQ,MAAM,CAAC;EAC/C,KAAK,OAAO;EACZ,KAAK,OAAO,QAAQ;EACpB,KAAK,WAAW,QAAQ;EACxB,KAAK,YAAY,QAAQ,aAAa;EACtC,KAAK,eAAe,QAAQ;EAE5B,OAAO,eAAe,MAAM,uBAAuB;GACjD,cAAc;GACd,YAAY;GACZ,OAAO;GACP,UAAU;EACZ,CAAC;CACH;CAEA,OAAO,WAAW,OAA0C;EAC1D,OACE,OAAO,UAAU,YACjB,UAAU,QACV,yBAAyB,SACxB,MAAuC,2BAA2B;CAEvE;AACF"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
type VoiceInputErrorCode = "unsupported-browser" | "permission-denied" | "device-not-found" | "device-busy" | "unauthorized" | "rate-limited" | "token-error" | "network-error" | "provider-error" | "unsupported-feature" | "invalid-configuration" | "audio-error" | "transform-error";
|
|
3
|
+
interface VoiceInputErrorOptions {
|
|
4
|
+
code: VoiceInputErrorCode;
|
|
5
|
+
message: string;
|
|
6
|
+
provider?: string;
|
|
7
|
+
retryable?: boolean;
|
|
8
|
+
retryAfterMs?: number;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
}
|
|
11
|
+
declare class VoiceInputError extends Error {
|
|
12
|
+
readonly code: VoiceInputErrorCode;
|
|
13
|
+
readonly provider: string | undefined;
|
|
14
|
+
readonly retryable: boolean;
|
|
15
|
+
readonly retryAfterMs: number | undefined;
|
|
16
|
+
constructor(options: VoiceInputErrorOptions);
|
|
17
|
+
static isInstance(value: unknown): value is VoiceInputError;
|
|
18
|
+
}
|
|
19
|
+
interface VoiceEndpointingOptions {
|
|
20
|
+
silenceMs: number;
|
|
21
|
+
}
|
|
22
|
+
interface VoiceTranscriptionOptions {
|
|
23
|
+
language?: string;
|
|
24
|
+
vocabulary?: readonly string[];
|
|
25
|
+
endpointing?: false | VoiceEndpointingOptions;
|
|
26
|
+
}
|
|
27
|
+
interface VoiceInputProviderV1CallOptions extends VoiceTranscriptionOptions {
|
|
28
|
+
abortSignal: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
type VoiceInputProviderV1StreamPart = {
|
|
31
|
+
type: "interim";
|
|
32
|
+
text: string;
|
|
33
|
+
segmentId?: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "final";
|
|
36
|
+
text: string;
|
|
37
|
+
segmentId?: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "speech-start";
|
|
40
|
+
} | {
|
|
41
|
+
type: "speech-end";
|
|
42
|
+
} | {
|
|
43
|
+
type: "error";
|
|
44
|
+
error: VoiceInputError;
|
|
45
|
+
};
|
|
46
|
+
interface VoiceInputProviderV1Session {
|
|
47
|
+
readonly stream: ReadableStream<VoiceInputProviderV1StreamPart>;
|
|
48
|
+
sendAudio(chunk: Int16Array): PromiseLike<void> | void;
|
|
49
|
+
finish(): PromiseLike<void> | void;
|
|
50
|
+
abort(reason?: unknown): void;
|
|
51
|
+
}
|
|
52
|
+
interface VoiceInputProviderV1 {
|
|
53
|
+
readonly specificationVersion: "v1";
|
|
54
|
+
readonly provider: string;
|
|
55
|
+
readonly modelId: string;
|
|
56
|
+
readonly sampleRate: number;
|
|
57
|
+
validateOptions(options: VoiceTranscriptionOptions): void;
|
|
58
|
+
doOpen(options: VoiceInputProviderV1CallOptions): PromiseLike<VoiceInputProviderV1Session>;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { VoiceEndpointingOptions, VoiceInputError, VoiceInputErrorCode, VoiceInputErrorOptions, VoiceInputProviderV1, VoiceInputProviderV1CallOptions, VoiceInputProviderV1Session, VoiceInputProviderV1StreamPart, VoiceTranscriptionOptions };
|
|
62
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";KAIY;UAeK;EACf,MAAM;EACN;EACA;EACA;EACA;EACA;;cAGW,wBAAwB;WAC1B,MAAM;WACN;WACA;WACA;EAET,YAAY,SAAS;SAgBd,WAAW,iBAAiB,SAAS;;UAU7B;EACf;;UAGe;EACf;EACA;EACA,sBAAsB;;UAGP,wCAAwC;EACvD,aAAa;;KAGH;EACN;EAAiB;EAAc;;EAC/B;EAAe;EAAc;;EAC7B;;EACA;;EACA;EAAe,OAAO;;UAEX;WACN,QAAQ,eAAe;EAChC,UAAU,OAAO,aAAa;EAC9B,UAAU;EACV,MAAM;;UAGS;WACN;WACA;WACA;WACA;EACT,gBAAgB,SAAS;EACzB,OACE,SAAS,kCACR,YAAY"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
type VoiceInputErrorCode = "unsupported-browser" | "permission-denied" | "device-not-found" | "device-busy" | "unauthorized" | "rate-limited" | "token-error" | "network-error" | "provider-error" | "unsupported-feature" | "invalid-configuration" | "audio-error" | "transform-error";
|
|
3
|
+
interface VoiceInputErrorOptions {
|
|
4
|
+
code: VoiceInputErrorCode;
|
|
5
|
+
message: string;
|
|
6
|
+
provider?: string;
|
|
7
|
+
retryable?: boolean;
|
|
8
|
+
retryAfterMs?: number;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
}
|
|
11
|
+
declare class VoiceInputError extends Error {
|
|
12
|
+
readonly code: VoiceInputErrorCode;
|
|
13
|
+
readonly provider: string | undefined;
|
|
14
|
+
readonly retryable: boolean;
|
|
15
|
+
readonly retryAfterMs: number | undefined;
|
|
16
|
+
constructor(options: VoiceInputErrorOptions);
|
|
17
|
+
static isInstance(value: unknown): value is VoiceInputError;
|
|
18
|
+
}
|
|
19
|
+
interface VoiceEndpointingOptions {
|
|
20
|
+
silenceMs: number;
|
|
21
|
+
}
|
|
22
|
+
interface VoiceTranscriptionOptions {
|
|
23
|
+
language?: string;
|
|
24
|
+
vocabulary?: readonly string[];
|
|
25
|
+
endpointing?: false | VoiceEndpointingOptions;
|
|
26
|
+
}
|
|
27
|
+
interface VoiceInputProviderV1CallOptions extends VoiceTranscriptionOptions {
|
|
28
|
+
abortSignal: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
type VoiceInputProviderV1StreamPart = {
|
|
31
|
+
type: "interim";
|
|
32
|
+
text: string;
|
|
33
|
+
segmentId?: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "final";
|
|
36
|
+
text: string;
|
|
37
|
+
segmentId?: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "speech-start";
|
|
40
|
+
} | {
|
|
41
|
+
type: "speech-end";
|
|
42
|
+
} | {
|
|
43
|
+
type: "error";
|
|
44
|
+
error: VoiceInputError;
|
|
45
|
+
};
|
|
46
|
+
interface VoiceInputProviderV1Session {
|
|
47
|
+
readonly stream: ReadableStream<VoiceInputProviderV1StreamPart>;
|
|
48
|
+
sendAudio(chunk: Int16Array): PromiseLike<void> | void;
|
|
49
|
+
finish(): PromiseLike<void> | void;
|
|
50
|
+
abort(reason?: unknown): void;
|
|
51
|
+
}
|
|
52
|
+
interface VoiceInputProviderV1 {
|
|
53
|
+
readonly specificationVersion: "v1";
|
|
54
|
+
readonly provider: string;
|
|
55
|
+
readonly modelId: string;
|
|
56
|
+
readonly sampleRate: number;
|
|
57
|
+
validateOptions(options: VoiceTranscriptionOptions): void;
|
|
58
|
+
doOpen(options: VoiceInputProviderV1CallOptions): PromiseLike<VoiceInputProviderV1Session>;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { VoiceEndpointingOptions, VoiceInputError, VoiceInputErrorCode, VoiceInputErrorOptions, VoiceInputProviderV1, VoiceInputProviderV1CallOptions, VoiceInputProviderV1Session, VoiceInputProviderV1StreamPart, VoiceTranscriptionOptions };
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";KAIY;UAeK;EACf,MAAM;EACN;EACA;EACA;EACA;EACA;;cAGW,wBAAwB;WAC1B,MAAM;WACN;WACA;WACA;EAET,YAAY,SAAS;SAgBd,WAAW,iBAAiB,SAAS;;UAU7B;EACf;;UAGe;EACf;EACA;EACA,sBAAsB;;UAGP,wCAAwC;EACvD,aAAa;;KAGH;EACN;EAAiB;EAAc;;EAC/B;EAAe;EAAc;;EAC7B;;EACA;;EACA;EAAe,OAAO;;UAEX;WACN,QAAQ,eAAe;EAChC,UAAU,OAAO,aAAa;EAC9B,UAAU;EACV,MAAM;;UAGS;WACN;WACA;WACA;WACA;EACT,gBAAgB,SAAS;EACzB,OACE,SAAS,kCACR,YAAY"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
const voiceInputErrorMarker = Symbol.for("@voiceinput/provider/VoiceInputError");
|
|
3
|
+
var VoiceInputError = class extends Error {
|
|
4
|
+
code;
|
|
5
|
+
provider;
|
|
6
|
+
retryable;
|
|
7
|
+
retryAfterMs;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options.message, { cause: options.cause });
|
|
10
|
+
this.name = "VoiceInputError";
|
|
11
|
+
this.code = options.code;
|
|
12
|
+
this.provider = options.provider;
|
|
13
|
+
this.retryable = options.retryable ?? false;
|
|
14
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
15
|
+
Object.defineProperty(this, voiceInputErrorMarker, {
|
|
16
|
+
configurable: false,
|
|
17
|
+
enumerable: false,
|
|
18
|
+
value: true,
|
|
19
|
+
writable: false
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
static isInstance(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && voiceInputErrorMarker in value && value[voiceInputErrorMarker] === true;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { VoiceInputError };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["const voiceInputErrorMarker = Symbol.for(\n \"@voiceinput/provider/VoiceInputError\",\n);\n\nexport type VoiceInputErrorCode =\n | \"unsupported-browser\"\n | \"permission-denied\"\n | \"device-not-found\"\n | \"device-busy\"\n | \"unauthorized\"\n | \"rate-limited\"\n | \"token-error\"\n | \"network-error\"\n | \"provider-error\"\n | \"unsupported-feature\"\n | \"invalid-configuration\"\n | \"audio-error\"\n | \"transform-error\";\n\nexport interface VoiceInputErrorOptions {\n code: VoiceInputErrorCode;\n message: string;\n provider?: string;\n retryable?: boolean;\n retryAfterMs?: number;\n cause?: unknown;\n}\n\nexport class VoiceInputError extends Error {\n readonly code: VoiceInputErrorCode;\n readonly provider: string | undefined;\n readonly retryable: boolean;\n readonly retryAfterMs: number | undefined;\n\n constructor(options: VoiceInputErrorOptions) {\n super(options.message, { cause: options.cause });\n this.name = \"VoiceInputError\";\n this.code = options.code;\n this.provider = options.provider;\n this.retryable = options.retryable ?? false;\n this.retryAfterMs = options.retryAfterMs;\n\n Object.defineProperty(this, voiceInputErrorMarker, {\n configurable: false,\n enumerable: false,\n value: true,\n writable: false,\n });\n }\n\n static isInstance(value: unknown): value is VoiceInputError {\n return (\n typeof value === \"object\" &&\n value !== null &&\n voiceInputErrorMarker in value &&\n (value as Record<PropertyKey, unknown>)[voiceInputErrorMarker] === true\n );\n }\n}\n\nexport interface VoiceEndpointingOptions {\n silenceMs: number;\n}\n\nexport interface VoiceTranscriptionOptions {\n language?: string;\n vocabulary?: readonly string[];\n endpointing?: false | VoiceEndpointingOptions;\n}\n\nexport interface VoiceInputProviderV1CallOptions extends VoiceTranscriptionOptions {\n abortSignal: AbortSignal;\n}\n\nexport type VoiceInputProviderV1StreamPart =\n | { type: \"interim\"; text: string; segmentId?: string }\n | { type: \"final\"; text: string; segmentId?: string }\n | { type: \"speech-start\" }\n | { type: \"speech-end\" }\n | { type: \"error\"; error: VoiceInputError };\n\nexport interface VoiceInputProviderV1Session {\n readonly stream: ReadableStream<VoiceInputProviderV1StreamPart>;\n sendAudio(chunk: Int16Array): PromiseLike<void> | void;\n finish(): PromiseLike<void> | void;\n abort(reason?: unknown): void;\n}\n\nexport interface VoiceInputProviderV1 {\n readonly specificationVersion: \"v1\";\n readonly provider: string;\n readonly modelId: string;\n readonly sampleRate: number;\n validateOptions(options: VoiceTranscriptionOptions): void;\n doOpen(\n options: VoiceInputProviderV1CallOptions,\n ): PromiseLike<VoiceInputProviderV1Session>;\n}\n"],"mappings":";AAAA,MAAM,wBAAwB,OAAO,IACnC,sCACF;AA0BA,IAAa,kBAAb,cAAqC,MAAM;CACzC;CACA;CACA;CACA;CAEA,YAAY,SAAiC;EAC3C,MAAM,QAAQ,SAAS,EAAE,OAAO,QAAQ,MAAM,CAAC;EAC/C,KAAK,OAAO;EACZ,KAAK,OAAO,QAAQ;EACpB,KAAK,WAAW,QAAQ;EACxB,KAAK,YAAY,QAAQ,aAAa;EACtC,KAAK,eAAe,QAAQ;EAE5B,OAAO,eAAe,MAAM,uBAAuB;GACjD,cAAc;GACd,YAAY;GACZ,OAAO;GACP,UAAU;EACZ,CAAC;CACH;CAEA,OAAO,WAAW,OAA0C;EAC1D,OACE,OAAO,UAAU,YACjB,UAAU,QACV,yBAAyB,SACxB,MAAuC,2BAA2B;CAEvE;AACF"}
|