@soniox/node 1.0.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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/index.cjs +3638 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3043 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +3043 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3597 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3043 @@
|
|
|
1
|
+
//#region src/constants.d.ts
|
|
2
|
+
declare const SONIOX_API_BASE_URL = "https://api.soniox.com";
|
|
3
|
+
declare const SONIOX_API_WS_URL = "wss://stt-rt.soniox.com/transcribe-websocket";
|
|
4
|
+
declare const SONIOX_TMP_API_KEY_USAGE_TYPE = "transcribe_websocket";
|
|
5
|
+
declare const SONIOX_TMP_API_KEY_DURATION_MIN = 1;
|
|
6
|
+
declare const SONIOX_TMP_API_KEY_DURATION_MAX = 3600;
|
|
7
|
+
declare const SONIOX_API_WEBHOOK_HEADER_ENV = "SONIOX_API_WEBHOOK_HEADER";
|
|
8
|
+
declare const SONIOX_API_WEBHOOK_SECRET_ENV = "SONIOX_API_WEBHOOK_SECRET";
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/types/public/errors.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Unified error types for the Soniox SDK
|
|
13
|
+
*
|
|
14
|
+
* All SDK errors extend SonioxError, providing a consistent interface
|
|
15
|
+
* for error handling across both REST (HTTP) and WebSocket (Real-time) APIs.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Error codes for HTTP client errors
|
|
19
|
+
*/
|
|
20
|
+
type HttpErrorCode = 'network_error' | 'timeout' | 'aborted' | 'http_error' | 'parse_error';
|
|
21
|
+
/**
|
|
22
|
+
* Error codes for Real-time (WebSocket) API errors
|
|
23
|
+
*/
|
|
24
|
+
type RealtimeErrorCode = 'auth_error' | 'bad_request' | 'quota_exceeded' | 'connection_error' | 'network_error' | 'aborted' | 'state_error' | 'realtime_error';
|
|
25
|
+
/**
|
|
26
|
+
* All possible SDK error codes
|
|
27
|
+
*/
|
|
28
|
+
type SonioxErrorCode = HttpErrorCode | RealtimeErrorCode | 'soniox_error';
|
|
29
|
+
/**
|
|
30
|
+
* HTTP methods supported by the client
|
|
31
|
+
*/
|
|
32
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
|
|
33
|
+
/**
|
|
34
|
+
* Error details for SonioxHttpError
|
|
35
|
+
*/
|
|
36
|
+
interface HttpErrorDetails {
|
|
37
|
+
code: HttpErrorCode;
|
|
38
|
+
message: string;
|
|
39
|
+
url: string;
|
|
40
|
+
method: HttpMethod;
|
|
41
|
+
statusCode?: number | undefined;
|
|
42
|
+
headers?: Record<string, string> | undefined;
|
|
43
|
+
/** Response body text (capped at 4KB) */
|
|
44
|
+
bodyText?: string | undefined;
|
|
45
|
+
cause?: unknown;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/types/public/http.d.ts
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Response types
|
|
52
|
+
*/
|
|
53
|
+
type HttpResponseType = 'json' | 'text' | 'arrayBuffer';
|
|
54
|
+
/**
|
|
55
|
+
* Request body types
|
|
56
|
+
*/
|
|
57
|
+
type HttpRequestBody = string | Record<string, unknown> | ArrayBuffer | Uint8Array | FormData | null;
|
|
58
|
+
/**
|
|
59
|
+
* Query parameters
|
|
60
|
+
*/
|
|
61
|
+
type QueryParams = Record<string, string | number | boolean | undefined>;
|
|
62
|
+
/**
|
|
63
|
+
* HTTP request configuration
|
|
64
|
+
*/
|
|
65
|
+
interface HttpRequest {
|
|
66
|
+
/** HTTP method */
|
|
67
|
+
method: HttpMethod;
|
|
68
|
+
/**
|
|
69
|
+
* URL path (relative to baseUrl) or absolute URL
|
|
70
|
+
*/
|
|
71
|
+
path: string;
|
|
72
|
+
/** Request headers */
|
|
73
|
+
headers?: Record<string, string>;
|
|
74
|
+
/** Query parameters (will be URL-encoded) */
|
|
75
|
+
query?: QueryParams;
|
|
76
|
+
/** Request body */
|
|
77
|
+
body?: HttpRequestBody;
|
|
78
|
+
/**
|
|
79
|
+
* Expected response type
|
|
80
|
+
* @default 'json'
|
|
81
|
+
*/
|
|
82
|
+
responseType?: HttpResponseType;
|
|
83
|
+
/**
|
|
84
|
+
* Request timeout in milliseconds
|
|
85
|
+
* If not specified, uses the client's default timeout
|
|
86
|
+
*/
|
|
87
|
+
timeoutMs?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Optional AbortSignal for request cancellation
|
|
90
|
+
* If provided along with timeoutMs, both will be respected
|
|
91
|
+
*/
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* HTTP response from the client
|
|
96
|
+
*/
|
|
97
|
+
interface HttpResponse<T> {
|
|
98
|
+
/** HTTP status code */
|
|
99
|
+
status: number;
|
|
100
|
+
/** Response headers (normalized to lowercase keys) */
|
|
101
|
+
headers: Record<string, string>;
|
|
102
|
+
/** Parsed response data */
|
|
103
|
+
data: T;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Metadata provided to observability hooks
|
|
107
|
+
*/
|
|
108
|
+
interface HttpRequestMeta {
|
|
109
|
+
/** Request start timestamp (Date.now()) */
|
|
110
|
+
startTime: number;
|
|
111
|
+
url: string;
|
|
112
|
+
method: HttpMethod;
|
|
113
|
+
headers: Record<string, string>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Metadata provided to response/error hooks
|
|
117
|
+
*/
|
|
118
|
+
interface HttpResponseMeta extends HttpRequestMeta {
|
|
119
|
+
/** Request duration in milliseconds */
|
|
120
|
+
durationMs: number;
|
|
121
|
+
/** Response status code (if available) */
|
|
122
|
+
status?: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Observability hooks for monitoring HTTP requests
|
|
126
|
+
*/
|
|
127
|
+
interface HttpObservabilityHooks {
|
|
128
|
+
/**
|
|
129
|
+
* Called before a request is sent
|
|
130
|
+
*/
|
|
131
|
+
onRequest?: (request: HttpRequest, meta: HttpRequestMeta) => void;
|
|
132
|
+
/**
|
|
133
|
+
* Called after a successful response is received
|
|
134
|
+
*/
|
|
135
|
+
onResponse?: <T>(response: HttpResponse<T>, meta: HttpResponseMeta) => void;
|
|
136
|
+
/**
|
|
137
|
+
* Called when an error occurs
|
|
138
|
+
*/
|
|
139
|
+
onError?: (error: Error, meta: HttpResponseMeta) => void;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Configuration options for the HTTP client
|
|
143
|
+
*/
|
|
144
|
+
interface HttpClientOptions {
|
|
145
|
+
/**
|
|
146
|
+
* Base URL for all requests
|
|
147
|
+
* @example 'https://api.soniox.com/v1'
|
|
148
|
+
*/
|
|
149
|
+
base_url?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Default headers to include in all requests
|
|
152
|
+
*/
|
|
153
|
+
default_headers?: Record<string, string>;
|
|
154
|
+
/**
|
|
155
|
+
* Default timeout in milliseconds
|
|
156
|
+
* @default 30000 (30 seconds)
|
|
157
|
+
*/
|
|
158
|
+
default_timeout_ms?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Observability hooks for monitoring requests
|
|
161
|
+
*/
|
|
162
|
+
hooks?: HttpObservabilityHooks;
|
|
163
|
+
/**
|
|
164
|
+
* Custom fetch implementation
|
|
165
|
+
* Defaults to global fetch
|
|
166
|
+
*/
|
|
167
|
+
fetch?: typeof fetch;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Pluggable HTTP client interface
|
|
171
|
+
*/
|
|
172
|
+
interface HttpClient {
|
|
173
|
+
/**
|
|
174
|
+
* Perform an HTTP request
|
|
175
|
+
*
|
|
176
|
+
* @param request - Request configuration
|
|
177
|
+
* @returns Promise resolving to the response
|
|
178
|
+
* @throws {SonioxHttpError} On network errors, timeouts, HTTP errors, or parse errors
|
|
179
|
+
*/
|
|
180
|
+
request<T>(request: HttpRequest): Promise<HttpResponse<T>>;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/types/public/files.d.ts
|
|
184
|
+
/**
|
|
185
|
+
* Raw file metadata from the API.
|
|
186
|
+
*/
|
|
187
|
+
type SonioxFileData = {
|
|
188
|
+
/**
|
|
189
|
+
* Unique identifier of the file.
|
|
190
|
+
* @format uuid
|
|
191
|
+
*/
|
|
192
|
+
id: string;
|
|
193
|
+
/**
|
|
194
|
+
* Name of the file.
|
|
195
|
+
*/
|
|
196
|
+
filename: string;
|
|
197
|
+
/**
|
|
198
|
+
* Size of the file in bytes.
|
|
199
|
+
*/
|
|
200
|
+
size: number;
|
|
201
|
+
/**
|
|
202
|
+
* UTC timestamp indicating when the file was uploaded.
|
|
203
|
+
* @format date-time
|
|
204
|
+
*/
|
|
205
|
+
created_at: string;
|
|
206
|
+
/**
|
|
207
|
+
* Optional tracking identifier string.
|
|
208
|
+
*/
|
|
209
|
+
client_reference_id?: string | null | undefined;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Options for listing files.
|
|
213
|
+
*/
|
|
214
|
+
type ListFilesOptions = {
|
|
215
|
+
/**
|
|
216
|
+
* Maximum number of files to return.
|
|
217
|
+
* @default 1000
|
|
218
|
+
* @minimum 1
|
|
219
|
+
* @maximum 1000
|
|
220
|
+
*/
|
|
221
|
+
limit?: number | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* Pagination cursor for the next page of results.
|
|
224
|
+
*/
|
|
225
|
+
cursor?: string | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* AbortSignal for cancelling the request
|
|
228
|
+
*/
|
|
229
|
+
signal?: AbortSignal | undefined;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Response from listing files.
|
|
233
|
+
*/
|
|
234
|
+
type ListFilesResponse<T> = {
|
|
235
|
+
/**
|
|
236
|
+
* List of uploaded files.
|
|
237
|
+
*/
|
|
238
|
+
files: T[];
|
|
239
|
+
/**
|
|
240
|
+
* A pagination token that references the next page of results.
|
|
241
|
+
* When null, no additional results are available.
|
|
242
|
+
*/
|
|
243
|
+
next_page_cursor: string | null;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* File identifier - either a string ID or an object with an id property.
|
|
247
|
+
*/
|
|
248
|
+
type FileIdentifier = string | {
|
|
249
|
+
readonly id: string;
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Supported input types for file upload
|
|
253
|
+
*/
|
|
254
|
+
type UploadFileInput = Buffer | Uint8Array | Blob | ReadableStream<Uint8Array> | NodeJS.ReadableStream;
|
|
255
|
+
/**
|
|
256
|
+
* Options for uploading a file
|
|
257
|
+
*/
|
|
258
|
+
type UploadFileOptions = {
|
|
259
|
+
/**
|
|
260
|
+
* Custom filename for the uploaded file
|
|
261
|
+
*/
|
|
262
|
+
filename?: string | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* Optional tracking identifier string. Does not need to be unique
|
|
265
|
+
* @maxLength 256
|
|
266
|
+
*/
|
|
267
|
+
client_reference_id?: string | undefined;
|
|
268
|
+
/**
|
|
269
|
+
* AbortSignal for cancelling the upload
|
|
270
|
+
*/
|
|
271
|
+
signal?: AbortSignal | undefined;
|
|
272
|
+
/**
|
|
273
|
+
* Request timeout in milliseconds
|
|
274
|
+
*/
|
|
275
|
+
timeout_ms?: number | undefined;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Options for purging all files.
|
|
279
|
+
*/
|
|
280
|
+
type PurgeFilesOptions = {
|
|
281
|
+
/**
|
|
282
|
+
* AbortSignal for cancelling the purge operation.
|
|
283
|
+
*/
|
|
284
|
+
signal?: AbortSignal | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* Callback invoked before each file is deleted.
|
|
287
|
+
* Receives the file data and its 0-based index.
|
|
288
|
+
*/
|
|
289
|
+
on_progress?: ((file: SonioxFileData, index: number) => void) | undefined;
|
|
290
|
+
};
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/types/public/transcriptions.d.ts
|
|
293
|
+
/**
|
|
294
|
+
* Status of a transcription request.
|
|
295
|
+
*/
|
|
296
|
+
type TranscriptionStatus = 'queued' | 'processing' | 'completed' | 'error';
|
|
297
|
+
/**
|
|
298
|
+
* Resource types that can be cleaned up after transcription completes.
|
|
299
|
+
*
|
|
300
|
+
* - `'file'` - The uploaded file
|
|
301
|
+
* - `'transcription'` - The transcription record
|
|
302
|
+
*/
|
|
303
|
+
type CleanupTarget = 'file' | 'transcription';
|
|
304
|
+
/**
|
|
305
|
+
* Key-value pair for general context information.
|
|
306
|
+
*/
|
|
307
|
+
type ContextGeneralEntry = {
|
|
308
|
+
/**
|
|
309
|
+
* The key describing the context type (e.g., "domain", "topic", "doctor").
|
|
310
|
+
*/
|
|
311
|
+
key: string;
|
|
312
|
+
/**
|
|
313
|
+
* The value for the context key.
|
|
314
|
+
*/
|
|
315
|
+
value: string;
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* Custom translation term mapping.
|
|
319
|
+
*/
|
|
320
|
+
type ContextTranslationTerm = {
|
|
321
|
+
/**
|
|
322
|
+
* The source term to translate.
|
|
323
|
+
*/
|
|
324
|
+
source: string;
|
|
325
|
+
/**
|
|
326
|
+
* The target translation for the term.
|
|
327
|
+
*/
|
|
328
|
+
target: string;
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Additional context to improve transcription and translation accuracy.
|
|
332
|
+
* All sections are optional - include only what's relevant for your use case.
|
|
333
|
+
*/
|
|
334
|
+
type TranscriptionContext = {
|
|
335
|
+
/**
|
|
336
|
+
* Structured key-value pairs describing domain, topic, intent, participant names, etc.
|
|
337
|
+
*/
|
|
338
|
+
general?: ContextGeneralEntry[] | undefined;
|
|
339
|
+
/**
|
|
340
|
+
* Longer free-form background text, prior interaction history, reference documents, or meeting notes.
|
|
341
|
+
*/
|
|
342
|
+
text?: string | undefined;
|
|
343
|
+
/**
|
|
344
|
+
* Domain-specific or uncommon words to recognize.
|
|
345
|
+
*/
|
|
346
|
+
terms?: string[] | undefined;
|
|
347
|
+
/**
|
|
348
|
+
* Custom translations for ambiguous terms.
|
|
349
|
+
*/
|
|
350
|
+
translation_terms?: ContextTranslationTerm[] | undefined;
|
|
351
|
+
};
|
|
352
|
+
/**
|
|
353
|
+
* One-way translation configuration.
|
|
354
|
+
* Translates all spoken languages into a single target language.
|
|
355
|
+
*/
|
|
356
|
+
type OneWayTranslationConfig = {
|
|
357
|
+
/**
|
|
358
|
+
* Translation type.
|
|
359
|
+
*/
|
|
360
|
+
type: 'one_way';
|
|
361
|
+
/**
|
|
362
|
+
* Target language code for translation (e.g., "fr", "es", "de").
|
|
363
|
+
*/
|
|
364
|
+
target_language: string;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Two-way translation configuration.
|
|
368
|
+
* Translates between two specified languages.
|
|
369
|
+
*/
|
|
370
|
+
type TwoWayTranslationConfig = {
|
|
371
|
+
/**
|
|
372
|
+
* Translation type.
|
|
373
|
+
*/
|
|
374
|
+
type: 'two_way';
|
|
375
|
+
/**
|
|
376
|
+
* First language code.
|
|
377
|
+
*/
|
|
378
|
+
language_a: string;
|
|
379
|
+
/**
|
|
380
|
+
* Second language code.
|
|
381
|
+
*/
|
|
382
|
+
language_b: string;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Translation configuration.
|
|
386
|
+
*/
|
|
387
|
+
type TranslationConfig = OneWayTranslationConfig | TwoWayTranslationConfig;
|
|
388
|
+
/**
|
|
389
|
+
* Raw transcription metadata from the API.
|
|
390
|
+
*/
|
|
391
|
+
type SonioxTranscriptionData = {
|
|
392
|
+
/**
|
|
393
|
+
* Unique identifier of the transcription.
|
|
394
|
+
* @format uuid
|
|
395
|
+
*/
|
|
396
|
+
id: string;
|
|
397
|
+
/**
|
|
398
|
+
* Current status of the transcription.
|
|
399
|
+
*/
|
|
400
|
+
status: TranscriptionStatus;
|
|
401
|
+
/**
|
|
402
|
+
* UTC timestamp when the transcription was created.
|
|
403
|
+
* @format date-time
|
|
404
|
+
*/
|
|
405
|
+
created_at: string;
|
|
406
|
+
/**
|
|
407
|
+
* Speech-to-text model used.
|
|
408
|
+
*/
|
|
409
|
+
model: string;
|
|
410
|
+
/**
|
|
411
|
+
* URL of the audio file being transcribed.
|
|
412
|
+
*/
|
|
413
|
+
audio_url?: string | null | undefined;
|
|
414
|
+
/**
|
|
415
|
+
* ID of the uploaded file being transcribed.
|
|
416
|
+
* @format uuid
|
|
417
|
+
*/
|
|
418
|
+
file_id?: string | null | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* Name of the file being transcribed.
|
|
421
|
+
*/
|
|
422
|
+
filename: string;
|
|
423
|
+
/**
|
|
424
|
+
* Expected languages in the audio. If not specified, languages are automatically detected.
|
|
425
|
+
*/
|
|
426
|
+
language_hints?: string[] | null | undefined;
|
|
427
|
+
/**
|
|
428
|
+
* When true, speakers are identified and separated in the transcription output.
|
|
429
|
+
*/
|
|
430
|
+
enable_speaker_diarization: boolean;
|
|
431
|
+
/**
|
|
432
|
+
* When true, language is detected for each part of the transcription.
|
|
433
|
+
*/
|
|
434
|
+
enable_language_identification: boolean;
|
|
435
|
+
/**
|
|
436
|
+
* Duration of the audio in milliseconds. Only available after processing begins.
|
|
437
|
+
*/
|
|
438
|
+
audio_duration_ms?: number | null | undefined;
|
|
439
|
+
/**
|
|
440
|
+
* Error type if transcription failed. Null for successful or in-progress transcriptions.
|
|
441
|
+
*/
|
|
442
|
+
error_type?: string | null | undefined;
|
|
443
|
+
/**
|
|
444
|
+
* Error message if transcription failed. Null for successful or in-progress transcriptions.
|
|
445
|
+
*/
|
|
446
|
+
error_message?: string | null | undefined;
|
|
447
|
+
/**
|
|
448
|
+
* URL to receive webhook notifications when transcription is completed or fails.
|
|
449
|
+
*/
|
|
450
|
+
webhook_url?: string | null | undefined;
|
|
451
|
+
/**
|
|
452
|
+
* Name of the authentication header sent with webhook notifications.
|
|
453
|
+
*/
|
|
454
|
+
webhook_auth_header_name?: string | null | undefined;
|
|
455
|
+
/**
|
|
456
|
+
* Authentication header value. Always returned masked.
|
|
457
|
+
*/
|
|
458
|
+
webhook_auth_header_value?: string | null | undefined;
|
|
459
|
+
/**
|
|
460
|
+
* HTTP status code received from your server when webhook was delivered. Null if not yet sent.
|
|
461
|
+
*/
|
|
462
|
+
webhook_status_code?: number | null | undefined;
|
|
463
|
+
/**
|
|
464
|
+
* Optional tracking identifier.
|
|
465
|
+
* @maxLength 256
|
|
466
|
+
*/
|
|
467
|
+
client_reference_id?: string | null | undefined;
|
|
468
|
+
/**
|
|
469
|
+
* Additional context provided for the transcription.
|
|
470
|
+
*/
|
|
471
|
+
context?: TranscriptionContext | null | undefined;
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* Options for creating a transcription.
|
|
475
|
+
*/
|
|
476
|
+
type CreateTranscriptionOptions = {
|
|
477
|
+
/**
|
|
478
|
+
* Speech-to-text model to use.
|
|
479
|
+
* @maxLength 32
|
|
480
|
+
*/
|
|
481
|
+
model: string;
|
|
482
|
+
/**
|
|
483
|
+
* URL of a publicly accessible audio file.
|
|
484
|
+
* @maxLength 4096
|
|
485
|
+
*/
|
|
486
|
+
audio_url?: string | undefined;
|
|
487
|
+
/**
|
|
488
|
+
* ID of a previously uploaded file.
|
|
489
|
+
* @format uuid
|
|
490
|
+
*/
|
|
491
|
+
file_id?: string | undefined;
|
|
492
|
+
/**
|
|
493
|
+
* Array of expected ISO language codes to bias recognition.
|
|
494
|
+
*/
|
|
495
|
+
language_hints?: string[] | undefined;
|
|
496
|
+
/**
|
|
497
|
+
* When true, model relies more heavily on language hints.
|
|
498
|
+
*/
|
|
499
|
+
language_hints_strict?: boolean | undefined;
|
|
500
|
+
/**
|
|
501
|
+
* Enable automatic language identification.
|
|
502
|
+
*/
|
|
503
|
+
enable_language_identification?: boolean | undefined;
|
|
504
|
+
/**
|
|
505
|
+
* Enable speaker diarization to identify different speakers.
|
|
506
|
+
*/
|
|
507
|
+
enable_speaker_diarization?: boolean | undefined;
|
|
508
|
+
/**
|
|
509
|
+
* Additional context to improve transcription accuracy and formatting of specialized terms.
|
|
510
|
+
*/
|
|
511
|
+
context?: TranscriptionContext | undefined;
|
|
512
|
+
/**
|
|
513
|
+
* Translation configuration.
|
|
514
|
+
*/
|
|
515
|
+
translation?: TranslationConfig | undefined;
|
|
516
|
+
/**
|
|
517
|
+
* URL to receive webhook notifications when transcription is completed or fails.
|
|
518
|
+
* @maxLength 256
|
|
519
|
+
*/
|
|
520
|
+
webhook_url?: string | undefined;
|
|
521
|
+
/**
|
|
522
|
+
* Name of the authentication header sent with webhook notifications.
|
|
523
|
+
* @maxLength 256
|
|
524
|
+
*/
|
|
525
|
+
webhook_auth_header_name?: string | undefined;
|
|
526
|
+
/**
|
|
527
|
+
* Authentication header value sent with webhook notifications.
|
|
528
|
+
* @maxLength 256
|
|
529
|
+
*/
|
|
530
|
+
webhook_auth_header_value?: string | undefined;
|
|
531
|
+
/**
|
|
532
|
+
* Optional tracking identifier.
|
|
533
|
+
* @maxLength 256
|
|
534
|
+
*/
|
|
535
|
+
client_reference_id?: string | undefined;
|
|
536
|
+
};
|
|
537
|
+
/**
|
|
538
|
+
* Options for polling/waiting for transcription completion.
|
|
539
|
+
*/
|
|
540
|
+
type WaitOptions = {
|
|
541
|
+
/**
|
|
542
|
+
* Polling interval in milliseconds.
|
|
543
|
+
* @default 1000
|
|
544
|
+
* @minimum 1000
|
|
545
|
+
*/
|
|
546
|
+
interval_ms?: number | undefined;
|
|
547
|
+
/**
|
|
548
|
+
* Maximum time to wait in milliseconds.
|
|
549
|
+
* @default 300000 (5 minutes)
|
|
550
|
+
*/
|
|
551
|
+
timeout_ms?: number | undefined;
|
|
552
|
+
/**
|
|
553
|
+
* Callback invoked when status changes.
|
|
554
|
+
*/
|
|
555
|
+
on_status_change?: ((status: TranscriptionStatus, transcription: SonioxTranscriptionData) => void) | undefined;
|
|
556
|
+
/**
|
|
557
|
+
* AbortSignal to cancel waiting.
|
|
558
|
+
*/
|
|
559
|
+
signal?: AbortSignal | undefined;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Base options shared by all audio source variants.
|
|
563
|
+
*/
|
|
564
|
+
type TranscribeBaseOptions = {
|
|
565
|
+
/**
|
|
566
|
+
* Speech-to-text model to use.
|
|
567
|
+
* @maxLength 32
|
|
568
|
+
*/
|
|
569
|
+
model: string;
|
|
570
|
+
/**
|
|
571
|
+
* Array of expected ISO language codes to bias recognition.
|
|
572
|
+
*/
|
|
573
|
+
language_hints?: string[] | undefined;
|
|
574
|
+
/**
|
|
575
|
+
* When true, model relies more heavily on language hints.
|
|
576
|
+
*/
|
|
577
|
+
language_hints_strict?: boolean | undefined;
|
|
578
|
+
/**
|
|
579
|
+
* Enable automatic language identification.
|
|
580
|
+
*/
|
|
581
|
+
enable_language_identification?: boolean | undefined;
|
|
582
|
+
/**
|
|
583
|
+
* Enable speaker diarization to identify different speakers.
|
|
584
|
+
*/
|
|
585
|
+
enable_speaker_diarization?: boolean | undefined;
|
|
586
|
+
/**
|
|
587
|
+
* Additional context to improve transcription accuracy and formatting of specialized terms.
|
|
588
|
+
*/
|
|
589
|
+
context?: TranscriptionContext | undefined;
|
|
590
|
+
/**
|
|
591
|
+
* Translation configuration.
|
|
592
|
+
*/
|
|
593
|
+
translation?: TranslationConfig | undefined;
|
|
594
|
+
/**
|
|
595
|
+
* URL to receive webhook notifications when transcription is completed or fails.
|
|
596
|
+
* @maxLength 256
|
|
597
|
+
*/
|
|
598
|
+
webhook_url?: string | undefined;
|
|
599
|
+
/**
|
|
600
|
+
* Name of the authentication header sent with webhook notifications.
|
|
601
|
+
* @maxLength 256
|
|
602
|
+
*/
|
|
603
|
+
webhook_auth_header_name?: string | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* Authentication header value sent with webhook notifications.
|
|
606
|
+
* @maxLength 256
|
|
607
|
+
*/
|
|
608
|
+
webhook_auth_header_value?: string | undefined;
|
|
609
|
+
/**
|
|
610
|
+
* Optional tracking identifier.
|
|
611
|
+
* @maxLength 256
|
|
612
|
+
*/
|
|
613
|
+
client_reference_id?: string | undefined;
|
|
614
|
+
/**
|
|
615
|
+
* When true, waits for transcription to complete before returning.
|
|
616
|
+
* @default false
|
|
617
|
+
*/
|
|
618
|
+
wait?: boolean | undefined;
|
|
619
|
+
/**
|
|
620
|
+
* Options for waiting (only used when wait=true).
|
|
621
|
+
*/
|
|
622
|
+
wait_options?: WaitOptions | undefined;
|
|
623
|
+
/**
|
|
624
|
+
* When true (default), fetches the transcript and attaches it to the result
|
|
625
|
+
* when wait=true and the transcription completes successfully.
|
|
626
|
+
* Set to false to skip fetching the full transcript payload.
|
|
627
|
+
* @default true
|
|
628
|
+
*/
|
|
629
|
+
fetch_transcript?: boolean | undefined;
|
|
630
|
+
/**
|
|
631
|
+
* Query parameters to append to the webhook URL.
|
|
632
|
+
* Useful for encoding metadata like transcription ID in the webhook callback.
|
|
633
|
+
* Can be a string, URLSearchParams, or Record<string, string>.
|
|
634
|
+
*/
|
|
635
|
+
webhook_query?: string | URLSearchParams | Record<string, string> | undefined;
|
|
636
|
+
/**
|
|
637
|
+
* AbortSignal to cancel the operation
|
|
638
|
+
*/
|
|
639
|
+
signal?: AbortSignal | undefined;
|
|
640
|
+
/**
|
|
641
|
+
* Timeout in milliseconds
|
|
642
|
+
*/
|
|
643
|
+
timeout_ms?: number | undefined;
|
|
644
|
+
/**
|
|
645
|
+
* Resources to clean up after transcription completes or on error/timeout.
|
|
646
|
+
* Only applies when `wait: true`.
|
|
647
|
+
*
|
|
648
|
+
* Cleanup runs in all cases when `wait: true`:
|
|
649
|
+
* - After successful completion
|
|
650
|
+
* - After transcription errors (status: 'error')
|
|
651
|
+
* - On timeout or abort
|
|
652
|
+
*
|
|
653
|
+
* This ensures no orphaned resources are left behind.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```typescript
|
|
657
|
+
* // Delete only the uploaded file
|
|
658
|
+
* cleanup: ['file']
|
|
659
|
+
*
|
|
660
|
+
* // Delete only the transcription record
|
|
661
|
+
* cleanup: ['transcription']
|
|
662
|
+
*
|
|
663
|
+
* // Delete both file and transcription
|
|
664
|
+
* cleanup: ['file', 'transcription']
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
cleanup?: CleanupTarget[] | undefined;
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* Transcribe from a direct file upload (Buffer, Uint8Array, Blob, or ReadableStream)
|
|
671
|
+
*/
|
|
672
|
+
type TranscribeFromFile = TranscribeBaseOptions & {
|
|
673
|
+
/**
|
|
674
|
+
* File data to upload and transcribe.
|
|
675
|
+
*/
|
|
676
|
+
file: UploadFileInput;
|
|
677
|
+
filename?: string | undefined;
|
|
678
|
+
file_id?: never;
|
|
679
|
+
audio_url?: never;
|
|
680
|
+
};
|
|
681
|
+
/**
|
|
682
|
+
* Transcribe from a previously uploaded file
|
|
683
|
+
*/
|
|
684
|
+
type TranscribeFromFileId = TranscribeBaseOptions & {
|
|
685
|
+
/**
|
|
686
|
+
* ID of a previously uploaded file.
|
|
687
|
+
* @format uuid
|
|
688
|
+
*/
|
|
689
|
+
file_id: string;
|
|
690
|
+
file?: never;
|
|
691
|
+
filename?: never;
|
|
692
|
+
audio_url?: never;
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* Transcribe from a publicly accessible audio URL
|
|
696
|
+
*/
|
|
697
|
+
type TranscribeFromUrl = TranscribeBaseOptions & {
|
|
698
|
+
/**
|
|
699
|
+
* URL of a publicly accessible audio file.
|
|
700
|
+
* @maxLength 4096
|
|
701
|
+
*/
|
|
702
|
+
audio_url: string;
|
|
703
|
+
file?: never;
|
|
704
|
+
filename?: never;
|
|
705
|
+
file_id?: never;
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
708
|
+
* Options for the unified transcribe method
|
|
709
|
+
* Exactly one audio source must be provided: `file`, `file_id`, or `audio_url`
|
|
710
|
+
*/
|
|
711
|
+
type TranscribeOptions = TranscribeFromFile | TranscribeFromFileId | TranscribeFromUrl;
|
|
712
|
+
/**
|
|
713
|
+
* Options for transcribing from a URL via `transcribeFromUrl`.
|
|
714
|
+
*/
|
|
715
|
+
type TranscribeFromUrlOptions = Omit<TranscribeFromUrl, 'audio_url'>;
|
|
716
|
+
/**
|
|
717
|
+
* Options for transcribing from a file via `transcribeFromFile`.
|
|
718
|
+
*/
|
|
719
|
+
type TranscribeFromFileOptions = Omit<TranscribeFromFile, 'file'>;
|
|
720
|
+
/**
|
|
721
|
+
* Options for transcribing from an uploaded file ID via `transcribeFromFileId`.
|
|
722
|
+
*/
|
|
723
|
+
type TranscribeFromFileIdOptions = Omit<TranscribeFromFileId, 'file_id'>;
|
|
724
|
+
/**
|
|
725
|
+
* Options for listing transcriptions
|
|
726
|
+
*/
|
|
727
|
+
type ListTranscriptionsOptions = {
|
|
728
|
+
/**
|
|
729
|
+
* Maximum number of transcriptions to return.
|
|
730
|
+
* @default 1000
|
|
731
|
+
* @minimum 1
|
|
732
|
+
* @maximum 1000
|
|
733
|
+
*/
|
|
734
|
+
limit?: number | undefined;
|
|
735
|
+
/**
|
|
736
|
+
* Pagination cursor for the next page of results
|
|
737
|
+
*/
|
|
738
|
+
cursor?: string | undefined;
|
|
739
|
+
};
|
|
740
|
+
/**
|
|
741
|
+
* Response from listing transcriptions.
|
|
742
|
+
*/
|
|
743
|
+
type ListTranscriptionsResponse<T> = {
|
|
744
|
+
/**
|
|
745
|
+
* List of transcriptions.
|
|
746
|
+
*/
|
|
747
|
+
transcriptions: T[];
|
|
748
|
+
/**
|
|
749
|
+
* A pagination token that references the next page of results.
|
|
750
|
+
* When null, no additional results are available.
|
|
751
|
+
* TODO: potentially can be undefined?
|
|
752
|
+
*/
|
|
753
|
+
next_page_cursor: string | null;
|
|
754
|
+
};
|
|
755
|
+
/**
|
|
756
|
+
* Transcription identifier - either a string ID or an object with an id property.
|
|
757
|
+
*/
|
|
758
|
+
type TranscriptionIdentifier = string | {
|
|
759
|
+
readonly id: string;
|
|
760
|
+
};
|
|
761
|
+
/**
|
|
762
|
+
* A single token from the transcript with timing and confidence information.
|
|
763
|
+
*/
|
|
764
|
+
type TranscriptToken = {
|
|
765
|
+
/**
|
|
766
|
+
* The text content of this token.
|
|
767
|
+
*/
|
|
768
|
+
text: string;
|
|
769
|
+
/**
|
|
770
|
+
* Start time of the token in milliseconds.
|
|
771
|
+
*/
|
|
772
|
+
start_ms: number;
|
|
773
|
+
/**
|
|
774
|
+
* End time of the token in milliseconds.
|
|
775
|
+
*/
|
|
776
|
+
end_ms: number;
|
|
777
|
+
/**
|
|
778
|
+
* Confidence score for this token (0.0 to 1.0).
|
|
779
|
+
*/
|
|
780
|
+
confidence: number;
|
|
781
|
+
/**
|
|
782
|
+
* Speaker identifier (if speaker diarization was enabled).
|
|
783
|
+
*/
|
|
784
|
+
speaker?: string | null | undefined;
|
|
785
|
+
/**
|
|
786
|
+
* Detected language code (if language identification was enabled).
|
|
787
|
+
*/
|
|
788
|
+
language?: string | null | undefined;
|
|
789
|
+
/**
|
|
790
|
+
* Translation status for this token.
|
|
791
|
+
*/
|
|
792
|
+
translation_status?: 'none' | 'original' | 'translation' | null | undefined;
|
|
793
|
+
/**
|
|
794
|
+
* Whether this token represents an audio event.
|
|
795
|
+
*/
|
|
796
|
+
is_audio_event?: boolean | null | undefined;
|
|
797
|
+
};
|
|
798
|
+
/**
|
|
799
|
+
* Response from getting a transcription transcript.
|
|
800
|
+
*/
|
|
801
|
+
type TranscriptResponse = {
|
|
802
|
+
/**
|
|
803
|
+
* Unique identifier of the transcription this transcript belongs to.
|
|
804
|
+
* @format uuid
|
|
805
|
+
*/
|
|
806
|
+
id: string;
|
|
807
|
+
/**
|
|
808
|
+
* Complete transcribed text content.
|
|
809
|
+
*/
|
|
810
|
+
text: string;
|
|
811
|
+
/**
|
|
812
|
+
* List of detailed token information with timestamps and metadata.
|
|
813
|
+
*/
|
|
814
|
+
tokens: TranscriptToken[];
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* Fields that can be used to group tokens into segments
|
|
818
|
+
*/
|
|
819
|
+
type SegmentGroupKey = 'speaker' | 'language';
|
|
820
|
+
/**
|
|
821
|
+
* Options for segmenting a transcript
|
|
822
|
+
*/
|
|
823
|
+
type SegmentTranscriptOptions = {
|
|
824
|
+
/**
|
|
825
|
+
* Fields to group by. A new segment starts when any of these fields changes
|
|
826
|
+
* @default ['speaker', 'language']
|
|
827
|
+
*/
|
|
828
|
+
group_by?: SegmentGroupKey[] | undefined;
|
|
829
|
+
};
|
|
830
|
+
/**
|
|
831
|
+
* A segment of contiguous tokens grouped by speaker and language
|
|
832
|
+
*/
|
|
833
|
+
type TranscriptSegment = {
|
|
834
|
+
/**
|
|
835
|
+
* Concatenated text of all tokens in this segment.
|
|
836
|
+
*/
|
|
837
|
+
text: string;
|
|
838
|
+
/**
|
|
839
|
+
* Start time of the segment in milliseconds (from first token).
|
|
840
|
+
*/
|
|
841
|
+
start_ms: number;
|
|
842
|
+
/**
|
|
843
|
+
* End time of the segment in milliseconds (from last token).
|
|
844
|
+
*/
|
|
845
|
+
end_ms: number;
|
|
846
|
+
/**
|
|
847
|
+
* Speaker identifier (if speaker diarization was enabled).
|
|
848
|
+
*/
|
|
849
|
+
speaker?: string | undefined;
|
|
850
|
+
/**
|
|
851
|
+
* Detected language code (if language identification was enabled).
|
|
852
|
+
*/
|
|
853
|
+
language?: string | undefined;
|
|
854
|
+
/**
|
|
855
|
+
* Original tokens in this segment.
|
|
856
|
+
*/
|
|
857
|
+
tokens: TranscriptToken[];
|
|
858
|
+
};
|
|
859
|
+
/**
|
|
860
|
+
* Options for purging all transcriptions.
|
|
861
|
+
*/
|
|
862
|
+
type PurgeTranscriptionsOptions = {
|
|
863
|
+
/**
|
|
864
|
+
* AbortSignal for cancelling the purge operation.
|
|
865
|
+
*/
|
|
866
|
+
signal?: AbortSignal | undefined;
|
|
867
|
+
/**
|
|
868
|
+
* Callback invoked before each transcription is deleted.
|
|
869
|
+
* Receives the transcription data and its 0-based index.
|
|
870
|
+
*/
|
|
871
|
+
on_progress?: ((transcription: SonioxTranscriptionData, index: number) => void) | undefined;
|
|
872
|
+
};
|
|
873
|
+
/**
|
|
874
|
+
* Type contract for SonioxTranscript class.
|
|
875
|
+
* @see SonioxTranscript for full documentation.
|
|
876
|
+
*/
|
|
877
|
+
interface ISonioxTranscript {
|
|
878
|
+
readonly id: string;
|
|
879
|
+
readonly text: string;
|
|
880
|
+
readonly tokens: TranscriptToken[];
|
|
881
|
+
segments(options?: SegmentTranscriptOptions): TranscriptSegment[];
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Type contract for SonioxTranscription class.
|
|
885
|
+
* @see SonioxTranscription for full documentation.
|
|
886
|
+
*/
|
|
887
|
+
interface ISonioxTranscription {
|
|
888
|
+
readonly id: string;
|
|
889
|
+
readonly status: TranscriptionStatus;
|
|
890
|
+
readonly created_at: string;
|
|
891
|
+
readonly model: string;
|
|
892
|
+
readonly audio_url: string | null | undefined;
|
|
893
|
+
readonly file_id: string | null | undefined;
|
|
894
|
+
readonly filename: string;
|
|
895
|
+
readonly language_hints: string[] | undefined;
|
|
896
|
+
readonly enable_speaker_diarization: boolean;
|
|
897
|
+
readonly enable_language_identification: boolean;
|
|
898
|
+
readonly audio_duration_ms: number | null | undefined;
|
|
899
|
+
readonly error_type: string | null | undefined;
|
|
900
|
+
readonly error_message: string | null | undefined;
|
|
901
|
+
readonly webhook_url: string | null | undefined;
|
|
902
|
+
readonly webhook_auth_header_name: string | null | undefined;
|
|
903
|
+
readonly webhook_auth_header_value: string | null | undefined;
|
|
904
|
+
readonly webhook_status_code: number | null | undefined;
|
|
905
|
+
readonly client_reference_id: string | null | undefined;
|
|
906
|
+
readonly context: TranscriptionContext | string | null | undefined;
|
|
907
|
+
readonly transcript: ISonioxTranscript | null | undefined;
|
|
908
|
+
toJSON(): SonioxTranscriptionData;
|
|
909
|
+
delete(): Promise<void>;
|
|
910
|
+
destroy(): Promise<void>;
|
|
911
|
+
getTranscript(options?: {
|
|
912
|
+
force?: boolean;
|
|
913
|
+
signal?: AbortSignal;
|
|
914
|
+
}): Promise<ISonioxTranscript | null>;
|
|
915
|
+
refresh(signal?: AbortSignal): Promise<ISonioxTranscription>;
|
|
916
|
+
wait(options?: WaitOptions): Promise<ISonioxTranscription>;
|
|
917
|
+
}
|
|
918
|
+
//#endregion
|
|
919
|
+
//#region src/types/public/realtime.d.ts
|
|
920
|
+
/**
|
|
921
|
+
* Supported audio formats for real-time transcription.
|
|
922
|
+
*/
|
|
923
|
+
type AudioFormat = 'pcm_s8' | 'pcm_s8le' | 'pcm_s8be' | 'pcm_s16le' | 'pcm_s16be' | 'pcm_s24le' | 'pcm_s24be' | 'pcm_s32le' | 'pcm_s32be' | 'pcm_u8' | 'pcm_u8le' | 'pcm_u8be' | 'pcm_u16le' | 'pcm_u16be' | 'pcm_u24le' | 'pcm_u24be' | 'pcm_u32le' | 'pcm_u32be' | 'pcm_f32le' | 'pcm_f32be' | 'pcm_f64le' | 'pcm_f64be' | 'mulaw' | 'alaw' | 'aac' | 'aiff' | 'amr' | 'asf' | 'wav' | 'mp3' | 'flac' | 'ogg' | 'webm';
|
|
924
|
+
/**
|
|
925
|
+
* Configuration sent to the Soniox WebSocket API when starting a session.
|
|
926
|
+
*/
|
|
927
|
+
type SttSessionConfig = {
|
|
928
|
+
/**
|
|
929
|
+
* Speech-to-text model to use.
|
|
930
|
+
*/
|
|
931
|
+
model: string;
|
|
932
|
+
/**
|
|
933
|
+
* Audio format. Use 'auto' for automatic detection of container formats.
|
|
934
|
+
* For raw PCM formats, also set sample_rate and num_channels.
|
|
935
|
+
* @default 'auto'
|
|
936
|
+
*/
|
|
937
|
+
audio_format?: 'auto' | AudioFormat | undefined;
|
|
938
|
+
/**
|
|
939
|
+
* Sample rate in Hz (required for PCM formats).
|
|
940
|
+
*/
|
|
941
|
+
sample_rate?: number | undefined;
|
|
942
|
+
/**
|
|
943
|
+
* Number of audio channels (required for raw audio formats).
|
|
944
|
+
*/
|
|
945
|
+
num_channels?: number | undefined;
|
|
946
|
+
/**
|
|
947
|
+
* Expected languages in the audio (ISO language codes).
|
|
948
|
+
*/
|
|
949
|
+
language_hints?: string[] | undefined;
|
|
950
|
+
/**
|
|
951
|
+
* When true, recognition is strongly biased toward language hints.
|
|
952
|
+
* Best-effort only, not a hard guarantee.
|
|
953
|
+
*/
|
|
954
|
+
language_hints_strict?: boolean | undefined;
|
|
955
|
+
/**
|
|
956
|
+
* Enable speaker identification.
|
|
957
|
+
*/
|
|
958
|
+
enable_speaker_diarization?: boolean | undefined;
|
|
959
|
+
/**
|
|
960
|
+
* Enable automatic language detection.
|
|
961
|
+
*/
|
|
962
|
+
enable_language_identification?: boolean | undefined;
|
|
963
|
+
/**
|
|
964
|
+
* Enable endpoint detection for utterance boundaries.
|
|
965
|
+
* Useful for voice AI agents.
|
|
966
|
+
*/
|
|
967
|
+
enable_endpoint_detection?: boolean | undefined;
|
|
968
|
+
/**
|
|
969
|
+
* Optional tracking identifier (max 256 chars).
|
|
970
|
+
*/
|
|
971
|
+
client_reference_id?: string | undefined;
|
|
972
|
+
/**
|
|
973
|
+
* Additional context to improve transcription accuracy.
|
|
974
|
+
*/
|
|
975
|
+
context?: TranscriptionContext | undefined;
|
|
976
|
+
/**
|
|
977
|
+
* Translation configuration.
|
|
978
|
+
*/
|
|
979
|
+
translation?: TranslationConfig | undefined;
|
|
980
|
+
};
|
|
981
|
+
/**
|
|
982
|
+
* SDK-level session options (not sent to the server).
|
|
983
|
+
*/
|
|
984
|
+
type SttSessionOptions = {
|
|
985
|
+
/**
|
|
986
|
+
* AbortSignal for cancellation.
|
|
987
|
+
*/
|
|
988
|
+
signal?: AbortSignal | undefined;
|
|
989
|
+
/**
|
|
990
|
+
* When true, sends keepalive messages while connected (not only when paused).
|
|
991
|
+
* @default false
|
|
992
|
+
*/
|
|
993
|
+
keepalive?: boolean | undefined;
|
|
994
|
+
/**
|
|
995
|
+
* Interval for sending keepalive messages while connected or paused (milliseconds).
|
|
996
|
+
* @default 5000
|
|
997
|
+
*/
|
|
998
|
+
keepalive_interval_ms?: number | undefined;
|
|
999
|
+
};
|
|
1000
|
+
/**
|
|
1001
|
+
* A single token from the real-time transcription.
|
|
1002
|
+
*/
|
|
1003
|
+
type RealtimeToken = {
|
|
1004
|
+
/**
|
|
1005
|
+
* The transcribed text.
|
|
1006
|
+
*/
|
|
1007
|
+
text: string;
|
|
1008
|
+
/**
|
|
1009
|
+
* Start time in milliseconds relative to audio start.
|
|
1010
|
+
*/
|
|
1011
|
+
start_ms?: number | undefined;
|
|
1012
|
+
/**
|
|
1013
|
+
* End time in milliseconds relative to audio start.
|
|
1014
|
+
*/
|
|
1015
|
+
end_ms?: number | undefined;
|
|
1016
|
+
/**
|
|
1017
|
+
* Confidence score (0.0 to 1.0).
|
|
1018
|
+
*/
|
|
1019
|
+
confidence: number;
|
|
1020
|
+
/**
|
|
1021
|
+
* Whether this is a finalized token.
|
|
1022
|
+
*/
|
|
1023
|
+
is_final: boolean;
|
|
1024
|
+
/**
|
|
1025
|
+
* Speaker identifier (if diarization enabled).
|
|
1026
|
+
*/
|
|
1027
|
+
speaker?: string | undefined;
|
|
1028
|
+
/**
|
|
1029
|
+
* Detected language code (if language identification enabled).
|
|
1030
|
+
*/
|
|
1031
|
+
language?: string | undefined;
|
|
1032
|
+
/**
|
|
1033
|
+
* Translation status of this token.
|
|
1034
|
+
*/
|
|
1035
|
+
translation_status?: 'none' | 'original' | 'translation' | undefined;
|
|
1036
|
+
/**
|
|
1037
|
+
* Source language for translated tokens.
|
|
1038
|
+
*/
|
|
1039
|
+
source_language?: string | undefined;
|
|
1040
|
+
};
|
|
1041
|
+
/**
|
|
1042
|
+
* A segment of contiguous real-time tokens grouped by speaker/language.
|
|
1043
|
+
*/
|
|
1044
|
+
type RealtimeSegment = {
|
|
1045
|
+
/**
|
|
1046
|
+
* Concatenated text of all tokens in this segment.
|
|
1047
|
+
*/
|
|
1048
|
+
text: string;
|
|
1049
|
+
/**
|
|
1050
|
+
* Start time of the segment in milliseconds (from first token).
|
|
1051
|
+
*/
|
|
1052
|
+
start_ms?: number | undefined;
|
|
1053
|
+
/**
|
|
1054
|
+
* End time of the segment in milliseconds (from last token).
|
|
1055
|
+
*/
|
|
1056
|
+
end_ms?: number | undefined;
|
|
1057
|
+
/**
|
|
1058
|
+
* Speaker identifier (if diarization enabled).
|
|
1059
|
+
*/
|
|
1060
|
+
speaker?: string | undefined;
|
|
1061
|
+
/**
|
|
1062
|
+
* Detected language code (if language identification enabled).
|
|
1063
|
+
*/
|
|
1064
|
+
language?: string | undefined;
|
|
1065
|
+
/**
|
|
1066
|
+
* Original tokens in this segment.
|
|
1067
|
+
*/
|
|
1068
|
+
tokens: RealtimeToken[];
|
|
1069
|
+
};
|
|
1070
|
+
/**
|
|
1071
|
+
* Options for segmenting real-time tokens.
|
|
1072
|
+
*/
|
|
1073
|
+
type RealtimeSegmentOptions = {
|
|
1074
|
+
/**
|
|
1075
|
+
* Fields to group by. A new segment starts when any of these fields changes
|
|
1076
|
+
* @default ['speaker', 'language']
|
|
1077
|
+
*/
|
|
1078
|
+
group_by?: SegmentGroupKey[] | undefined;
|
|
1079
|
+
/**
|
|
1080
|
+
* When true, only tokens marked as final are included.
|
|
1081
|
+
* @default false
|
|
1082
|
+
*/
|
|
1083
|
+
final_only?: boolean | undefined;
|
|
1084
|
+
};
|
|
1085
|
+
/**
|
|
1086
|
+
* Options for rolling real-time segmentation buffers.
|
|
1087
|
+
*/
|
|
1088
|
+
type RealtimeSegmentBufferOptions = {
|
|
1089
|
+
/**
|
|
1090
|
+
* Fields to group by. A new segment starts when any of these fields changes
|
|
1091
|
+
* @default ['speaker', 'language']
|
|
1092
|
+
*/
|
|
1093
|
+
group_by?: SegmentGroupKey[] | undefined;
|
|
1094
|
+
/**
|
|
1095
|
+
* When true, only tokens marked as final are buffered.
|
|
1096
|
+
* @default true
|
|
1097
|
+
*/
|
|
1098
|
+
final_only?: boolean | undefined;
|
|
1099
|
+
/**
|
|
1100
|
+
* Maximum number of tokens to keep in the buffer.
|
|
1101
|
+
* @default 2000
|
|
1102
|
+
*/
|
|
1103
|
+
max_tokens?: number | undefined;
|
|
1104
|
+
/**
|
|
1105
|
+
* Maximum time window to keep in milliseconds (requires token timings).
|
|
1106
|
+
*/
|
|
1107
|
+
max_ms?: number | undefined;
|
|
1108
|
+
};
|
|
1109
|
+
/**
|
|
1110
|
+
* A single utterance built from real-time segments.
|
|
1111
|
+
*/
|
|
1112
|
+
type RealtimeUtterance = {
|
|
1113
|
+
/**
|
|
1114
|
+
* Concatenated text of all segments in this utterance.
|
|
1115
|
+
*/
|
|
1116
|
+
text: string;
|
|
1117
|
+
/**
|
|
1118
|
+
* Segments included in this utterance.
|
|
1119
|
+
*/
|
|
1120
|
+
segments: RealtimeSegment[];
|
|
1121
|
+
/**
|
|
1122
|
+
* Tokens included in this utterance.
|
|
1123
|
+
*/
|
|
1124
|
+
tokens: RealtimeToken[];
|
|
1125
|
+
/**
|
|
1126
|
+
* Start time of the utterance in milliseconds (from first segment).
|
|
1127
|
+
*/
|
|
1128
|
+
start_ms?: number | undefined;
|
|
1129
|
+
/**
|
|
1130
|
+
* End time of the utterance in milliseconds (from last segment).
|
|
1131
|
+
*/
|
|
1132
|
+
end_ms?: number | undefined;
|
|
1133
|
+
/**
|
|
1134
|
+
* Speaker identifier when consistent across segments.
|
|
1135
|
+
*/
|
|
1136
|
+
speaker?: string | undefined;
|
|
1137
|
+
/**
|
|
1138
|
+
* Detected language code when consistent across segments.
|
|
1139
|
+
*/
|
|
1140
|
+
language?: string | undefined;
|
|
1141
|
+
/**
|
|
1142
|
+
* Milliseconds of audio that have been finalized at flush time.
|
|
1143
|
+
*/
|
|
1144
|
+
final_audio_proc_ms?: number | undefined;
|
|
1145
|
+
/**
|
|
1146
|
+
* Total milliseconds of audio processed at flush time.
|
|
1147
|
+
*/
|
|
1148
|
+
total_audio_proc_ms?: number | undefined;
|
|
1149
|
+
};
|
|
1150
|
+
/**
|
|
1151
|
+
* Options for buffering real-time utterances.
|
|
1152
|
+
*/
|
|
1153
|
+
type RealtimeUtteranceBufferOptions = {
|
|
1154
|
+
/**
|
|
1155
|
+
* Fields to group by. A new segment starts when any of these fields changes
|
|
1156
|
+
* @default ['speaker', 'language']
|
|
1157
|
+
*/
|
|
1158
|
+
group_by?: SegmentGroupKey[] | undefined;
|
|
1159
|
+
/**
|
|
1160
|
+
* When true, only tokens marked as final are buffered.
|
|
1161
|
+
* @default true
|
|
1162
|
+
*/
|
|
1163
|
+
final_only?: boolean | undefined;
|
|
1164
|
+
/**
|
|
1165
|
+
* Maximum number of tokens to keep in the buffer.
|
|
1166
|
+
* @default 2000
|
|
1167
|
+
*/
|
|
1168
|
+
max_tokens?: number | undefined;
|
|
1169
|
+
/**
|
|
1170
|
+
* Maximum time window to keep in milliseconds (requires token timings).
|
|
1171
|
+
*/
|
|
1172
|
+
max_ms?: number | undefined;
|
|
1173
|
+
};
|
|
1174
|
+
/**
|
|
1175
|
+
* A result message from the real-time WebSocket.
|
|
1176
|
+
*/
|
|
1177
|
+
type RealtimeResult = {
|
|
1178
|
+
/**
|
|
1179
|
+
* Tokens in this result.
|
|
1180
|
+
*/
|
|
1181
|
+
tokens: RealtimeToken[];
|
|
1182
|
+
/**
|
|
1183
|
+
* Milliseconds of audio that have been finalized.
|
|
1184
|
+
*/
|
|
1185
|
+
final_audio_proc_ms: number;
|
|
1186
|
+
/**
|
|
1187
|
+
* Total milliseconds of audio processed.
|
|
1188
|
+
*/
|
|
1189
|
+
total_audio_proc_ms: number;
|
|
1190
|
+
/**
|
|
1191
|
+
* Whether this is the final result (session ending).
|
|
1192
|
+
*/
|
|
1193
|
+
finished?: boolean | undefined;
|
|
1194
|
+
};
|
|
1195
|
+
/**
|
|
1196
|
+
* Typed event for async iterator consumption.
|
|
1197
|
+
*/
|
|
1198
|
+
type RealtimeEvent = {
|
|
1199
|
+
kind: 'result';
|
|
1200
|
+
data: RealtimeResult;
|
|
1201
|
+
} | {
|
|
1202
|
+
kind: 'endpoint';
|
|
1203
|
+
} | {
|
|
1204
|
+
kind: 'finalized';
|
|
1205
|
+
} | {
|
|
1206
|
+
kind: 'finished';
|
|
1207
|
+
};
|
|
1208
|
+
/**
|
|
1209
|
+
* Session lifecycle states.
|
|
1210
|
+
*/
|
|
1211
|
+
type SttSessionState = 'idle' | 'connecting' | 'connected' | 'finishing' | 'finished' | 'canceled' | 'closed' | 'error';
|
|
1212
|
+
/**
|
|
1213
|
+
* Event handlers for the STT session.
|
|
1214
|
+
*/
|
|
1215
|
+
type SttSessionEvents = {
|
|
1216
|
+
/**
|
|
1217
|
+
* Parsed result received.
|
|
1218
|
+
*/
|
|
1219
|
+
result: (result: RealtimeResult) => void;
|
|
1220
|
+
/**
|
|
1221
|
+
* Individual token received.
|
|
1222
|
+
*/
|
|
1223
|
+
token: (token: RealtimeToken) => void;
|
|
1224
|
+
/**
|
|
1225
|
+
* Error occurred.
|
|
1226
|
+
*/
|
|
1227
|
+
error: (error: Error) => void;
|
|
1228
|
+
/**
|
|
1229
|
+
* Endpoint detected (<end> token).
|
|
1230
|
+
*/
|
|
1231
|
+
endpoint: () => void;
|
|
1232
|
+
/**
|
|
1233
|
+
* Finalization complete (<fin> token).
|
|
1234
|
+
*/
|
|
1235
|
+
finalized: () => void;
|
|
1236
|
+
/**
|
|
1237
|
+
* Session finished (server signaled end of stream).
|
|
1238
|
+
*/
|
|
1239
|
+
finished: () => void;
|
|
1240
|
+
/**
|
|
1241
|
+
* Session connected and ready.
|
|
1242
|
+
*/
|
|
1243
|
+
connected: () => void;
|
|
1244
|
+
/**
|
|
1245
|
+
* Session disconnected.
|
|
1246
|
+
*/
|
|
1247
|
+
disconnected: (reason?: string) => void;
|
|
1248
|
+
/**
|
|
1249
|
+
* Session state transition.
|
|
1250
|
+
*/
|
|
1251
|
+
state_change: (update: {
|
|
1252
|
+
old_state: SttSessionState;
|
|
1253
|
+
new_state: SttSessionState;
|
|
1254
|
+
}) => void;
|
|
1255
|
+
};
|
|
1256
|
+
/**
|
|
1257
|
+
* Audio data types accepted by sendAudio.
|
|
1258
|
+
*/
|
|
1259
|
+
type AudioData = Buffer | Uint8Array | ArrayBuffer;
|
|
1260
|
+
/**
|
|
1261
|
+
* Options for streaming audio from an async iterable source.
|
|
1262
|
+
*/
|
|
1263
|
+
type SendStreamOptions = {
|
|
1264
|
+
/**
|
|
1265
|
+
* Delay in milliseconds between sending chunks.
|
|
1266
|
+
* Useful for simulating real-time pace when streaming pre-recorded files.
|
|
1267
|
+
* Not needed for live audio sources.
|
|
1268
|
+
*/
|
|
1269
|
+
pace_ms?: number | undefined;
|
|
1270
|
+
/**
|
|
1271
|
+
* When true, calls finish() automatically after the stream ends.
|
|
1272
|
+
* @default false
|
|
1273
|
+
*/
|
|
1274
|
+
finish?: boolean | undefined;
|
|
1275
|
+
};
|
|
1276
|
+
/**
|
|
1277
|
+
* Real-time API configuration options for the client.
|
|
1278
|
+
*/
|
|
1279
|
+
type RealtimeClientOptions = {
|
|
1280
|
+
/**
|
|
1281
|
+
* API key for real-time sessions.
|
|
1282
|
+
*/
|
|
1283
|
+
api_key: string;
|
|
1284
|
+
/**
|
|
1285
|
+
* WebSocket base URL for real-time connections.
|
|
1286
|
+
* @default 'wss://stt-rt.soniox.com/transcribe-websocket'
|
|
1287
|
+
*/
|
|
1288
|
+
ws_base_url: string;
|
|
1289
|
+
/**
|
|
1290
|
+
* Default session options applied to all real-time sessions.
|
|
1291
|
+
* Can be overridden per-session.
|
|
1292
|
+
*/
|
|
1293
|
+
default_session_options?: SttSessionOptions | undefined;
|
|
1294
|
+
};
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/types/public/models.d.ts
|
|
1297
|
+
/**
|
|
1298
|
+
* Transcription mode of the model.
|
|
1299
|
+
*/
|
|
1300
|
+
type SonioxTranscriptionMode = 'real_time' | 'async';
|
|
1301
|
+
type SonioxLanguage = {
|
|
1302
|
+
/**
|
|
1303
|
+
* 2-letter language code.
|
|
1304
|
+
*/
|
|
1305
|
+
code: string;
|
|
1306
|
+
/**
|
|
1307
|
+
* Language name.
|
|
1308
|
+
*/
|
|
1309
|
+
name: string;
|
|
1310
|
+
};
|
|
1311
|
+
type SonioxTranslationTarget = {
|
|
1312
|
+
target_language: string;
|
|
1313
|
+
source_languages: string[];
|
|
1314
|
+
exclude_source_languages: string[];
|
|
1315
|
+
};
|
|
1316
|
+
type SonioxModel = {
|
|
1317
|
+
/**
|
|
1318
|
+
* Unique identifier of the model.
|
|
1319
|
+
*/
|
|
1320
|
+
id: string;
|
|
1321
|
+
/**
|
|
1322
|
+
* If this is an alias, the id of the aliased model. Null for non-alias models.
|
|
1323
|
+
*/
|
|
1324
|
+
aliased_model_id: string | null;
|
|
1325
|
+
/**
|
|
1326
|
+
* Name of the model.
|
|
1327
|
+
*/
|
|
1328
|
+
name: string;
|
|
1329
|
+
/**
|
|
1330
|
+
* Version of context supported.
|
|
1331
|
+
*/
|
|
1332
|
+
context_version: number | null;
|
|
1333
|
+
/**
|
|
1334
|
+
* Transcription mode of the model.
|
|
1335
|
+
*/
|
|
1336
|
+
transcription_mode: SonioxTranscriptionMode;
|
|
1337
|
+
/**
|
|
1338
|
+
* List of languages supported by the model.
|
|
1339
|
+
*/
|
|
1340
|
+
languages: SonioxLanguage[];
|
|
1341
|
+
/**
|
|
1342
|
+
* TODO: Add documentation
|
|
1343
|
+
*/
|
|
1344
|
+
supports_language_hints_strict: boolean;
|
|
1345
|
+
/**
|
|
1346
|
+
* List of supported one-way translation targets. If list is empty, check for one_way_translation field
|
|
1347
|
+
*/
|
|
1348
|
+
translation_targets: SonioxTranslationTarget[];
|
|
1349
|
+
/**
|
|
1350
|
+
* List of supported two-way translation pairs. If list is empty, check for two_way_translation field
|
|
1351
|
+
*/
|
|
1352
|
+
two_way_translation_pairs: string[];
|
|
1353
|
+
/**
|
|
1354
|
+
* When contains string 'all_languages', any laguage from languages can be used
|
|
1355
|
+
*/
|
|
1356
|
+
one_way_translation: string | null;
|
|
1357
|
+
/**
|
|
1358
|
+
* When contains string 'all_languages',' any laguage pair from languages can be used
|
|
1359
|
+
*/
|
|
1360
|
+
two_way_translation: string | null;
|
|
1361
|
+
supports_max_endpoint_delay: boolean;
|
|
1362
|
+
};
|
|
1363
|
+
//#endregion
|
|
1364
|
+
//#region src/types/public/webhooks.d.ts
|
|
1365
|
+
/**
|
|
1366
|
+
* Webhook event status values
|
|
1367
|
+
*/
|
|
1368
|
+
type WebhookEventStatus = 'completed' | 'error';
|
|
1369
|
+
/**
|
|
1370
|
+
* Webhook event payload sent by Soniox when a transcription completes or fails.
|
|
1371
|
+
*/
|
|
1372
|
+
type WebhookEvent = {
|
|
1373
|
+
/**
|
|
1374
|
+
* Transcription ID
|
|
1375
|
+
* @format uuid
|
|
1376
|
+
*/
|
|
1377
|
+
id: string;
|
|
1378
|
+
/**
|
|
1379
|
+
* Transcription result status
|
|
1380
|
+
*/
|
|
1381
|
+
status: WebhookEventStatus;
|
|
1382
|
+
};
|
|
1383
|
+
/**
|
|
1384
|
+
* Authentication configuration for webhook verification
|
|
1385
|
+
*/
|
|
1386
|
+
type WebhookAuthConfig = {
|
|
1387
|
+
/**
|
|
1388
|
+
* Expected header name (case-insensitive comparison)
|
|
1389
|
+
*/
|
|
1390
|
+
name: string;
|
|
1391
|
+
/**
|
|
1392
|
+
* Expected header value (exact match)
|
|
1393
|
+
*/
|
|
1394
|
+
value: string;
|
|
1395
|
+
};
|
|
1396
|
+
/**
|
|
1397
|
+
* Headers object type - supports both standard headers and record types
|
|
1398
|
+
*/
|
|
1399
|
+
type WebhookHeaders = Headers | Record<string, string | string[] | undefined> | {
|
|
1400
|
+
get(name: string): string | null;
|
|
1401
|
+
};
|
|
1402
|
+
/**
|
|
1403
|
+
* Result of webhook handling
|
|
1404
|
+
*/
|
|
1405
|
+
type WebhookHandlerResult = {
|
|
1406
|
+
/**
|
|
1407
|
+
* Whether the webhook was handled successfully
|
|
1408
|
+
*/
|
|
1409
|
+
ok: boolean;
|
|
1410
|
+
/**
|
|
1411
|
+
* HTTP status code to return
|
|
1412
|
+
*/
|
|
1413
|
+
status: number;
|
|
1414
|
+
/**
|
|
1415
|
+
* Parsed webhook event (only present when ok=true)
|
|
1416
|
+
*/
|
|
1417
|
+
event?: WebhookEvent;
|
|
1418
|
+
/**
|
|
1419
|
+
* Error message (only present when ok=false)
|
|
1420
|
+
*/
|
|
1421
|
+
error?: string;
|
|
1422
|
+
};
|
|
1423
|
+
/**
|
|
1424
|
+
* Result of webhook handling with lazy fetch capabilities.
|
|
1425
|
+
*
|
|
1426
|
+
* When using `client.webhooks.handleExpress()` (or other framework handlers),
|
|
1427
|
+
* the result includes helper methods to fetch the transcript or transcription.
|
|
1428
|
+
*/
|
|
1429
|
+
type WebhookHandlerResultWithFetch = WebhookHandlerResult & {
|
|
1430
|
+
/**
|
|
1431
|
+
* Fetch the transcript for a completed transcription.
|
|
1432
|
+
* Only available when `ok=true` and `event.status='completed'`.
|
|
1433
|
+
*
|
|
1434
|
+
* @returns The transcript with text and tokens, or null if not found
|
|
1435
|
+
*
|
|
1436
|
+
* @example
|
|
1437
|
+
* ```typescript
|
|
1438
|
+
* const result = soniox.webhooks.handleExpress(req);
|
|
1439
|
+
* if (result.ok && result.event.status === 'completed') {
|
|
1440
|
+
* const transcript = await result.fetchTranscript();
|
|
1441
|
+
* console.log(transcript?.text);
|
|
1442
|
+
* }
|
|
1443
|
+
* ```
|
|
1444
|
+
*/
|
|
1445
|
+
fetchTranscript: (() => Promise<ISonioxTranscript | null>) | undefined;
|
|
1446
|
+
/**
|
|
1447
|
+
* Fetch the full transcription object.
|
|
1448
|
+
* Useful for both completed (metadata) and error (error details) statuses.
|
|
1449
|
+
*
|
|
1450
|
+
* @returns The transcription object, or null if not found
|
|
1451
|
+
*
|
|
1452
|
+
* @example
|
|
1453
|
+
* ```typescript
|
|
1454
|
+
* const result = soniox.webhooks.handleExpress(req);
|
|
1455
|
+
* if (result.ok && result.event.status === 'error') {
|
|
1456
|
+
* const transcription = await result.fetchTranscription();
|
|
1457
|
+
* console.log(transcription?.error_message);
|
|
1458
|
+
* }
|
|
1459
|
+
* ```
|
|
1460
|
+
*/
|
|
1461
|
+
fetchTranscription: (() => Promise<ISonioxTranscription | null>) | undefined;
|
|
1462
|
+
};
|
|
1463
|
+
/**
|
|
1464
|
+
* Options for the handleWebhook function
|
|
1465
|
+
*/
|
|
1466
|
+
type HandleWebhookOptions = {
|
|
1467
|
+
/**
|
|
1468
|
+
* HTTP method of the request
|
|
1469
|
+
*/
|
|
1470
|
+
method: string;
|
|
1471
|
+
/**
|
|
1472
|
+
* Request headers
|
|
1473
|
+
*/
|
|
1474
|
+
headers: WebhookHeaders;
|
|
1475
|
+
/**
|
|
1476
|
+
* Request body (parsed JSON or raw string)
|
|
1477
|
+
*/
|
|
1478
|
+
body: unknown;
|
|
1479
|
+
/**
|
|
1480
|
+
* Optional authentication configuration
|
|
1481
|
+
*/
|
|
1482
|
+
auth?: WebhookAuthConfig;
|
|
1483
|
+
};
|
|
1484
|
+
/**
|
|
1485
|
+
* Express/Connect-style request object
|
|
1486
|
+
*/
|
|
1487
|
+
type ExpressLikeRequest = {
|
|
1488
|
+
method: string;
|
|
1489
|
+
headers: Record<string, string | string[] | undefined>;
|
|
1490
|
+
body?: unknown;
|
|
1491
|
+
};
|
|
1492
|
+
/**
|
|
1493
|
+
* Fastify-style request object
|
|
1494
|
+
*/
|
|
1495
|
+
type FastifyLikeRequest = {
|
|
1496
|
+
method: string;
|
|
1497
|
+
headers: Record<string, string | string[] | undefined>;
|
|
1498
|
+
body?: unknown;
|
|
1499
|
+
};
|
|
1500
|
+
/**
|
|
1501
|
+
* NestJS-style request object (uses Express under the hood by default)
|
|
1502
|
+
*/
|
|
1503
|
+
type NestJSLikeRequest = {
|
|
1504
|
+
method: string;
|
|
1505
|
+
headers: Record<string, string | string[] | undefined>;
|
|
1506
|
+
body?: unknown;
|
|
1507
|
+
};
|
|
1508
|
+
/**
|
|
1509
|
+
* Hono context object
|
|
1510
|
+
*/
|
|
1511
|
+
type HonoLikeContext = {
|
|
1512
|
+
req: {
|
|
1513
|
+
method: string;
|
|
1514
|
+
header(name: string): string | undefined;
|
|
1515
|
+
json(): Promise<unknown>;
|
|
1516
|
+
};
|
|
1517
|
+
};
|
|
1518
|
+
//#endregion
|
|
1519
|
+
//#region src/types/public/index.d.ts
|
|
1520
|
+
/**
|
|
1521
|
+
* Result of a purge operation.
|
|
1522
|
+
*/
|
|
1523
|
+
type PurgeResult = {
|
|
1524
|
+
/**
|
|
1525
|
+
* Number of resources deleted.
|
|
1526
|
+
*/
|
|
1527
|
+
deleted: number;
|
|
1528
|
+
};
|
|
1529
|
+
type TemporaryApiKeyUsageType = 'transcribe_websocket';
|
|
1530
|
+
type TemporaryApiKeyRequest = {
|
|
1531
|
+
/**
|
|
1532
|
+
* Intended usage of the temporary API key.
|
|
1533
|
+
*/
|
|
1534
|
+
usage_type: TemporaryApiKeyUsageType;
|
|
1535
|
+
/**
|
|
1536
|
+
* Duration in seconds until the temporary API key expires
|
|
1537
|
+
* @minimum 1
|
|
1538
|
+
* @maximum 3600
|
|
1539
|
+
*/
|
|
1540
|
+
expires_in_seconds: number;
|
|
1541
|
+
/**
|
|
1542
|
+
* Optional tracking identifier string. Does not need to be unique
|
|
1543
|
+
* @maxLength 256
|
|
1544
|
+
*/
|
|
1545
|
+
client_reference_id?: string;
|
|
1546
|
+
};
|
|
1547
|
+
type TemporaryApiKeyResponse = {
|
|
1548
|
+
/**
|
|
1549
|
+
* Created temporary API key.
|
|
1550
|
+
*/
|
|
1551
|
+
api_key: string;
|
|
1552
|
+
/**
|
|
1553
|
+
* UTC timestamp indicating when generated temporary API key will expire
|
|
1554
|
+
* @format date-time
|
|
1555
|
+
*/
|
|
1556
|
+
expires_at: string;
|
|
1557
|
+
};
|
|
1558
|
+
/**
|
|
1559
|
+
* Real-time configuration options for the main client.
|
|
1560
|
+
*/
|
|
1561
|
+
type RealtimeOptions = {
|
|
1562
|
+
/**
|
|
1563
|
+
* WebSocket base URL for real-time connections.
|
|
1564
|
+
* Falls back to SONIOX_WS_URL environment variable,
|
|
1565
|
+
* then to 'wss://stt-rt.soniox.com/transcribe-websocket'.
|
|
1566
|
+
*/
|
|
1567
|
+
ws_base_url?: string | undefined;
|
|
1568
|
+
/**
|
|
1569
|
+
* Default session options applied to all real-time sessions.
|
|
1570
|
+
* Can be overridden per-session.
|
|
1571
|
+
*/
|
|
1572
|
+
default_session_options?: SttSessionOptions | undefined;
|
|
1573
|
+
};
|
|
1574
|
+
type SonioxNodeClientOptions = {
|
|
1575
|
+
/**
|
|
1576
|
+
* API key for authentication.
|
|
1577
|
+
* Falls back to SONIOX_API_KEY environment variable if not provided.
|
|
1578
|
+
*/
|
|
1579
|
+
api_key?: string;
|
|
1580
|
+
/**
|
|
1581
|
+
* Base URL for the REST API.
|
|
1582
|
+
* Falls back to SONIOX_API_BASE_URL environment variable,
|
|
1583
|
+
* then to 'https://api.soniox.com'.
|
|
1584
|
+
*/
|
|
1585
|
+
base_url?: string;
|
|
1586
|
+
/**
|
|
1587
|
+
* Custom HTTP client implementation.
|
|
1588
|
+
*/
|
|
1589
|
+
http_client?: HttpClient;
|
|
1590
|
+
/**
|
|
1591
|
+
* Real-time API configuration options.
|
|
1592
|
+
*/
|
|
1593
|
+
realtime?: RealtimeOptions;
|
|
1594
|
+
};
|
|
1595
|
+
//#endregion
|
|
1596
|
+
//#region src/async/auth.d.ts
|
|
1597
|
+
declare class SonioxAuthAPI {
|
|
1598
|
+
private http;
|
|
1599
|
+
constructor(http: HttpClient);
|
|
1600
|
+
/**
|
|
1601
|
+
* Creates a temporary API key for client-side use.
|
|
1602
|
+
*
|
|
1603
|
+
* @param request - Request parameters for the temporary key
|
|
1604
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
1605
|
+
* @returns The temporary API key response
|
|
1606
|
+
*/
|
|
1607
|
+
createTemporaryKey(request: TemporaryApiKeyRequest, signal?: AbortSignal): Promise<TemporaryApiKeyResponse>;
|
|
1608
|
+
}
|
|
1609
|
+
//#endregion
|
|
1610
|
+
//#region src/async/files.d.ts
|
|
1611
|
+
/**
|
|
1612
|
+
* Uploaded file
|
|
1613
|
+
*/
|
|
1614
|
+
declare class SonioxFile {
|
|
1615
|
+
private readonly _http;
|
|
1616
|
+
readonly id: string;
|
|
1617
|
+
readonly filename: string;
|
|
1618
|
+
readonly size: number;
|
|
1619
|
+
readonly created_at: string;
|
|
1620
|
+
readonly client_reference_id: string | undefined;
|
|
1621
|
+
constructor(data: SonioxFileData, _http: HttpClient);
|
|
1622
|
+
/**
|
|
1623
|
+
* Returns the raw data for this file.
|
|
1624
|
+
*/
|
|
1625
|
+
toJSON(): SonioxFileData;
|
|
1626
|
+
/**
|
|
1627
|
+
* Permanently deletes this file.
|
|
1628
|
+
* This operation is idempotent - succeeds even if the file doesn't exist.
|
|
1629
|
+
*
|
|
1630
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
1631
|
+
* @throws {SonioxHttpError} On API errors (except 404)
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* ```typescript
|
|
1635
|
+
* const file = await client.files.get('550e8400-e29b-41d4-a716-446655440000');
|
|
1636
|
+
* if (file) {
|
|
1637
|
+
* await file.delete();
|
|
1638
|
+
* }
|
|
1639
|
+
* ```
|
|
1640
|
+
*/
|
|
1641
|
+
delete(signal?: AbortSignal): Promise<void>;
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Result set for file listing
|
|
1645
|
+
*/
|
|
1646
|
+
declare class FileListResult implements AsyncIterable<SonioxFile> {
|
|
1647
|
+
private readonly _http;
|
|
1648
|
+
private readonly _limit;
|
|
1649
|
+
private readonly _signal;
|
|
1650
|
+
/**
|
|
1651
|
+
* Files from the first page of results
|
|
1652
|
+
*/
|
|
1653
|
+
readonly files: SonioxFile[];
|
|
1654
|
+
/**
|
|
1655
|
+
* Pagination cursor for the next page. Null if no more pages
|
|
1656
|
+
*/
|
|
1657
|
+
readonly next_page_cursor: string | null;
|
|
1658
|
+
constructor(initialResponse: ListFilesResponse<SonioxFileData>, _http: HttpClient, _limit: number | undefined, _signal?: AbortSignal | undefined);
|
|
1659
|
+
/**
|
|
1660
|
+
* Returns the raw data for this list result.
|
|
1661
|
+
* Also used by JSON.stringify() to prevent serialization of internal HTTP client.
|
|
1662
|
+
*/
|
|
1663
|
+
toJSON(): ListFilesResponse<SonioxFileData>;
|
|
1664
|
+
/**
|
|
1665
|
+
* Returns true if there are more pages of results beyond the first page
|
|
1666
|
+
*/
|
|
1667
|
+
isPaged(): boolean;
|
|
1668
|
+
/**
|
|
1669
|
+
* Async iterator that automatically fetches all pages
|
|
1670
|
+
* Use with `for await...of` to iterate through all files
|
|
1671
|
+
*/
|
|
1672
|
+
[Symbol.asyncIterator](): AsyncIterator<SonioxFile>;
|
|
1673
|
+
}
|
|
1674
|
+
declare class SonioxFilesAPI {
|
|
1675
|
+
private http;
|
|
1676
|
+
constructor(http: HttpClient);
|
|
1677
|
+
/**
|
|
1678
|
+
* Uploads a file to Soniox for transcription
|
|
1679
|
+
*
|
|
1680
|
+
* @param file - Buffer, Uint8Array, Blob, or ReadableStream
|
|
1681
|
+
* @param options - Upload options
|
|
1682
|
+
* @returns The uploaded file metadata
|
|
1683
|
+
* @throws {SonioxHttpError} On API errors
|
|
1684
|
+
* @throws {Error} On validation errors (file too large, invalid input)
|
|
1685
|
+
*
|
|
1686
|
+
* @example Upload from file path (Node.js)
|
|
1687
|
+
* ```typescript
|
|
1688
|
+
* import * as fs from 'node:fs';
|
|
1689
|
+
*
|
|
1690
|
+
* const buffer = await fs.promises.readFile('/path/to/audio.mp3');
|
|
1691
|
+
* const file = await client.files.upload(buffer, { filename: 'audio.mp3' });
|
|
1692
|
+
* ```
|
|
1693
|
+
*
|
|
1694
|
+
* @example Upload from file path (Bun)
|
|
1695
|
+
* ```typescript
|
|
1696
|
+
* const file = await client.files.upload(Bun.file('/path/to/audio.mp3'));
|
|
1697
|
+
* ```
|
|
1698
|
+
*
|
|
1699
|
+
* @example Upload with tracking ID
|
|
1700
|
+
* ```typescript
|
|
1701
|
+
* const file = await client.files.upload(buffer, {
|
|
1702
|
+
* filename: 'audio.mp3',
|
|
1703
|
+
* client_reference_id: 'order-12345',
|
|
1704
|
+
* });
|
|
1705
|
+
* ```
|
|
1706
|
+
*
|
|
1707
|
+
* @example Upload with cancellation
|
|
1708
|
+
* ```typescript
|
|
1709
|
+
* const controller = new AbortController();
|
|
1710
|
+
* setTimeout(() => controller.abort(), 30000);
|
|
1711
|
+
*
|
|
1712
|
+
* const file = await client.files.upload(buffer, {
|
|
1713
|
+
* filename: 'audio.mp3',
|
|
1714
|
+
* signal: controller.signal,
|
|
1715
|
+
* });
|
|
1716
|
+
* ```
|
|
1717
|
+
*/
|
|
1718
|
+
upload(file: UploadFileInput, options?: UploadFileOptions): Promise<SonioxFile>;
|
|
1719
|
+
/**
|
|
1720
|
+
* Retrieves list of uploaded files
|
|
1721
|
+
*
|
|
1722
|
+
* The returned result is async iterable - use `for await...of`
|
|
1723
|
+
*
|
|
1724
|
+
* @param options - Optional pagination and cancellation parameters
|
|
1725
|
+
* @returns FileListResult
|
|
1726
|
+
* @throws {SonioxHttpError}
|
|
1727
|
+
*
|
|
1728
|
+
* @example
|
|
1729
|
+
* ```typescript
|
|
1730
|
+
* const result = await client.files.list();
|
|
1731
|
+
*
|
|
1732
|
+
* // Automatic paging - iterates through ALL files across all pages
|
|
1733
|
+
* for await (const file of result) {
|
|
1734
|
+
* console.log(file.filename, file.size);
|
|
1735
|
+
* }
|
|
1736
|
+
*
|
|
1737
|
+
* // Or access just the first page
|
|
1738
|
+
* for (const file of result.files) {
|
|
1739
|
+
* console.log(file.filename);
|
|
1740
|
+
* }
|
|
1741
|
+
*
|
|
1742
|
+
* // Check if there are more pages
|
|
1743
|
+
* if (result.isPaged()) {
|
|
1744
|
+
* console.log('More pages available');
|
|
1745
|
+
* }
|
|
1746
|
+
*
|
|
1747
|
+
* // Manual paging using cursor
|
|
1748
|
+
* const page1 = await client.files.list({ limit: 10 });
|
|
1749
|
+
* if (page1.next_page_cursor) {
|
|
1750
|
+
* const page2 = await client.files.list({ cursor: page1.next_page_cursor });
|
|
1751
|
+
* }
|
|
1752
|
+
*
|
|
1753
|
+
* // With cancellation
|
|
1754
|
+
* const controller = new AbortController();
|
|
1755
|
+
* const result = await client.files.list({ signal: controller.signal });
|
|
1756
|
+
* ```
|
|
1757
|
+
*/
|
|
1758
|
+
list(options?: ListFilesOptions): Promise<FileListResult>;
|
|
1759
|
+
/**
|
|
1760
|
+
* Retrieve metadata for an uploaded file.
|
|
1761
|
+
*
|
|
1762
|
+
* @param file - The UUID of the file or a SonioxFile instance
|
|
1763
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
1764
|
+
* @returns The file instance, or null if not found
|
|
1765
|
+
* @throws {SonioxHttpError} On API errors (except 404)
|
|
1766
|
+
*
|
|
1767
|
+
* @example
|
|
1768
|
+
* ```typescript
|
|
1769
|
+
* const file = await client.files.get('550e8400-e29b-41d4-a716-446655440000');
|
|
1770
|
+
* if (file) {
|
|
1771
|
+
* console.log(file.filename, file.size);
|
|
1772
|
+
* }
|
|
1773
|
+
* ```
|
|
1774
|
+
*/
|
|
1775
|
+
get(file: FileIdentifier, signal?: AbortSignal): Promise<SonioxFile | null>;
|
|
1776
|
+
/**
|
|
1777
|
+
* Permanently deletes a file.
|
|
1778
|
+
* This operation is idempotent - succeeds even if the file doesn't exist.
|
|
1779
|
+
*
|
|
1780
|
+
* @param file - The UUID of the file or a SonioxFile instance
|
|
1781
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
1782
|
+
* @throws {SonioxHttpError} On API errors (except 404)
|
|
1783
|
+
*
|
|
1784
|
+
* @example
|
|
1785
|
+
* ```typescript
|
|
1786
|
+
* // Delete by ID
|
|
1787
|
+
* await client.files.delete('550e8400-e29b-41d4-a716-446655440000');
|
|
1788
|
+
*
|
|
1789
|
+
* // Or delete a file instance
|
|
1790
|
+
* const file = await client.files.get('550e8400-e29b-41d4-a716-446655440000');
|
|
1791
|
+
* if (file) {
|
|
1792
|
+
* await client.files.delete(file);
|
|
1793
|
+
* }
|
|
1794
|
+
*
|
|
1795
|
+
* // Or just use the instance method
|
|
1796
|
+
* await file.delete();
|
|
1797
|
+
* ```
|
|
1798
|
+
*/
|
|
1799
|
+
delete(file: FileIdentifier, signal?: AbortSignal): Promise<void>;
|
|
1800
|
+
/**
|
|
1801
|
+
* Permanently deletes all uploaded files.
|
|
1802
|
+
* Iterates through all pages of files and deletes each one.
|
|
1803
|
+
*
|
|
1804
|
+
* @param options - Optional signal and progress callback.
|
|
1805
|
+
* @returns The number of files deleted.
|
|
1806
|
+
* @throws {SonioxHttpError} On API errors.
|
|
1807
|
+
* @throws {Error} If the operation is aborted via signal.
|
|
1808
|
+
*
|
|
1809
|
+
* @example
|
|
1810
|
+
* ```typescript
|
|
1811
|
+
* // Delete all files
|
|
1812
|
+
* const { deleted } = await client.files.purge();
|
|
1813
|
+
* console.log(`Deleted ${deleted} files.`);
|
|
1814
|
+
*
|
|
1815
|
+
* // With progress logging
|
|
1816
|
+
* const { deleted } = await client.files.purge({
|
|
1817
|
+
* on_progress: (file, index) => {
|
|
1818
|
+
* console.log(`Deleting file: ${file.id} (${index + 1})`);
|
|
1819
|
+
* },
|
|
1820
|
+
* });
|
|
1821
|
+
*
|
|
1822
|
+
* // With cancellation
|
|
1823
|
+
* const controller = new AbortController();
|
|
1824
|
+
* const { deleted } = await client.files.purge({ signal: controller.signal });
|
|
1825
|
+
* ```
|
|
1826
|
+
*/
|
|
1827
|
+
purge(options?: PurgeFilesOptions): Promise<PurgeResult>;
|
|
1828
|
+
}
|
|
1829
|
+
//#endregion
|
|
1830
|
+
//#region src/async/models.d.ts
|
|
1831
|
+
declare class SonioxModelsAPI {
|
|
1832
|
+
private http;
|
|
1833
|
+
constructor(http: HttpClient);
|
|
1834
|
+
/**
|
|
1835
|
+
* List of available models and their attributes.
|
|
1836
|
+
* @see https://soniox.com/docs/stt/api-reference/models/get_models
|
|
1837
|
+
* @param signal - Optional AbortSignal for cancellation
|
|
1838
|
+
* @returns List of available models and their attributes.
|
|
1839
|
+
*/
|
|
1840
|
+
list(signal?: AbortSignal): Promise<SonioxModel[]>;
|
|
1841
|
+
}
|
|
1842
|
+
//#endregion
|
|
1843
|
+
//#region src/async/stt.d.ts
|
|
1844
|
+
/**
|
|
1845
|
+
* Groups contiguous tokens into segments based on specified grouping keys.
|
|
1846
|
+
* A new segment starts when any of the `group_by` fields changes
|
|
1847
|
+
*
|
|
1848
|
+
* @param tokens - Array of transcript tokens to segment
|
|
1849
|
+
* @param options - Segmentation options
|
|
1850
|
+
* @param options.group_by - Fields to group by (default: ['speaker', 'language'])
|
|
1851
|
+
* @returns Array of segments with combined text and timing
|
|
1852
|
+
*
|
|
1853
|
+
* @example
|
|
1854
|
+
* ```typescript
|
|
1855
|
+
* const transcript = await transcription.getTranscript();
|
|
1856
|
+
*
|
|
1857
|
+
* // Group by both speaker and language (default)
|
|
1858
|
+
* const segments = segmentTranscript(transcript.tokens);
|
|
1859
|
+
*
|
|
1860
|
+
* // Group by speaker only
|
|
1861
|
+
* const bySpeaker = segmentTranscript(transcript.tokens, { group_by: ['speaker'] });
|
|
1862
|
+
*
|
|
1863
|
+
* // Group by language only
|
|
1864
|
+
* const byLanguage = segmentTranscript(transcript.tokens, { group_by: ['language'] });
|
|
1865
|
+
*
|
|
1866
|
+
* for (const seg of segments) {
|
|
1867
|
+
* console.log(`[Speaker ${seg.speaker}] ${seg.text}`);
|
|
1868
|
+
* }
|
|
1869
|
+
* ```
|
|
1870
|
+
*/
|
|
1871
|
+
declare function segmentTranscript(tokens: TranscriptToken[], options?: SegmentTranscriptOptions): TranscriptSegment[];
|
|
1872
|
+
/**
|
|
1873
|
+
* A Transcript result containing the transcribed text and tokens.
|
|
1874
|
+
*/
|
|
1875
|
+
declare class SonioxTranscript implements ISonioxTranscript {
|
|
1876
|
+
/**
|
|
1877
|
+
* Unique identifier of the transcription this transcript belongs to.
|
|
1878
|
+
*/
|
|
1879
|
+
readonly id: string;
|
|
1880
|
+
/**
|
|
1881
|
+
* Complete transcribed text content.
|
|
1882
|
+
*/
|
|
1883
|
+
readonly text: string;
|
|
1884
|
+
/**
|
|
1885
|
+
* List of detailed token information with timestamps and metadata.
|
|
1886
|
+
*/
|
|
1887
|
+
readonly tokens: TranscriptToken[];
|
|
1888
|
+
constructor(data: TranscriptResponse);
|
|
1889
|
+
/**
|
|
1890
|
+
* Groups tokens into segments based on specified grouping keys.
|
|
1891
|
+
*
|
|
1892
|
+
* A new segment starts when any of the `group_by` fields changes.
|
|
1893
|
+
*
|
|
1894
|
+
* @param options - Segmentation options
|
|
1895
|
+
* @param options.group_by - Fields to group by (default: ['speaker', 'language'])
|
|
1896
|
+
* @returns Array of segments with combined text and timing
|
|
1897
|
+
*
|
|
1898
|
+
* @example
|
|
1899
|
+
* ```typescript
|
|
1900
|
+
* const transcript = await transcription.getTranscript();
|
|
1901
|
+
*
|
|
1902
|
+
* // Group by both speaker and language (default)
|
|
1903
|
+
* const segments = transcript.segments();
|
|
1904
|
+
*
|
|
1905
|
+
* // Group by speaker only
|
|
1906
|
+
* const bySpeaker = transcript.segments({ group_by: ['speaker'] });
|
|
1907
|
+
*
|
|
1908
|
+
* for (const s of segments) {
|
|
1909
|
+
* console.log(`[Speaker ${s.speaker}] ${s.text}`);
|
|
1910
|
+
* }
|
|
1911
|
+
* ```
|
|
1912
|
+
*/
|
|
1913
|
+
segments(options?: SegmentTranscriptOptions): TranscriptSegment[];
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* A Transcription instance
|
|
1917
|
+
*/
|
|
1918
|
+
declare class SonioxTranscription implements ISonioxTranscription {
|
|
1919
|
+
private readonly _http;
|
|
1920
|
+
/**
|
|
1921
|
+
* Unique identifier of the transcription.
|
|
1922
|
+
*/
|
|
1923
|
+
readonly id: string;
|
|
1924
|
+
/**
|
|
1925
|
+
* Current status of the transcription.
|
|
1926
|
+
*/
|
|
1927
|
+
readonly status: TranscriptionStatus;
|
|
1928
|
+
/**
|
|
1929
|
+
* UTC timestamp when the transcription was created.
|
|
1930
|
+
*/
|
|
1931
|
+
readonly created_at: string;
|
|
1932
|
+
/**
|
|
1933
|
+
* Speech-to-text model used.
|
|
1934
|
+
*/
|
|
1935
|
+
readonly model: string;
|
|
1936
|
+
/**
|
|
1937
|
+
* URL of the audio file being transcribed.
|
|
1938
|
+
*/
|
|
1939
|
+
readonly audio_url: string | null | undefined;
|
|
1940
|
+
/**
|
|
1941
|
+
* ID of the uploaded file being transcribed.
|
|
1942
|
+
*/
|
|
1943
|
+
readonly file_id: string | null | undefined;
|
|
1944
|
+
/**
|
|
1945
|
+
* Name of the file being transcribed.
|
|
1946
|
+
*/
|
|
1947
|
+
readonly filename: string;
|
|
1948
|
+
/**
|
|
1949
|
+
* Expected languages in the audio.
|
|
1950
|
+
*/
|
|
1951
|
+
readonly language_hints: string[] | undefined;
|
|
1952
|
+
/**
|
|
1953
|
+
* When true, speakers are identified and separated in the transcription output.
|
|
1954
|
+
*/
|
|
1955
|
+
readonly enable_speaker_diarization: boolean;
|
|
1956
|
+
/**
|
|
1957
|
+
* When true, language is detected for each part of the transcription.
|
|
1958
|
+
*/
|
|
1959
|
+
readonly enable_language_identification: boolean;
|
|
1960
|
+
/**
|
|
1961
|
+
* Duration of the audio in milliseconds. Only available after processing begins.
|
|
1962
|
+
*/
|
|
1963
|
+
readonly audio_duration_ms: number | null | undefined;
|
|
1964
|
+
/**
|
|
1965
|
+
* Error type if transcription failed.
|
|
1966
|
+
*/
|
|
1967
|
+
readonly error_type: string | null | undefined;
|
|
1968
|
+
/**
|
|
1969
|
+
* Error message if transcription failed.
|
|
1970
|
+
*/
|
|
1971
|
+
readonly error_message: string | null | undefined;
|
|
1972
|
+
/**
|
|
1973
|
+
* URL to receive webhook notifications.
|
|
1974
|
+
*/
|
|
1975
|
+
readonly webhook_url: string | null | undefined;
|
|
1976
|
+
/**
|
|
1977
|
+
* Name of the authentication header sent with webhook notifications.
|
|
1978
|
+
*/
|
|
1979
|
+
readonly webhook_auth_header_name: string | null | undefined;
|
|
1980
|
+
/**
|
|
1981
|
+
* Authentication header value (masked).
|
|
1982
|
+
*/
|
|
1983
|
+
readonly webhook_auth_header_value: string | null | undefined;
|
|
1984
|
+
/**
|
|
1985
|
+
* HTTP status code received when webhook was delivered.
|
|
1986
|
+
*/
|
|
1987
|
+
readonly webhook_status_code: number | null | undefined;
|
|
1988
|
+
/**
|
|
1989
|
+
* Optional tracking identifier.
|
|
1990
|
+
*/
|
|
1991
|
+
readonly client_reference_id: string | null | undefined;
|
|
1992
|
+
/**
|
|
1993
|
+
* Additional context provided for the transcription.
|
|
1994
|
+
*/
|
|
1995
|
+
readonly context: TranscriptionContext | null | undefined;
|
|
1996
|
+
/**
|
|
1997
|
+
* Pre-fetched transcript. Only available when using `transcribe()` with `wait: true`,
|
|
1998
|
+
* `fetch_transcript !== false`, and the transcription completed successfully
|
|
1999
|
+
*/
|
|
2000
|
+
readonly transcript: SonioxTranscript | null | undefined;
|
|
2001
|
+
constructor(data: SonioxTranscriptionData, _http: HttpClient, transcript?: SonioxTranscript | null);
|
|
2002
|
+
/**
|
|
2003
|
+
* Returns the raw data for this transcription.
|
|
2004
|
+
*/
|
|
2005
|
+
toJSON(): SonioxTranscriptionData;
|
|
2006
|
+
/**
|
|
2007
|
+
* Permanently deletes this transcription.
|
|
2008
|
+
* This operation is idempotent - succeeds even if the transcription doesn't exist.
|
|
2009
|
+
*
|
|
2010
|
+
* @throws {SonioxHttpError} On API errors (except 404)
|
|
2011
|
+
*
|
|
2012
|
+
* @example
|
|
2013
|
+
* ```typescript
|
|
2014
|
+
* const transcription = await client.stt.get('550e8400-e29b-41d4-a716-446655440000');
|
|
2015
|
+
* await transcription.delete();
|
|
2016
|
+
* ```
|
|
2017
|
+
*/
|
|
2018
|
+
delete(): Promise<void>;
|
|
2019
|
+
/**
|
|
2020
|
+
* Permanently deletes this transcription and its associated file (if any).
|
|
2021
|
+
* This operation is idempotent - succeeds even if resources don't exist.
|
|
2022
|
+
*
|
|
2023
|
+
* @throws {SonioxHttpError} On API errors (except 404)
|
|
2024
|
+
*
|
|
2025
|
+
* @example
|
|
2026
|
+
* ```typescript
|
|
2027
|
+
* // Clean up both transcription and uploaded file
|
|
2028
|
+
* const transcription = await client.stt.transcribe({
|
|
2029
|
+
* model: 'stt-async-v4',
|
|
2030
|
+
* file: buffer,
|
|
2031
|
+
* wait: true,
|
|
2032
|
+
* });
|
|
2033
|
+
* // ... use transcription ...
|
|
2034
|
+
* await transcription.destroy(); // Deletes both transcription and file
|
|
2035
|
+
* ```
|
|
2036
|
+
*/
|
|
2037
|
+
destroy(): Promise<void>;
|
|
2038
|
+
/**
|
|
2039
|
+
* Retrieves the full transcript text and tokens for this transcription.
|
|
2040
|
+
* Only available for successfully completed transcriptions.
|
|
2041
|
+
*
|
|
2042
|
+
* Returns cached transcript if available (when using `transcribe()` with `wait: true`).
|
|
2043
|
+
* Use `force: true` to bypass the cache and fetch fresh data from the API.
|
|
2044
|
+
*
|
|
2045
|
+
* @param options - Optional settings
|
|
2046
|
+
* @param options.force - If true, bypasses cached transcript and fetches from API
|
|
2047
|
+
* @param options.signal - Optional AbortSignal for request cancellation
|
|
2048
|
+
* @returns The transcript with text and detailed tokens, or null if not found.
|
|
2049
|
+
* @throws {SonioxHttpError} On API errors (except 404).
|
|
2050
|
+
*
|
|
2051
|
+
* @example
|
|
2052
|
+
* ```typescript
|
|
2053
|
+
* const transcription = await client.stt.get('550e8400-e29b-41d4-a716-446655440000');
|
|
2054
|
+
* if (transcription) {
|
|
2055
|
+
* const transcript = await transcription.getTranscript();
|
|
2056
|
+
* if (transcript) {
|
|
2057
|
+
* console.log(transcript.text);
|
|
2058
|
+
* }
|
|
2059
|
+
* }
|
|
2060
|
+
*
|
|
2061
|
+
* // Force re-fetch from API
|
|
2062
|
+
* const freshTranscript = await transcription.getTranscript({ force: true });
|
|
2063
|
+
* ```
|
|
2064
|
+
*/
|
|
2065
|
+
getTranscript(options?: {
|
|
2066
|
+
force?: boolean;
|
|
2067
|
+
signal?: AbortSignal;
|
|
2068
|
+
}): Promise<SonioxTranscript | null>;
|
|
2069
|
+
/**
|
|
2070
|
+
* Re-fetches this transcription to get the latest status.
|
|
2071
|
+
* @param signal - Optional AbortSignal for request cancellation.
|
|
2072
|
+
* @returns A new SonioxTranscription instance with updated data.
|
|
2073
|
+
* @throws {SonioxHttpError}
|
|
2074
|
+
*
|
|
2075
|
+
* @example
|
|
2076
|
+
* ```typescript
|
|
2077
|
+
* let transcription = await client.stt.get('550e8400-e29b-41d4-a716-446655440000');
|
|
2078
|
+
* transcription = await transcription.refresh();
|
|
2079
|
+
* console.log(transcription.status);
|
|
2080
|
+
* ```
|
|
2081
|
+
*/
|
|
2082
|
+
refresh(signal?: AbortSignal): Promise<SonioxTranscription>;
|
|
2083
|
+
/**
|
|
2084
|
+
* Waits for the transcription to complete or fail.
|
|
2085
|
+
* Polls the API at the specified interval until the status is 'completed' or 'error'.
|
|
2086
|
+
*
|
|
2087
|
+
* @param options - Wait options including polling interval, timeout, and callbacks.
|
|
2088
|
+
* @returns The completed or errored transcription.
|
|
2089
|
+
* @throws {Error} If the wait times out or is aborted.
|
|
2090
|
+
* @throws {SonioxHttpError} On API errors.
|
|
2091
|
+
*
|
|
2092
|
+
* @example
|
|
2093
|
+
* ```typescript
|
|
2094
|
+
* const transcription = await client.stt.create({
|
|
2095
|
+
* model: 'stt-async-v4',
|
|
2096
|
+
* audio_url: 'https://soniox.com/media/examples/coffee_shop.mp3',
|
|
2097
|
+
* });
|
|
2098
|
+
*
|
|
2099
|
+
* // Simple wait
|
|
2100
|
+
* const completed = await transcription.wait();
|
|
2101
|
+
*
|
|
2102
|
+
* // Wait with progress callback
|
|
2103
|
+
* const completed = await transcription.wait({
|
|
2104
|
+
* interval_ms: 2000,
|
|
2105
|
+
* on_status_change: (status) => console.log(`Status: ${status}`),
|
|
2106
|
+
* });
|
|
2107
|
+
* ```
|
|
2108
|
+
*/
|
|
2109
|
+
wait(options?: WaitOptions): Promise<SonioxTranscription>;
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* Result set for transcription listing.
|
|
2113
|
+
*/
|
|
2114
|
+
declare class TranscriptionListResult implements AsyncIterable<SonioxTranscription> {
|
|
2115
|
+
private readonly _http;
|
|
2116
|
+
private readonly _options;
|
|
2117
|
+
/**
|
|
2118
|
+
* Transcriptions from the first page of results.
|
|
2119
|
+
*/
|
|
2120
|
+
readonly transcriptions: SonioxTranscription[];
|
|
2121
|
+
/**
|
|
2122
|
+
* Pagination cursor for the next page. Null if no more pages.
|
|
2123
|
+
*/
|
|
2124
|
+
readonly next_page_cursor: string | null;
|
|
2125
|
+
constructor(initialResponse: ListTranscriptionsResponse<SonioxTranscriptionData>, _http: HttpClient, _options: ListTranscriptionsOptions);
|
|
2126
|
+
/**
|
|
2127
|
+
* Returns the raw data for this list result
|
|
2128
|
+
*/
|
|
2129
|
+
toJSON(): ListTranscriptionsResponse<SonioxTranscriptionData>;
|
|
2130
|
+
/**
|
|
2131
|
+
* Returns true if there are more pages of results beyond the first page.
|
|
2132
|
+
*/
|
|
2133
|
+
isPaged(): boolean;
|
|
2134
|
+
/**
|
|
2135
|
+
* Async iterator that automatically fetches all pages.
|
|
2136
|
+
* Use with `for await...of` to iterate through all transcriptions.
|
|
2137
|
+
*/
|
|
2138
|
+
[Symbol.asyncIterator](): AsyncIterator<SonioxTranscription>;
|
|
2139
|
+
}
|
|
2140
|
+
declare class SonioxSttApi {
|
|
2141
|
+
private http;
|
|
2142
|
+
private filesApi;
|
|
2143
|
+
constructor(http: HttpClient, filesApi: SonioxFilesAPI);
|
|
2144
|
+
/**
|
|
2145
|
+
* Creates a new transcription from audio_url or file_id
|
|
2146
|
+
*
|
|
2147
|
+
* @param options - Transcription options including model and audio source.
|
|
2148
|
+
* @returns The created transcription.
|
|
2149
|
+
* @throws {SonioxHttpError} On API errors.
|
|
2150
|
+
*
|
|
2151
|
+
* @example
|
|
2152
|
+
* ```typescript
|
|
2153
|
+
* // Transcribe from URL
|
|
2154
|
+
* const transcription = await client.stt.create({
|
|
2155
|
+
* model: 'stt-async-v4',
|
|
2156
|
+
* audio_url: 'https://soniox.com/media/examples/coffee_shop.mp3',
|
|
2157
|
+
* });
|
|
2158
|
+
*
|
|
2159
|
+
* // Transcribe from uploaded file
|
|
2160
|
+
* const file = await client.files.upload(buffer);
|
|
2161
|
+
* const transcription = await client.stt.create({
|
|
2162
|
+
* model: 'stt-async-v4',
|
|
2163
|
+
* file_id: file.id,
|
|
2164
|
+
* });
|
|
2165
|
+
*
|
|
2166
|
+
* // With speaker diarization
|
|
2167
|
+
* const transcription = await client.stt.create({
|
|
2168
|
+
* model: 'stt-async-v4',
|
|
2169
|
+
* audio_url: 'https://soniox.com/media/examples/coffee_shop.mp3',
|
|
2170
|
+
* enable_speaker_diarization: true,
|
|
2171
|
+
* });
|
|
2172
|
+
* ```
|
|
2173
|
+
*/
|
|
2174
|
+
create(options: CreateTranscriptionOptions, signal?: AbortSignal): Promise<SonioxTranscription>;
|
|
2175
|
+
/**
|
|
2176
|
+
* Retrieves list of transcriptions
|
|
2177
|
+
*
|
|
2178
|
+
* The returned result is async iterable - use `for await...of` to iterate through all pages
|
|
2179
|
+
*
|
|
2180
|
+
* @param options - Optional pagination and filter parameters.
|
|
2181
|
+
* @returns TranscriptionListResult with async iteration support.
|
|
2182
|
+
* @throws {SonioxHttpError} On API errors.
|
|
2183
|
+
*
|
|
2184
|
+
* @example
|
|
2185
|
+
* ```typescript
|
|
2186
|
+
* const result = await client.stt.list();
|
|
2187
|
+
*
|
|
2188
|
+
* // Automatic paging - iterates through ALL transcriptions across all pages
|
|
2189
|
+
* for await (const transcription of result) {
|
|
2190
|
+
* console.log(transcription.id, transcription.status);
|
|
2191
|
+
* }
|
|
2192
|
+
*
|
|
2193
|
+
* // Or access just the first page
|
|
2194
|
+
* for (const transcription of result.transcriptions) {
|
|
2195
|
+
* console.log(transcription.id);
|
|
2196
|
+
* }
|
|
2197
|
+
*
|
|
2198
|
+
* // Check if there are more pages
|
|
2199
|
+
* if (result.isPaged()) {
|
|
2200
|
+
* console.log('More pages available');
|
|
2201
|
+
* }
|
|
2202
|
+
* ```
|
|
2203
|
+
*/
|
|
2204
|
+
list(options?: ListTranscriptionsOptions): Promise<TranscriptionListResult>;
|
|
2205
|
+
/**
|
|
2206
|
+
* Retrieves a transcription by ID
|
|
2207
|
+
*
|
|
2208
|
+
* @param id - The UUID of the transcription or a SonioxTranscription instance.
|
|
2209
|
+
* @returns The transcription, or null if not found.
|
|
2210
|
+
* @throws {SonioxHttpError} On API errors (except 404).
|
|
2211
|
+
*
|
|
2212
|
+
* @example
|
|
2213
|
+
* ```typescript
|
|
2214
|
+
* const transcription = await client.stt.get('550e8400-e29b-41d4-a716-446655440000');
|
|
2215
|
+
* if (transcription) {
|
|
2216
|
+
* console.log(transcription.status, transcription.model);
|
|
2217
|
+
* }
|
|
2218
|
+
* ```
|
|
2219
|
+
*/
|
|
2220
|
+
get(id: TranscriptionIdentifier): Promise<SonioxTranscription | null>;
|
|
2221
|
+
/**
|
|
2222
|
+
* Permanently deletes a transcription.
|
|
2223
|
+
* This operation is idempotent - succeeds even if the transcription doesn't exist.
|
|
2224
|
+
*
|
|
2225
|
+
* @param id - The UUID of the transcription or a SonioxTranscription instance
|
|
2226
|
+
* @throws {SonioxHttpError} On API errors (except 404)
|
|
2227
|
+
*
|
|
2228
|
+
* @example
|
|
2229
|
+
* ```typescript
|
|
2230
|
+
* // Delete by ID
|
|
2231
|
+
* await client.stt.delete('550e8400-e29b-41d4-a716-446655440000');
|
|
2232
|
+
*
|
|
2233
|
+
* // Or delete a transcription instance
|
|
2234
|
+
* const transcription = await client.stt.get('550e8400-e29b-41d4-a716-446655440000');
|
|
2235
|
+
* if (transcription) {
|
|
2236
|
+
* await client.stt.delete(transcription);
|
|
2237
|
+
* }
|
|
2238
|
+
* ```
|
|
2239
|
+
*/
|
|
2240
|
+
delete(id: TranscriptionIdentifier): Promise<void>;
|
|
2241
|
+
/**
|
|
2242
|
+
* Permanently deletes a transcription and its associated file (if any).
|
|
2243
|
+
* This operation is idempotent - succeeds even if resources don't exist.
|
|
2244
|
+
*
|
|
2245
|
+
* @param id - The UUID of the transcription or a SonioxTranscription instance
|
|
2246
|
+
* @throws {SonioxHttpError} On API errors (except 404)
|
|
2247
|
+
*
|
|
2248
|
+
* @example
|
|
2249
|
+
* ```typescript
|
|
2250
|
+
* // Clean up both transcription and uploaded file
|
|
2251
|
+
* const transcription = await client.stt.transcribe({
|
|
2252
|
+
* model: 'stt-async-v4',
|
|
2253
|
+
* file: buffer,
|
|
2254
|
+
* wait: true,
|
|
2255
|
+
* });
|
|
2256
|
+
* // ... use transcription ...
|
|
2257
|
+
* await client.stt.destroy(transcription); // Deletes both
|
|
2258
|
+
*
|
|
2259
|
+
* // Or by ID
|
|
2260
|
+
* await client.stt.destroy('550e8400-e29b-41d4-a716-446655440000');
|
|
2261
|
+
* ```
|
|
2262
|
+
*/
|
|
2263
|
+
destroy(id: TranscriptionIdentifier): Promise<void>;
|
|
2264
|
+
/**
|
|
2265
|
+
* Retrieves the full transcript text and tokens for a completed transcription.
|
|
2266
|
+
* Only available for successfully completed transcriptions.
|
|
2267
|
+
*
|
|
2268
|
+
* @param id - The UUID of the transcription or a SonioxTranscription instance
|
|
2269
|
+
* @returns The transcript with text and detailed tokens, or null if not found
|
|
2270
|
+
* @throws {SonioxHttpError} On API errors (except 404)
|
|
2271
|
+
*
|
|
2272
|
+
* @example
|
|
2273
|
+
* ```typescript
|
|
2274
|
+
* const transcript = await client.stt.getTranscript('550e8400-e29b-41d4-a716-446655440000');
|
|
2275
|
+
* if (transcript) {
|
|
2276
|
+
* console.log(transcript.text);
|
|
2277
|
+
* for (const token of transcript.tokens) {
|
|
2278
|
+
* console.log(token.text, token.start_ms, token.end_ms, token.confidence);
|
|
2279
|
+
* }
|
|
2280
|
+
* }
|
|
2281
|
+
* ```
|
|
2282
|
+
*/
|
|
2283
|
+
getTranscript(id: TranscriptionIdentifier, signal?: AbortSignal): Promise<SonioxTranscript | null>;
|
|
2284
|
+
/**
|
|
2285
|
+
* Waits for a transcription to complete
|
|
2286
|
+
*
|
|
2287
|
+
* @param id - The UUID of the transcription or a SonioxTranscription instance.
|
|
2288
|
+
* @param options - Wait options including polling interval, timeout, and callbacks.
|
|
2289
|
+
* @returns The completed or errored transcription.
|
|
2290
|
+
* @throws {Error} If the wait times out or is aborted.
|
|
2291
|
+
* @throws {SonioxHttpError} On API errors.
|
|
2292
|
+
*
|
|
2293
|
+
* @example
|
|
2294
|
+
* ```typescript
|
|
2295
|
+
* const completed = await client.stt.wait('550e8400-e29b-41d4-a716-446655440000');
|
|
2296
|
+
*
|
|
2297
|
+
* // With progress callback
|
|
2298
|
+
* const completed = await client.stt.wait('id', {
|
|
2299
|
+
* interval_ms: 2000,
|
|
2300
|
+
* on_status_change: (status) => console.log(`Status: ${status}`),
|
|
2301
|
+
* });
|
|
2302
|
+
* ```
|
|
2303
|
+
*/
|
|
2304
|
+
wait(id: TranscriptionIdentifier, options?: WaitOptions): Promise<SonioxTranscription>;
|
|
2305
|
+
/**
|
|
2306
|
+
* Wrapper to transcribe from a URL.
|
|
2307
|
+
*
|
|
2308
|
+
* @param audio_url - Publicly accessible audio URL
|
|
2309
|
+
* @param options - Transcription options (excluding audio_url)
|
|
2310
|
+
* @returns The transcription (completed if wait=true, otherwise in queued/processing state).
|
|
2311
|
+
*/
|
|
2312
|
+
transcribeFromUrl(audio_url: string, options: TranscribeFromUrlOptions): Promise<SonioxTranscription>;
|
|
2313
|
+
/**
|
|
2314
|
+
* Wrapper to transcribe from an uploaded file ID.
|
|
2315
|
+
*
|
|
2316
|
+
* @param file_id - ID of a previously uploaded file
|
|
2317
|
+
* @param options - Transcription options (excluding file_id)
|
|
2318
|
+
* @returns The transcription (completed if wait=true, otherwise in queued/processing state).
|
|
2319
|
+
*/
|
|
2320
|
+
transcribeFromFileId(file_id: string, options: TranscribeFromFileIdOptions): Promise<SonioxTranscription>;
|
|
2321
|
+
/**
|
|
2322
|
+
* Wrapper to transcribe from raw file data.
|
|
2323
|
+
*
|
|
2324
|
+
* @param file - Buffer, Uint8Array, Blob, or ReadableStream
|
|
2325
|
+
* @param options - Transcription options (excluding file)
|
|
2326
|
+
* @returns The transcription (completed if wait=true, otherwise in queued/processing state).
|
|
2327
|
+
*/
|
|
2328
|
+
transcribeFromFile(file: UploadFileInput, options: TranscribeFromFileOptions): Promise<SonioxTranscription>;
|
|
2329
|
+
/**
|
|
2330
|
+
* Unified transcribe method - supports direct file upload
|
|
2331
|
+
*
|
|
2332
|
+
* When `file` is provided, uploads it first then creates a transcription
|
|
2333
|
+
* When `wait: true`, waits for completion before returning
|
|
2334
|
+
* When `cleanup` is specified (requires `wait: true`), cleans up resources after completion or on error/timeout
|
|
2335
|
+
*
|
|
2336
|
+
* @param options - Transcribe options including model, audio source, and wait settings.
|
|
2337
|
+
* @returns The transcription (completed if wait=true, otherwise in queued/processing state).
|
|
2338
|
+
* @throws {SonioxHttpError} On API errors.
|
|
2339
|
+
* @throws {Error} On validation errors or wait timeout.
|
|
2340
|
+
*
|
|
2341
|
+
* @example
|
|
2342
|
+
* ```typescript
|
|
2343
|
+
* // Transcribe from URL and wait for completion
|
|
2344
|
+
* const result = await client.stt.transcribe({
|
|
2345
|
+
* model: 'stt-async-v4',
|
|
2346
|
+
* audio_url: 'https://soniox.com/media/examples/coffee_shop.mp3',
|
|
2347
|
+
* wait: true,
|
|
2348
|
+
* });
|
|
2349
|
+
*
|
|
2350
|
+
* // Upload file and transcribe in one call
|
|
2351
|
+
* const result = await client.stt.transcribe({
|
|
2352
|
+
* model: 'stt-async-v4',
|
|
2353
|
+
* file: buffer, // or Blob, ReadableStream
|
|
2354
|
+
* filename: 'meeting.mp3',
|
|
2355
|
+
* enable_speaker_diarization: true,
|
|
2356
|
+
* wait: true,
|
|
2357
|
+
* });
|
|
2358
|
+
*
|
|
2359
|
+
* // With wait progress callback
|
|
2360
|
+
* const result = await client.stt.transcribe({
|
|
2361
|
+
* model: 'stt-async-v4',
|
|
2362
|
+
* file: buffer,
|
|
2363
|
+
* wait: true,
|
|
2364
|
+
* wait_options: {
|
|
2365
|
+
* interval_ms: 2000,
|
|
2366
|
+
* on_status_change: (status) => console.log(`Status: ${status}`),
|
|
2367
|
+
* },
|
|
2368
|
+
* });
|
|
2369
|
+
*
|
|
2370
|
+
* // Auto-cleanup uploaded file after transcription
|
|
2371
|
+
* const result = await client.stt.transcribe({
|
|
2372
|
+
* model: 'stt-async-v4',
|
|
2373
|
+
* file: buffer,
|
|
2374
|
+
* wait: true,
|
|
2375
|
+
* cleanup: ['file'], // Deletes uploaded file, keeps transcription record
|
|
2376
|
+
* });
|
|
2377
|
+
*
|
|
2378
|
+
* // Auto-cleanup everything after transcription
|
|
2379
|
+
* const result = await client.stt.transcribe({
|
|
2380
|
+
* model: 'stt-async-v4',
|
|
2381
|
+
* file: buffer,
|
|
2382
|
+
* wait: true,
|
|
2383
|
+
* cleanup: ['file', 'transcription'], // Deletes both file and transcription record
|
|
2384
|
+
* });
|
|
2385
|
+
* ```
|
|
2386
|
+
*/
|
|
2387
|
+
transcribe(options: TranscribeOptions): Promise<SonioxTranscription>;
|
|
2388
|
+
/**
|
|
2389
|
+
* Permanently deletes all transcriptions.
|
|
2390
|
+
* Iterates through all pages of transcriptions and deletes each one.
|
|
2391
|
+
*
|
|
2392
|
+
* @param options - Optional signal and progress callback.
|
|
2393
|
+
* @returns The number of transcriptions deleted.
|
|
2394
|
+
* @throws {SonioxHttpError} On API errors.
|
|
2395
|
+
* @throws {Error} If the operation is aborted via signal.
|
|
2396
|
+
*
|
|
2397
|
+
* @example
|
|
2398
|
+
* ```typescript
|
|
2399
|
+
* // Delete all transcriptions
|
|
2400
|
+
* const { deleted } = await client.stt.purge();
|
|
2401
|
+
* console.log(`Deleted ${deleted} transcriptions.`);
|
|
2402
|
+
*
|
|
2403
|
+
* // With progress logging
|
|
2404
|
+
* const { deleted } = await client.stt.purge({
|
|
2405
|
+
* on_progress: (transcription, index) => {
|
|
2406
|
+
* console.log(`Deleting transcription: ${transcription.id} (${index + 1})`);
|
|
2407
|
+
* },
|
|
2408
|
+
* });
|
|
2409
|
+
*
|
|
2410
|
+
* // With cancellation
|
|
2411
|
+
* const controller = new AbortController();
|
|
2412
|
+
* const { deleted } = await client.stt.purge({ signal: controller.signal });
|
|
2413
|
+
* ```
|
|
2414
|
+
*/
|
|
2415
|
+
purge(options?: PurgeTranscriptionsOptions): Promise<PurgeResult>;
|
|
2416
|
+
}
|
|
2417
|
+
//#endregion
|
|
2418
|
+
//#region src/async/webhooks.d.ts
|
|
2419
|
+
/**
|
|
2420
|
+
* Webhook utilities API accessible via client.webhooks
|
|
2421
|
+
*
|
|
2422
|
+
* Provides methods for handling incoming Soniox webhook requests.
|
|
2423
|
+
* When used via the client, results include lazy fetch helpers for transcripts.
|
|
2424
|
+
*/
|
|
2425
|
+
declare class SonioxWebhooksAPI {
|
|
2426
|
+
private stt;
|
|
2427
|
+
/**
|
|
2428
|
+
* @internal
|
|
2429
|
+
*/
|
|
2430
|
+
constructor(stt?: SonioxSttApi);
|
|
2431
|
+
/**
|
|
2432
|
+
* Enhance a webhook result with fetch helpers
|
|
2433
|
+
*/
|
|
2434
|
+
private withFetchHelpers;
|
|
2435
|
+
/**
|
|
2436
|
+
* Get webhook authentication configuration from environment variables.
|
|
2437
|
+
*
|
|
2438
|
+
* Reads `SONIOX_API_WEBHOOK_HEADER` and `SONIOX_API_WEBHOOK_SECRET` environment variables.
|
|
2439
|
+
* Returns undefined if either variable is not set (both are required for authentication).
|
|
2440
|
+
*/
|
|
2441
|
+
getAuthFromEnv(): WebhookAuthConfig | undefined;
|
|
2442
|
+
/**
|
|
2443
|
+
* Type guard to check if a value is a valid WebhookEvent
|
|
2444
|
+
*/
|
|
2445
|
+
isEvent(payload: unknown): payload is WebhookEvent;
|
|
2446
|
+
/**
|
|
2447
|
+
* Parse and validate a webhook event payload
|
|
2448
|
+
*/
|
|
2449
|
+
parseEvent(payload: unknown): WebhookEvent;
|
|
2450
|
+
/**
|
|
2451
|
+
* Verify webhook authentication header
|
|
2452
|
+
*/
|
|
2453
|
+
verifyAuth(headers: WebhookHeaders, auth: WebhookAuthConfig): boolean;
|
|
2454
|
+
/**
|
|
2455
|
+
* Framework-agnostic webhook handler
|
|
2456
|
+
*/
|
|
2457
|
+
handle(options: HandleWebhookOptions): WebhookHandlerResultWithFetch;
|
|
2458
|
+
/**
|
|
2459
|
+
* Handle a webhook from a Fetch API Request
|
|
2460
|
+
*/
|
|
2461
|
+
handleRequest(request: Request, auth?: WebhookAuthConfig): Promise<WebhookHandlerResultWithFetch>;
|
|
2462
|
+
/**
|
|
2463
|
+
* Handle a webhook from an Express-like request
|
|
2464
|
+
*
|
|
2465
|
+
* @example
|
|
2466
|
+
* ```typescript
|
|
2467
|
+
* app.post('/webhook', async (req, res) => {
|
|
2468
|
+
* const result = soniox.webhooks.handleExpress(req);
|
|
2469
|
+
*
|
|
2470
|
+
* if (result.ok && result.event.status === 'completed') {
|
|
2471
|
+
* const transcript = await result.fetchTranscript();
|
|
2472
|
+
* console.log(transcript?.text);
|
|
2473
|
+
* }
|
|
2474
|
+
*
|
|
2475
|
+
* res.status(result.status).json({ received: true });
|
|
2476
|
+
* });
|
|
2477
|
+
* ```
|
|
2478
|
+
*/
|
|
2479
|
+
handleExpress(req: ExpressLikeRequest, auth?: WebhookAuthConfig): WebhookHandlerResultWithFetch;
|
|
2480
|
+
/**
|
|
2481
|
+
* Handle a webhook from a Fastify request
|
|
2482
|
+
*/
|
|
2483
|
+
handleFastify(req: FastifyLikeRequest, auth?: WebhookAuthConfig): WebhookHandlerResultWithFetch;
|
|
2484
|
+
/**
|
|
2485
|
+
* Handle a webhook from a NestJS request
|
|
2486
|
+
*/
|
|
2487
|
+
handleNestJS(req: NestJSLikeRequest, auth?: WebhookAuthConfig): WebhookHandlerResultWithFetch;
|
|
2488
|
+
/**
|
|
2489
|
+
* Handle a webhook from a Hono context
|
|
2490
|
+
*/
|
|
2491
|
+
handleHono(c: HonoLikeContext, auth?: WebhookAuthConfig): Promise<WebhookHandlerResultWithFetch>;
|
|
2492
|
+
}
|
|
2493
|
+
//#endregion
|
|
2494
|
+
//#region src/realtime/stt.d.ts
|
|
2495
|
+
/**
|
|
2496
|
+
* Real-time Speech-to-Text session
|
|
2497
|
+
*
|
|
2498
|
+
* Provides WebSocket-based streaming transcription with support for:
|
|
2499
|
+
* - Event-based and async iterator consumption
|
|
2500
|
+
* - Pause/resume with automatic keepalive
|
|
2501
|
+
* - AbortSignal cancellation
|
|
2502
|
+
*
|
|
2503
|
+
* @example
|
|
2504
|
+
* ```typescript
|
|
2505
|
+
* const session = client.realtime.stt({ model: 'stt-rt-preview' });
|
|
2506
|
+
*
|
|
2507
|
+
* session.on('result', (result) => {
|
|
2508
|
+
* console.log(result.tokens.map(t => t.text).join(''));
|
|
2509
|
+
* });
|
|
2510
|
+
*
|
|
2511
|
+
* await session.connect();
|
|
2512
|
+
* await session.sendAudio(audioChunk);
|
|
2513
|
+
* await session.finish();
|
|
2514
|
+
* ```
|
|
2515
|
+
*/
|
|
2516
|
+
declare class RealtimeSttSession implements AsyncIterable<RealtimeEvent> {
|
|
2517
|
+
private readonly emitter;
|
|
2518
|
+
private readonly eventQueue;
|
|
2519
|
+
private readonly apiKey;
|
|
2520
|
+
private readonly wsBaseUrl;
|
|
2521
|
+
private readonly config;
|
|
2522
|
+
private readonly keepaliveIntervalMs;
|
|
2523
|
+
private readonly keepaliveEnabled;
|
|
2524
|
+
private readonly signal;
|
|
2525
|
+
private ws;
|
|
2526
|
+
private _state;
|
|
2527
|
+
private _paused;
|
|
2528
|
+
private keepaliveInterval;
|
|
2529
|
+
private finishResolver;
|
|
2530
|
+
private finishRejecter;
|
|
2531
|
+
private abortHandler;
|
|
2532
|
+
constructor(apiKey: string, wsBaseUrl: string, config: SttSessionConfig, options?: SttSessionOptions);
|
|
2533
|
+
/**
|
|
2534
|
+
* Current session state.
|
|
2535
|
+
*/
|
|
2536
|
+
get state(): SttSessionState;
|
|
2537
|
+
/**
|
|
2538
|
+
* Whether the session is currently paused.
|
|
2539
|
+
*/
|
|
2540
|
+
get paused(): boolean;
|
|
2541
|
+
/**
|
|
2542
|
+
* Connect to the Soniox WebSocket API.
|
|
2543
|
+
*
|
|
2544
|
+
* @throws {AbortError} If aborted
|
|
2545
|
+
* @throws {NetworkError} If connection fails
|
|
2546
|
+
* @throws {StateError} If already connected
|
|
2547
|
+
*/
|
|
2548
|
+
connect(): Promise<void>;
|
|
2549
|
+
/**
|
|
2550
|
+
* Send audio data to the server
|
|
2551
|
+
*
|
|
2552
|
+
* @param data - Audio data as Buffer, Uint8Array, or ArrayBuffer
|
|
2553
|
+
* @throws {AbortError} If aborted
|
|
2554
|
+
* @throws {StateError} If not connected
|
|
2555
|
+
*/
|
|
2556
|
+
sendAudio(data: AudioData): void;
|
|
2557
|
+
/**
|
|
2558
|
+
* Stream audio data from an async iterable source.
|
|
2559
|
+
*
|
|
2560
|
+
* Reads chunks from the iterable and sends each via {@link sendAudio}.
|
|
2561
|
+
* Works with Node.js ReadableStreams, Web ReadableStreams, async generators,
|
|
2562
|
+
* and any other `AsyncIterable<AudioData>`.
|
|
2563
|
+
*
|
|
2564
|
+
* @param stream - Async iterable yielding audio chunks
|
|
2565
|
+
* @param options - Optional pacing and auto-finish settings
|
|
2566
|
+
* @throws {AbortError} If aborted during streaming
|
|
2567
|
+
* @throws {StateError} If not connected
|
|
2568
|
+
*
|
|
2569
|
+
* @example
|
|
2570
|
+
* ```typescript
|
|
2571
|
+
* // Stream from a Node.js file
|
|
2572
|
+
* import fs from 'fs';
|
|
2573
|
+
* await session.sendStream(fs.createReadStream('audio.mp3'), { finish: true });
|
|
2574
|
+
*
|
|
2575
|
+
* // Stream with simulated real-time pacing
|
|
2576
|
+
* await session.sendStream(
|
|
2577
|
+
* fs.createReadStream('audio.pcm_s16le', { highWaterMark: 3840 }),
|
|
2578
|
+
* { pace_ms: 120, finish: true }
|
|
2579
|
+
* );
|
|
2580
|
+
*
|
|
2581
|
+
* // Stream from a Web fetch response
|
|
2582
|
+
* const response = await fetch('https://soniox.com/media/examples/coffee_shop.mp3');
|
|
2583
|
+
* await session.sendStream(response.body, { finish: true });
|
|
2584
|
+
* ```
|
|
2585
|
+
*/
|
|
2586
|
+
sendStream(stream: AsyncIterable<AudioData>, options?: SendStreamOptions): Promise<void>;
|
|
2587
|
+
/**
|
|
2588
|
+
* Pause audio transmission and starts automatic keepalive messages
|
|
2589
|
+
*/
|
|
2590
|
+
pause(): void;
|
|
2591
|
+
/**
|
|
2592
|
+
* Resume audio transmission
|
|
2593
|
+
*/
|
|
2594
|
+
resume(): void;
|
|
2595
|
+
/**
|
|
2596
|
+
* Requests the server to finalize current transcription
|
|
2597
|
+
*/
|
|
2598
|
+
finalize(options?: {
|
|
2599
|
+
trailing_silence_ms?: number;
|
|
2600
|
+
}): void;
|
|
2601
|
+
/**
|
|
2602
|
+
* Send a keepalive message
|
|
2603
|
+
*/
|
|
2604
|
+
keepAlive(): void;
|
|
2605
|
+
/**
|
|
2606
|
+
* Gracefully finish the session
|
|
2607
|
+
*/
|
|
2608
|
+
finish(): Promise<void>;
|
|
2609
|
+
/**
|
|
2610
|
+
* Close (cancel) the session immediately without waiting
|
|
2611
|
+
*/
|
|
2612
|
+
close(): void;
|
|
2613
|
+
/**
|
|
2614
|
+
* Register an event handler
|
|
2615
|
+
*/
|
|
2616
|
+
on<E extends keyof SttSessionEvents>(event: E, handler: SttSessionEvents[E]): this;
|
|
2617
|
+
/**
|
|
2618
|
+
* Register a one-time event handler
|
|
2619
|
+
*/
|
|
2620
|
+
once<E extends keyof SttSessionEvents>(event: E, handler: SttSessionEvents[E]): this;
|
|
2621
|
+
/**
|
|
2622
|
+
* Remove an event handler
|
|
2623
|
+
*/
|
|
2624
|
+
off<E extends keyof SttSessionEvents>(event: E, handler: SttSessionEvents[E]): this;
|
|
2625
|
+
/**
|
|
2626
|
+
* Async iterator for consuming events.
|
|
2627
|
+
*/
|
|
2628
|
+
[Symbol.asyncIterator](): AsyncIterator<RealtimeEvent>;
|
|
2629
|
+
private createWebSocket;
|
|
2630
|
+
private handleMessage;
|
|
2631
|
+
private handleClose;
|
|
2632
|
+
private handleError;
|
|
2633
|
+
private handleAbort;
|
|
2634
|
+
private setState;
|
|
2635
|
+
private cleanup;
|
|
2636
|
+
private isTerminalState;
|
|
2637
|
+
private checkAborted;
|
|
2638
|
+
private settleFinish;
|
|
2639
|
+
private sendMessage;
|
|
2640
|
+
private startKeepalive;
|
|
2641
|
+
private stopKeepalive;
|
|
2642
|
+
private updateKeepalive;
|
|
2643
|
+
}
|
|
2644
|
+
//#endregion
|
|
2645
|
+
//#region src/realtime/segments.d.ts
|
|
2646
|
+
/**
|
|
2647
|
+
* Groups real-time tokens into segments based on specified grouping keys.
|
|
2648
|
+
*
|
|
2649
|
+
* A new segment starts when any of the `group_by` fields changes.
|
|
2650
|
+
* Tokens are concatenated as-is.
|
|
2651
|
+
*
|
|
2652
|
+
* @param tokens - Array of real-time tokens to segment
|
|
2653
|
+
* @param options - Segmentation options
|
|
2654
|
+
* @param options.group_by - Fields to group by (default: ['speaker', 'language'])
|
|
2655
|
+
* @param options.final_only - When true, only finalized tokens are included
|
|
2656
|
+
* @returns Array of segments with combined text and timing (if available)
|
|
2657
|
+
*/
|
|
2658
|
+
declare function segmentRealtimeTokens(tokens: RealtimeToken[], options?: RealtimeSegmentOptions): RealtimeSegment[];
|
|
2659
|
+
//#endregion
|
|
2660
|
+
//#region src/realtime/segment-buffer.d.ts
|
|
2661
|
+
/**
|
|
2662
|
+
* Rolling buffer for turning real-time results into stable segments.
|
|
2663
|
+
*/
|
|
2664
|
+
declare class RealtimeSegmentBuffer {
|
|
2665
|
+
private tokens;
|
|
2666
|
+
private readonly groupBy;
|
|
2667
|
+
private readonly finalOnly;
|
|
2668
|
+
private readonly maxTokens;
|
|
2669
|
+
private readonly maxMs;
|
|
2670
|
+
constructor(options?: RealtimeSegmentBufferOptions);
|
|
2671
|
+
/**
|
|
2672
|
+
* Number of tokens currently buffered.
|
|
2673
|
+
*/
|
|
2674
|
+
get size(): number;
|
|
2675
|
+
/**
|
|
2676
|
+
* Add a real-time result and return stable segments.
|
|
2677
|
+
*/
|
|
2678
|
+
add(result: RealtimeResult): RealtimeSegment[];
|
|
2679
|
+
/**
|
|
2680
|
+
* Clear all buffered tokens.
|
|
2681
|
+
*/
|
|
2682
|
+
reset(): void;
|
|
2683
|
+
/**
|
|
2684
|
+
* Flush all buffered tokens into segments and clear the buffer.
|
|
2685
|
+
*
|
|
2686
|
+
* Includes tokens that are not yet stable by final_audio_proc_ms.
|
|
2687
|
+
*/
|
|
2688
|
+
flushAll(): RealtimeSegment[];
|
|
2689
|
+
private flushStable;
|
|
2690
|
+
private trim;
|
|
2691
|
+
}
|
|
2692
|
+
//#endregion
|
|
2693
|
+
//#region src/realtime/utterance-buffer.d.ts
|
|
2694
|
+
/**
|
|
2695
|
+
* Collects real-time results into utterances for endpoint-driven workflows.
|
|
2696
|
+
*/
|
|
2697
|
+
declare class RealtimeUtteranceBuffer {
|
|
2698
|
+
private readonly segmentBuffer;
|
|
2699
|
+
private pendingSegments;
|
|
2700
|
+
private lastFinalAudioProcMs;
|
|
2701
|
+
private lastTotalAudioProcMs;
|
|
2702
|
+
constructor(options?: RealtimeUtteranceBufferOptions);
|
|
2703
|
+
/**
|
|
2704
|
+
* Add a real-time result and collect stable segments.
|
|
2705
|
+
*/
|
|
2706
|
+
addResult(result: RealtimeResult): RealtimeSegment[];
|
|
2707
|
+
/**
|
|
2708
|
+
* Mark an endpoint and flush the current utterance.
|
|
2709
|
+
*/
|
|
2710
|
+
markEndpoint(): RealtimeUtterance | undefined;
|
|
2711
|
+
/**
|
|
2712
|
+
* Clear buffered segments and tokens.
|
|
2713
|
+
*/
|
|
2714
|
+
reset(): void;
|
|
2715
|
+
}
|
|
2716
|
+
//#endregion
|
|
2717
|
+
//#region src/http/errors.d.ts
|
|
2718
|
+
/**
|
|
2719
|
+
* Base error class for all Soniox SDK errors.
|
|
2720
|
+
*
|
|
2721
|
+
* All SDK errors extend this class for error handling across both REST (HTTP) and WebSocket (Real-time) APIs.
|
|
2722
|
+
*
|
|
2723
|
+
* @example
|
|
2724
|
+
* ```typescript
|
|
2725
|
+
* try {
|
|
2726
|
+
* await client.transcribe(file);
|
|
2727
|
+
* await session.connect();
|
|
2728
|
+
* } catch (error) {
|
|
2729
|
+
* if (error instanceof SonioxError) {
|
|
2730
|
+
* console.log(error.code); // 'auth_error', 'network_error', etc.
|
|
2731
|
+
* console.log(error.statusCode); // 401, 500, etc. (when applicable)
|
|
2732
|
+
* console.log(error.toJSON()); // Consistent serialization
|
|
2733
|
+
* }
|
|
2734
|
+
* }
|
|
2735
|
+
* ```
|
|
2736
|
+
*/
|
|
2737
|
+
declare class SonioxError extends Error {
|
|
2738
|
+
/**
|
|
2739
|
+
* Error code describing the type of error
|
|
2740
|
+
*/
|
|
2741
|
+
readonly code: SonioxErrorCode;
|
|
2742
|
+
/**
|
|
2743
|
+
* HTTP status code when applicable (e.g., 401 for auth errors, 500 for server errors).
|
|
2744
|
+
*/
|
|
2745
|
+
readonly statusCode: number | undefined;
|
|
2746
|
+
/**
|
|
2747
|
+
* The underlying error that caused this error, if any.
|
|
2748
|
+
*/
|
|
2749
|
+
readonly cause: unknown;
|
|
2750
|
+
constructor(message: string, code?: SonioxErrorCode, statusCode?: number, cause?: unknown);
|
|
2751
|
+
/**
|
|
2752
|
+
* Creates a human-readable string representation
|
|
2753
|
+
*/
|
|
2754
|
+
toString(): string;
|
|
2755
|
+
/**
|
|
2756
|
+
* Converts to a plain object for logging/serialization
|
|
2757
|
+
*/
|
|
2758
|
+
toJSON(): Record<string, unknown>;
|
|
2759
|
+
}
|
|
2760
|
+
/**
|
|
2761
|
+
* HTTP error class for all HTTP-related failures (REST API).
|
|
2762
|
+
*
|
|
2763
|
+
* Thrown when HTTP requests fail due to network issues, timeouts,
|
|
2764
|
+
* server errors, or response parsing failures.
|
|
2765
|
+
*/
|
|
2766
|
+
declare class SonioxHttpError extends SonioxError {
|
|
2767
|
+
/** Categorized HTTP error code */
|
|
2768
|
+
readonly code: HttpErrorCode;
|
|
2769
|
+
/** Request URL */
|
|
2770
|
+
readonly url: string;
|
|
2771
|
+
/** HTTP method */
|
|
2772
|
+
readonly method: HttpMethod;
|
|
2773
|
+
/** Response headers (only for http_error) */
|
|
2774
|
+
readonly headers: Record<string, string> | undefined;
|
|
2775
|
+
/** Response body text, capped at 4KB (only for http_error/parse_error) */
|
|
2776
|
+
readonly bodyText: string | undefined;
|
|
2777
|
+
constructor(details: HttpErrorDetails);
|
|
2778
|
+
/**
|
|
2779
|
+
* Creates a human-readable string representation
|
|
2780
|
+
*/
|
|
2781
|
+
toString(): string;
|
|
2782
|
+
/**
|
|
2783
|
+
* Converts to a plain object for logging/serialization
|
|
2784
|
+
*/
|
|
2785
|
+
toJSON(): Record<string, unknown>;
|
|
2786
|
+
}
|
|
2787
|
+
/**
|
|
2788
|
+
* Creates a network error
|
|
2789
|
+
*/
|
|
2790
|
+
declare function createNetworkError(url: string, method: HttpMethod, cause: unknown): SonioxHttpError;
|
|
2791
|
+
/**
|
|
2792
|
+
* Creates a timeout error
|
|
2793
|
+
*/
|
|
2794
|
+
declare function createTimeoutError(url: string, method: HttpMethod, timeoutMs: number): SonioxHttpError;
|
|
2795
|
+
/**
|
|
2796
|
+
* Creates an abort error
|
|
2797
|
+
*/
|
|
2798
|
+
declare function createAbortError(url: string, method: HttpMethod, cause?: unknown): SonioxHttpError;
|
|
2799
|
+
/**
|
|
2800
|
+
* Creates an HTTP error (non-2xx status)
|
|
2801
|
+
*/
|
|
2802
|
+
declare function createHttpError(url: string, method: HttpMethod, statusCode: number, headers: Record<string, string>, bodyText: string): SonioxHttpError;
|
|
2803
|
+
/**
|
|
2804
|
+
* Creates a parse error (invalid JSON, etc.)
|
|
2805
|
+
*/
|
|
2806
|
+
declare function createParseError(url: string, method: HttpMethod, bodyText: string, cause: unknown): SonioxHttpError;
|
|
2807
|
+
/**
|
|
2808
|
+
* Type guard to check if an error is an AbortError
|
|
2809
|
+
*/
|
|
2810
|
+
declare function isAbortError(error: unknown): boolean;
|
|
2811
|
+
/**
|
|
2812
|
+
* Type guard to check if an error is any SonioxError (base class).
|
|
2813
|
+
* This catches all SDK errors including HTTP and real-time errors.
|
|
2814
|
+
*/
|
|
2815
|
+
declare function isSonioxError(error: unknown): error is SonioxError;
|
|
2816
|
+
/**
|
|
2817
|
+
* Type guard to check if an error is a SonioxHttpError
|
|
2818
|
+
*/
|
|
2819
|
+
declare function isSonioxHttpError(error: unknown): error is SonioxHttpError;
|
|
2820
|
+
//#endregion
|
|
2821
|
+
//#region src/realtime/errors.d.ts
|
|
2822
|
+
/**
|
|
2823
|
+
* Base error class for all real-time (WebSocket) SDK errors
|
|
2824
|
+
*/
|
|
2825
|
+
declare class RealtimeError extends SonioxError {
|
|
2826
|
+
/** Real-time error code */
|
|
2827
|
+
readonly code: RealtimeErrorCode;
|
|
2828
|
+
/**
|
|
2829
|
+
* Original response payload for debugging.
|
|
2830
|
+
* Contains the raw WebSocket message that caused the error.
|
|
2831
|
+
*/
|
|
2832
|
+
readonly raw: unknown;
|
|
2833
|
+
constructor(message: string, code?: RealtimeErrorCode, statusCode?: number, raw?: unknown);
|
|
2834
|
+
/**
|
|
2835
|
+
* Creates a human-readable string representation
|
|
2836
|
+
*/
|
|
2837
|
+
toString(): string;
|
|
2838
|
+
/**
|
|
2839
|
+
* Converts to a plain object for logging/serialization
|
|
2840
|
+
*/
|
|
2841
|
+
toJSON(): Record<string, unknown>;
|
|
2842
|
+
}
|
|
2843
|
+
/**
|
|
2844
|
+
* Authentication error (401).
|
|
2845
|
+
* Thrown when the API key is invalid or expired.
|
|
2846
|
+
*/
|
|
2847
|
+
declare class AuthError extends RealtimeError {
|
|
2848
|
+
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
2849
|
+
}
|
|
2850
|
+
/**
|
|
2851
|
+
* Bad request error (400).
|
|
2852
|
+
* Thrown for invalid configuration or parameters.
|
|
2853
|
+
*/
|
|
2854
|
+
declare class BadRequestError extends RealtimeError {
|
|
2855
|
+
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
2856
|
+
}
|
|
2857
|
+
/**
|
|
2858
|
+
* Quota error (402, 429).
|
|
2859
|
+
* Thrown when rate limits are exceeded or quota is exhausted.
|
|
2860
|
+
*/
|
|
2861
|
+
declare class QuotaError extends RealtimeError {
|
|
2862
|
+
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
2863
|
+
}
|
|
2864
|
+
/**
|
|
2865
|
+
* Connection error.
|
|
2866
|
+
* Thrown for WebSocket connection failures and transport errors.
|
|
2867
|
+
*/
|
|
2868
|
+
declare class ConnectionError extends RealtimeError {
|
|
2869
|
+
constructor(message: string, raw?: unknown);
|
|
2870
|
+
}
|
|
2871
|
+
/**
|
|
2872
|
+
* Network error.
|
|
2873
|
+
* Thrown for server-side network issues (408, 500, 503).
|
|
2874
|
+
*/
|
|
2875
|
+
declare class NetworkError extends RealtimeError {
|
|
2876
|
+
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
2877
|
+
}
|
|
2878
|
+
/**
|
|
2879
|
+
* Abort error.
|
|
2880
|
+
* Thrown when an operation is cancelled via AbortSignal.
|
|
2881
|
+
*/
|
|
2882
|
+
declare class AbortError extends RealtimeError {
|
|
2883
|
+
constructor(message?: string);
|
|
2884
|
+
}
|
|
2885
|
+
/**
|
|
2886
|
+
* State error.
|
|
2887
|
+
* Thrown when an operation is attempted in an invalid state.
|
|
2888
|
+
*/
|
|
2889
|
+
declare class StateError extends RealtimeError {
|
|
2890
|
+
constructor(message: string);
|
|
2891
|
+
}
|
|
2892
|
+
//#endregion
|
|
2893
|
+
//#region src/realtime/index.d.ts
|
|
2894
|
+
/**
|
|
2895
|
+
* Real-time API factory for creating STT sessions.
|
|
2896
|
+
*
|
|
2897
|
+
* @example
|
|
2898
|
+
* ```typescript
|
|
2899
|
+
* const session = client.realtime.stt({
|
|
2900
|
+
* model: 'stt-rt-preview',
|
|
2901
|
+
* enable_endpoint_detection: true,
|
|
2902
|
+
* });
|
|
2903
|
+
*
|
|
2904
|
+
* await session.connect();
|
|
2905
|
+
* ```
|
|
2906
|
+
*/
|
|
2907
|
+
declare class SonioxRealtimeApi {
|
|
2908
|
+
private readonly options;
|
|
2909
|
+
constructor(options: RealtimeClientOptions);
|
|
2910
|
+
/**
|
|
2911
|
+
* Create a new Speech-to-Text session.
|
|
2912
|
+
*
|
|
2913
|
+
* @param config - Session configuration (sent to server)
|
|
2914
|
+
* @param options - Session options (SDK-level settings)
|
|
2915
|
+
* @returns New STT session instance
|
|
2916
|
+
*/
|
|
2917
|
+
stt(config: SttSessionConfig, options?: SttSessionOptions): RealtimeSttSession;
|
|
2918
|
+
}
|
|
2919
|
+
//#endregion
|
|
2920
|
+
//#region src/client.d.ts
|
|
2921
|
+
/**
|
|
2922
|
+
* Soniox Node Client
|
|
2923
|
+
* @returns {SonioxNodeClient}
|
|
2924
|
+
*
|
|
2925
|
+
* @example
|
|
2926
|
+
* ```typescript
|
|
2927
|
+
* import { SonioxNodeClient } from '@soniox/node';
|
|
2928
|
+
*
|
|
2929
|
+
* const client = new SonioxNodeClient({
|
|
2930
|
+
* api_key: 'your-api-key',
|
|
2931
|
+
* });
|
|
2932
|
+
* ```
|
|
2933
|
+
*/
|
|
2934
|
+
declare class SonioxNodeClient {
|
|
2935
|
+
readonly files: SonioxFilesAPI;
|
|
2936
|
+
readonly stt: SonioxSttApi;
|
|
2937
|
+
readonly models: SonioxModelsAPI;
|
|
2938
|
+
readonly webhooks: SonioxWebhooksAPI;
|
|
2939
|
+
readonly auth: SonioxAuthAPI;
|
|
2940
|
+
readonly realtime: SonioxRealtimeApi;
|
|
2941
|
+
constructor(options?: SonioxNodeClientOptions);
|
|
2942
|
+
}
|
|
2943
|
+
//#endregion
|
|
2944
|
+
//#region src/http/fetch-adapter.d.ts
|
|
2945
|
+
/**
|
|
2946
|
+
* Default fetch-based HTTP client.
|
|
2947
|
+
*
|
|
2948
|
+
* @example Basic usage
|
|
2949
|
+
* ```typescript
|
|
2950
|
+
* const client = new FetchHttpClient({
|
|
2951
|
+
* base_url: 'https://api.example.com/v1',
|
|
2952
|
+
* default_headers: {
|
|
2953
|
+
* 'Authorization': 'Bearer token',
|
|
2954
|
+
* },
|
|
2955
|
+
* });
|
|
2956
|
+
*
|
|
2957
|
+
* const response = await client.request<{ users: User[] }>({
|
|
2958
|
+
* method: 'GET',
|
|
2959
|
+
* path: '/users',
|
|
2960
|
+
* query: { active: true },
|
|
2961
|
+
* });
|
|
2962
|
+
* ```
|
|
2963
|
+
*
|
|
2964
|
+
* @example With custom fetch (e.g., for testing)
|
|
2965
|
+
* ```typescript
|
|
2966
|
+
* const mockFetch = vi.fn().mockResolvedValue(new Response('{}'));
|
|
2967
|
+
* const client = new FetchHttpClient({
|
|
2968
|
+
* base_url: 'https://api.example.com',
|
|
2969
|
+
* fetch: mockFetch,
|
|
2970
|
+
* });
|
|
2971
|
+
* ```
|
|
2972
|
+
*
|
|
2973
|
+
* @example Sending different body types
|
|
2974
|
+
* ```typescript
|
|
2975
|
+
* // JSON body (default for objects)
|
|
2976
|
+
* await client.request({
|
|
2977
|
+
* method: 'POST',
|
|
2978
|
+
* path: '/data',
|
|
2979
|
+
* body: { name: 'test', value: 123 },
|
|
2980
|
+
* });
|
|
2981
|
+
*
|
|
2982
|
+
* // Text body
|
|
2983
|
+
* await client.request({
|
|
2984
|
+
* method: 'POST',
|
|
2985
|
+
* path: '/text',
|
|
2986
|
+
* body: 'plain text content',
|
|
2987
|
+
* headers: { 'Content-Type': 'text/plain' },
|
|
2988
|
+
* });
|
|
2989
|
+
*
|
|
2990
|
+
* // Binary body
|
|
2991
|
+
* await client.request({
|
|
2992
|
+
* method: 'POST',
|
|
2993
|
+
* path: '/upload',
|
|
2994
|
+
* body: new Uint8Array([1, 2, 3]),
|
|
2995
|
+
* });
|
|
2996
|
+
*
|
|
2997
|
+
* // FormData (for file uploads)
|
|
2998
|
+
* const formData = new FormData();
|
|
2999
|
+
* formData.append('file', fileBlob, 'document.pdf');
|
|
3000
|
+
* await client.request({
|
|
3001
|
+
* method: 'POST',
|
|
3002
|
+
* path: '/files',
|
|
3003
|
+
* body: formData,
|
|
3004
|
+
* });
|
|
3005
|
+
* ```
|
|
3006
|
+
*/
|
|
3007
|
+
declare class FetchHttpClient implements HttpClient {
|
|
3008
|
+
private readonly baseUrl;
|
|
3009
|
+
private readonly defaultHeaders;
|
|
3010
|
+
private readonly defaultTimeoutMs;
|
|
3011
|
+
private readonly hooks;
|
|
3012
|
+
private readonly fetchImpl;
|
|
3013
|
+
constructor(options?: HttpClientOptions);
|
|
3014
|
+
/**
|
|
3015
|
+
* Performs an HTTP request.
|
|
3016
|
+
*
|
|
3017
|
+
* @param request - Request configuration
|
|
3018
|
+
* @returns Promise resolving to the response
|
|
3019
|
+
* @throws {SonioxHttpError}
|
|
3020
|
+
*/
|
|
3021
|
+
request<T>(request: HttpRequest): Promise<HttpResponse<T>>;
|
|
3022
|
+
/**
|
|
3023
|
+
* Normalizes various error types into SonioxHttpError.
|
|
3024
|
+
*/
|
|
3025
|
+
private normalizeError;
|
|
3026
|
+
}
|
|
3027
|
+
//#endregion
|
|
3028
|
+
//#region src/http/url.d.ts
|
|
3029
|
+
/**
|
|
3030
|
+
* Builds a complete URL from base URL, path, and query parameters
|
|
3031
|
+
*/
|
|
3032
|
+
declare function buildUrl(baseUrl: string | undefined, path: string, query?: QueryParams): string;
|
|
3033
|
+
/**
|
|
3034
|
+
* Normalizes fetch Headers to a plain object with lowercase keys
|
|
3035
|
+
*/
|
|
3036
|
+
declare function normalizeHeaders(headers: Headers): Record<string, string>;
|
|
3037
|
+
/**
|
|
3038
|
+
* Merges header objects
|
|
3039
|
+
*/
|
|
3040
|
+
declare function mergeHeaders(...headerObjects: (Record<string, string> | undefined)[]): Record<string, string>;
|
|
3041
|
+
//#endregion
|
|
3042
|
+
export { AbortError, type AudioData, type AudioFormat, AuthError, BadRequestError, type CleanupTarget, ConnectionError, type ContextGeneralEntry, type ContextTranslationTerm, type CreateTranscriptionOptions, type ExpressLikeRequest, type FastifyLikeRequest, FetchHttpClient, type FileIdentifier, FileListResult, type HandleWebhookOptions, type HonoLikeContext, type HttpClient, type HttpClientOptions, type HttpErrorCode, type HttpErrorDetails, type HttpMethod, type HttpObservabilityHooks, type HttpRequest, type HttpRequestBody, type HttpRequestMeta, type HttpResponse, type HttpResponseMeta, type HttpResponseType, type ISonioxTranscript, type ISonioxTranscription, type ListFilesOptions, type ListFilesResponse, type ListTranscriptionsOptions, type ListTranscriptionsResponse, type NestJSLikeRequest, NetworkError, type OneWayTranslationConfig, type PurgeFilesOptions, PurgeResult, type PurgeTranscriptionsOptions, type QueryParams, QuotaError, type RealtimeClientOptions, RealtimeError, type RealtimeErrorCode, type RealtimeEvent, RealtimeOptions, type RealtimeResult, type RealtimeSegment, RealtimeSegmentBuffer, type RealtimeSegmentBufferOptions, type RealtimeSegmentOptions, RealtimeSttSession, type RealtimeToken, type RealtimeUtterance, RealtimeUtteranceBuffer, type RealtimeUtteranceBufferOptions, SONIOX_API_BASE_URL, SONIOX_API_WEBHOOK_HEADER_ENV, SONIOX_API_WEBHOOK_SECRET_ENV, SONIOX_API_WS_URL, SONIOX_TMP_API_KEY_DURATION_MAX, SONIOX_TMP_API_KEY_DURATION_MIN, SONIOX_TMP_API_KEY_USAGE_TYPE, type SegmentGroupKey, type SegmentTranscriptOptions, type SendStreamOptions, SonioxError, type SonioxErrorCode, SonioxFile, type SonioxFileData, SonioxHttpError, type SonioxLanguage, type SonioxModel, SonioxNodeClient, SonioxNodeClientOptions, SonioxRealtimeApi, SonioxTranscript, SonioxTranscription, type SonioxTranscriptionData, type SonioxTranscriptionMode, type SonioxTranslationTarget, StateError, type SttSessionConfig, type SttSessionEvents, type SttSessionOptions, type SttSessionState, TemporaryApiKeyRequest, TemporaryApiKeyResponse, TemporaryApiKeyUsageType, type TranscribeBaseOptions, type TranscribeFromFile, type TranscribeFromFileId, type TranscribeFromFileIdOptions, type TranscribeFromFileOptions, type TranscribeFromUrl, type TranscribeFromUrlOptions, type TranscribeOptions, type TranscriptResponse, type TranscriptSegment, type TranscriptToken, type TranscriptionContext, type TranscriptionIdentifier, TranscriptionListResult, type TranscriptionStatus, type TranslationConfig, type TwoWayTranslationConfig, type UploadFileInput, type UploadFileOptions, type WaitOptions, type WebhookAuthConfig, type WebhookEvent, type WebhookEventStatus, type WebhookHandlerResult, type WebhookHandlerResultWithFetch, type WebhookHeaders, buildUrl, createAbortError, createHttpError, createNetworkError, createParseError, createTimeoutError, isAbortError, isSonioxError, isSonioxHttpError, mergeHeaders, normalizeHeaders, segmentRealtimeTokens, segmentTranscript };
|
|
3043
|
+
//# sourceMappingURL=index.d.mts.map
|