assemblyai 4.5.0-beta.0 → 4.6.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/CHANGELOG.md +41 -0
- package/README.md +53 -9
- package/dist/assemblyai.streaming.umd.js +317 -0
- package/dist/assemblyai.streaming.umd.min.js +1 -0
- package/dist/assemblyai.umd.js +160 -12
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +154 -11
- package/dist/bun.mjs +154 -11
- package/dist/deno.mjs +154 -11
- package/dist/exports/index.d.ts +2 -0
- package/dist/exports/streaming.d.ts +4 -0
- package/dist/index.cjs +160 -12
- package/dist/index.mjs +160 -12
- package/dist/node.cjs +154 -11
- package/dist/node.mjs +154 -11
- package/dist/polyfills/fetch/default.d.ts +1 -0
- package/dist/polyfills/fetch/workerd.d.ts +1 -0
- package/dist/services/base.d.ts +1 -0
- package/dist/services/lemur/index.d.ts +8 -1
- package/dist/services/realtime/service.d.ts +60 -0
- package/dist/services/transcripts/index.d.ts +16 -3
- package/dist/streaming.browser.mjs +268 -0
- package/dist/streaming.cjs +306 -0
- package/dist/streaming.mjs +303 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/openapi.generated.d.ts +75 -29
- package/dist/types/services/index.d.ts +7 -0
- package/dist/types/transcripts/index.d.ts +9 -0
- package/dist/utils/userAgent.d.ts +2 -0
- package/dist/workerd.mjs +751 -0
- package/docs/reference-types-from-js.md +27 -0
- package/package.json +57 -25
- package/src/exports/index.ts +2 -0
- package/src/exports/streaming.ts +4 -0
- package/src/polyfills/fetch/default.ts +3 -0
- package/src/polyfills/fetch/workerd.ts +1 -0
- package/src/services/base.ts +27 -7
- package/src/services/files/index.ts +19 -2
- package/src/services/index.ts +2 -1
- package/src/services/lemur/index.ts +12 -0
- package/src/services/realtime/service.ts +65 -0
- package/src/services/transcripts/index.ts +41 -4
- package/src/types/index.ts +9 -0
- package/src/types/openapi.generated.ts +224 -48
- package/src/types/services/index.ts +8 -0
- package/src/types/transcripts/index.ts +10 -0
- package/src/utils/path.ts +1 -0
- package/src/utils/userAgent.ts +51 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import ws from 'ws';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
22
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
24
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
31
|
+
var e = new Error(message);
|
|
32
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const { WritableStream } = typeof window !== "undefined"
|
|
36
|
+
? window
|
|
37
|
+
: typeof global !== "undefined"
|
|
38
|
+
? global
|
|
39
|
+
: globalThis;
|
|
40
|
+
|
|
41
|
+
const factory = (url, params) => new ws(url, params);
|
|
42
|
+
|
|
43
|
+
var RealtimeErrorType;
|
|
44
|
+
(function (RealtimeErrorType) {
|
|
45
|
+
RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
|
|
46
|
+
RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
|
|
47
|
+
// Both InsufficientFunds and FreeAccount error use 4002
|
|
48
|
+
RealtimeErrorType[RealtimeErrorType["InsufficientFundsOrFreeAccount"] = 4002] = "InsufficientFundsOrFreeAccount";
|
|
49
|
+
RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
|
|
50
|
+
RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
|
|
51
|
+
RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
|
|
52
|
+
RealtimeErrorType[RealtimeErrorType["RateLimited"] = 4029] = "RateLimited";
|
|
53
|
+
RealtimeErrorType[RealtimeErrorType["UniqueSessionViolation"] = 4030] = "UniqueSessionViolation";
|
|
54
|
+
RealtimeErrorType[RealtimeErrorType["SessionTimeout"] = 4031] = "SessionTimeout";
|
|
55
|
+
RealtimeErrorType[RealtimeErrorType["AudioTooShort"] = 4032] = "AudioTooShort";
|
|
56
|
+
RealtimeErrorType[RealtimeErrorType["AudioTooLong"] = 4033] = "AudioTooLong";
|
|
57
|
+
RealtimeErrorType[RealtimeErrorType["BadJson"] = 4100] = "BadJson";
|
|
58
|
+
RealtimeErrorType[RealtimeErrorType["BadSchema"] = 4101] = "BadSchema";
|
|
59
|
+
RealtimeErrorType[RealtimeErrorType["TooManyStreams"] = 4102] = "TooManyStreams";
|
|
60
|
+
RealtimeErrorType[RealtimeErrorType["Reconnected"] = 4103] = "Reconnected";
|
|
61
|
+
RealtimeErrorType[RealtimeErrorType["ReconnectAttemptsExhausted"] = 1013] = "ReconnectAttemptsExhausted";
|
|
62
|
+
})(RealtimeErrorType || (RealtimeErrorType = {}));
|
|
63
|
+
const RealtimeErrorMessages = {
|
|
64
|
+
[RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
65
|
+
[RealtimeErrorType.AuthFailed]: "Not Authorized",
|
|
66
|
+
[RealtimeErrorType.InsufficientFundsOrFreeAccount]: "Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",
|
|
67
|
+
[RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
|
|
68
|
+
[RealtimeErrorType.SessionExpired]: "Session has expired",
|
|
69
|
+
[RealtimeErrorType.ClosedSession]: "Session is closed",
|
|
70
|
+
[RealtimeErrorType.RateLimited]: "Rate limited",
|
|
71
|
+
[RealtimeErrorType.UniqueSessionViolation]: "Unique session violation",
|
|
72
|
+
[RealtimeErrorType.SessionTimeout]: "Session Timeout",
|
|
73
|
+
[RealtimeErrorType.AudioTooShort]: "Audio too short",
|
|
74
|
+
[RealtimeErrorType.AudioTooLong]: "Audio too long",
|
|
75
|
+
[RealtimeErrorType.BadJson]: "Bad JSON",
|
|
76
|
+
[RealtimeErrorType.BadSchema]: "Bad schema",
|
|
77
|
+
[RealtimeErrorType.TooManyStreams]: "Too many streams",
|
|
78
|
+
[RealtimeErrorType.Reconnected]: "Reconnected",
|
|
79
|
+
[RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
|
|
80
|
+
};
|
|
81
|
+
class RealtimeError extends Error {
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
85
|
+
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
86
|
+
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
87
|
+
/**
|
|
88
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
89
|
+
*/
|
|
90
|
+
class RealtimeTranscriber {
|
|
91
|
+
/**
|
|
92
|
+
* Create a new RealtimeTranscriber.
|
|
93
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
94
|
+
*/
|
|
95
|
+
constructor(params) {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
this.listeners = {};
|
|
98
|
+
this.realtimeUrl = (_a = params.realtimeUrl) !== null && _a !== void 0 ? _a : defaultRealtimeUrl;
|
|
99
|
+
this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
|
|
100
|
+
this.wordBoost = params.wordBoost;
|
|
101
|
+
this.encoding = params.encoding;
|
|
102
|
+
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
103
|
+
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
104
|
+
if ("token" in params && params.token)
|
|
105
|
+
this.token = params.token;
|
|
106
|
+
if ("apiKey" in params && params.apiKey)
|
|
107
|
+
this.apiKey = params.apiKey;
|
|
108
|
+
if (!(this.token || this.apiKey)) {
|
|
109
|
+
throw new Error("API key or temporary token is required.");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
connectionUrl() {
|
|
113
|
+
const url = new URL(this.realtimeUrl);
|
|
114
|
+
if (url.protocol !== "wss:") {
|
|
115
|
+
throw new Error("Invalid protocol, must be wss");
|
|
116
|
+
}
|
|
117
|
+
const searchParams = new URLSearchParams();
|
|
118
|
+
if (this.token) {
|
|
119
|
+
searchParams.set("token", this.token);
|
|
120
|
+
}
|
|
121
|
+
searchParams.set("sample_rate", this.sampleRate.toString());
|
|
122
|
+
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
123
|
+
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
124
|
+
}
|
|
125
|
+
if (this.encoding) {
|
|
126
|
+
searchParams.set("encoding", this.encoding);
|
|
127
|
+
}
|
|
128
|
+
searchParams.set("enable_extra_session_information", "true");
|
|
129
|
+
if (this.disablePartialTranscripts) {
|
|
130
|
+
searchParams.set("disable_partial_transcripts", this.disablePartialTranscripts.toString());
|
|
131
|
+
}
|
|
132
|
+
url.search = searchParams.toString();
|
|
133
|
+
return url;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Add a listener for an event.
|
|
137
|
+
* @param event - The event to listen for.
|
|
138
|
+
* @param listener - The function to call when the event is emitted.
|
|
139
|
+
*/
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
+
on(event, listener) {
|
|
142
|
+
this.listeners[event] = listener;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Connect to the server and begin a new session.
|
|
146
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
147
|
+
*/
|
|
148
|
+
connect() {
|
|
149
|
+
return new Promise((resolve) => {
|
|
150
|
+
if (this.socket) {
|
|
151
|
+
throw new Error("Already connected");
|
|
152
|
+
}
|
|
153
|
+
const url = this.connectionUrl();
|
|
154
|
+
if (this.token) {
|
|
155
|
+
this.socket = factory(url.toString());
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.socket = factory(url.toString(), {
|
|
159
|
+
headers: { Authorization: this.apiKey },
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
this.socket.binaryType = "arraybuffer";
|
|
163
|
+
this.socket.onopen = () => {
|
|
164
|
+
if (this.endUtteranceSilenceThreshold === undefined ||
|
|
165
|
+
this.endUtteranceSilenceThreshold === null) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold);
|
|
169
|
+
};
|
|
170
|
+
this.socket.onclose = ({ code, reason }) => {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
if (!reason) {
|
|
173
|
+
if (code in RealtimeErrorType) {
|
|
174
|
+
reason = RealtimeErrorMessages[code];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
(_b = (_a = this.listeners).close) === null || _b === void 0 ? void 0 : _b.call(_a, code, reason);
|
|
178
|
+
};
|
|
179
|
+
this.socket.onerror = (event) => {
|
|
180
|
+
var _a, _b, _c, _d;
|
|
181
|
+
if (event.error)
|
|
182
|
+
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, event.error);
|
|
183
|
+
else
|
|
184
|
+
(_d = (_c = this.listeners).error) === null || _d === void 0 ? void 0 : _d.call(_c, new Error(event.message));
|
|
185
|
+
};
|
|
186
|
+
this.socket.onmessage = ({ data }) => {
|
|
187
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
188
|
+
const message = JSON.parse(data.toString());
|
|
189
|
+
if ("error" in message) {
|
|
190
|
+
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, new RealtimeError(message.error));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
switch (message.message_type) {
|
|
194
|
+
case "SessionBegins": {
|
|
195
|
+
const openObject = {
|
|
196
|
+
sessionId: message.session_id,
|
|
197
|
+
expiresAt: new Date(message.expires_at),
|
|
198
|
+
};
|
|
199
|
+
resolve(openObject);
|
|
200
|
+
(_d = (_c = this.listeners).open) === null || _d === void 0 ? void 0 : _d.call(_c, openObject);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case "PartialTranscript": {
|
|
204
|
+
// message.created is actually a string when coming from the socket
|
|
205
|
+
message.created = new Date(message.created);
|
|
206
|
+
(_f = (_e = this.listeners).transcript) === null || _f === void 0 ? void 0 : _f.call(_e, message);
|
|
207
|
+
(_h = (_g = this.listeners)["transcript.partial"]) === null || _h === void 0 ? void 0 : _h.call(_g, message);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
case "FinalTranscript": {
|
|
211
|
+
// message.created is actually a string when coming from the socket
|
|
212
|
+
message.created = new Date(message.created);
|
|
213
|
+
(_k = (_j = this.listeners).transcript) === null || _k === void 0 ? void 0 : _k.call(_j, message);
|
|
214
|
+
(_m = (_l = this.listeners)["transcript.final"]) === null || _m === void 0 ? void 0 : _m.call(_l, message);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case "SessionInformation": {
|
|
218
|
+
(_p = (_o = this.listeners).session_information) === null || _p === void 0 ? void 0 : _p.call(_o, message);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case "SessionTerminated": {
|
|
222
|
+
(_q = this.sessionTerminatedResolve) === null || _q === void 0 ? void 0 : _q.call(this);
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Send audio data to the server.
|
|
231
|
+
* @param audio - The audio data to send to the server.
|
|
232
|
+
*/
|
|
233
|
+
sendAudio(audio) {
|
|
234
|
+
this.send(audio);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
238
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
239
|
+
*/
|
|
240
|
+
stream() {
|
|
241
|
+
return new WritableStream({
|
|
242
|
+
write: (chunk) => {
|
|
243
|
+
this.sendAudio(chunk);
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Manually end an utterance
|
|
249
|
+
*/
|
|
250
|
+
forceEndUtterance() {
|
|
251
|
+
this.send(forceEndOfUtteranceMessage);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
|
|
255
|
+
* @param threshold - The duration of the end utterance silence threshold in milliseconds.
|
|
256
|
+
* This value must be an integer between 0 and 20_000.
|
|
257
|
+
*/
|
|
258
|
+
configureEndUtteranceSilenceThreshold(threshold) {
|
|
259
|
+
this.send(`{"end_utterance_silence_threshold":${threshold}}`);
|
|
260
|
+
}
|
|
261
|
+
send(data) {
|
|
262
|
+
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
263
|
+
throw new Error("Socket is not open for communication");
|
|
264
|
+
}
|
|
265
|
+
this.socket.send(data);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Close the connection to the server.
|
|
269
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
270
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
271
|
+
*/
|
|
272
|
+
close() {
|
|
273
|
+
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
274
|
+
var _a;
|
|
275
|
+
if (this.socket) {
|
|
276
|
+
if (this.socket.readyState === this.socket.OPEN) {
|
|
277
|
+
if (waitForSessionTermination) {
|
|
278
|
+
const sessionTerminatedPromise = new Promise((resolve) => {
|
|
279
|
+
this.sessionTerminatedResolve = resolve;
|
|
280
|
+
});
|
|
281
|
+
this.socket.send(terminateSessionMessage);
|
|
282
|
+
yield sessionTerminatedPromise;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
this.socket.send(terminateSessionMessage);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.removeAllListeners)
|
|
289
|
+
this.socket.removeAllListeners();
|
|
290
|
+
this.socket.close();
|
|
291
|
+
}
|
|
292
|
+
this.listeners = {};
|
|
293
|
+
this.socket = undefined;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
299
|
+
*/
|
|
300
|
+
class RealtimeService extends RealtimeTranscriber {
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export { RealtimeService, RealtimeTranscriber };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,3 +5,10 @@ export * from "./services";
|
|
|
5
5
|
export * from "./asyncapi.generated";
|
|
6
6
|
export * from "./openapi.generated";
|
|
7
7
|
export * from "./deprecated";
|
|
8
|
+
export type UserAgentItem = {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
};
|
|
12
|
+
export type UserAgent = {
|
|
13
|
+
[component: string]: UserAgentItem | undefined | null | false;
|
|
14
|
+
};
|
|
@@ -476,7 +476,7 @@ export type Entity = {
|
|
|
476
476
|
/**
|
|
477
477
|
* The type of entity for the detected entity
|
|
478
478
|
*/
|
|
479
|
-
export type EntityType = "banking_information" | "blood_type" | "credit_card_cvv" | "credit_card_expiration" | "credit_card_number" | "date" | "date_of_birth" | "drivers_license" | "drug" | "email_address" | "event" | "injury" | "language" | "location" | "medical_condition" | "medical_process" | "money_amount" | "nationality" | "occupation" | "organization" | "password" | "person_age" | "person_name" | "phone_number" | "political_affiliation" | "religion" | "time" | "url" | "us_social_security_number";
|
|
479
|
+
export type EntityType = "account_number" | "banking_information" | "blood_type" | "credit_card_cvv" | "credit_card_expiration" | "credit_card_number" | "date" | "date_interval" | "date_of_birth" | "drivers_license" | "drug" | "duration" | "email_address" | "event" | "filename" | "gender_sexuality" | "healthcare_number" | "injury" | "ip_address" | "language" | "location" | "marital_status" | "medical_condition" | "medical_process" | "money_amount" | "nationality" | "number_sequence" | "occupation" | "organization" | "passport_number" | "password" | "person_age" | "person_name" | "phone_number" | "physical_attribute" | "political_affiliation" | "religion" | "statistics" | "time" | "url" | "us_social_security_number" | "username" | "vehicle_id" | "zodiac_sign";
|
|
480
480
|
/**
|
|
481
481
|
* @example
|
|
482
482
|
* ```js
|
|
@@ -521,7 +521,11 @@ export type LemurActionItemsParams = LemurBaseParams & {
|
|
|
521
521
|
* ```js
|
|
522
522
|
* {
|
|
523
523
|
* "request_id": "5"e1b27c2-691f-4414-8bc5-f14678442f9e",
|
|
524
|
-
* "response": "Here are some potential action items based on the transcript:\n\n- Monitor air quality levels in affected areas and issue warnings as needed.\n\n- Advise vulnerable populations like children, the elderly, and those with respiratory conditions to limit time outdoors.\n\n- Have schools cancel outdoor activities when air quality is poor.\n\n- Educate the public on health impacts of smoke inhalation and precautions to take.\n\n- Track progression of smoke plumes using weather and air quality monitoring systems.\n\n- Coordinate cross-regionally to manage smoke exposure as air masses shift.\n\n- Plan for likely increase in such events due to climate change. Expand monitoring and forecasting capabilities.\n\n- Conduct research to better understand health impacts of wildfire smoke and mitigation strategies.\n\n- Develop strategies to prevent and manage wildfires to limit air quality impacts.\n"
|
|
524
|
+
* "response": "Here are some potential action items based on the transcript:\n\n- Monitor air quality levels in affected areas and issue warnings as needed.\n\n- Advise vulnerable populations like children, the elderly, and those with respiratory conditions to limit time outdoors.\n\n- Have schools cancel outdoor activities when air quality is poor.\n\n- Educate the public on health impacts of smoke inhalation and precautions to take.\n\n- Track progression of smoke plumes using weather and air quality monitoring systems.\n\n- Coordinate cross-regionally to manage smoke exposure as air masses shift.\n\n- Plan for likely increase in such events due to climate change. Expand monitoring and forecasting capabilities.\n\n- Conduct research to better understand health impacts of wildfire smoke and mitigation strategies.\n\n- Develop strategies to prevent and manage wildfires to limit air quality impacts.\n",
|
|
525
|
+
* "usage": {
|
|
526
|
+
* "input_tokens": 27,
|
|
527
|
+
* "output_tokens": 3
|
|
528
|
+
* }
|
|
525
529
|
* }
|
|
526
530
|
* ```
|
|
527
531
|
*/
|
|
@@ -558,7 +562,6 @@ export type LemurBaseParams = {
|
|
|
558
562
|
]>;
|
|
559
563
|
/**
|
|
560
564
|
* The model that is used for the final prompt after compression is performed.
|
|
561
|
-
* Defaults to "default".
|
|
562
565
|
*
|
|
563
566
|
* @defaultValue "default
|
|
564
567
|
*/
|
|
@@ -588,7 +591,11 @@ export type LemurBaseParams = {
|
|
|
588
591
|
* @example
|
|
589
592
|
* ```js
|
|
590
593
|
* {
|
|
591
|
-
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e"
|
|
594
|
+
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e",
|
|
595
|
+
* "usage": {
|
|
596
|
+
* "input_tokens": 27,
|
|
597
|
+
* "output_tokens": 3
|
|
598
|
+
* }
|
|
592
599
|
* }
|
|
593
600
|
* ```
|
|
594
601
|
*/
|
|
@@ -597,12 +604,16 @@ export type LemurBaseResponse = {
|
|
|
597
604
|
* The ID of the LeMUR request
|
|
598
605
|
*/
|
|
599
606
|
request_id: string;
|
|
607
|
+
/**
|
|
608
|
+
* The usage numbers for the LeMUR request
|
|
609
|
+
*/
|
|
610
|
+
usage: LemurUsage;
|
|
600
611
|
};
|
|
601
612
|
/**
|
|
602
613
|
* The model that is used for the final prompt after compression is performed.
|
|
603
614
|
*
|
|
604
615
|
*/
|
|
605
|
-
export type LemurModel = "
|
|
616
|
+
export type LemurModel = "anthropic/claude-3-5-sonnet" | "anthropic/claude-3-opus" | "anthropic/claude-3-haiku" | "anthropic/claude-3-sonnet" | "anthropic/claude-2-1" | "anthropic/claude-2" | "default" | "anthropic/claude-instant-1-2" | "basic" | "assemblyai/mistral-7b";
|
|
606
617
|
/**
|
|
607
618
|
* @example
|
|
608
619
|
* ```js
|
|
@@ -706,7 +717,11 @@ export type LemurQuestionAnswerParams = LemurBaseParams & {
|
|
|
706
717
|
* "answer": "yes",
|
|
707
718
|
* "question": "Is global warming affecting wildfires?"
|
|
708
719
|
* }
|
|
709
|
-
* ]
|
|
720
|
+
* ],
|
|
721
|
+
* "usage": {
|
|
722
|
+
* "input_tokens": 27,
|
|
723
|
+
* "output_tokens": 3
|
|
724
|
+
* }
|
|
710
725
|
* }
|
|
711
726
|
* ```
|
|
712
727
|
*/
|
|
@@ -716,12 +731,13 @@ export type LemurQuestionAnswerResponse = LemurBaseResponse & {
|
|
|
716
731
|
*/
|
|
717
732
|
response: LemurQuestionAnswer[];
|
|
718
733
|
};
|
|
734
|
+
export type LemurResponse = LemurTaskResponse | LemurSummaryResponse | LemurQuestionAnswerResponse | LemurActionItemsResponse;
|
|
719
735
|
/**
|
|
720
736
|
* @example
|
|
721
737
|
* ```js
|
|
722
738
|
* {
|
|
723
739
|
* "transcript_ids": [
|
|
724
|
-
* "
|
|
740
|
+
* "47b95ba5-8889-44d8-bc80-5de38306e582"
|
|
725
741
|
* ],
|
|
726
742
|
* "context": "This is an interview about wildfires.",
|
|
727
743
|
* "final_model": "default",
|
|
@@ -741,7 +757,11 @@ export type LemurSummaryParams = LemurBaseParams & {
|
|
|
741
757
|
* ```js
|
|
742
758
|
* {
|
|
743
759
|
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e",
|
|
744
|
-
* "response": "- Wildfires in Canada are sending smoke and air pollution across parts of the US, triggering air quality alerts from Maine to Minnesota. Concentrations of particulate matter have exceeded safety levels.\n\n- Weather systems are channeling the smoke through Pennsylvania into the Mid-Atlantic and Northeast regions. New York City has canceled outdoor activities to keep children and vulnerable groups indoors.\n\n- Very small particulate matter can enter the lungs and impact respiratory, cardiovascular and neurological health. Young children, the elderly and those with preexisting conditions are most at risk.\n\n- The conditions causing the poor air quality could get worse or shift to different areas in coming days depending on weather patterns. More wildfires may also contribute to higher concentrations.\n\n- Climate change is leading to longer and more severe fire seasons. Events of smoke traveling long distances and affecting air quality over wide areas will likely become more common in the future.\"\n"
|
|
760
|
+
* "response": "- Wildfires in Canada are sending smoke and air pollution across parts of the US, triggering air quality alerts from Maine to Minnesota. Concentrations of particulate matter have exceeded safety levels.\n\n- Weather systems are channeling the smoke through Pennsylvania into the Mid-Atlantic and Northeast regions. New York City has canceled outdoor activities to keep children and vulnerable groups indoors.\n\n- Very small particulate matter can enter the lungs and impact respiratory, cardiovascular and neurological health. Young children, the elderly and those with preexisting conditions are most at risk.\n\n- The conditions causing the poor air quality could get worse or shift to different areas in coming days depending on weather patterns. More wildfires may also contribute to higher concentrations.\n\n- Climate change is leading to longer and more severe fire seasons. Events of smoke traveling long distances and affecting air quality over wide areas will likely become more common in the future.\"\n",
|
|
761
|
+
* "usage": {
|
|
762
|
+
* "input_tokens": 27,
|
|
763
|
+
* "output_tokens": 3
|
|
764
|
+
* }
|
|
745
765
|
* }
|
|
746
766
|
* ```
|
|
747
767
|
*/
|
|
@@ -777,7 +797,11 @@ export type LemurTaskParams = {
|
|
|
777
797
|
* ```js
|
|
778
798
|
* {
|
|
779
799
|
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e",
|
|
780
|
-
* "response": "Based on the transcript, the following locations were mentioned as being affected by wildfire smoke from Canada:\n\n- Maine\n- Maryland\n- Minnesota\n- Mid Atlantic region\n- Northeast region\n- New York City\n- Baltimore\n"
|
|
800
|
+
* "response": "Based on the transcript, the following locations were mentioned as being affected by wildfire smoke from Canada:\n\n- Maine\n- Maryland\n- Minnesota\n- Mid Atlantic region\n- Northeast region\n- New York City\n- Baltimore\n",
|
|
801
|
+
* "usage": {
|
|
802
|
+
* "input_tokens": 27,
|
|
803
|
+
* "output_tokens": 3
|
|
804
|
+
* }
|
|
781
805
|
* }
|
|
782
806
|
* ```
|
|
783
807
|
*/
|
|
@@ -787,6 +811,19 @@ export type LemurTaskResponse = {
|
|
|
787
811
|
*/
|
|
788
812
|
response: string;
|
|
789
813
|
} & LemurBaseResponse;
|
|
814
|
+
/**
|
|
815
|
+
* The usage numbers for the LeMUR request
|
|
816
|
+
*/
|
|
817
|
+
export type LemurUsage = {
|
|
818
|
+
/**
|
|
819
|
+
* The number of input tokens used by the model
|
|
820
|
+
*/
|
|
821
|
+
input_tokens: number;
|
|
822
|
+
/**
|
|
823
|
+
* The number of output tokens generated by the model
|
|
824
|
+
*/
|
|
825
|
+
output_tokens: number;
|
|
826
|
+
};
|
|
790
827
|
/**
|
|
791
828
|
* @example
|
|
792
829
|
* ```js
|
|
@@ -828,7 +865,6 @@ export type ListTranscriptParams = {
|
|
|
828
865
|
throttled_only?: boolean;
|
|
829
866
|
};
|
|
830
867
|
/**
|
|
831
|
-
* Details of the transcript page.
|
|
832
868
|
* Details of the transcript page. Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts.
|
|
833
869
|
* @example
|
|
834
870
|
* ```js
|
|
@@ -851,12 +887,10 @@ export type PageDetails = {
|
|
|
851
887
|
*/
|
|
852
888
|
limit: number;
|
|
853
889
|
/**
|
|
854
|
-
* The URL to the next page of transcripts
|
|
855
890
|
* The URL to the next page of transcripts. The next URL always points to a page with newer transcripts.
|
|
856
891
|
*/
|
|
857
892
|
next_url: string | null;
|
|
858
893
|
/**
|
|
859
|
-
* The URL to the previous page of transcripts
|
|
860
894
|
* The URL to the next page of transcripts. The previous URL always points to a page with older transcripts.
|
|
861
895
|
*/
|
|
862
896
|
prev_url: string | null;
|
|
@@ -948,7 +982,10 @@ export type ParagraphsResponse = {
|
|
|
948
982
|
id: string;
|
|
949
983
|
paragraphs: TranscriptParagraph[];
|
|
950
984
|
};
|
|
951
|
-
|
|
985
|
+
/**
|
|
986
|
+
* The type of PII to redact
|
|
987
|
+
*/
|
|
988
|
+
export type PiiPolicy = "account_number" | "banking_information" | "blood_type" | "credit_card_cvv" | "credit_card_expiration" | "credit_card_number" | "date" | "date_interval" | "date_of_birth" | "drivers_license" | "drug" | "duration" | "email_address" | "event" | "filename" | "gender_sexuality" | "healthcare_number" | "injury" | "ip_address" | "language" | "location" | "marital_status" | "medical_condition" | "medical_process" | "money_amount" | "nationality" | "number_sequence" | "occupation" | "organization" | "passport_number" | "password" | "person_age" | "person_name" | "phone_number" | "physical_attribute" | "political_affiliation" | "religion" | "statistics" | "time" | "url" | "us_social_security_number" | "username" | "vehicle_id" | "zodiac_sign";
|
|
952
989
|
/**
|
|
953
990
|
* @example
|
|
954
991
|
* ```js
|
|
@@ -987,6 +1024,10 @@ export type RealtimeTemporaryTokenResponse = {
|
|
|
987
1024
|
*/
|
|
988
1025
|
token: string;
|
|
989
1026
|
};
|
|
1027
|
+
/**
|
|
1028
|
+
* The notification when the redacted audio is ready.
|
|
1029
|
+
*/
|
|
1030
|
+
export type RedactedAudioNotification = RedactedAudioResponse;
|
|
990
1031
|
/**
|
|
991
1032
|
* @example
|
|
992
1033
|
* ```js
|
|
@@ -1124,7 +1165,7 @@ export type SentencesResponse = {
|
|
|
1124
1165
|
};
|
|
1125
1166
|
export type Sentiment = "POSITIVE" | "NEUTRAL" | "NEGATIVE";
|
|
1126
1167
|
/**
|
|
1127
|
-
* The result of the
|
|
1168
|
+
* The result of the Sentiment Analysis model
|
|
1128
1169
|
* @example
|
|
1129
1170
|
* ```js
|
|
1130
1171
|
* {
|
|
@@ -2114,7 +2155,7 @@ export type Transcript = {
|
|
|
2114
2155
|
auto_highlights: boolean;
|
|
2115
2156
|
/**
|
|
2116
2157
|
* An array of results for the Key Phrases model, if it is enabled.
|
|
2117
|
-
* See {@link https://www.assemblyai.com/docs/models/key-phrases | Key
|
|
2158
|
+
* See {@link https://www.assemblyai.com/docs/models/key-phrases | Key Phrases } for more information.
|
|
2118
2159
|
*/
|
|
2119
2160
|
auto_highlights_result?: AutoHighlightsResult | null;
|
|
2120
2161
|
/**
|
|
@@ -2236,7 +2277,7 @@ export type Transcript = {
|
|
|
2236
2277
|
sentiment_analysis?: boolean | null;
|
|
2237
2278
|
/**
|
|
2238
2279
|
* An array of results for the Sentiment Analysis model, if it is enabled.
|
|
2239
|
-
* See {@link https://www.assemblyai.com/docs/models/sentiment-analysis | Sentiment
|
|
2280
|
+
* See {@link https://www.assemblyai.com/docs/models/sentiment-analysis | Sentiment Analysis } for more information.
|
|
2240
2281
|
*/
|
|
2241
2282
|
sentiment_analysis_results?: SentimentAnalysisResult[] | null;
|
|
2242
2283
|
/**
|
|
@@ -2305,15 +2346,17 @@ export type Transcript = {
|
|
|
2305
2346
|
*/
|
|
2306
2347
|
webhook_auth: boolean;
|
|
2307
2348
|
/**
|
|
2308
|
-
* The header name
|
|
2349
|
+
* The header name to be sent with the transcript completed or failed webhook requests
|
|
2309
2350
|
*/
|
|
2310
2351
|
webhook_auth_header_name?: string | null;
|
|
2311
2352
|
/**
|
|
2312
|
-
* The status code we received from your server when delivering
|
|
2353
|
+
* The status code we received from your server when delivering the transcript completed or failed webhook request, if a webhook URL was provided
|
|
2313
2354
|
*/
|
|
2314
2355
|
webhook_status_code?: number | null;
|
|
2315
2356
|
/**
|
|
2316
|
-
* The URL to which we send
|
|
2357
|
+
* The URL to which we send webhook requests.
|
|
2358
|
+
* We sends two different types of webhook requests.
|
|
2359
|
+
* One request when a transcript is completed or failed, and one request when the redacted audio is ready if redact_pii_audio is enabled.
|
|
2317
2360
|
*/
|
|
2318
2361
|
webhook_url?: string | null;
|
|
2319
2362
|
/**
|
|
@@ -2358,9 +2401,8 @@ export type TranscriptCustomSpelling = {
|
|
|
2358
2401
|
*
|
|
2359
2402
|
* @defaultValue "en_us
|
|
2360
2403
|
*/
|
|
2361
|
-
export type TranscriptLanguageCode = "en" | "en_au" | "en_uk" | "en_us" | "es" | "fr" | "de" | "it" | "pt" | "nl" | "
|
|
2404
|
+
export type TranscriptLanguageCode = "en" | "en_au" | "en_uk" | "en_us" | "es" | "fr" | "de" | "it" | "pt" | "nl" | "af" | "sq" | "am" | "ar" | "hy" | "as" | "az" | "ba" | "eu" | "be" | "bn" | "bs" | "br" | "bg" | "my" | "ca" | "zh" | "hr" | "cs" | "da" | "et" | "fo" | "fi" | "gl" | "ka" | "el" | "gu" | "ht" | "ha" | "haw" | "he" | "hi" | "hu" | "is" | "id" | "ja" | "jw" | "kn" | "kk" | "km" | "ko" | "lo" | "la" | "lv" | "ln" | "lt" | "lb" | "mk" | "mg" | "ms" | "ml" | "mt" | "mi" | "mr" | "mn" | "ne" | "no" | "nn" | "oc" | "pa" | "ps" | "fa" | "pl" | "ro" | "ru" | "sa" | "sr" | "sn" | "sd" | "si" | "sk" | "sl" | "so" | "su" | "sw" | "sv" | "tl" | "tg" | "ta" | "tt" | "te" | "th" | "bo" | "tr" | "tk" | "uk" | "ur" | "uz" | "vi" | "cy" | "yi" | "yo";
|
|
2362
2405
|
/**
|
|
2363
|
-
* A list of transcripts
|
|
2364
2406
|
* A list of transcripts. Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts.
|
|
2365
2407
|
* @example
|
|
2366
2408
|
* ```js
|
|
@@ -2498,7 +2540,7 @@ export type TranscriptOptionalParams = {
|
|
|
2498
2540
|
*/
|
|
2499
2541
|
auto_chapters?: boolean;
|
|
2500
2542
|
/**
|
|
2501
|
-
*
|
|
2543
|
+
* Enable Key Phrases, either true or false
|
|
2502
2544
|
*/
|
|
2503
2545
|
auto_highlights?: boolean;
|
|
2504
2546
|
/**
|
|
@@ -2510,7 +2552,7 @@ export type TranscriptOptionalParams = {
|
|
|
2510
2552
|
*/
|
|
2511
2553
|
content_safety?: boolean;
|
|
2512
2554
|
/**
|
|
2513
|
-
* The confidence threshold for
|
|
2555
|
+
* The confidence threshold for the Content Moderation model. Values must be between 25 and 100.
|
|
2514
2556
|
*/
|
|
2515
2557
|
content_safety_confidence?: number;
|
|
2516
2558
|
/**
|
|
@@ -2518,7 +2560,7 @@ export type TranscriptOptionalParams = {
|
|
|
2518
2560
|
*/
|
|
2519
2561
|
custom_spelling?: TranscriptCustomSpelling[];
|
|
2520
2562
|
/**
|
|
2521
|
-
*
|
|
2563
|
+
* Enable custom topics, either true or false
|
|
2522
2564
|
*/
|
|
2523
2565
|
custom_topics?: boolean;
|
|
2524
2566
|
/**
|
|
@@ -2551,7 +2593,7 @@ export type TranscriptOptionalParams = {
|
|
|
2551
2593
|
*/
|
|
2552
2594
|
language_code?: LiteralUnion<TranscriptLanguageCode, string> | null;
|
|
2553
2595
|
/**
|
|
2554
|
-
*
|
|
2596
|
+
* Enable {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection }, either true or false.
|
|
2555
2597
|
*/
|
|
2556
2598
|
language_detection?: boolean;
|
|
2557
2599
|
/**
|
|
@@ -2619,21 +2661,21 @@ export type TranscriptOptionalParams = {
|
|
|
2619
2661
|
*/
|
|
2620
2662
|
summary_type?: SummaryType;
|
|
2621
2663
|
/**
|
|
2622
|
-
* The list of custom topics
|
|
2664
|
+
* The list of custom topics
|
|
2623
2665
|
*/
|
|
2624
2666
|
topics?: string[];
|
|
2625
2667
|
/**
|
|
2626
|
-
* The header name
|
|
2668
|
+
* The header name to be sent with the transcript completed or failed webhook requests
|
|
2627
2669
|
* @defaultValue null
|
|
2628
2670
|
*/
|
|
2629
2671
|
webhook_auth_header_name?: string | null;
|
|
2630
2672
|
/**
|
|
2631
|
-
*
|
|
2673
|
+
* The header value to send back with the transcript completed or failed webhook requests for added security
|
|
2632
2674
|
* @defaultValue null
|
|
2633
2675
|
*/
|
|
2634
2676
|
webhook_auth_header_value?: string | null;
|
|
2635
2677
|
/**
|
|
2636
|
-
* The URL to which
|
|
2678
|
+
* The URL to which we send webhook requests. We sends two different types of webhook requests. One request when a transcript is completed or failed, and one request when the redacted audio is ready if redact_pii_audio is enabled.
|
|
2637
2679
|
*/
|
|
2638
2680
|
webhook_url?: string;
|
|
2639
2681
|
/**
|
|
@@ -2976,6 +3018,10 @@ export type TranscriptUtterance = {
|
|
|
2976
3018
|
*/
|
|
2977
3019
|
words: TranscriptWord[];
|
|
2978
3020
|
};
|
|
3021
|
+
/**
|
|
3022
|
+
* The notifications sent to the webhook URL.
|
|
3023
|
+
*/
|
|
3024
|
+
export type TranscriptWebhookNotification = TranscriptReadyNotification | RedactedAudioNotification;
|
|
2979
3025
|
/**
|
|
2980
3026
|
* @example
|
|
2981
3027
|
* ```js
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { UserAgent } from "..";
|
|
1
2
|
type BaseServiceParams = {
|
|
2
3
|
apiKey: string;
|
|
3
4
|
baseUrl?: string;
|
|
5
|
+
/**
|
|
6
|
+
* The AssemblyAI user agent to use for requests.
|
|
7
|
+
* The provided components will be merged into the default AssemblyAI user agent.
|
|
8
|
+
* If `false`, the AssemblyAI user agent will be removed.
|
|
9
|
+
*/
|
|
10
|
+
userAgent?: UserAgent | false;
|
|
4
11
|
};
|
|
5
12
|
export type { BaseServiceParams };
|
|
@@ -46,3 +46,12 @@ export type SubmitParams = TranscribeParams;
|
|
|
46
46
|
* The options to transcribe an audio file, including polling options.
|
|
47
47
|
*/
|
|
48
48
|
export type TranscribeOptions = PollingOptions;
|
|
49
|
+
/**
|
|
50
|
+
* The PII redacted audio file, transmitted over the network.
|
|
51
|
+
*/
|
|
52
|
+
export type RedactedAudioFile = {
|
|
53
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
54
|
+
blob: () => Promise<Blob>;
|
|
55
|
+
body: ReadableStream<Uint8Array> | null;
|
|
56
|
+
bodyUsed: boolean;
|
|
57
|
+
};
|