@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,240 @@
|
|
|
1
|
+
import { StreamingAudioChunk, StreamingAudioFormat, StreamingSession, StreamingSessionEventName, StreamingSessionListener, StreamingSessionState, StreamingTurnDetection } from './streaming-types.js';
|
|
2
|
+
import { TurnLimit } from './turn-limit.js';
|
|
3
|
+
import { TranscriptResult } from './types.js';
|
|
4
|
+
import { SpeechUsageCallback } from './usage.js';
|
|
5
|
+
import { SpeechWebSocketFactory } from './websocket.js';
|
|
6
|
+
export declare const DEFAULT_STREAMING_TIMEOUT_MS = 30000;
|
|
7
|
+
export declare const DEFAULT_STREAMING_CONNECT_TIMEOUT_MS = 10000;
|
|
8
|
+
export declare const DEFAULT_STREAMING_HIGH_WATER_MARK: number;
|
|
9
|
+
export declare const DEFAULT_STREAMING_MAX_BUFFERED_BYTES: number;
|
|
10
|
+
/** Normalised events a protocol parser returns for one server message. */
|
|
11
|
+
export type RealtimeProtocolEvent = {
|
|
12
|
+
type: 'session';
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
}
|
|
15
|
+
/** The provider committed a turn (from a client commit or server VAD). */
|
|
16
|
+
| {
|
|
17
|
+
type: 'committed';
|
|
18
|
+
itemId?: string;
|
|
19
|
+
}
|
|
20
|
+
/** The provider rejected a commit because its buffer was empty. Not fatal. */
|
|
21
|
+
| {
|
|
22
|
+
type: 'commit_empty';
|
|
23
|
+
} | {
|
|
24
|
+
type: 'partial';
|
|
25
|
+
itemId?: string;
|
|
26
|
+
delta: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'final';
|
|
29
|
+
itemId?: string;
|
|
30
|
+
text: string;
|
|
31
|
+
providerUsage?: Record<string, unknown>;
|
|
32
|
+
raw?: unknown;
|
|
33
|
+
/**
|
|
34
|
+
* `false` when the provider reports that the turn consumed no audio
|
|
35
|
+
* (vLLM: `usage.prompt_tokens <= 1`). A turn that was sent audio but
|
|
36
|
+
* consumed none means the provider's turn state is out of sync, and the
|
|
37
|
+
* session fails instead of silently dropping that audio.
|
|
38
|
+
*/
|
|
39
|
+
audioConsumed?: boolean;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'speech_started';
|
|
42
|
+
itemId?: string;
|
|
43
|
+
audioMs?: number;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'speech_stopped';
|
|
46
|
+
itemId?: string;
|
|
47
|
+
audioMs?: number;
|
|
48
|
+
}
|
|
49
|
+
/** A fatal provider error. */
|
|
50
|
+
| {
|
|
51
|
+
type: 'error';
|
|
52
|
+
message: string;
|
|
53
|
+
code?: string;
|
|
54
|
+
raw?: unknown;
|
|
55
|
+
};
|
|
56
|
+
/** Resolved per-session settings handed to the protocol. */
|
|
57
|
+
export interface RealtimeSessionConfig {
|
|
58
|
+
model: string;
|
|
59
|
+
format: StreamingAudioFormat;
|
|
60
|
+
turnDetection: StreamingTurnDetection;
|
|
61
|
+
language?: string;
|
|
62
|
+
prompt?: string;
|
|
63
|
+
}
|
|
64
|
+
/** Wire format of one realtime provider. */
|
|
65
|
+
export interface RealtimeProtocol {
|
|
66
|
+
/** Adapter name used for errors and usage, e.g. `openai-realtime`. */
|
|
67
|
+
readonly provider: string;
|
|
68
|
+
/**
|
|
69
|
+
* How a client commit is acknowledged: by a `committed` event (OpenAI), or
|
|
70
|
+
* only by the turn's `final` event (servers without a commit ack).
|
|
71
|
+
*/
|
|
72
|
+
readonly commitAck: 'committed' | 'final';
|
|
73
|
+
/**
|
|
74
|
+
* Whether `end()` commits only when uncommitted audio remains
|
|
75
|
+
* (`if-audio`), or always sends a final commit (`always`, for servers that
|
|
76
|
+
* need an explicit end-of-stream marker).
|
|
77
|
+
*/
|
|
78
|
+
readonly endCommit: 'if-audio' | 'always';
|
|
79
|
+
/**
|
|
80
|
+
* Default per-turn audio cap in seconds, for providers whose model context
|
|
81
|
+
* covers one turn (vLLM resets it after each final commit). Adapters pass
|
|
82
|
+
* it to `resolveTurnLimit()`; a session with a turn limit rolls over to a
|
|
83
|
+
* new turn before the cap, or rejects writes past it. Unset: no default.
|
|
84
|
+
*/
|
|
85
|
+
readonly maxTurnSeconds?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Shortest audio, in seconds, the provider accepts in one commit (OpenAI:
|
|
88
|
+
* 100 ms; shorter commits are rejected as empty). A session with a turn
|
|
89
|
+
* limit pads a shorter, non-empty turn with silence before committing it,
|
|
90
|
+
* so the tail left after a rollover is transcribed instead of dropped.
|
|
91
|
+
*/
|
|
92
|
+
readonly minCommitSeconds?: number;
|
|
93
|
+
/** Messages sent once the socket opens (session configuration). */
|
|
94
|
+
sessionMessages(config: RealtimeSessionConfig): unknown[];
|
|
95
|
+
/** One audio chunk, already base64-encoded. */
|
|
96
|
+
appendMessage(base64Audio: string): unknown;
|
|
97
|
+
/** Ends the current turn. `final` is true for the commit sent by `end()`. */
|
|
98
|
+
commitMessage(options: {
|
|
99
|
+
final: boolean;
|
|
100
|
+
}): unknown;
|
|
101
|
+
/**
|
|
102
|
+
* Opens a turn before its first audio, for servers that only start
|
|
103
|
+
* generating after an explicit start signal (vLLM's non-final
|
|
104
|
+
* `input_audio_buffer.commit`). When set, the session sends it before the
|
|
105
|
+
* first append of every turn, and holds audio written after a commit until
|
|
106
|
+
* every outstanding turn has been acknowledged, so a server that resets its
|
|
107
|
+
* buffer between turns never drops audio.
|
|
108
|
+
*/
|
|
109
|
+
turnStartMessage?(): unknown;
|
|
110
|
+
/** Maps one parsed JSON server message to zero or more events. */
|
|
111
|
+
parse(message: unknown): RealtimeProtocolEvent[];
|
|
112
|
+
}
|
|
113
|
+
/** Where and how to open the socket; resolved per session. */
|
|
114
|
+
export interface RealtimeConnection {
|
|
115
|
+
url: string;
|
|
116
|
+
protocols: string[];
|
|
117
|
+
headers: Record<string, string>;
|
|
118
|
+
/** Credentials to redact from surfaced provider text. */
|
|
119
|
+
secrets: string[];
|
|
120
|
+
}
|
|
121
|
+
export interface RealtimeSessionInit {
|
|
122
|
+
protocol: RealtimeProtocol;
|
|
123
|
+
config: RealtimeSessionConfig;
|
|
124
|
+
/** Resolves the connection (may mint a short-lived token). */
|
|
125
|
+
connect: () => Promise<RealtimeConnection>;
|
|
126
|
+
createWebSocket: SpeechWebSocketFactory;
|
|
127
|
+
timeoutMs: number;
|
|
128
|
+
connectTimeoutMs: number;
|
|
129
|
+
highWaterMark: number;
|
|
130
|
+
maxBufferedBytes: number;
|
|
131
|
+
signal?: AbortSignal;
|
|
132
|
+
/** Called in order with the aggregated usage when `end()` succeeds. */
|
|
133
|
+
onUsage: Array<SpeechUsageCallback | undefined>;
|
|
134
|
+
/** Per-turn audio limit; unset means turns are unbounded. */
|
|
135
|
+
turnLimit?: TurnLimit;
|
|
136
|
+
}
|
|
137
|
+
export declare class RealtimeTranscriptionSession implements StreamingSession {
|
|
138
|
+
state: StreamingSessionState;
|
|
139
|
+
sessionId?: string;
|
|
140
|
+
readonly ready: Promise<void>;
|
|
141
|
+
private readonly init;
|
|
142
|
+
private readonly provider;
|
|
143
|
+
private resolveReady;
|
|
144
|
+
private rejectReady;
|
|
145
|
+
private socket?;
|
|
146
|
+
private opened;
|
|
147
|
+
private secrets;
|
|
148
|
+
private queue;
|
|
149
|
+
private queued;
|
|
150
|
+
private pumping;
|
|
151
|
+
private totalBytes;
|
|
152
|
+
private uncommittedBytes;
|
|
153
|
+
private outstandingCommits;
|
|
154
|
+
/** Per outstanding commit, in order: whether it carried audio. */
|
|
155
|
+
private readonly commitHadAudio;
|
|
156
|
+
private turnOpen;
|
|
157
|
+
/** `Date.now()` of the last server message; bounds inactivity waits. */
|
|
158
|
+
private lastServerMessageAt;
|
|
159
|
+
private readonly itemOrder;
|
|
160
|
+
private readonly pendingItems;
|
|
161
|
+
private readonly vadStoppedItems;
|
|
162
|
+
private readonly partials;
|
|
163
|
+
private readonly finals;
|
|
164
|
+
private readonly listeners;
|
|
165
|
+
private error?;
|
|
166
|
+
private endPromise?;
|
|
167
|
+
private endWaiter?;
|
|
168
|
+
private connectTimer?;
|
|
169
|
+
private endTimer?;
|
|
170
|
+
private closeEmitted;
|
|
171
|
+
/** Measures the current turn in write order when a turn limit applies. */
|
|
172
|
+
private readonly splitter?;
|
|
173
|
+
private readonly onAbort;
|
|
174
|
+
constructor(init: RealtimeSessionInit);
|
|
175
|
+
get queuedBytes(): number;
|
|
176
|
+
write(chunk: StreamingAudioChunk): Promise<void>;
|
|
177
|
+
commit(): void;
|
|
178
|
+
end(): Promise<TranscriptResult>;
|
|
179
|
+
/**
|
|
180
|
+
* (Re)starts the end timeout. It measures provider inactivity: every server
|
|
181
|
+
* message restarts it, so a long recording that is still being transcribed
|
|
182
|
+
* is not cut off, while a silent provider still fails after `timeoutMs`.
|
|
183
|
+
*/
|
|
184
|
+
private armEndTimer;
|
|
185
|
+
abort(reason?: unknown): void;
|
|
186
|
+
on<E extends StreamingSessionEventName>(event: E, listener: StreamingSessionListener<E>): () => void;
|
|
187
|
+
off<E extends StreamingSessionEventName>(event: E, listener: StreamingSessionListener<E>): void;
|
|
188
|
+
private enqueueAudio;
|
|
189
|
+
private connect;
|
|
190
|
+
private onOpen;
|
|
191
|
+
private onMessage;
|
|
192
|
+
private handle;
|
|
193
|
+
/** Acknowledges the oldest outstanding commit; returns whether it carried audio. */
|
|
194
|
+
private ackCommit;
|
|
195
|
+
private pump;
|
|
196
|
+
private sendCommit;
|
|
197
|
+
/**
|
|
198
|
+
* In a session with a turn limit, tops up a non-empty turn shorter than the
|
|
199
|
+
* protocol's `minCommitSeconds` with silence (not counted as streamed
|
|
200
|
+
* audio). Rollover can leave such a tail, which the provider would
|
|
201
|
+
* otherwise reject as empty and drop. Returns false when the send failed.
|
|
202
|
+
*/
|
|
203
|
+
private padShortTurn;
|
|
204
|
+
/**
|
|
205
|
+
* For protocols with an explicit turn start: before the next audio, waits
|
|
206
|
+
* for every outstanding turn to be acknowledged, then opens a new turn. Like
|
|
207
|
+
* the end timeout, the wait is bounded by provider inactivity: it fails only
|
|
208
|
+
* after `timeoutMs` without any server message. Returns false when the
|
|
209
|
+
* session has failed.
|
|
210
|
+
*/
|
|
211
|
+
private openTurnIfNeeded;
|
|
212
|
+
/**
|
|
213
|
+
* Waits until the socket's send buffer is at or below `highWaterMark`. A
|
|
214
|
+
* socket that stays congested for `timeoutMs` fails the session, so a
|
|
215
|
+
* stalled connection can never leave `write()` pending forever.
|
|
216
|
+
*/
|
|
217
|
+
private waitForDrain;
|
|
218
|
+
private send;
|
|
219
|
+
private checkEnded;
|
|
220
|
+
private finish;
|
|
221
|
+
private rank;
|
|
222
|
+
private onClose;
|
|
223
|
+
private fail;
|
|
224
|
+
private cleanup;
|
|
225
|
+
private closeSocket;
|
|
226
|
+
private emit;
|
|
227
|
+
private isTerminal;
|
|
228
|
+
private redact;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Throws when a turn cap is below the provider's minimum commit length:
|
|
232
|
+
* padding a short turn up to that minimum would then exceed the cap.
|
|
233
|
+
*/
|
|
234
|
+
export declare function assertTurnLimitFitsProtocol(protocol: Pick<RealtimeProtocol, 'provider' | 'minCommitSeconds'>, limit: Pick<TurnLimit, 'maxTurnSeconds'> | undefined): void;
|
|
235
|
+
/**
|
|
236
|
+
* Sums numeric fields of per-turn provider usage blocks (recursively), keeping
|
|
237
|
+
* the first value of non-numeric fields such as `type`.
|
|
238
|
+
*/
|
|
239
|
+
export declare function sumUsage(blocks: Array<Record<string, unknown> | undefined>): Record<string, unknown> | undefined;
|
|
240
|
+
//# sourceMappingURL=realtime-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime-session.d.ts","sourceRoot":"","sources":["../../src/shared/realtime-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,yBAAyB,EAEzB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,YAAY,CAAC;AACtE,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAIL,KAAK,sBAAsB,EAC5B,MAAM,gBAAgB,CAAC;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IACpF,OAAO,CAAC,SAAS;YAKH,IAAI;IA6ClB,OAAO,CAAC,UAAU;IAelB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IA2BpB;;;;;;OAMG;YACW,gBAAgB;IA2B9B;;;;OAIG;YACW,YAAY;IAoB1B,OAAO,CAAC,IAAI;IAUZ,OAAO,CAAC,UAAU;YAmBJ,MAAM;IA4CpB,OAAO,CAAC,IAAI;IAKZ,OAAO,CAAC,OAAO;IAoBf,OAAO,CAAC,IAAI;IAwBZ,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,IAAI;IAgBZ,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,MAAM;CAOf;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,kBAAkB,CAAC,EACjE,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,GAAG,SAAS,GACnD,IAAI,CAQN;AAaD;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,GACjD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA0BrC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SpeechFactoryContext } from './factory.js';
|
|
2
|
+
import { GetTranscriberOptions, Transcriber, TranscriberType } from './types.js';
|
|
3
|
+
export type OptionalTranscriberFactory = (options: GetTranscriberOptions, context: SpeechFactoryContext) => Transcriber | Promise<Transcriber>;
|
|
4
|
+
export declare function registerOptionalTranscriber(type: TranscriberType, factory: OptionalTranscriberFactory): void;
|
|
5
|
+
export declare function getOptionalTranscriberFactory(type: string): OptionalTranscriberFactory | undefined;
|
|
6
|
+
/** Subpath that registers `type`, when it is an opt-in adapter. */
|
|
7
|
+
export declare function optionalTranscriberEntry(type: string): string | undefined;
|
|
8
|
+
export declare function registeredOptionalTranscribers(): TranscriberType[];
|
|
9
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/shared/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EACV,qBAAqB,EACrB,WAAW,EACX,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,0BAA0B,GAAG,CACvC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,oBAAoB,KAC1B,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AASxC,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,0BAA0B,GAClC,IAAI,CAEN;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,GACX,0BAA0B,GAAG,SAAS,CAExC;AAED,mEAAmE;AACnE,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEzE;AAED,wBAAgB,8BAA8B,IAAI,eAAe,EAAE,CAElE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry with exponential backoff for speech provider calls. Retries only
|
|
3
|
+
* rate-limit (429) and server (5xx) responses, honours `Retry-After`, and
|
|
4
|
+
* stops immediately when the caller aborts.
|
|
5
|
+
*/
|
|
6
|
+
export interface SpeechRetryOptions {
|
|
7
|
+
/** Retries after the first attempt. Default `2`. `0` disables retries. */
|
|
8
|
+
maxRetries?: number;
|
|
9
|
+
/** First backoff delay in milliseconds. Default `500`. */
|
|
10
|
+
initialDelayMs?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Upper bound for any single wait in milliseconds. Default `30000`. A
|
|
13
|
+
* `Retry-After` longer than this ends retrying rather than retrying early.
|
|
14
|
+
*/
|
|
15
|
+
maxDelayMs?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const DEFAULT_SPEECH_RETRY: Required<SpeechRetryOptions>;
|
|
18
|
+
export declare function resolveRetryOptions(retry: SpeechRetryOptions | false | undefined, defaults?: Required<SpeechRetryOptions> | false): Required<SpeechRetryOptions> | false;
|
|
19
|
+
export declare function isRetryableStatus(status: number | undefined): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Parses a `Retry-After` header (delta-seconds or HTTP-date) into
|
|
22
|
+
* milliseconds. Returns `undefined` when absent or unparseable.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseRetryAfter(value: string | null | undefined, now?: number): number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Runs `attempt` until it succeeds, throws a non-retryable error, or the
|
|
27
|
+
* retry budget is exhausted. Retryable errors are {@link SpeechProviderError}
|
|
28
|
+
* instances whose `status` is 429 or 5xx.
|
|
29
|
+
*/
|
|
30
|
+
export declare function withSpeechRetry<T>(attempt: (attemptNumber: number) => Promise<T>, retry: Required<SpeechRetryOptions> | false, signal?: AbortSignal): Promise<T>;
|
|
31
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/shared/retry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,kBAAkB,CAI7D,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,kBAAkB,GAAG,KAAK,GAAG,SAAS,EAC7C,QAAQ,GAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,KAA4B,GACpE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,KAAK,CAyBtC;AAwBD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAErE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,GAAG,GAAE,MAAmB,GACvB,MAAM,GAAG,SAAS,CAYpB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,OAAO,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9C,KAAK,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG,KAAK,EAC3C,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CA6BZ"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { SpeechEnv } from './env.js';
|
|
2
|
+
import { OpenAIRealtimeTranscriberOptions, StreamingAudioFormat, StreamingTranscriberType, StreamingTurnDetection } from './streaming-types.js';
|
|
3
|
+
import { SpeechFetch } from './types.js';
|
|
4
|
+
/** Default client-secret lifetime: long enough to connect, short if leaked. */
|
|
5
|
+
export declare const DEFAULT_CLIENT_SECRET_TTL_SECONDS = 60;
|
|
6
|
+
/** OpenAI's accepted `expires_after.seconds` range. */
|
|
7
|
+
export declare const CLIENT_SECRET_TTL_RANGE: {
|
|
8
|
+
readonly min: 10;
|
|
9
|
+
readonly max: 7200;
|
|
10
|
+
};
|
|
11
|
+
export interface CreateStreamingClientSecretOptions {
|
|
12
|
+
/** Streaming adapter. Default `HAVE_SPEECH_STREAMING_TYPE`, then `openai-realtime`. */
|
|
13
|
+
type?: StreamingTranscriberType;
|
|
14
|
+
/** Long-lived server key. Default `HAVE_SPEECH_STREAMING_API_KEY`. */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/**
|
|
17
|
+
* API base. Accepts the same values as the streaming adapter
|
|
18
|
+
* (`https://api.openai.com`, `…/v1`, or `wss://…/v1/realtime`). Default
|
|
19
|
+
* `HAVE_SPEECH_STREAMING_BASE_URL`, then `https://api.openai.com/v1`.
|
|
20
|
+
*/
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
/** Secret lifetime in seconds, 10–7200. Default 60. */
|
|
23
|
+
ttlSeconds?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Tenant the secret is minted for. Echoed in the result for your usage
|
|
26
|
+
* ledger; OpenAI's transcription client secrets carry no attribution field.
|
|
27
|
+
*/
|
|
28
|
+
tenantId?: string;
|
|
29
|
+
/** Your session id (e.g. the dictation session), echoed in the result. */
|
|
30
|
+
sessionId?: string;
|
|
31
|
+
/** Extra attribution echoed in the result. Never sent to the provider. */
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
/** Transcription model the secret is bound to. Default `HAVE_SPEECH_STREAMING_MODEL`, then `gpt-4o-transcribe`. */
|
|
34
|
+
model?: string;
|
|
35
|
+
language?: string;
|
|
36
|
+
prompt?: string;
|
|
37
|
+
/** Default `HAVE_SPEECH_STREAMING_TURN_DETECTION`, then `server_vad`. */
|
|
38
|
+
turnDetection?: StreamingTurnDetection;
|
|
39
|
+
/** Default PCM16 24 kHz mono. */
|
|
40
|
+
format?: Partial<StreamingAudioFormat>;
|
|
41
|
+
noiseReduction?: OpenAIRealtimeTranscriberOptions['noiseReduction'];
|
|
42
|
+
include?: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Extra `transcription` fields. The typed `model`, `language`, and `prompt`
|
|
45
|
+
* take precedence, so the secret is bound to the model the result reports.
|
|
46
|
+
*/
|
|
47
|
+
transcriptionOptions?: Record<string, unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* Headers for the mint request, e.g. a per-tenant gateway virtual key
|
|
50
|
+
* (`x-bf-vk`) for provider-side attribution. Merged over
|
|
51
|
+
* `HAVE_SPEECH_STREAMING_HEADERS`.
|
|
52
|
+
*/
|
|
53
|
+
headers?: HeadersInit;
|
|
54
|
+
fetch?: SpeechFetch;
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
/** Request timeout. Default `HAVE_SPEECH_STREAMING_TIMEOUT[_MS]`, then 10000. */
|
|
57
|
+
timeoutMs?: number;
|
|
58
|
+
}
|
|
59
|
+
/** A minted browser credential plus the attribution it was minted for. */
|
|
60
|
+
export interface StreamingClientSecretResult {
|
|
61
|
+
type: StreamingTranscriberType;
|
|
62
|
+
/** The short-lived secret. Send it to the browser as `clientSecret`. */
|
|
63
|
+
value: string;
|
|
64
|
+
/** Expiry as epoch milliseconds. */
|
|
65
|
+
expiresAt: number;
|
|
66
|
+
ttlSeconds: number;
|
|
67
|
+
model: string;
|
|
68
|
+
tenantId?: string;
|
|
69
|
+
sessionId?: string;
|
|
70
|
+
metadata?: Record<string, unknown>;
|
|
71
|
+
/** The provider's echoed session config. */
|
|
72
|
+
session?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
export interface StreamingClientSecretContext {
|
|
75
|
+
env?: SpeechEnv;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Mints a short-lived, session-scoped client secret for browser streaming.
|
|
79
|
+
* Server-side only: throws in a browser runtime, and for adapters without an
|
|
80
|
+
* ephemeral-token mechanism (`voxtral-realtime`).
|
|
81
|
+
*/
|
|
82
|
+
export declare function createStreamingClientSecret(options?: CreateStreamingClientSecretOptions, context?: StreamingClientSecretContext): Promise<StreamingClientSecretResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Resolves the client-secret endpoint from any accepted realtime base:
|
|
85
|
+
* `ws(s)` becomes `http(s)`, a trailing `/realtime` and query are dropped,
|
|
86
|
+
* then `/v1/realtime/client_secrets` (or `/realtime/client_secrets` under a
|
|
87
|
+
* versioned root) is appended.
|
|
88
|
+
*/
|
|
89
|
+
export declare function resolveClientSecretUrl(baseUrl: string): string;
|
|
90
|
+
//# sourceMappingURL=streaming-client-secret.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-client-secret.d.ts","sourceRoot":"","sources":["../../src/shared/streaming-client-secret.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAQH,OAAO,EAML,KAAK,SAAS,EACf,MAAM,UAAU,CAAC;AAiBlB,OAAO,KAAK,EACV,gCAAgC,EAChC,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,+EAA+E;AAC/E,eAAO,MAAM,iCAAiC,KAAK,CAAC;AACpD,uDAAuD;AACvD,eAAO,MAAM,uBAAuB;;;CAAkC,CAAC;AAEvE,MAAM,WAAW,kCAAkC;IACjD,uFAAuF;IACvF,IAAI,CAAC,EAAE,wBAAwB,CAAC;IAChC,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,mHAAmH;IACnH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC,iCAAiC;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACvC,cAAc,CAAC,EAAE,gCAAgC,CAAC,gBAAgB,CAAC,CAAC;IACpE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C;;;;OAIG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,0EAA0E;AAC1E,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,wBAAwB,CAAC;IAC/B,wEAAwE;IACxE,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,4BAA4B;IAC3C,GAAG,CAAC,EAAE,SAAS,CAAC;CACjB;AAID;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,GAAE,kCAAuC,EAChD,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,2BAA2B,CAAC,CAuHtC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAc9D"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { SpeechEnv } from './env.js';
|
|
2
|
+
import { GetStreamingTranscriberOptions, StreamingTranscriber, StreamingTranscriberType, StreamingTurnDetection } from './streaming-types.js';
|
|
3
|
+
import { Transcriber } from './types.js';
|
|
4
|
+
/** Streaming adapters `getStreamingTranscriber()` can build. */
|
|
5
|
+
export declare const STREAMING_TRANSCRIBER_TYPES: readonly StreamingTranscriberType[];
|
|
6
|
+
/** Environment variable names read for each streaming setting, in priority order. */
|
|
7
|
+
export declare const STREAMING_TRANSCRIBER_ENV_KEYS: {
|
|
8
|
+
readonly type: readonly ["HAVE_SPEECH_STREAMING_TYPE"];
|
|
9
|
+
readonly baseUrl: readonly ["HAVE_SPEECH_STREAMING_BASE_URL"];
|
|
10
|
+
readonly model: readonly ["HAVE_SPEECH_STREAMING_MODEL"];
|
|
11
|
+
readonly apiKey: readonly ["HAVE_SPEECH_STREAMING_API_KEY"];
|
|
12
|
+
readonly language: readonly ["HAVE_SPEECH_STREAMING_LANGUAGE"];
|
|
13
|
+
readonly turnDetection: readonly ["HAVE_SPEECH_STREAMING_TURN_DETECTION"];
|
|
14
|
+
readonly timeoutMs: readonly ["HAVE_SPEECH_STREAMING_TIMEOUT", "HAVE_SPEECH_STREAMING_TIMEOUT_MS"];
|
|
15
|
+
readonly connectTimeoutMs: readonly ["HAVE_SPEECH_STREAMING_CONNECT_TIMEOUT_MS"];
|
|
16
|
+
readonly headers: readonly ["HAVE_SPEECH_STREAMING_HEADERS"];
|
|
17
|
+
readonly maxTurnSeconds: readonly ["HAVE_SPEECH_STREAMING_MAX_TURN_SECONDS"];
|
|
18
|
+
};
|
|
19
|
+
export interface StreamingFactoryContext {
|
|
20
|
+
env?: SpeechEnv;
|
|
21
|
+
/** Headers merged under explicit `headers` (env → context → options). */
|
|
22
|
+
headers?: HeadersInit;
|
|
23
|
+
}
|
|
24
|
+
export declare function isStreamingTranscriberType(type: string | undefined): type is StreamingTranscriberType;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a realtime streaming transcriber. Explicit options win over
|
|
27
|
+
* `HAVE_SPEECH_STREAMING_*` environment variables. The type defaults to
|
|
28
|
+
* `openai-realtime`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getStreamingTranscriber(options?: GetStreamingTranscriberOptions, context?: StreamingFactoryContext): StreamingTranscriber;
|
|
31
|
+
export declare function parseTurnDetection(value: string | undefined): StreamingTurnDetection | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Parses `HAVE_SPEECH_STREAMING_MAX_TURN_SECONDS`: a positive number of
|
|
34
|
+
* seconds, or `Infinity` for no limit.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseMaxTurnSeconds(value: string | undefined): number | undefined;
|
|
37
|
+
export interface StreamingTranscriberWrapperOptions {
|
|
38
|
+
/** Bytes per `write()`. Default 64 KiB. */
|
|
39
|
+
chunkBytes?: number;
|
|
40
|
+
/** Upload limit in bytes. Default 25 MB; `Infinity` disables it. */
|
|
41
|
+
maxBytes?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Turn detection for wrapped sessions. Default `manual`: the whole clip is
|
|
44
|
+
* one turn, committed by `end()`.
|
|
45
|
+
*/
|
|
46
|
+
turnDetection?: StreamingTurnDetection;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Adapts a streaming transcriber to the request/response `Transcriber`
|
|
50
|
+
* interface for record-then-send callers. Each `transcribe()` opens one
|
|
51
|
+
* session, streams the recording, and returns `session.end()`.
|
|
52
|
+
*
|
|
53
|
+
* Input must be raw audio: a PCM16/G.711 WAV file, `audio/pcm` or
|
|
54
|
+
* `audio/L16` (optionally with `rate`/`channels` parameters), `audio/pcmu`,
|
|
55
|
+
* `audio/pcma`, or untyped bytes in the adapter's default format. WAV headers
|
|
56
|
+
* and MIME parameters set the session format; compressed recordings are
|
|
57
|
+
* rejected, so use an HTTP transcriber for WebM/MP4/Ogg.
|
|
58
|
+
*
|
|
59
|
+
* A clip longer than the adapter's per-turn limit (`maxTurnSeconds`) is
|
|
60
|
+
* never sent as one turn: with rollover (the default) the session splits it
|
|
61
|
+
* into several turns at quiet boundaries, and with `rollover: false` the clip
|
|
62
|
+
* is rejected with `SPEECH_TURN_TOO_LONG` before connecting.
|
|
63
|
+
*/
|
|
64
|
+
export declare function wrapStreamingTranscriber(streaming: StreamingTranscriber, options?: StreamingTranscriberWrapperOptions): Transcriber;
|
|
65
|
+
//# sourceMappingURL=streaming-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-factory.d.ts","sourceRoot":"","sources":["../../src/shared/streaming-factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAML,KAAK,SAAS,EACf,MAAM,UAAU,CAAC;AAOlB,OAAO,KAAK,EACV,8BAA8B,EAE9B,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,WAAW,EAGZ,MAAM,YAAY,CAAC;AAEpB,gEAAgE;AAChE,eAAO,MAAM,2BAA2B,EAAE,SAAS,wBAAwB,EAClC,CAAC;AAE1C,qFAAqF;AACrF,eAAO,MAAM,8BAA8B;;;;;;;;;;;CAcjC,CAAC;AAEX,MAAM,WAAW,uBAAuB;IACtC,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,yEAAyE;IACzE,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,IAAI,wBAAwB,CAKlC;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,8BAAmC,EAC5C,OAAO,GAAE,uBAA4B,GACpC,oBAAoB,CA4CtB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,sBAAsB,GAAG,SAAS,CAcpC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,MAAM,GAAG,SAAS,CAWpB;AAED,MAAM,WAAW,kCAAkC;IACjD,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAA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