assemblyai 4.35.4 → 4.36.4

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +98 -0
  3. package/dist/assemblyai.streaming.umd.js +28 -11
  4. package/dist/assemblyai.streaming.umd.min.js +1 -1
  5. package/dist/assemblyai.umd.js +488 -83
  6. package/dist/assemblyai.umd.min.js +1 -1
  7. package/dist/browser.mjs +430 -78
  8. package/dist/bun.mjs +420 -67
  9. package/dist/deno.mjs +420 -67
  10. package/dist/index.cjs +481 -76
  11. package/dist/index.mjs +479 -77
  12. package/dist/node.cjs +418 -62
  13. package/dist/node.mjs +416 -63
  14. package/dist/services/base.d.ts +1 -0
  15. package/dist/services/index.d.ts +7 -1
  16. package/dist/services/streaming/service.d.ts +2 -1
  17. package/dist/services/sync/index.d.ts +1 -0
  18. package/dist/services/sync/service.d.ts +48 -0
  19. package/dist/streaming.browser.mjs +24 -9
  20. package/dist/streaming.cjs +27 -10
  21. package/dist/streaming.mjs +27 -10
  22. package/dist/types/asyncapi.generated.d.ts +1 -1
  23. package/dist/types/index.d.ts +1 -0
  24. package/dist/types/services/index.d.ts +1 -0
  25. package/dist/types/streaming/index.d.ts +14 -4
  26. package/dist/types/sync/index.d.ts +133 -0
  27. package/dist/utils/errors/index.d.ts +1 -0
  28. package/dist/utils/errors/sync.d.ts +20 -0
  29. package/dist/workerd.mjs +424 -71
  30. package/package.json +1 -1
  31. package/src/services/base.ts +18 -8
  32. package/src/services/index.ts +19 -0
  33. package/src/services/streaming/service.ts +22 -3
  34. package/src/services/sync/index.ts +1 -0
  35. package/src/services/sync/service.ts +369 -0
  36. package/src/types/asyncapi.generated.ts +6 -1
  37. package/src/types/index.ts +1 -0
  38. package/src/types/services/index.ts +1 -0
  39. package/src/types/streaming/index.ts +16 -3
  40. package/src/types/sync/index.ts +145 -0
  41. package/src/utils/errors/index.ts +2 -0
  42. package/src/utils/errors/sync.ts +25 -0
@@ -584,9 +584,12 @@ 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.');
587
+ const isSelfDescribing = params.encoding === "opus" ||
588
+ params.encoding === "ogg_opus" ||
589
+ params.encoding === "aac";
590
+ if (params.sampleRate === undefined &&
591
+ (!isSelfDescribing || params.channels)) {
592
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
590
593
  }
