@happyvertical/speech 0.96.1 → 0.98.0
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/AGENT.md +42 -3
- package/README.md +335 -3
- package/dist/__tests__/fake-websocket.d.ts +38 -0
- package/dist/__tests__/fake-websocket.d.ts.map +1 -0
- package/dist/adapters/local/abort.d.ts +6 -0
- package/dist/adapters/local/abort.d.ts.map +1 -0
- package/dist/adapters/local/audio.d.ts +45 -0
- package/dist/adapters/local/audio.d.ts.map +1 -0
- package/dist/adapters/local/env.d.ts +15 -0
- package/dist/adapters/local/env.d.ts.map +1 -0
- package/dist/adapters/local/runtime.d.ts +58 -0
- package/dist/adapters/local/runtime.d.ts.map +1 -0
- package/dist/adapters/local/transcriber.d.ts +40 -0
- package/dist/adapters/local/transcriber.d.ts.map +1 -0
- package/dist/adapters/local/transformers-shim.d.ts +8 -0
- package/dist/adapters/local/transformers-shim.d.ts.map +1 -0
- package/dist/adapters/local/types.d.ts +92 -0
- package/dist/adapters/local/types.d.ts.map +1 -0
- package/dist/adapters/local/worker.d.ts +118 -0
- package/dist/adapters/local/worker.d.ts.map +1 -0
- package/dist/adapters/openai-compatible-transcriber.d.ts +23 -0
- package/dist/adapters/openai-compatible-transcriber.d.ts.map +1 -0
- package/dist/adapters/openai-compatible.d.ts +2 -1
- package/dist/adapters/openai-compatible.d.ts.map +1 -1
- package/dist/adapters/openai-realtime.d.ts +48 -0
- package/dist/adapters/openai-realtime.d.ts.map +1 -0
- package/dist/adapters/studio-server.d.ts.map +1 -1
- package/dist/adapters/voxtral-realtime.d.ts +44 -0
- package/dist/adapters/voxtral-realtime.d.ts.map +1 -0
- package/dist/chunks/registry-DfID41Ew.js +343 -0
- package/dist/chunks/registry-DfID41Ew.js.map +1 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2148 -85
- package/dist/index.js.map +1 -1
- package/dist/local.d.ts +21 -0
- package/dist/local.d.ts.map +1 -0
- package/dist/local.js +963 -0
- package/dist/local.js.map +1 -0
- package/dist/shared/audio.d.ts +47 -0
- package/dist/shared/audio.d.ts.map +1 -0
- package/dist/shared/env.d.ts +75 -0
- package/dist/shared/env.d.ts.map +1 -0
- package/dist/shared/errors.d.ts +3 -0
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/factory.d.ts +1 -4
- package/dist/shared/factory.d.ts.map +1 -1
- package/dist/shared/http.d.ts +29 -3
- package/dist/shared/http.d.ts.map +1 -1
- package/dist/shared/pcm.d.ts +21 -0
- package/dist/shared/pcm.d.ts.map +1 -0
- package/dist/shared/realtime-auth.d.ts +34 -0
- package/dist/shared/realtime-auth.d.ts.map +1 -0
- package/dist/shared/realtime-session.d.ts +240 -0
- package/dist/shared/realtime-session.d.ts.map +1 -0
- package/dist/shared/registry.d.ts +9 -0
- package/dist/shared/registry.d.ts.map +1 -0
- package/dist/shared/retry.d.ts +31 -0
- package/dist/shared/retry.d.ts.map +1 -0
- package/dist/shared/streaming-client-secret.d.ts +90 -0
- package/dist/shared/streaming-client-secret.d.ts.map +1 -0
- package/dist/shared/streaming-factory.d.ts +65 -0
- package/dist/shared/streaming-factory.d.ts.map +1 -0
- package/dist/shared/streaming-types.d.ts +303 -0
- package/dist/shared/streaming-types.d.ts.map +1 -0
- package/dist/shared/turn-limit.d.ts +84 -0
- package/dist/shared/turn-limit.d.ts.map +1 -0
- package/dist/shared/types.d.ts +84 -6
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/usage.d.ts +35 -0
- package/dist/shared/usage.d.ts.map +1 -0
- package/dist/shared/websocket.d.ts +56 -0
- package/dist/shared/websocket.d.ts.map +1 -0
- package/metadata.json +7 -1
- package/package.json +19 -3
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { TranscriptResult } from './types.js';
|
|
2
|
+
import { SpeechUsageCallback } from './usage.js';
|
|
3
|
+
import { SpeechWebSocketConstructor, SpeechWebSocketFactory } from './websocket.js';
|
|
4
|
+
/** Streaming adapter identifiers. */
|
|
5
|
+
export type StreamingTranscriberType = 'openai-realtime' | 'voxtral-realtime';
|
|
6
|
+
/**
|
|
7
|
+
* Raw audio sample encodings. Streaming adapters never decode containers
|
|
8
|
+
* (WebM, MP4, Ogg) or resample: callers send audio in the negotiated format.
|
|
9
|
+
*
|
|
10
|
+
* - `pcm16`: signed 16-bit little-endian PCM, interleaved when multi-channel.
|
|
11
|
+
* - `g711_ulaw` / `g711_alaw`: 8-bit G.711 companded audio.
|
|
12
|
+
*/
|
|
13
|
+
export type StreamingAudioEncoding = 'pcm16' | 'g711_ulaw' | 'g711_alaw';
|
|
14
|
+
/** Explicit audio format for a streaming session. */
|
|
15
|
+
export interface StreamingAudioFormat {
|
|
16
|
+
encoding: StreamingAudioEncoding;
|
|
17
|
+
/** Samples per second, e.g. `24000`. */
|
|
18
|
+
sampleRate: number;
|
|
19
|
+
/** Channel count. Realtime providers generally require mono (`1`). */
|
|
20
|
+
channels: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Turn detection (voice activity detection).
|
|
24
|
+
*
|
|
25
|
+
* - `server_vad`: the provider commits a turn after `silenceDurationMs` of
|
|
26
|
+
* silence and emits a `final` per turn. The default for live sessions.
|
|
27
|
+
* - `semantic_vad`: the provider decides turn ends from content.
|
|
28
|
+
* - `manual`: nothing is committed until `session.commit()` or `end()`. The
|
|
29
|
+
* default for the record-then-send `Transcriber` wrapper.
|
|
30
|
+
*/
|
|
31
|
+
export type StreamingTurnDetection = {
|
|
32
|
+
type: 'server_vad';
|
|
33
|
+
/** Activation threshold 0-1. Provider default `0.5`. */
|
|
34
|
+
threshold?: number;
|
|
35
|
+
/** Audio kept before detected speech. Provider default `300`. */
|
|
36
|
+
prefixPaddingMs?: number;
|
|
37
|
+
/** Silence that ends a turn. Provider default `500`. */
|
|
38
|
+
silenceDurationMs?: number;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'semantic_vad';
|
|
41
|
+
eagerness?: 'low' | 'medium' | 'high' | 'auto';
|
|
42
|
+
} | {
|
|
43
|
+
type: 'manual';
|
|
44
|
+
};
|
|
45
|
+
/** Audio accepted by {@link StreamingSession.write}. `Buffer` is a `Uint8Array`. */
|
|
46
|
+
export type StreamingAudioChunk = Uint8Array | ArrayBuffer | ArrayBufferView;
|
|
47
|
+
/**
|
|
48
|
+
* A short-lived browser credential, or a function that mints one per session
|
|
49
|
+
* (for example by calling your server, which asks the provider for an
|
|
50
|
+
* ephemeral client secret scoped to the current tenant).
|
|
51
|
+
*/
|
|
52
|
+
export type StreamingClientSecret = string | (() => string | Promise<string>);
|
|
53
|
+
/** Settings shared by adapter construction and individual sessions. */
|
|
54
|
+
export interface StreamingSessionSettings {
|
|
55
|
+
/** Transcription model. */
|
|
56
|
+
model?: string;
|
|
57
|
+
/** ISO-639-1 language hint, e.g. `en`. */
|
|
58
|
+
language?: string;
|
|
59
|
+
/** Vocabulary or style prompt. */
|
|
60
|
+
prompt?: string;
|
|
61
|
+
/** Turn detection. Adapter default `server_vad`. */
|
|
62
|
+
turnDetection?: StreamingTurnDetection;
|
|
63
|
+
/** Audio format; unset fields use the adapter default. */
|
|
64
|
+
format?: Partial<StreamingAudioFormat>;
|
|
65
|
+
/**
|
|
66
|
+
* Extra headers sent on the WebSocket handshake (e.g. gateway `x-bf-vk`).
|
|
67
|
+
* Node-only: browsers cannot set WebSocket headers.
|
|
68
|
+
*/
|
|
69
|
+
headers?: HeadersInit;
|
|
70
|
+
/** Short-lived credential sent as a WebSocket subprotocol (browser-safe). */
|
|
71
|
+
clientSecret?: StreamingClientSecret;
|
|
72
|
+
/** Called with aggregated usage when `end()` succeeds. */
|
|
73
|
+
onUsage?: SpeechUsageCallback;
|
|
74
|
+
/**
|
|
75
|
+
* Most audio one turn may hold, in seconds, for providers whose context is
|
|
76
|
+
* per turn. `voxtral-realtime` defaults to `270` (headroom under vLLM's
|
|
77
|
+
* `max_model_len` 4096). `openai-realtime` has no default and applies it
|
|
78
|
+
* only to `manual` sessions, where it is opt-in; server VAD ends turns
|
|
79
|
+
* there. `Infinity` removes the limit. Env
|
|
80
|
+
* `HAVE_SPEECH_STREAMING_MAX_TURN_SECONDS`.
|
|
81
|
+
*/
|
|
82
|
+
maxTurnSeconds?: number;
|
|
83
|
+
/**
|
|
84
|
+
* What happens when a turn reaches `maxTurnSeconds`. Default `true`: the
|
|
85
|
+
* session commits the turn at a quiet boundary (or at the cap when none is
|
|
86
|
+
* found), emits its `final`, and continues in a new turn without losing
|
|
87
|
+
* audio. `false`: a `write()` that would push the turn past the cap rejects
|
|
88
|
+
* with the non-fatal code `SPEECH_TURN_TOO_LONG`; call `commit()` and keep
|
|
89
|
+
* writing. An object enables rollover with tuning.
|
|
90
|
+
*/
|
|
91
|
+
rollover?: boolean | StreamingRolloverOptions;
|
|
92
|
+
}
|
|
93
|
+
/** Tuning for automatic turn rollover. */
|
|
94
|
+
export interface StreamingRolloverOptions {
|
|
95
|
+
/**
|
|
96
|
+
* How long before `maxTurnSeconds` to start looking for a quiet boundary.
|
|
97
|
+
* Default `15`.
|
|
98
|
+
*/
|
|
99
|
+
windowSeconds?: number;
|
|
100
|
+
/**
|
|
101
|
+
* RMS level, from 0 to 1 of full scale, below which a 20 ms frame counts as
|
|
102
|
+
* quiet. Default `0.01` (about -40 dBFS).
|
|
103
|
+
*/
|
|
104
|
+
silenceThreshold?: number;
|
|
105
|
+
/** Continuous quiet audio needed to commit early. Default `300`. */
|
|
106
|
+
minSilenceMs?: number;
|
|
107
|
+
}
|
|
108
|
+
/** The per-turn audio limit a session enforces; see `maxTurnSeconds`. */
|
|
109
|
+
export interface StreamingTurnLimit {
|
|
110
|
+
maxTurnSeconds: number;
|
|
111
|
+
/** `true` when the session rolls over, `false` when writes past the cap reject. */
|
|
112
|
+
rollover: boolean;
|
|
113
|
+
/** The cap in bytes of the session's audio format (whole sample frames). */
|
|
114
|
+
maxTurnBytes: number;
|
|
115
|
+
}
|
|
116
|
+
/** Options for {@link StreamingTranscriber.start}. Values override adapter defaults. */
|
|
117
|
+
export interface StreamingSessionOptions extends StreamingSessionSettings {
|
|
118
|
+
/** Aborting fails the session and closes the socket. */
|
|
119
|
+
signal?: AbortSignal;
|
|
120
|
+
metadata?: Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
/** Session lifecycle states. `closed` and `failed` are terminal. */
|
|
123
|
+
export type StreamingSessionState = 'connecting' | 'open' | 'ending' | 'closed' | 'failed';
|
|
124
|
+
export interface StreamingPartialEvent {
|
|
125
|
+
/** Newly recognised text. */
|
|
126
|
+
delta: string;
|
|
127
|
+
/** Text recognised so far for this turn (all deltas joined). */
|
|
128
|
+
text: string;
|
|
129
|
+
/** Provider turn/item id, when the protocol has one. */
|
|
130
|
+
itemId?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface StreamingFinalEvent {
|
|
133
|
+
/** Final text for one committed turn. */
|
|
134
|
+
text: string;
|
|
135
|
+
itemId?: string;
|
|
136
|
+
/** Provider usage block for this turn, passed through untouched. */
|
|
137
|
+
providerUsage?: Record<string, unknown>;
|
|
138
|
+
raw?: unknown;
|
|
139
|
+
}
|
|
140
|
+
export interface StreamingSpeechEvent {
|
|
141
|
+
itemId?: string;
|
|
142
|
+
/** Offset into the session audio, in milliseconds. */
|
|
143
|
+
audioMs?: number;
|
|
144
|
+
}
|
|
145
|
+
export interface StreamingCloseEvent {
|
|
146
|
+
code: number;
|
|
147
|
+
reason: string;
|
|
148
|
+
}
|
|
149
|
+
/** Events emitted by a {@link StreamingSession}. */
|
|
150
|
+
export interface StreamingSessionEvents {
|
|
151
|
+
/** The socket is open and the session configuration has been sent. */
|
|
152
|
+
open: {
|
|
153
|
+
sessionId?: string;
|
|
154
|
+
};
|
|
155
|
+
partial: StreamingPartialEvent;
|
|
156
|
+
final: StreamingFinalEvent;
|
|
157
|
+
speech_started: StreamingSpeechEvent;
|
|
158
|
+
speech_stopped: StreamingSpeechEvent;
|
|
159
|
+
/**
|
|
160
|
+
* A fatal session error. Emitted once; `end()` and pending `write()` calls
|
|
161
|
+
* reject with the same error.
|
|
162
|
+
*/
|
|
163
|
+
error: Error;
|
|
164
|
+
/** The socket closed (normally after `end()`, or unexpectedly). */
|
|
165
|
+
close: StreamingCloseEvent;
|
|
166
|
+
}
|
|
167
|
+
export type StreamingSessionEventName = keyof StreamingSessionEvents;
|
|
168
|
+
export type StreamingSessionListener<E extends StreamingSessionEventName> = (event: StreamingSessionEvents[E]) => void;
|
|
169
|
+
/**
|
|
170
|
+
* One realtime transcription session over a WebSocket.
|
|
171
|
+
*
|
|
172
|
+
* **Backpressure.** `write()` returns a promise that resolves once the chunk
|
|
173
|
+
* has been handed to the socket and the socket's send buffer has drained to
|
|
174
|
+
* `highWaterMark` or below. Await each write to stream at the rate the network
|
|
175
|
+
* accepts. Writes are queued in order, including before the socket opens; a
|
|
176
|
+
* write that would push queued, unsent audio past `maxBufferedBytes` rejects
|
|
177
|
+
* instead of growing memory without bound.
|
|
178
|
+
*
|
|
179
|
+
* **Reconnect policy.** None. The provider holds the audio buffer and turn
|
|
180
|
+
* state, so a mid-session socket drop cannot be resumed without losing or
|
|
181
|
+
* duplicating text. An unexpected close fails the session: queued audio is
|
|
182
|
+
* discarded, pending `write()` calls and `end()` reject with a
|
|
183
|
+
* `SpeechProviderError`, and `error` then `close` are emitted. Start a new
|
|
184
|
+
* session to continue; finals already emitted remain valid.
|
|
185
|
+
*/
|
|
186
|
+
export interface StreamingSession {
|
|
187
|
+
readonly state: StreamingSessionState;
|
|
188
|
+
/** Provider session id, once known. */
|
|
189
|
+
readonly sessionId?: string;
|
|
190
|
+
/** Resolves when the session is open; rejects if it fails first. */
|
|
191
|
+
readonly ready: Promise<void>;
|
|
192
|
+
/** Queued audio bytes not yet handed to the socket. */
|
|
193
|
+
readonly queuedBytes: number;
|
|
194
|
+
/**
|
|
195
|
+
* Queues audio in the session's negotiated format. See backpressure above.
|
|
196
|
+
* With a turn limit and `rollover: false`, rejects with the non-fatal
|
|
197
|
+
* `SPEECH_TURN_TOO_LONG` instead of letting the current turn grow past it.
|
|
198
|
+
*/
|
|
199
|
+
write(chunk: StreamingAudioChunk): Promise<void>;
|
|
200
|
+
/** Ends the current turn now (manual turn detection). Ordered after queued writes. */
|
|
201
|
+
commit(): void;
|
|
202
|
+
/**
|
|
203
|
+
* Flushes queued audio, commits any uncommitted audio, waits for every
|
|
204
|
+
* pending turn's final transcript (bounded by `timeoutMs`), closes the
|
|
205
|
+
* socket, and resolves with the joined transcript and usage. Idempotent.
|
|
206
|
+
*/
|
|
207
|
+
end(): Promise<TranscriptResult>;
|
|
208
|
+
/** Fails the session immediately and closes the socket. */
|
|
209
|
+
abort(reason?: unknown): void;
|
|
210
|
+
/** Adds a listener; returns a function that removes it. */
|
|
211
|
+
on<E extends StreamingSessionEventName>(event: E, listener: StreamingSessionListener<E>): () => void;
|
|
212
|
+
off<E extends StreamingSessionEventName>(event: E, listener: StreamingSessionListener<E>): void;
|
|
213
|
+
}
|
|
214
|
+
/** Factory for realtime sessions against one configured provider. */
|
|
215
|
+
export interface StreamingTranscriber {
|
|
216
|
+
readonly type: StreamingTranscriberType;
|
|
217
|
+
/** Default audio format for new sessions. */
|
|
218
|
+
readonly audioFormat: StreamingAudioFormat;
|
|
219
|
+
/** Opens a session. Connection happens in the background; see `session.ready`. */
|
|
220
|
+
start(options?: StreamingSessionOptions): StreamingSession;
|
|
221
|
+
/**
|
|
222
|
+
* The per-turn limit a session started with `options` would enforce, or
|
|
223
|
+
* `undefined` when its turns are unbounded. Throws like `start()` on an
|
|
224
|
+
* invalid limit. Optional for custom implementations.
|
|
225
|
+
*/
|
|
226
|
+
turnLimit?(options?: StreamingSessionOptions): StreamingTurnLimit | undefined;
|
|
227
|
+
}
|
|
228
|
+
/** Adapter options shared by WebSocket streaming transcribers. */
|
|
229
|
+
export interface StreamingTranscriberOptions extends StreamingSessionSettings {
|
|
230
|
+
/**
|
|
231
|
+
* WebSocket URL or HTTP(S) base URL. `http` becomes `ws` and `https`
|
|
232
|
+
* becomes `wss`. A server root gets `/v1/realtime`; a base ending in a
|
|
233
|
+
* version segment gets `/realtime`; a URL ending in `/realtime` is used as-is.
|
|
234
|
+
*/
|
|
235
|
+
baseUrl?: string;
|
|
236
|
+
/**
|
|
237
|
+
* Long-lived API key sent as `Authorization: Bearer`. Node-only: refused in
|
|
238
|
+
* browsers. Browsers use `clientSecret`.
|
|
239
|
+
*/
|
|
240
|
+
apiKey?: string;
|
|
241
|
+
/**
|
|
242
|
+
* Maximum provider inactivity while waiting for final transcripts after
|
|
243
|
+
* `end()` (every server message restarts it), and maximum wait for a
|
|
244
|
+
* congested socket to drain during `write()`. Default `30000`.
|
|
245
|
+
*/
|
|
246
|
+
timeoutMs?: number;
|
|
247
|
+
/** Maximum wait for the socket to open. Default `10000`. */
|
|
248
|
+
connectTimeoutMs?: number;
|
|
249
|
+
/** Socket send-buffer size at which `write()` waits. Default 1 MiB. */
|
|
250
|
+
highWaterMark?: number;
|
|
251
|
+
/** Queued, unsent audio at which `write()` rejects. Default 16 MiB. */
|
|
252
|
+
maxBufferedBytes?: number;
|
|
253
|
+
/**
|
|
254
|
+
* WebSocket constructor. Defaults to `globalThis.WebSocket` (Node 22+,
|
|
255
|
+
* browsers, Deno, Bun). Handshake headers are passed as
|
|
256
|
+
* `new WebSocket(url, { protocols, headers })`, which Node's built-in
|
|
257
|
+
* WebSocket supports; use `createWebSocket` for other clients such as `ws`.
|
|
258
|
+
*/
|
|
259
|
+
WebSocket?: SpeechWebSocketConstructor;
|
|
260
|
+
/** Full control over socket creation; wins over `WebSocket`. */
|
|
261
|
+
createWebSocket?: SpeechWebSocketFactory;
|
|
262
|
+
}
|
|
263
|
+
/** Options for the `openai-realtime` adapter. */
|
|
264
|
+
export interface OpenAIRealtimeTranscriberOptions extends StreamingTranscriberOptions {
|
|
265
|
+
type?: 'openai-realtime';
|
|
266
|
+
/** Default `wss://api.openai.com/v1/realtime`. */
|
|
267
|
+
baseUrl?: string;
|
|
268
|
+
/** Default `gpt-4o-transcribe`. */
|
|
269
|
+
model?: string;
|
|
270
|
+
/** `audio.input.noise_reduction.type`. Omitted by default. */
|
|
271
|
+
noiseReduction?: 'near_field' | 'far_field';
|
|
272
|
+
/** Session `include` list, e.g. `['item.input_audio_transcription.logprobs']`. */
|
|
273
|
+
include?: string[];
|
|
274
|
+
/**
|
|
275
|
+
* Extra fields merged into `audio.input.transcription`, e.g.
|
|
276
|
+
* `{ delay: 'low', languages: ['en', 'fr'] }` for `gpt-live-transcribe`.
|
|
277
|
+
* The typed `model`, `language`, and `prompt` settings take precedence.
|
|
278
|
+
*/
|
|
279
|
+
transcriptionOptions?: Record<string, unknown>;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Options for the `voxtral-realtime` adapter (vLLM's `/v1/realtime`). Audio is
|
|
283
|
+
* fixed at PCM16 16 kHz mono and turns are manual; `language` and `prompt`
|
|
284
|
+
* are not sent because vLLM's realtime session accepts only `model`.
|
|
285
|
+
*/
|
|
286
|
+
export interface VoxtralRealtimeTranscriberOptions extends StreamingTranscriberOptions {
|
|
287
|
+
type?: 'voxtral-realtime';
|
|
288
|
+
/**
|
|
289
|
+
* Required: the vLLM server root (`http://host:8000`), its `/v1` API root,
|
|
290
|
+
* or the full `ws(s)://…/v1/realtime` URL.
|
|
291
|
+
*/
|
|
292
|
+
baseUrl?: string;
|
|
293
|
+
/**
|
|
294
|
+
* The model name vLLM serves, e.g. a `--served-model-name`. Default
|
|
295
|
+
* `mistralai/Voxtral-Mini-4B-Realtime-2602`.
|
|
296
|
+
*/
|
|
297
|
+
model?: string;
|
|
298
|
+
}
|
|
299
|
+
/** Options accepted by `getStreamingTranscriber()`. */
|
|
300
|
+
export interface GetStreamingTranscriberOptions extends Omit<OpenAIRealtimeTranscriberOptions, 'type'> {
|
|
301
|
+
type?: StreamingTranscriberType;
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=streaming-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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AM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uEAAuE;IACvE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,0BAA0B,CAAC;IACvC,gEAAgE;IAChE,eAAe,CAAC,EAAE,sBAAsB,CAAC;CAC1C;AAED,iDAAiD;AACjD,MAAM,WAAW,gCACf,SAAQ,2BAA2B;IACnC,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,cAAc,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;IAC5C,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChD;AAED;;;;GAIG;AACH,MAAM,WAAW,iCACf,SAAQ,2BAA2B;IACnC,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,uDAAuD;AACvD,MAAM,WAAW,8BACf,SAAQ,IAAI,CAAC,gCAAgC,EAAE,MAAM,CAAC;IACtD,IAAI,CAAC,EAAE,wBAAwB,CAAC;CACjC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { StreamingAudioFormat, StreamingSessionSettings, StreamingTurnLimit } from './streaming-types.js';
|
|
2
|
+
/** Default per-turn audio cap for providers that need one (`voxtral-realtime`). */
|
|
3
|
+
export declare const DEFAULT_MAX_TURN_SECONDS = 270;
|
|
4
|
+
/** How long before the cap the rollover starts looking for silence. */
|
|
5
|
+
export declare const DEFAULT_ROLLOVER_WINDOW_SECONDS = 15;
|
|
6
|
+
/** RMS level (0-1 of full scale, about -40 dBFS) below which audio is quiet. */
|
|
7
|
+
export declare const DEFAULT_ROLLOVER_SILENCE_THRESHOLD = 0.01;
|
|
8
|
+
/** Quiet audio needed before the rollover commits. */
|
|
9
|
+
export declare const DEFAULT_ROLLOVER_MIN_SILENCE_MS = 300;
|
|
10
|
+
/** A resolved per-turn limit; `undefined` means turns are unbounded. */
|
|
11
|
+
export interface TurnLimit {
|
|
12
|
+
maxTurnSeconds: number;
|
|
13
|
+
/** `false`: writes past the cap reject with `SPEECH_TURN_TOO_LONG`. */
|
|
14
|
+
rollover: boolean;
|
|
15
|
+
windowSeconds: number;
|
|
16
|
+
silenceThreshold: number;
|
|
17
|
+
minSilenceMs: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolves the turn limit from settings, highest priority first (session
|
|
21
|
+
* options, then adapter options, which already carry environment values),
|
|
22
|
+
* falling back to `defaultMaxTurnSeconds`. Returns `undefined` when no limit
|
|
23
|
+
* applies or `maxTurnSeconds` is `Infinity`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveTurnLimit(adapter: string, defaultMaxTurnSeconds: number | undefined, ...settings: Array<Pick<StreamingSessionSettings, 'maxTurnSeconds' | 'rollover'> | undefined>): TurnLimit | undefined;
|
|
26
|
+
/** Bytes of one sample frame (one sample per channel). */
|
|
27
|
+
export declare function blockAlign(format: StreamingAudioFormat): number;
|
|
28
|
+
/** Whole sample frames in `seconds` of audio, as bytes (rounded down). */
|
|
29
|
+
export declare function bytesForSeconds(seconds: number, format: StreamingAudioFormat): number;
|
|
30
|
+
/** Digital silence in `format`: zero samples, encoded. */
|
|
31
|
+
export declare function silence(bytes: number, format: StreamingAudioFormat): Uint8Array;
|
|
32
|
+
/** Bytes of audio one turn may hold: whole sample frames, at least one. */
|
|
33
|
+
export declare function turnCapBytes(limit: TurnLimit, format: StreamingAudioFormat): number;
|
|
34
|
+
/** The public view of a resolved limit for a session format. */
|
|
35
|
+
export declare function describeTurnLimit(limit: TurnLimit | undefined, format: StreamingAudioFormat): StreamingTurnLimit | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Tracks the audio of the current turn and finds rollover points.
|
|
38
|
+
*
|
|
39
|
+
* Feed every chunk in write order to {@link split} (rollover on) or
|
|
40
|
+
* {@link add} (rollover off), and call {@link reset} whenever the turn ends
|
|
41
|
+
* for another reason (a manual commit).
|
|
42
|
+
*/
|
|
43
|
+
export declare class TurnSplitter {
|
|
44
|
+
/** Bytes of the current turn so far. */
|
|
45
|
+
turnBytes: number;
|
|
46
|
+
readonly capBytes: number;
|
|
47
|
+
private readonly windowStartBytes;
|
|
48
|
+
private readonly frameBytes;
|
|
49
|
+
private readonly minSilenceBytes;
|
|
50
|
+
private readonly threshold;
|
|
51
|
+
private readonly encoding;
|
|
52
|
+
private readonly sampleBytes;
|
|
53
|
+
private frameFill;
|
|
54
|
+
private frameSumSquares;
|
|
55
|
+
private frameSamples;
|
|
56
|
+
/** Trailing bytes of a sample split across chunks. */
|
|
57
|
+
private carry;
|
|
58
|
+
/** Consecutive quiet bytes ending at the last complete frame. */
|
|
59
|
+
private quietRun;
|
|
60
|
+
constructor(limit: TurnLimit, format: StreamingAudioFormat);
|
|
61
|
+
/** Ends the current turn: the next byte starts a new one. */
|
|
62
|
+
reset(): void;
|
|
63
|
+
/** Whether `bytes` more would push the current turn past the cap. */
|
|
64
|
+
wouldOverflow(bytes: number): boolean;
|
|
65
|
+
/** Counts `bytes` toward the current turn without analysing them. */
|
|
66
|
+
add(bytes: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Feeds one chunk and returns the offsets inside it where the turn should
|
|
69
|
+
* end (each in `1..chunk.byteLength`, ascending). The splitter resets at
|
|
70
|
+
* each offset, so bytes after it count toward the next turn.
|
|
71
|
+
*/
|
|
72
|
+
split(chunk: Uint8Array): number[];
|
|
73
|
+
private frameIsQuiet;
|
|
74
|
+
private measure;
|
|
75
|
+
private addSample;
|
|
76
|
+
private addSampleAt;
|
|
77
|
+
private addLinear;
|
|
78
|
+
private decodeG711;
|
|
79
|
+
}
|
|
80
|
+
/** G.711 mu-law byte to a 16-bit linear sample (ITU-T G.711). */
|
|
81
|
+
export declare function decodeMuLaw(byte: number): number;
|
|
82
|
+
/** G.711 A-law byte to a 16-bit linear sample (ITU-T G.711). */
|
|
83
|
+
export declare function decodeALaw(byte: number): number;
|
|
84
|
+
//# sourceMappingURL=turn-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-limit.d.ts","sourceRoot":"","sources":["../../src/shared/turn-limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAEV,oBAAoB,EAEpB,wBAAwB,EACxB,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,mFAAmF;AACnF,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,uEAAuE;AACvE,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAClD,gFAAgF;AAChF,eAAO,MAAM,kCAAkC,OAAO,CAAC;AACvD,sDAAsD;AACtD,eAAO,MAAM,+BAA+B,MAAM,CAAC;AAUnD,wEAAwE;AACxE,MAAM,WAAW,SAAS;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,qBAAqB,EAAE,MAAM,GAAG,SAAS,EACzC,GAAG,QAAQ,EAAE,KAAK,CAChB,IAAI,CAAC,wBAAwB,EAAE,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DAA6D;IAC7D,KAAK,IAAI,IAAI;IASb,qEAAqE;IACrE,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIrC,qEAAqE;IACrE,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxB;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IA+ClC,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,OAAO;IAoBf,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,UAAU;CAGnB;AAQD,iEAAiE;AACjE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMhD;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/C"}
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { LocalTranscriberSettings } from '../adapters/local/types.js';
|
|
2
|
+
import { SpeechRetryOptions } from './retry.js';
|
|
3
|
+
import { GetStreamingTranscriberOptions, StreamingTranscriberType } from './streaming-types.js';
|
|
4
|
+
import { SpeechUsage, SpeechUsageCallback } from './usage.js';
|
|
5
|
+
export type { SpeechRetryOptions } from './retry.js';
|
|
6
|
+
export type { SpeechOperation, SpeechUsage, SpeechUsageCallback, } from './usage.js';
|
|
7
|
+
export type SpeechAdapterType = 'studio-server' | 'qwen3-tts' | 'openai-compatible' | 'local' | StreamingTranscriberType;
|
|
8
|
+
/**
|
|
9
|
+
* Request/response transcribers, including wrapped streaming adapters.
|
|
10
|
+
* `local` requires importing `@happyvertical/speech/local` first.
|
|
11
|
+
*/
|
|
12
|
+
export type TranscriberType = 'studio-server' | 'openai-compatible' | 'local' | StreamingTranscriberType;
|
|
3
13
|
export type SpeechSynthesizerType = 'studio-server' | 'qwen3-tts' | 'openai-compatible';
|
|
4
14
|
export interface SpeechAdapterAvailability {
|
|
5
15
|
transcribers: TranscriberType[];
|
|
16
|
+
/** Adapters available through `getStreamingTranscriber()`. */
|
|
17
|
+
streamingTranscribers: StreamingTranscriberType[];
|
|
6
18
|
synthesizers: SpeechSynthesizerType[];
|
|
7
19
|
}
|
|
8
20
|
export type AudioBytes = ArrayBuffer | Uint8Array | Blob;
|
|
21
|
+
/**
|
|
22
|
+
* Raw audio accepted by transcribers. `Buffer` is a `Uint8Array` subclass.
|
|
23
|
+
* Streams are buffered (bounded by `maxBytes`) before upload.
|
|
24
|
+
*/
|
|
25
|
+
export type AudioSource = AudioBytes | ReadableStream<Uint8Array>;
|
|
9
26
|
export interface AudioInput {
|
|
10
|
-
data:
|
|
27
|
+
data: AudioSource;
|
|
28
|
+
/** MIME type, e.g. `audio/webm;codecs=opus`. Alias of `contentType`. */
|
|
29
|
+
mimeType?: string;
|
|
11
30
|
contentType?: string;
|
|
12
31
|
filename?: string;
|
|
13
32
|
sampleRate?: number;
|
|
@@ -37,15 +56,30 @@ export interface TranscriptResult {
|
|
|
37
56
|
provider?: string;
|
|
38
57
|
model?: string;
|
|
39
58
|
raw?: unknown;
|
|
59
|
+
/** Usage for billing/attribution, when the adapter reports it. */
|
|
60
|
+
usage?: SpeechUsage;
|
|
40
61
|
}
|
|
62
|
+
export type TranscriptionResponseFormat = 'json' | 'text' | 'verbose_json';
|
|
63
|
+
export type TimestampGranularity = 'word' | 'segment';
|
|
41
64
|
export interface TranscriptionRequest {
|
|
42
|
-
|
|
65
|
+
/** Audio wrapper, or a bare Blob/Buffer/Uint8Array/ArrayBuffer/ReadableStream. */
|
|
66
|
+
audio: AudioInput | AudioSource;
|
|
67
|
+
/** MIME type for bare audio sources; wins over `AudioInput` and Blob types. */
|
|
68
|
+
mimeType?: string;
|
|
43
69
|
signal?: AbortSignal;
|
|
44
70
|
language?: string;
|
|
45
71
|
model?: string;
|
|
46
72
|
prompt?: string;
|
|
47
73
|
temperature?: number;
|
|
48
|
-
responseFormat?:
|
|
74
|
+
responseFormat?: TranscriptionResponseFormat;
|
|
75
|
+
/** Requested timestamp detail (OpenAI `timestamp_granularities[]`). */
|
|
76
|
+
timestampGranularities?: TimestampGranularity[];
|
|
77
|
+
/** Per-request headers, merged over adapter headers (e.g. a per-tenant `x-bf-vk`). */
|
|
78
|
+
headers?: HeadersInit;
|
|
79
|
+
/** Per-request byte limit; overrides the adapter `maxBytes`. */
|
|
80
|
+
maxBytes?: number;
|
|
81
|
+
/** Per-request usage callback, invoked after any adapter-level `onUsage`. */
|
|
82
|
+
onUsage?: SpeechUsageCallback;
|
|
49
83
|
metadata?: Record<string, unknown>;
|
|
50
84
|
}
|
|
51
85
|
export interface SpeechVoice {
|
|
@@ -109,6 +143,28 @@ export interface StudioServerTranscriberOptions extends HttpSpeechOptions {
|
|
|
109
143
|
type?: 'studio-server';
|
|
110
144
|
transcribePath?: string;
|
|
111
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Options for the OpenAI-compatible transcriber (`POST /audio/transcriptions`).
|
|
148
|
+
* Server-side only: the adapter holds the API key.
|
|
149
|
+
*/
|
|
150
|
+
export interface OpenAICompatibleTranscriberOptions extends HttpSpeechOptions {
|
|
151
|
+
type: 'openai-compatible';
|
|
152
|
+
/**
|
|
153
|
+
* Server root (`https://api.openai.com`), API root (`http://gateway/stt/v1`),
|
|
154
|
+
* or the full endpoint (`.../audio/transcriptions`).
|
|
155
|
+
*/
|
|
156
|
+
baseUrl: string;
|
|
157
|
+
/** Default model. Default `whisper-1`. */
|
|
158
|
+
model?: string;
|
|
159
|
+
/** Default response format. Default `verbose_json` (or `json` for json-only models). */
|
|
160
|
+
responseFormat?: TranscriptionResponseFormat;
|
|
161
|
+
/** Upload limit in bytes. Default 25 MB; `Infinity` disables it. */
|
|
162
|
+
maxBytes?: number;
|
|
163
|
+
/** Retry policy for 429/5xx. Default 2 retries; `false` disables. */
|
|
164
|
+
retry?: SpeechRetryOptions | false;
|
|
165
|
+
/** Called with usage after every successful transcription. */
|
|
166
|
+
onUsage?: SpeechUsageCallback;
|
|
167
|
+
}
|
|
112
168
|
export interface StudioServerSpeechSynthesizerOptions extends HttpSpeechOptions {
|
|
113
169
|
type: 'studio-server';
|
|
114
170
|
synthesizePath?: string;
|
|
@@ -126,8 +182,30 @@ export interface OpenAICompatibleSpeechSynthesizerOptions extends HttpSpeechOpti
|
|
|
126
182
|
defaultModel?: string;
|
|
127
183
|
defaultVoice?: string;
|
|
128
184
|
}
|
|
129
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Transcriber factory options. `local` settings (device, dtype, cacheDir, ...)
|
|
187
|
+
* apply only to `type: 'local'`.
|
|
188
|
+
*/
|
|
189
|
+
export interface GetTranscriberOptions extends Partial<HttpSpeechOptions>, Omit<LocalTranscriberSettings, 'model' | 'maxBytes' | 'onUsage'> {
|
|
130
190
|
type?: TranscriberType;
|
|
191
|
+
/** Studio Server only. */
|
|
192
|
+
transcribePath?: string;
|
|
193
|
+
/** OpenAI-compatible and local. */
|
|
194
|
+
model?: string;
|
|
195
|
+
/** OpenAI-compatible only. */
|
|
196
|
+
responseFormat?: TranscriptionResponseFormat;
|
|
197
|
+
/** OpenAI-compatible and local. */
|
|
198
|
+
maxBytes?: number;
|
|
199
|
+
/** OpenAI-compatible only. */
|
|
200
|
+
retry?: SpeechRetryOptions | false;
|
|
201
|
+
/** OpenAI-compatible, local, and streaming types. */
|
|
202
|
+
onUsage?: SpeechUsageCallback;
|
|
203
|
+
/**
|
|
204
|
+
* Streaming types only (e.g. `openai-realtime`): extra adapter settings such
|
|
205
|
+
* as `turnDetection`, `WebSocket`, or `connectTimeoutMs`. Top-level fields
|
|
206
|
+
* win over these.
|
|
207
|
+
*/
|
|
208
|
+
streaming?: Omit<GetStreamingTranscriberOptions, 'type'>;
|
|
131
209
|
}
|
|
132
210
|
export interface GetSpeechSynthesizerOptions extends Partial<HttpSpeechOptions> {
|
|
133
211
|
type?: SpeechSynthesizerType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GACzB,eAAe,GACf,WAAW,GACX,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EACV,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEnE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,YAAY,EACV,eAAe,EACf,WAAW,EACX,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,iBAAiB,GACzB,eAAe,GACf,WAAW,GACX,mBAAmB,GACnB,OAAO,GACP,wBAAwB,CAAC;AAE7B;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,eAAe,GACf,mBAAmB,GACnB,OAAO,GACP,wBAAwB,CAAC;AAE7B,MAAM,MAAM,qBAAqB,GAC7B,eAAe,GACf,WAAW,GACX,mBAAmB,CAAC;AAExB,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,8DAA8D;IAC9D,qBAAqB,EAAE,wBAAwB,EAAE,CAAC;IAClD,YAAY,EAAE,qBAAqB,EAAE,CAAC;CACvC;AAED,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;AAElE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,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,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,qBACf,SAAQ,OAAO,CAAC,iBAAiB,CAAC,EAChC,IAAI,CAAC,wBAAwB,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC;IAClE,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,0BAA0B;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,cAAc,CAAC,EAAE,2BAA2B,CAAC;IAC7C,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,kBAAkB,GAAG,KAAK,CAAC;IACnC,qDAAqD;IACrD,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,8BAA8B,EAAE,MAAM,CAAC,CAAC;CAC1D;AAED,MAAM,WAAW,2BACf,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IAClC,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,qBAAqB,GAAG,KAAK,CAAC;IAC5C,WAAW,CAAC,EAAE,2BAA2B,GAAG,KAAK,CAAC;CACnD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage reporting shared by speech adapters.
|
|
3
|
+
*
|
|
4
|
+
* Adapters attach a {@link SpeechUsage} record to their results and call the
|
|
5
|
+
* optional {@link SpeechUsageCallback} so callers can attribute each provider
|
|
6
|
+
* call (for example to a tenant for billing).
|
|
7
|
+
*/
|
|
8
|
+
export type SpeechOperation = 'transcription' | 'synthesis';
|
|
9
|
+
export interface SpeechUsage {
|
|
10
|
+
/** Operation that produced this usage record. */
|
|
11
|
+
operation: SpeechOperation;
|
|
12
|
+
/** Adapter type that made the provider call, e.g. `openai-compatible`. */
|
|
13
|
+
provider: string;
|
|
14
|
+
/** Model identifier sent to (or reported by) the provider. */
|
|
15
|
+
model?: string;
|
|
16
|
+
/** Audio duration in seconds, when the provider or caller reports it. */
|
|
17
|
+
audioSeconds?: number;
|
|
18
|
+
/** Size of the audio payload in bytes (uploaded for STT, received for TTS). */
|
|
19
|
+
bytes?: number;
|
|
20
|
+
/** Provider usage block, passed through untouched (e.g. OpenAI `usage`). */
|
|
21
|
+
providerUsage?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export type SpeechUsageCallback = (usage: SpeechUsage) => void | Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Invokes every configured usage callback in order (adapter-level first, then
|
|
26
|
+
* request-level). Callback errors propagate to the caller so that billing
|
|
27
|
+
* hooks never fail silently.
|
|
28
|
+
*/
|
|
29
|
+
export declare function reportSpeechUsage(usage: SpeechUsage, ...callbacks: Array<SpeechUsageCallback | undefined>): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Extracts audio seconds from an OpenAI-style `usage` block
|
|
32
|
+
* (`{ type: 'duration', seconds }`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function audioSecondsFromProviderUsage(providerUsage: Record<string, unknown> | undefined): number | undefined;
|
|
35
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/shared/usage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG,WAAW,CAAC;AAE5D,MAAM,WAAW,WAAW;IAC1B,iDAAiD;IACjD,SAAS,EAAE,eAAe,CAAC;IAC3B,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/E;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,WAAW,EAClB,GAAG,SAAS,EAAE,KAAK,CAAC,mBAAmB,GAAG,SAAS,CAAC,GACnD,OAAO,CAAC,IAAI,CAAC,CAMf;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GACjD,MAAM,GAAG,SAAS,CASpB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal WebSocket surface used by streaming adapters. Browser, Node 22+
|
|
3
|
+
* (`globalThis.WebSocket`), Deno, Bun, and the `ws` package all satisfy it.
|
|
4
|
+
*/
|
|
5
|
+
/** `WebSocket.OPEN`. */
|
|
6
|
+
export declare const WEBSOCKET_OPEN = 1;
|
|
7
|
+
export interface SpeechWebSocketMessageEvent {
|
|
8
|
+
data: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface SpeechWebSocketCloseEvent {
|
|
11
|
+
code?: number;
|
|
12
|
+
reason?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The subset of the WHATWG `WebSocket` interface the adapters use. */
|
|
15
|
+
export interface SpeechWebSocket {
|
|
16
|
+
readonly readyState: number;
|
|
17
|
+
readonly bufferedAmount: number;
|
|
18
|
+
binaryType?: string;
|
|
19
|
+
send(data: string): void;
|
|
20
|
+
close(code?: number, reason?: string): void;
|
|
21
|
+
addEventListener(type: 'open', listener: (event: unknown) => void): void;
|
|
22
|
+
addEventListener(type: 'message', listener: (event: SpeechWebSocketMessageEvent) => void): void;
|
|
23
|
+
addEventListener(type: 'error', listener: (event: unknown) => void): void;
|
|
24
|
+
addEventListener(type: 'close', listener: (event: SpeechWebSocketCloseEvent) => void): void;
|
|
25
|
+
}
|
|
26
|
+
/** Handshake details passed to a {@link SpeechWebSocketFactory}. */
|
|
27
|
+
export interface SpeechWebSocketInit {
|
|
28
|
+
protocols: string[];
|
|
29
|
+
/** Handshake headers; empty in browsers. */
|
|
30
|
+
headers: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
export type SpeechWebSocketFactory = (url: string, init: SpeechWebSocketInit) => SpeechWebSocket;
|
|
33
|
+
/**
|
|
34
|
+
* A WebSocket constructor. Standard constructors accept `protocols`; Node's
|
|
35
|
+
* built-in WebSocket also accepts `{ protocols, headers }`.
|
|
36
|
+
*/
|
|
37
|
+
export type SpeechWebSocketConstructor = new (url: string, protocols?: string | string[] | {
|
|
38
|
+
protocols?: string[];
|
|
39
|
+
headers?: Record<string, string>;
|
|
40
|
+
}) => SpeechWebSocket;
|
|
41
|
+
/** True in browsers and web workers, where API keys must never be used. */
|
|
42
|
+
export declare function isBrowserRuntime(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves a socket factory from explicit options, falling back to
|
|
45
|
+
* `globalThis.WebSocket`. Headers are only passed when present, so standard
|
|
46
|
+
* constructors that cannot send them are never handed an options object.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveWebSocketFactory(adapter: string, options: {
|
|
49
|
+
createWebSocket?: SpeechWebSocketFactory;
|
|
50
|
+
WebSocket?: SpeechWebSocketConstructor;
|
|
51
|
+
}): SpeechWebSocketFactory;
|
|
52
|
+
/** Converts `http(s)://` to `ws(s)://`; leaves `ws(s)://` unchanged. */
|
|
53
|
+
export declare function toWebSocketUrl(url: string, adapter: string): string;
|
|
54
|
+
/** Converts a message payload to text; returns `undefined` for unsupported data. */
|
|
55
|
+
export declare function messageDataToText(data: unknown): string | undefined;
|
|
56
|
+
//# sourceMappingURL=websocket.d.ts.map
|