assemblyai 4.35.3 → 4.36.3
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/CHANGELOG.md +24 -0
- package/README.md +98 -0
- package/dist/assemblyai.streaming.umd.js +26 -11
- package/dist/assemblyai.streaming.umd.min.js +1 -1
- package/dist/assemblyai.umd.js +486 -83
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +430 -80
- package/dist/bun.mjs +420 -69
- package/dist/deno.mjs +420 -69
- package/dist/index.cjs +479 -76
- package/dist/index.mjs +477 -77
- package/dist/node.cjs +418 -64
- package/dist/node.mjs +416 -65
- package/dist/services/base.d.ts +1 -0
- package/dist/services/index.d.ts +7 -1
- package/dist/services/sync/index.d.ts +1 -0
- package/dist/services/sync/service.d.ts +48 -0
- package/dist/streaming.browser.mjs +24 -11
- package/dist/streaming.cjs +25 -10
- package/dist/streaming.mjs +25 -10
- package/dist/types/index.d.ts +1 -0
- package/dist/types/services/index.d.ts +1 -0
- package/dist/types/streaming/index.d.ts +6 -1
- package/dist/types/sync/index.d.ts +133 -0
- package/dist/utils/errors/index.d.ts +1 -0
- package/dist/utils/errors/sync.d.ts +20 -0
- package/dist/workerd.mjs +424 -73
- package/package.json +1 -1
- package/src/services/base.ts +18 -8
- package/src/services/index.ts +19 -0
- package/src/services/streaming/service.ts +17 -6
- package/src/services/sync/index.ts +1 -0
- package/src/services/sync/service.ts +369 -0
- package/src/types/index.ts +1 -0
- package/src/types/services/index.ts +1 -0
- package/src/types/streaming/index.ts +6 -1
- package/src/types/sync/index.ts +145 -0
- package/src/utils/errors/index.ts +2 -0
- package/src/utils/errors/sync.ts +25 -0
|
@@ -584,6 +584,10 @@ class StreamingTranscriber {
|
|
|
584
584
|
if (!(this.token || this.apiKey)) {
|
|
585
585
|
throw new Error("API key or temporary token is required.");
|
|
586
586
|
}
|
|
587
|
+
const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
|
|
588
|
+
if (params.sampleRate === undefined && (!isOpus || params.channels)) {
|
|
589
|
+
throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
|
|
590
|
+
}
|
|
587
591
|
if (params.channels) {
|
|
588
592
|
if (params.channels.length !== 2) {
|
|
589
593
|
throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
|
|
@@ -609,10 +613,12 @@ class StreamingTranscriber {
|
|
|
609
613
|
"speaker-history") {
|
|
610
614
|
this.speakerHistory = new Map();
|
|
611
615
|
}
|
|
612
|
-
// 20 ms VAD frames at the transcriber's target sample rate.
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
this.
|
|
616
|
+
// 20 ms VAD frames at the transcriber's target sample rate. The
|
|
617
|
+
// constructor check above guarantees sampleRate in dual-channel mode.
|
|
618
|
+
const sampleRate = params.sampleRate;
|
|
619
|
+
this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
|
|
620
|
+
this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
|
|
621
|
+
this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
|
|
616
622
|
this.channelBuffers = new Map(names.map((n) => [n, []]));
|
|
617
623
|
this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
|
|
618
624
|
this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
|
|
@@ -630,7 +636,9 @@ class StreamingTranscriber {
|
|
|
630
636
|
if (this.token) {
|
|
631
637
|
searchParams.set("token", this.token);
|
|
632
638
|
}
|
|
633
|
-
|
|
639
|
+
if (this.params.sampleRate !== undefined) {
|
|
640
|
+
searchParams.set("sample_rate", this.params.sampleRate.toString());
|
|
641
|
+
}
|
|
634
642
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
635
643
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
636
644
|
}
|
|
@@ -1304,7 +1312,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
1304
1312
|
defaultUserAgentString += navigator.userAgent;
|
|
1305
1313
|
}
|
|
1306
1314
|
const defaultUserAgent = {
|
|
1307
|
-
sdk: { name: "JavaScript", version: "4.
|
|
1315
|
+
sdk: { name: "JavaScript", version: "4.36.3" },
|
|
1308
1316
|
};
|
|
1309
1317
|
if (typeof process !== "undefined") {
|
|
1310
1318
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -1343,12 +1351,15 @@ class BaseService {
|
|
|
1343
1351
|
this.userAgent = buildUserAgent(params.userAgent || {});
|
|
1344
1352
|
}
|
|
1345
1353
|
}
|
|
1346
|
-
async
|
|
1354
|
+
async fetchResponse(input, init) {
|
|
1347
1355
|
init = { ...DEFAULT_FETCH_INIT, ...init };
|
|
1348
1356
|
let headers = {
|
|
1349
1357
|
Authorization: this.params.apiKey,
|
|
1350
|
-
"Content-Type": "application/json",
|
|
1351
1358
|
};
|
|
1359
|
+
// FormData bodies must let fetch set the multipart boundary itself.
|
|
1360
|
+
if (!(init.body instanceof FormData)) {
|
|
1361
|
+
headers["Content-Type"] = "application/json";
|
|
1362
|
+
}
|
|
1352
1363
|
if (DEFAULT_FETCH_INIT?.headers)
|
|
1353
1364
|
headers = { ...headers, ...DEFAULT_FETCH_INIT.headers };
|
|
1354
1365
|
if (init?.headers)
|
|
@@ -1358,15 +1369,17 @@ class BaseService {
|
|
|
1358
1369
|
{
|
|
1359
1370
|
// chromium browsers have a bug where the user agent can't be modified
|
|
1360
1371
|
if (typeof window !== "undefined" && "chrome" in window) {
|
|
1361
|
-
headers["AssemblyAI-Agent"] =
|
|
1362
|
-
this.userAgent;
|
|
1372
|
+
headers["AssemblyAI-Agent"] = this.userAgent;
|
|
1363
1373
|
}
|
|
1364
1374
|
}
|
|
1365
1375
|
}
|
|
1366
1376
|
init.headers = headers;
|
|
1367
1377
|
if (!input.startsWith("http"))
|
|
1368
1378
|
input = this.params.baseUrl + input;
|
|
1369
|
-
|
|
1379
|
+
return await fetch(input, init);
|
|
1380
|
+
}
|
|
1381
|
+
async fetch(input, init) {
|
|
1382
|
+
const response = await this.fetchResponse(input, init);
|
|
1370
1383
|
if (response.status >= 400) {
|
|
1371
1384
|
let json;
|
|
1372
1385
|
const text = await response.text();
|
package/dist/streaming.cjs
CHANGED
|
@@ -630,6 +630,10 @@ class StreamingTranscriber {
|
|
|
630
630
|
if (!(this.token || this.apiKey)) {
|
|
631
631
|
throw new Error("API key or temporary token is required.");
|
|
632
632
|
}
|
|
633
|
+
const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
|
|
634
|
+
if (params.sampleRate === undefined && (!isOpus || params.channels)) {
|
|
635
|
+
throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
|
|
636
|
+
}
|
|
633
637
|
if (params.channels) {
|
|
634
638
|
if (params.channels.length !== 2) {
|
|
635
639
|
throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
|
|
@@ -655,10 +659,12 @@ class StreamingTranscriber {
|
|
|
655
659
|
"speaker-history") {
|
|
656
660
|
this.speakerHistory = new Map();
|
|
657
661
|
}
|
|
658
|
-
// 20 ms VAD frames at the transcriber's target sample rate.
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
this.
|
|
662
|
+
// 20 ms VAD frames at the transcriber's target sample rate. The
|
|
663
|
+
// constructor check above guarantees sampleRate in dual-channel mode.
|
|
664
|
+
const sampleRate = params.sampleRate;
|
|
665
|
+
this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
|
|
666
|
+
this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
|
|
667
|
+
this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
|
|
662
668
|
this.channelBuffers = new Map(names.map((n) => [n, []]));
|
|
663
669
|
this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
|
|
664
670
|
this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
|
|
@@ -677,7 +683,9 @@ class StreamingTranscriber {
|
|
|
677
683
|
if (this.token) {
|
|
678
684
|
searchParams.set("token", this.token);
|
|
679
685
|
}
|
|
680
|
-
|
|
686
|
+
if (this.params.sampleRate !== undefined) {
|
|
687
|
+
searchParams.set("sample_rate", this.params.sampleRate.toString());
|
|
688
|
+
}
|
|
681
689
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
682
690
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
683
691
|
}
|
|
@@ -1395,13 +1403,16 @@ class BaseService {
|
|
|
1395
1403
|
this.userAgent = buildUserAgent(params.userAgent || {});
|
|
1396
1404
|
}
|
|
1397
1405
|
}
|
|
1398
|
-
|
|
1406
|
+
fetchResponse(input, init) {
|
|
1399
1407
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1400
1408
|
init = Object.assign(Object.assign({}, DEFAULT_FETCH_INIT), init);
|
|
1401
1409
|
let headers = {
|
|
1402
1410
|
Authorization: this.params.apiKey,
|
|
1403
|
-
"Content-Type": "application/json",
|
|
1404
1411
|
};
|
|
1412
|
+
// FormData bodies must let fetch set the multipart boundary itself.
|
|
1413
|
+
if (!(init.body instanceof FormData)) {
|
|
1414
|
+
headers["Content-Type"] = "application/json";
|
|
1415
|
+
}
|
|
1405
1416
|
if (DEFAULT_FETCH_INIT === null || DEFAULT_FETCH_INIT === void 0 ? void 0 : DEFAULT_FETCH_INIT.headers)
|
|
1406
1417
|
headers = Object.assign(Object.assign({}, headers), DEFAULT_FETCH_INIT.headers);
|
|
1407
1418
|
if (init === null || init === void 0 ? void 0 : init.headers)
|
|
@@ -1411,15 +1422,19 @@ class BaseService {
|
|
|
1411
1422
|
{
|
|
1412
1423
|
// chromium browsers have a bug where the user agent can't be modified
|
|
1413
1424
|
if (typeof window !== "undefined" && "chrome" in window) {
|
|
1414
|
-
headers["AssemblyAI-Agent"] =
|
|
1415
|
-
this.userAgent;
|
|
1425
|
+
headers["AssemblyAI-Agent"] = this.userAgent;
|
|
1416
1426
|
}
|
|
1417
1427
|
}
|
|
1418
1428
|
}
|
|
1419
1429
|
init.headers = headers;
|
|
1420
1430
|
if (!input.startsWith("http"))
|
|
1421
1431
|
input = this.params.baseUrl + input;
|
|
1422
|
-
|
|
1432
|
+
return yield fetch(input, init);
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
fetch(input, init) {
|
|
1436
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1437
|
+
const response = yield this.fetchResponse(input, init);
|
|
1423
1438
|
if (response.status >= 400) {
|
|
1424
1439
|
let json;
|
|
1425
1440
|
const text = yield response.text();
|
package/dist/streaming.mjs
CHANGED
|
@@ -628,6 +628,10 @@ class StreamingTranscriber {
|
|
|
628
628
|
if (!(this.token || this.apiKey)) {
|
|
629
629
|
throw new Error("API key or temporary token is required.");
|
|
630
630
|
}
|
|
631
|
+
const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
|
|
632
|
+
if (params.sampleRate === undefined && (!isOpus || params.channels)) {
|
|
633
|
+
throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
|
|
634
|
+
}
|
|
631
635
|
if (params.channels) {
|
|
632
636
|
if (params.channels.length !== 2) {
|
|
633
637
|
throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
|
|
@@ -653,10 +657,12 @@ class StreamingTranscriber {
|
|
|
653
657
|
"speaker-history") {
|
|
654
658
|
this.speakerHistory = new Map();
|
|
655
659
|
}
|
|
656
|
-
// 20 ms VAD frames at the transcriber's target sample rate.
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
this.
|
|
660
|
+
// 20 ms VAD frames at the transcriber's target sample rate. The
|
|
661
|
+
// constructor check above guarantees sampleRate in dual-channel mode.
|
|
662
|
+
const sampleRate = params.sampleRate;
|
|
663
|
+
this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
|
|
664
|
+
this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
|
|
665
|
+
this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
|
|
660
666
|
this.channelBuffers = new Map(names.map((n) => [n, []]));
|
|
661
667
|
this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
|
|
662
668
|
this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
|
|
@@ -675,7 +681,9 @@ class StreamingTranscriber {
|
|
|
675
681
|
if (this.token) {
|
|
676
682
|
searchParams.set("token", this.token);
|
|
677
683
|
}
|
|
678
|
-
|
|
684
|
+
if (this.params.sampleRate !== undefined) {
|
|
685
|
+
searchParams.set("sample_rate", this.params.sampleRate.toString());
|
|
686
|
+
}
|
|
679
687
|
if (this.params.endOfTurnConfidenceThreshold) {
|
|
680
688
|
searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
|
|
681
689
|
}
|
|
@@ -1393,13 +1401,16 @@ class BaseService {
|
|
|
1393
1401
|
this.userAgent = buildUserAgent(params.userAgent || {});
|
|
1394
1402
|
}
|
|
1395
1403
|
}
|
|
1396
|
-
|
|
1404
|
+
fetchResponse(input, init) {
|
|
1397
1405
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1398
1406
|
init = Object.assign(Object.assign({}, DEFAULT_FETCH_INIT), init);
|
|
1399
1407
|
let headers = {
|
|
1400
1408
|
Authorization: this.params.apiKey,
|
|
1401
|
-
"Content-Type": "application/json",
|
|
1402
1409
|
};
|
|
1410
|
+
// FormData bodies must let fetch set the multipart boundary itself.
|
|
1411
|
+
if (!(init.body instanceof FormData)) {
|
|
1412
|
+
headers["Content-Type"] = "application/json";
|
|
1413
|
+
}
|
|
1403
1414
|
if (DEFAULT_FETCH_INIT === null || DEFAULT_FETCH_INIT === void 0 ? void 0 : DEFAULT_FETCH_INIT.headers)
|
|
1404
1415
|
headers = Object.assign(Object.assign({}, headers), DEFAULT_FETCH_INIT.headers);
|
|
1405
1416
|
if (init === null || init === void 0 ? void 0 : init.headers)
|
|
@@ -1409,15 +1420,19 @@ class BaseService {
|
|
|
1409
1420
|
{
|
|
1410
1421
|
// chromium browsers have a bug where the user agent can't be modified
|
|
1411
1422
|
if (typeof window !== "undefined" && "chrome" in window) {
|
|
1412
|
-
headers["AssemblyAI-Agent"] =
|
|
1413
|
-
this.userAgent;
|
|
1423
|
+
headers["AssemblyAI-Agent"] = this.userAgent;
|
|
1414
1424
|
}
|
|
1415
1425
|
}
|
|
1416
1426
|
}
|
|
1417
1427
|
init.headers = headers;
|
|
1418
1428
|
if (!input.startsWith("http"))
|
|
1419
1429
|
input = this.params.baseUrl + input;
|
|
1420
|
-
|
|
1430
|
+
return yield fetch(input, init);
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
fetch(input, init) {
|
|
1434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1435
|
+
const response = yield this.fetchResponse(input, init);
|
|
1421
1436
|
if (response.status >= 400) {
|
|
1422
1437
|
let json;
|
|
1423
1438
|
const text = yield response.text();
|
package/dist/types/index.d.ts
CHANGED
|
@@ -87,7 +87,12 @@ export type StreamingTranscriberParams = {
|
|
|
87
87
|
* Milliseconds to wait between connection attempts. Defaults to 500.
|
|
88
88
|
*/
|
|
89
89
|
connectionRetryDelay?: number;
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Required for PCM encodings (and for dual-channel mode). May be omitted
|
|
92
|
+
* for Opus encodings (`opus`, `ogg_opus`) — the stream is self-describing
|
|
93
|
+
* and the server ignores the value.
|
|
94
|
+
*/
|
|
95
|
+
sampleRate?: number;
|
|
91
96
|
encoding?: AudioEncoding;
|
|
92
97
|
endOfTurnConfidenceThreshold?: number;
|
|
93
98
|
/**
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LiteralUnion } from "../helpers";
|
|
3
|
+
/**
|
|
4
|
+
* The speech models available on the synchronous transcription API.
|
|
5
|
+
*/
|
|
6
|
+
export type SyncSpeechModel = LiteralUnion<"universal-3-5-pro", string>;
|
|
7
|
+
/**
|
|
8
|
+
* The default speech model for synchronous transcription.
|
|
9
|
+
*/
|
|
10
|
+
export declare const defaultSyncSpeechModel: SyncSpeechModel;
|
|
11
|
+
/**
|
|
12
|
+
* Audio input for synchronous transcription: a local file path or
|
|
13
|
+
* data URL (file system access requires Node.js, Bun, or Deno), raw audio
|
|
14
|
+
* bytes, a Blob/File, or a readable stream.
|
|
15
|
+
*
|
|
16
|
+
* URLs are not accepted — the sync API has no URL ingestion; use
|
|
17
|
+
* `client.transcripts` for URL or asynchronous transcription.
|
|
18
|
+
*/
|
|
19
|
+
export type SyncAudioInput = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array> | NodeJS.ReadableStream;
|
|
20
|
+
/**
|
|
21
|
+
* Options for a synchronous transcription request.
|
|
22
|
+
*
|
|
23
|
+
* `sample_rate` and `channels` are required only for raw PCM audio — WAV
|
|
24
|
+
* carries them in its header. `model` is sent as the `X-AAI-Model` routing
|
|
25
|
+
* header and is never included in the request body.
|
|
26
|
+
*/
|
|
27
|
+
export type SyncTranscriptionConfig = {
|
|
28
|
+
/**
|
|
29
|
+
* The sync speech model to route to, sent as the `X-AAI-Model` header.
|
|
30
|
+
* Defaults to `"universal-3-5-pro"`.
|
|
31
|
+
*/
|
|
32
|
+
model?: SyncSpeechModel;
|
|
33
|
+
/**
|
|
34
|
+
* Custom transcription instruction. Maximum 4096 characters — longer
|
|
35
|
+
* prompts are rejected.
|
|
36
|
+
*/
|
|
37
|
+
prompt?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Terms to bias the decoder towards. Whitespace is stripped and empty
|
|
40
|
+
* terms are dropped. Maximum 2048 characters in total — longer lists are
|
|
41
|
+
* rejected.
|
|
42
|
+
*/
|
|
43
|
+
keyterms_prompt?: string[];
|
|
44
|
+
/**
|
|
45
|
+
* Prior turns from the same conversation, oldest first, most recent last.
|
|
46
|
+
* A single string is treated as one turn. Capped at 100 turns and 4096
|
|
47
|
+
* characters in total — over-cap context is trimmed (oldest turns dropped
|
|
48
|
+
* first), not rejected.
|
|
49
|
+
*/
|
|
50
|
+
conversation_context?: string | string[];
|
|
51
|
+
/**
|
|
52
|
+
* ISO 639-1 codes for the language(s) of the audio — a single-element
|
|
53
|
+
* array (e.g. `["es"]`) for monolingual audio, or several codes (e.g.
|
|
54
|
+
* `["en", "es"]`) for multilingual audio. Ignored when `prompt` is set.
|
|
55
|
+
* Defaults to English.
|
|
56
|
+
*/
|
|
57
|
+
language_codes?: string[];
|
|
58
|
+
/**
|
|
59
|
+
* The source sample rate in Hz. Required for raw PCM audio; ignored for
|
|
60
|
+
* WAV.
|
|
61
|
+
*/
|
|
62
|
+
sample_rate?: number;
|
|
63
|
+
/**
|
|
64
|
+
* The channel count (1 for mono, 2 for stereo). Required for raw PCM
|
|
65
|
+
* audio; ignored for WAV.
|
|
66
|
+
*/
|
|
67
|
+
channels?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Whether to compute per-word `start`/`end` timestamps. When `true`,
|
|
70
|
+
* words carry accurate timestamps at a small latency cost. Defaults to
|
|
71
|
+
* `false`: no timestamps are returned.
|
|
72
|
+
*/
|
|
73
|
+
timestamps?: boolean;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Client-side options for a synchronous transcription request.
|
|
77
|
+
* These are not sent to the server.
|
|
78
|
+
*/
|
|
79
|
+
export type SyncTranscribeOptions = {
|
|
80
|
+
/**
|
|
81
|
+
* The request timeout in milliseconds. Defaults to 60 000, which is kept
|
|
82
|
+
* above the server's 30 s deadline so the client doesn't race it.
|
|
83
|
+
*/
|
|
84
|
+
timeout?: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* A single word in a sync transcript.
|
|
88
|
+
*
|
|
89
|
+
* `start`/`end` are in milliseconds and present only when the request set
|
|
90
|
+
* `timestamps: true`; otherwise they are omitted.
|
|
91
|
+
*/
|
|
92
|
+
export type SyncWord = {
|
|
93
|
+
/** The text of the word. */
|
|
94
|
+
text: string;
|
|
95
|
+
/**
|
|
96
|
+
* The start time of the word in milliseconds. Absent unless `timestamps`
|
|
97
|
+
* was requested.
|
|
98
|
+
*/
|
|
99
|
+
start?: number;
|
|
100
|
+
/**
|
|
101
|
+
* The end time of the word in milliseconds. Absent unless `timestamps`
|
|
102
|
+
* was requested.
|
|
103
|
+
*/
|
|
104
|
+
end?: number;
|
|
105
|
+
/** The confidence score of the word, in the range 0-1. */
|
|
106
|
+
confidence: number;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* The result of a synchronous transcription request.
|
|
110
|
+
*/
|
|
111
|
+
export type SyncTranscriptResponse = {
|
|
112
|
+
/** The full transcript text. */
|
|
113
|
+
text: string;
|
|
114
|
+
/**
|
|
115
|
+
* Per-word confidence, plus `start`/`end` timings when the request set
|
|
116
|
+
* `timestamps: true`.
|
|
117
|
+
*/
|
|
118
|
+
words: SyncWord[];
|
|
119
|
+
/** The overall transcript confidence, in the range 0-1. */
|
|
120
|
+
confidence: number;
|
|
121
|
+
/** The total audio duration in milliseconds. */
|
|
122
|
+
audio_duration_ms: number;
|
|
123
|
+
/**
|
|
124
|
+
* The server-generated UUID for this request. Record it to correlate a
|
|
125
|
+
* request with support.
|
|
126
|
+
*/
|
|
127
|
+
session_id: string;
|
|
128
|
+
/**
|
|
129
|
+
* The end-to-end server-side request time in milliseconds. `undefined`
|
|
130
|
+
* when the server predates the field.
|
|
131
|
+
*/
|
|
132
|
+
request_time_ms?: number;
|
|
133
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when a synchronous transcription request fails.
|
|
3
|
+
*/
|
|
4
|
+
export declare class SyncTranscriptError extends Error {
|
|
5
|
+
readonly status?: number | undefined;
|
|
6
|
+
readonly errorCode?: string | undefined;
|
|
7
|
+
readonly retryAfter?: number | undefined;
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new SyncTranscriptError.
|
|
11
|
+
* @param message - The human-readable error message.
|
|
12
|
+
* @param status - The HTTP status code of the failed request.
|
|
13
|
+
* @param errorCode - Machine-readable code — the snake_cased
|
|
14
|
+
* problem-details `title` from the server (e.g. `bad_audio`,
|
|
15
|
+
* `audio_too_large`, `capacity_exceeded`, `inference_timeout`).
|
|
16
|
+
* @param retryAfter - Seconds to wait before retrying, from the
|
|
17
|
+
* `Retry-After` header on 429/503 responses.
|
|
18
|
+
*/
|
|
19
|
+
constructor(message: string, status?: number | undefined, errorCode?: string | undefined, retryAfter?: number | undefined);
|
|
20
|
+
}
|