591
594
  if (params.channels) {
592
595
  if (params.channels.length !== 2) {
@@ -664,6 +667,9 @@ class StreamingTranscriber {
664
667
  if (this.params.formatTurns) {
665
668
  searchParams.set("format_turns", this.params.formatTurns.toString());
666
669
  }
670
+ if (this.params.sessionHeartbeat !== undefined) {
671
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
672
+ }
667
673
  if (this.params.encoding) {
668
674
  searchParams.set("encoding", this.params.encoding.toString());
669
675
  }
@@ -952,6 +958,10 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
952
958
  this.listeners.warning?.(warning);
953
959
  break;
954
960
  }
961
+ case "Heartbeat": {
962
+ this.listeners.heartbeat?.(message);
963
+ break;
964
+ }
955
965
  case "Termination": {
956
966
  this.sessionTerminatedResolve?.();
957
967
  break;
@@ -1312,7 +1322,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
1312
1322
  defaultUserAgentString += navigator.userAgent;
1313
1323
  }
1314
1324
  const defaultUserAgent = {
1315
- sdk: { name: "JavaScript", version: "4.35.4" },
1325
+ sdk: { name: "JavaScript", version: "4.36.4" },
1316
1326
  };
1317
1327
  if (typeof process !== "undefined") {
1318
1328
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1351,12 +1361,15 @@ class BaseService {
1351
1361
  this.userAgent = buildUserAgent(params.userAgent || {});
1352
1362
  }
1353
1363
  }
1354
- async fetch(input, init) {
1364
+ async fetchResponse(input, init) {
1355
1365
  init = { ...DEFAULT_FETCH_INIT, ...init };
1356
1366
  let headers = {
1357
1367
  Authorization: this.params.apiKey,
1358
- "Content-Type": "application/json",
1359
1368
  };
1369
+ // FormData bodies must let fetch set the multipart boundary itself.
1370
+ if (!(init.body instanceof FormData)) {
1371
+ headers["Content-Type"] = "application/json";
1372
+ }
1360
1373
  if (DEFAULT_FETCH_INIT?.headers)
1361
1374
  headers = { ...headers, ...DEFAULT_FETCH_INIT.headers };
1362
1375
  if (init?.headers)
@@ -1366,15 +1379,17 @@ class BaseService {
1366
1379
  {
1367
1380
  // chromium browsers have a bug where the user agent can't be modified
1368
1381
  if (typeof window !== "undefined" && "chrome" in window) {
1369
- headers["AssemblyAI-Agent"] =
1370
- this.userAgent;
1382
+ headers["AssemblyAI-Agent"] = this.userAgent;
1371
1383
  }
1372
1384
  }
1373
1385
  }
1374
1386
  init.headers = headers;
1375
1387
  if (!input.startsWith("http"))
1376
1388
  input = this.params.baseUrl + input;
1377
- const response = await fetch(input, init);
1389
+ return await fetch(input, init);
1390
+ }
1391
+ async fetch(input, init) {
1392
+ const response = await this.fetchResponse(input, init);
1378
1393
  if (response.status >= 400) {
1379
1394
  let json;
1380
1395
  const text = await response.text();
@@ -630,9 +630,12 @@ 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.');
633
+ const isSelfDescribing = params.encoding === "opus" ||
634
+ params.encoding === "ogg_opus" ||
635
+ params.encoding === "aac";
636
+ if (params.sampleRate === undefined &&
637
+ (!isSelfDescribing || params.channels)) {
638
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
636
639
  }
637
640
  if (params.channels) {
638
641
  if (params.channels.length !== 2) {
@@ -710,6 +713,9 @@ class StreamingTranscriber {
710
713
  if (this.params.formatTurns) {
711
714
  searchParams.set("format_turns", this.params.formatTurns.toString());
712
715
  }
716
+ if (this.params.sessionHeartbeat !== undefined) {
717
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
718
+ }
713
719
  if (this.params.encoding) {
714
720
  searchParams.set("encoding", this.params.encoding.toString());
715
721
  }
@@ -941,7 +947,7 @@ class StreamingTranscriber {
941
947
  (_c = (_b = this.listeners).error) === null || _c === void 0 ? void 0 : _c.call(_b, error);
942
948
  };
943
949
  this.socket.onmessage = ({ data }) => {
944
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
950
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
945
951
  const message = JSON.parse(data.toString());
946
952
  if ("error" in message) {
947
953
  const err = new StreamingError(message.error);
@@ -1001,8 +1007,12 @@ class StreamingTranscriber {
1001
1007
  (_p = (_o = this.listeners).warning) === null || _p === void 0 ? void 0 : _p.call(_o, warning);
1002
1008
  break;
1003
1009
  }
1010
+ case "Heartbeat": {
1011
+ (_r = (_q = this.listeners).heartbeat) === null || _r === void 0 ? void 0 : _r.call(_q, message);
1012
+ break;
1013
+ }
1004
1014
  case "Termination": {
1005
- (_q = this.sessionTerminatedResolve) === null || _q === void 0 ? void 0 : _q.call(this);
1015
+ (_s = this.sessionTerminatedResolve) === null || _s === void 0 ? void 0 : _s.call(this);
1006
1016
  break;
1007
1017
  }
1008
1018
  }
@@ -1403,13 +1413,16 @@ class BaseService {
1403
1413
  this.userAgent = buildUserAgent(params.userAgent || {});
1404
1414
  }
1405
1415
  }
1406
- fetch(input, init) {
1416
+ fetchResponse(input, init) {
1407
1417
  return __awaiter(this, void 0, void 0, function* () {
1408
1418
  init = Object.assign(Object.assign({}, DEFAULT_FETCH_INIT), init);
1409
1419
  let headers = {
1410
1420
  Authorization: this.params.apiKey,
1411
- "Content-Type": "application/json",
1412
1421
  };
1422
+ // FormData bodies must let fetch set the multipart boundary itself.
1423
+ if (!(init.body instanceof FormData)) {
1424
+ headers["Content-Type"] = "application/json";
1425
+ }
1413
1426
  if (DEFAULT_FETCH_INIT === null || DEFAULT_FETCH_INIT === void 0 ? void 0 : DEFAULT_FETCH_INIT.headers)
1414
1427
  headers = Object.assign(Object.assign({}, headers), DEFAULT_FETCH_INIT.headers);
1415
1428
  if (init === null || init === void 0 ? void 0 : init.headers)
@@ -1419,15 +1432,19 @@ class BaseService {
1419
1432
  {
1420
1433
  // chromium browsers have a bug where the user agent can't be modified
1421
1434
  if (typeof window !== "undefined" && "chrome" in window) {
1422
- headers["AssemblyAI-Agent"] =
1423
- this.userAgent;
1435
+ headers["AssemblyAI-Agent"] = this.userAgent;
1424
1436
  }
1425
1437
  }
1426
1438
  }
1427
1439
  init.headers = headers;
1428
1440
  if (!input.startsWith("http"))
1429
1441
  input = this.params.baseUrl + input;
1430
- const response = yield fetch(input, init);
1442
+ return yield fetch(input, init);
1443
+ });
1444
+ }
1445
+ fetch(input, init) {
1446
+ return __awaiter(this, void 0, void 0, function* () {
1447
+ const response = yield this.fetchResponse(input, init);
1431
1448
  if (response.status >= 400) {
1432
1449
  let json;
1433
1450
  const text = yield response.text();
@@ -628,9 +628,12 @@ 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.');
631
+ const isSelfDescribing = params.encoding === "opus" ||
632
+ params.encoding === "ogg_opus" ||
633
+ params.encoding === "aac";
634
+ if (params.sampleRate === undefined &&
635
+ (!isSelfDescribing || params.channels)) {
636
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
634
637
  }
635
638
  if (params.channels) {
636
639
  if (params.channels.length !== 2) {
@@ -708,6 +711,9 @@ class StreamingTranscriber {
708
711
  if (this.params.formatTurns) {
709
712
  searchParams.set("format_turns", this.params.formatTurns.toString());
710
713
  }
714
+ if (this.params.sessionHeartbeat !== undefined) {
715
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
716
+ }
711
717
  if (this.params.encoding) {
712
718
  searchParams.set("encoding", this.params.encoding.toString());
713
719
  }
@@ -939,7 +945,7 @@ class StreamingTranscriber {
939
945
  (_c = (_b = this.listeners).error) === null || _c === void 0 ? void 0 : _c.call(_b, error);
940
946
  };
941
947
  this.socket.onmessage = ({ data }) => {
942
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
948
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
943
949
  const message = JSON.parse(data.toString());
944
950
  if ("error" in message) {
945
951
  const err = new StreamingError(message.error);
@@ -999,8 +1005,12 @@ class StreamingTranscriber {
999
1005
  (_p = (_o = this.listeners).warning) === null || _p === void 0 ? void 0 : _p.call(_o, warning);
1000
1006
  break;
1001
1007
  }
1008
+ case "Heartbeat": {
1009
+ (_r = (_q = this.listeners).heartbeat) === null || _r === void 0 ? void 0 : _r.call(_q, message);
1010
+ break;
1011
+ }
1002
1012
  case "Termination": {
1003
- (_q = this.sessionTerminatedResolve) === null || _q === void 0 ? void 0 : _q.call(this);
1013
+ (_s = this.sessionTerminatedResolve) === null || _s === void 0 ? void 0 : _s.call(this);
1004
1014
  break;
1005
1015
  }
1006
1016
  }
@@ -1401,13 +1411,16 @@ class BaseService {
1401
1411
  this.userAgent = buildUserAgent(params.userAgent || {});
1402
1412
  }
1403
1413
  }
1404
- fetch(input, init) {
1414
+ fetchResponse(input, init) {
1405
1415
  return __awaiter(this, void 0, void 0, function* () {
1406
1416
  init = Object.assign(Object.assign({}, DEFAULT_FETCH_INIT), init);
1407
1417
  let headers = {
1408
1418
  Authorization: this.params.apiKey,
1409
- "Content-Type": "application/json",
1410
1419
  };
1420
+ // FormData bodies must let fetch set the multipart boundary itself.
1421
+ if (!(init.body instanceof FormData)) {
1422
+ headers["Content-Type"] = "application/json";
1423
+ }
1411
1424
  if (DEFAULT_FETCH_INIT === null || DEFAULT_FETCH_INIT === void 0 ? void 0 : DEFAULT_FETCH_INIT.headers)
1412
1425
  headers = Object.assign(Object.assign({}, headers), DEFAULT_FETCH_INIT.headers);
1413
1426
  if (init === null || init === void 0 ? void 0 : init.headers)
@@ -1417,15 +1430,19 @@ class BaseService {
1417
1430
  {
1418
1431
  // chromium browsers have a bug where the user agent can't be modified
1419
1432
  if (typeof window !== "undefined" && "chrome" in window) {
1420
- headers["AssemblyAI-Agent"] =
1421
- this.userAgent;
1433
+ headers["AssemblyAI-Agent"] = this.userAgent;
1422
1434
  }
1423
1435
  }
1424
1436
  }
1425
1437
  init.headers = headers;
1426
1438
  if (!input.startsWith("http"))
1427
1439
  input = this.params.baseUrl + input;
1428
- const response = yield fetch(input, init);
1440
+ return yield fetch(input, init);
1441
+ });
1442
+ }
1443
+ fetch(input, init) {
1444
+ return __awaiter(this, void 0, void 0, function* () {
1445
+ const response = yield this.fetchResponse(input, init);
1429
1446
  if (response.status >= 400) {
1430
1447
  let json;
1431
1448
  const text = yield response.text();
@@ -6,7 +6,7 @@ export type AudioData = ArrayBufferLike;
6
6
  * The encoding of the audio data
7
7
  * @defaultValue "pcm_s16"le
8
8
  */
9
- export type AudioEncoding = "pcm_s16le" | "pcm_mulaw" | "opus" | "ogg_opus";
9
+ export type AudioEncoding = "pcm_s16le" | "pcm_mulaw" | "opus" | "ogg_opus" | "aac";
10
10
  /**
11
11
  * Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
12
12
  */
@@ -1,3 +1,4 @@
1
+ export * from "./sync";
1
2
  export * from "./files";
2
3
  export * from "./transcripts";
3
4
  export * from "./realtime";
@@ -3,6 +3,7 @@ type BaseServiceParams = {
3
3
  apiKey: string;
4
4
  baseUrl?: string;
5
5
  streamingBaseUrl?: string;
6
+ syncBaseUrl?: string;
6
7
  /**
7
8
  * The AssemblyAI user agent to use for requests.
8
9
  * The provided components will be merged into the default AssemblyAI user agent.
@@ -89,8 +89,8 @@ export type StreamingTranscriberParams = {
89
89
  connectionRetryDelay?: number;
90
90
  /**
91
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.
92
+ * for self-describing encodings (`opus`, `ogg_opus`, `aac`) — the stream
93
+ * carries its own rate and the server ignores the value.
94
94
  */
95
95
  sampleRate?: number;
96
96
  encoding?: AudioEncoding;
@@ -103,6 +103,7 @@ export type StreamingTranscriberParams = {
103
103
  maxTurnSilence?: number;
104
104
  vadThreshold?: number;
105
105
  formatTurns?: boolean;
106
+ sessionHeartbeat?: boolean;
106
107
  filterProfanity?: boolean;
107
108
  keyterms?: string[];
108
109
  keytermsPrompt?: string[];
@@ -172,7 +173,7 @@ export type StreamingTranscriberParams = {
172
173
  /** Tuning for dual-channel attribution. Ignored when `channels` is unset. */
173
174
  channelAttribution?: ChannelAttributionParams;
174
175
  };
175
- export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "speakerRevision" | "warning" | "vad" | "error";
176
+ export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "speakerRevision" | "warning" | "heartbeat" | "vad" | "error";
176
177
  export type StreamingListeners = {
177
178
  open?: (event: BeginEvent) => void;
178
179
  close?: (code: number, reason: string) => void;
@@ -181,6 +182,7 @@ export type StreamingListeners = {
181
182
  llmGatewayResponse?: (event: LLMGatewayResponseEvent) => void;
182
183
  speakerRevision?: (event: SpeakerRevisionEvent) => void;
183
184
  warning?: (event: WarningEvent) => void;
185
+ heartbeat?: (event: HeartbeatEvent) => void;
184
186
  vad?: (event: VadFrame) => void;
185
187
  error?: (error: Error) => void;
186
188
  };
@@ -266,6 +268,7 @@ export type StreamingUpdateConfiguration = {
266
268
  max_turn_silence?: number;
267
269
  vad_threshold?: number;
268
270
  format_turns?: boolean;
271
+ session_heartbeat?: boolean;
269
272
  keyterms_prompt?: string[];
270
273
  prompt?: string;
271
274
  agent_context?: string;
@@ -295,6 +298,13 @@ export type WarningEvent = {
295
298
  warning_code: number;
296
299
  warning: string;
297
300
  };
301
+ export type HeartbeatEvent = {
302
+ type: "Heartbeat";
303
+ total_audio_received_ms: number;
304
+ total_duration_ms: number;
305
+ realtime_factor: number;
306
+ max_speech_probability: number;
307
+ };
298
308
  export type LLMGatewayResponseEvent = {
299
309
  type: "LLMGatewayResponse";
300
310
  turn_order: number;
@@ -323,5 +333,5 @@ export type SpeakerRevisionEvent = {
323
333
  type: "SpeakerRevision";
324
334
  revisions: SpeakerRevisionItem[];
325
335
  };
326
- export type StreamingEventMessage = BeginEvent | TurnEvent | SpeechStartedEvent | TerminationEvent | LLMGatewayResponseEvent | SpeakerRevisionEvent | ErrorEvent | WarningEvent;
336
+ export type StreamingEventMessage = BeginEvent | TurnEvent | SpeechStartedEvent | TerminationEvent | LLMGatewayResponseEvent | SpeakerRevisionEvent | ErrorEvent | WarningEvent | HeartbeatEvent;
327
337
  export type StreamingOperationMessage = StreamingUpdateConfiguration | StreamingForceEndpoint | StreamingKeepAlive | StreamingTerminateSession;
@@ -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
+ };
@@ -1,2 +1,3 @@
1
+ export { SyncTranscriptError } from "./sync";
1
2
  export { RealtimeError, RealtimeErrorType, RealtimeErrorMessages, } from "./realtime";
2
3
  export { StreamingError, StreamingErrorType, StreamingErrorMessages, } from "./streaming";
@@ -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
+ }