assemblyai 4.35.4 → 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 +20 -0
- package/README.md +98 -0
- package/dist/assemblyai.streaming.umd.js +13 -6
- package/dist/assemblyai.streaming.umd.min.js +1 -1
- package/dist/assemblyai.umd.js +473 -78
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +417 -75
- package/dist/bun.mjs +407 -64
- package/dist/deno.mjs +407 -64
- package/dist/index.cjs +466 -71
- package/dist/index.mjs +464 -72
- package/dist/node.cjs +405 -59
- package/dist/node.mjs +403 -60
- 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 +11 -6
- package/dist/streaming.cjs +12 -5
- package/dist/streaming.mjs +12 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/services/index.d.ts +1 -0
- 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 +411 -68
- package/package.json +1 -1
- package/src/services/base.ts +18 -8
- package/src/services/index.ts +19 -0
- 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/sync/index.ts +145 -0
- package/src/utils/errors/index.ts +2 -0
- package/src/utils/errors/sync.ts +25 -0
package/dist/streaming.cjs
CHANGED
|
@@ -1403,13 +1403,16 @@ class BaseService {
|
|
|
1403
1403
|
this.userAgent = buildUserAgent(params.userAgent || {});
|
|
1404
1404
|
}
|
|
1405
1405
|
}
|
|
1406
|
-
|
|
1406
|
+
fetchResponse(input, init) {
|
|
1407
1407
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1408
1408
|
init = Object.assign(Object.assign({}, DEFAULT_FETCH_INIT), init);
|
|
1409
1409
|
let headers = {
|
|
1410
1410
|
Authorization: this.params.apiKey,
|
|
1411
|
-
"Content-Type": "application/json",
|
|
1412
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
|
+
}
|
|
1413
1416
|
if (DEFAULT_FETCH_INIT === null || DEFAULT_FETCH_INIT === void 0 ? void 0 : DEFAULT_FETCH_INIT.headers)
|
|
1414
1417
|
headers = Object.assign(Object.assign({}, headers), DEFAULT_FETCH_INIT.headers);
|
|
1415
1418
|
if (init === null || init === void 0 ? void 0 : init.headers)
|
|
@@ -1419,15 +1422,19 @@ class BaseService {
|
|
|
1419
1422
|
{
|
|
1420
1423
|
// chromium browsers have a bug where the user agent can't be modified
|
|
1421
1424
|
if (typeof window !== "undefined" && "chrome" in window) {
|
|
1422
|
-
headers["AssemblyAI-Agent"] =
|
|
1423
|
-
this.userAgent;
|
|
1425
|
+
headers["AssemblyAI-Agent"] = this.userAgent;
|
|
1424
1426
|
}
|
|
1425
1427
|
}
|
|
1426
1428
|
}
|
|
1427
1429
|
init.headers = headers;
|
|
1428
1430
|
if (!input.startsWith("http"))
|
|
1429
1431
|
input = this.params.baseUrl + input;
|
|
1430
|
-
|
|
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);
|
|
1431
1438
|
if (response.status >= 400) {
|
|
1432
1439
|
let json;
|
|
1433
1440
|
const text = yield response.text();
|
package/dist/streaming.mjs
CHANGED
|
@@ -1401,13 +1401,16 @@ class BaseService {
|
|
|
1401
1401
|
this.userAgent = buildUserAgent(params.userAgent || {});
|
|
1402
1402
|
}
|
|
1403
1403
|
}
|
|
1404
|
-
|
|
1404
|
+
fetchResponse(input, init) {
|
|
1405
1405
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1406
1406
|
init = Object.assign(Object.assign({}, DEFAULT_FETCH_INIT), init);
|
|
1407
1407
|
let headers = {
|
|
1408
1408
|
Authorization: this.params.apiKey,
|
|
1409
|
-
"Content-Type": "application/json",
|
|
1410
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
|
+
}
|
|
1411
1414
|
if (DEFAULT_FETCH_INIT === null || DEFAULT_FETCH_INIT === void 0 ? void 0 : DEFAULT_FETCH_INIT.headers)
|
|
1412
1415
|
headers = Object.assign(Object.assign({}, headers), DEFAULT_FETCH_INIT.headers);
|
|
1413
1416
|
if (init === null || init === void 0 ? void 0 : init.headers)
|
|
@@ -1417,15 +1420,19 @@ class BaseService {
|
|
|
1417
1420
|
{
|
|
1418
1421
|
// chromium browsers have a bug where the user agent can't be modified
|
|
1419
1422
|
if (typeof window !== "undefined" && "chrome" in window) {
|
|
1420
|
-
headers["AssemblyAI-Agent"] =
|
|
1421
|
-
this.userAgent;
|
|
1423
|
+
headers["AssemblyAI-Agent"] = this.userAgent;
|
|
1422
1424
|
}
|
|
1423
1425
|
}
|
|
1424
1426
|
}
|
|
1425
1427
|
init.headers = headers;
|
|
1426
1428
|
if (!input.startsWith("http"))
|
|
1427
1429
|
input = this.params.baseUrl + input;
|
|
1428
|
-
|
|
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);
|
|
1429
1436
|
if (response.status >= 400) {
|
|
1430
1437
|
let json;
|
|
1431
1438
|
const text = yield response.text();
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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
|
+
}
|