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
@@ -0,0 +1,145 @@
1
+ import { LiteralUnion } from "../helpers";
2
+
3
+ /**
4
+ * The speech models available on the synchronous transcription API.
5
+ */
6
+ export type SyncSpeechModel = LiteralUnion<"universal-3-5-pro", string>;
7
+
8
+ /**
9
+ * The default speech model for synchronous transcription.
10
+ */
11
+ export const defaultSyncSpeechModel: SyncSpeechModel = "universal-3-5-pro";
12
+
13
+ /**
14
+ * Audio input for synchronous transcription: a local file path or
15
+ * data URL (file system access requires Node.js, Bun, or Deno), raw audio
16
+ * bytes, a Blob/File, or a readable stream.
17
+ *
18
+ * URLs are not accepted — the sync API has no URL ingestion; use
19
+ * `client.transcripts` for URL or asynchronous transcription.
20
+ */
21
+ export type SyncAudioInput =
22
+ | string
23
+ | Uint8Array
24
+ | ArrayBuffer
25
+ | Blob
26
+ | ReadableStream<Uint8Array>
27
+ | NodeJS.ReadableStream;
28
+
29
+ /**
30
+ * Options for a synchronous transcription request.
31
+ *
32
+ * `sample_rate` and `channels` are required only for raw PCM audio — WAV
33
+ * carries them in its header. `model` is sent as the `X-AAI-Model` routing
34
+ * header and is never included in the request body.
35
+ */
36
+ export type SyncTranscriptionConfig = {
37
+ /**
38
+ * The sync speech model to route to, sent as the `X-AAI-Model` header.
39
+ * Defaults to `"universal-3-5-pro"`.
40
+ */
41
+ model?: SyncSpeechModel;
42
+ /**
43
+ * Custom transcription instruction. Maximum 4096 characters — longer
44
+ * prompts are rejected.
45
+ */
46
+ prompt?: string;
47
+ /**
48
+ * Terms to bias the decoder towards. Whitespace is stripped and empty
49
+ * terms are dropped. Maximum 2048 characters in total — longer lists are
50
+ * rejected.
51
+ */
52
+ keyterms_prompt?: string[];
53
+ /**
54
+ * Prior turns from the same conversation, oldest first, most recent last.
55
+ * A single string is treated as one turn. Capped at 100 turns and 4096
56
+ * characters in total — over-cap context is trimmed (oldest turns dropped
57
+ * first), not rejected.
58
+ */
59
+ conversation_context?: string | string[];
60
+ /**
61
+ * ISO 639-1 codes for the language(s) of the audio — a single-element
62
+ * array (e.g. `["es"]`) for monolingual audio, or several codes (e.g.
63
+ * `["en", "es"]`) for multilingual audio. Ignored when `prompt` is set.
64
+ * Defaults to English.
65
+ */
66
+ language_codes?: string[];
67
+ /**
68
+ * The source sample rate in Hz. Required for raw PCM audio; ignored for
69
+ * WAV.
70
+ */
71
+ sample_rate?: number;
72
+ /**
73
+ * The channel count (1 for mono, 2 for stereo). Required for raw PCM
74
+ * audio; ignored for WAV.
75
+ */
76
+ channels?: number;
77
+ /**
78
+ * Whether to compute per-word `start`/`end` timestamps. When `true`,
79
+ * words carry accurate timestamps at a small latency cost. Defaults to
80
+ * `false`: no timestamps are returned.
81
+ */
82
+ timestamps?: boolean;
83
+ };
84
+
85
+ /**
86
+ * Client-side options for a synchronous transcription request.
87
+ * These are not sent to the server.
88
+ */
89
+ export type SyncTranscribeOptions = {
90
+ /**
91
+ * The request timeout in milliseconds. Defaults to 60 000, which is kept
92
+ * above the server's 30 s deadline so the client doesn't race it.
93
+ */
94
+ timeout?: number;
95
+ };
96
+
97
+ /**
98
+ * A single word in a sync transcript.
99
+ *
100
+ * `start`/`end` are in milliseconds and present only when the request set
101
+ * `timestamps: true`; otherwise they are omitted.
102
+ */
103
+ export type SyncWord = {
104
+ /** The text of the word. */
105
+ text: string;
106
+ /**
107
+ * The start time of the word in milliseconds. Absent unless `timestamps`
108
+ * was requested.
109
+ */
110
+ start?: number;
111
+ /**
112
+ * The end time of the word in milliseconds. Absent unless `timestamps`
113
+ * was requested.
114
+ */
115
+ end?: number;
116
+ /** The confidence score of the word, in the range 0-1. */
117
+ confidence: number;
118
+ };
119
+
120
+ /**
121
+ * The result of a synchronous transcription request.
122
+ */
123
+ export type SyncTranscriptResponse = {
124
+ /** The full transcript text. */
125
+ text: string;
126
+ /**
127
+ * Per-word confidence, plus `start`/`end` timings when the request set
128
+ * `timestamps: true`.
129
+ */
130
+ words: SyncWord[];
131
+ /** The overall transcript confidence, in the range 0-1. */
132
+ confidence: number;
133
+ /** The total audio duration in milliseconds. */
134
+ audio_duration_ms: number;
135
+ /**
136
+ * The server-generated UUID for this request. Record it to correlate a
137
+ * request with support.
138
+ */
139
+ session_id: string;
140
+ /**
141
+ * The end-to-end server-side request time in milliseconds. `undefined`
142
+ * when the server predates the field.
143
+ */
144
+ request_time_ms?: number;
145
+ };
@@ -1,3 +1,5 @@
1
+ export { SyncTranscriptError } from "./sync";
2
+
1
3
  export {
2
4
  RealtimeError,
3
5
  RealtimeErrorType,
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Error thrown when a synchronous transcription request fails.
3
+ */
4
+ export class SyncTranscriptError extends Error {
5
+ override name = "SyncTranscriptError";
6
+
7
+ /**
8
+ * Create a new SyncTranscriptError.
9
+ * @param message - The human-readable error message.
10
+ * @param status - The HTTP status code of the failed request.
11
+ * @param errorCode - Machine-readable code — the snake_cased
12
+ * problem-details `title` from the server (e.g. `bad_audio`,
13
+ * `audio_too_large`, `capacity_exceeded`, `inference_timeout`).
14
+ * @param retryAfter - Seconds to wait before retrying, from the
15
+ * `Retry-After` header on 429/503 responses.
16
+ */
17
+ constructor(
18
+ message: string,
19
+ public readonly status?: number,
20
+ public readonly errorCode?: string,
21
+ public readonly retryAfter?: number,
22
+ ) {
23
+ super(message);
24
+ }
25
+ }