assemblyai 2.0.0-beta → 2.0.1-beta
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/README.md +148 -48
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +218 -123
- package/dist/index.js +225 -123
- package/dist/services/base.d.ts +0 -2
- package/dist/services/index.d.ts +7 -9
- package/dist/services/lemur/index.d.ts +6 -6
- package/dist/services/realtime/factory.d.ts +10 -0
- package/dist/services/realtime/index.d.ts +2 -16
- package/dist/services/realtime/service.d.ts +22 -0
- package/dist/services/transcripts/index.d.ts +37 -20
- package/dist/types/asyncapi.generated.d.ts +87 -0
- package/dist/types/index.d.ts +3 -4
- package/dist/types/openapi.generated.d.ts +685 -0
- package/dist/types/realtime/index.d.ts +30 -11
- package/dist/types/services/abstractions.d.ts +8 -36
- package/dist/types/services/index.d.ts +2 -5
- package/dist/types/transcripts/index.d.ts +5 -0
- package/dist/utils/axios.d.ts +3 -0
- package/dist/utils/errors/realtime.d.ts +1 -4
- package/package.json +8 -5
- package/src/index.ts +3 -0
- package/src/services/base.ts +1 -3
- package/src/services/files/index.ts +4 -4
- package/src/services/index.ts +18 -35
- package/src/services/lemur/index.ts +20 -16
- package/src/services/realtime/factory.ts +32 -0
- package/src/services/realtime/index.ts +2 -106
- package/src/services/realtime/service.ts +184 -0
- package/src/services/transcripts/index.ts +85 -63
- package/src/types/asyncapi.generated.ts +124 -0
- package/src/types/index.ts +3 -4
- package/src/types/openapi.generated.ts +834 -0
- package/src/types/realtime/index.ts +53 -13
- package/src/types/services/abstractions.ts +8 -40
- package/src/types/services/index.ts +2 -6
- package/src/types/transcripts/index.ts +5 -0
- package/src/utils/axios.ts +19 -0
- package/src/utils/errors/realtime.ts +5 -18
- package/dist/services/transcripts/redactions.d.ts +0 -14
- package/dist/services/transcripts/subtitles.d.ts +0 -12
- package/dist/types/core/index.d.ts +0 -2
- package/dist/types/core/params.d.ts +0 -2
- package/dist/types/core/segments.d.ts +0 -28
- package/dist/types/core/transcript.d.ts +0 -113
- package/dist/types/lemur/index.d.ts +0 -79
- package/dist/types/models/auto_chapter.d.ts +0 -8
- package/dist/types/models/auto_highlights.d.ts +0 -11
- package/dist/types/models/content_safety.d.ts +0 -25
- package/dist/types/models/entity_detection.d.ts +0 -7
- package/dist/types/models/index.d.ts +0 -8
- package/dist/types/models/pii.d.ts +0 -3
- package/dist/types/models/sentiment_analysis.d.ts +0 -9
- package/dist/types/models/shared.d.ts +0 -3
- package/dist/types/models/summarization.d.ts +0 -3
- package/dist/types/models/topic_detection.d.ts +0 -17
- package/dist/types/shared/index.d.ts +0 -2
- package/dist/types/shared/pagination.d.ts +0 -7
- package/dist/types/shared/timestamp.d.ts +0 -5
- package/src/services/transcripts/redactions.ts +0 -27
- package/src/services/transcripts/subtitles.ts +0 -26
- package/src/types/core/index.ts +0 -2
- package/src/types/core/params.ts +0 -3
- package/src/types/core/segments.ts +0 -29
- package/src/types/core/transcript.ts +0 -159
- package/src/types/lemur/index.ts +0 -97
- package/src/types/models/auto_chapter.ts +0 -9
- package/src/types/models/auto_highlights.ts +0 -14
- package/src/types/models/content_safety.ts +0 -34
- package/src/types/models/entity_detection.ts +0 -8
- package/src/types/models/index.ts +0 -8
- package/src/types/models/pii.ts +0 -32
- package/src/types/models/sentiment_analysis.ts +0 -11
- package/src/types/models/shared.ts +0 -4
- package/src/types/models/summarization.ts +0 -10
- package/src/types/models/topic_detection.ts +0 -21
- package/src/types/shared/index.ts +0 -2
- package/src/types/shared/pagination.ts +0 -8
- package/src/types/shared/timestamp.ts +0 -6
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import axios, { isAxiosError } from 'axios';
|
|
2
2
|
import WebSocket from 'ws';
|
|
3
|
-
import
|
|
3
|
+
import { readFile } from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
function createAxiosClient(params) {
|
|
6
|
+
const client = axios.create({
|
|
7
|
+
baseURL: params.baseUrl,
|
|
8
|
+
headers: { Authorization: params.apiKey },
|
|
9
|
+
});
|
|
10
|
+
client.interceptors.response.use(undefined, throwApiError);
|
|
11
|
+
return client;
|
|
12
|
+
}
|
|
13
|
+
function throwApiError(error) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
if (isAxiosError(error) && ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)) {
|
|
16
|
+
return Promise.reject(new Error(error.response.data.error));
|
|
17
|
+
}
|
|
18
|
+
return Promise.reject(error);
|
|
19
|
+
}
|
|
4
20
|
|
|
5
21
|
/******************************************************************************
|
|
6
22
|
Copyright (c) Microsoft Corporation.
|
|
@@ -47,7 +63,7 @@ class BaseService {
|
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
65
|
|
|
50
|
-
class
|
|
66
|
+
class LemurService extends BaseService {
|
|
51
67
|
summary(params) {
|
|
52
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
69
|
const { data } = yield this.client.post("/lemur/v3/generate/summary", params);
|
|
@@ -78,8 +94,8 @@ var RealtimeErrorType;
|
|
|
78
94
|
(function (RealtimeErrorType) {
|
|
79
95
|
RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
|
|
80
96
|
RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
|
|
81
|
-
|
|
82
|
-
RealtimeErrorType[RealtimeErrorType["
|
|
97
|
+
// Both InsufficientFunds and FreeAccount error use 4002
|
|
98
|
+
RealtimeErrorType[RealtimeErrorType["InsufficientFundsOrFreeAccount"] = 4002] = "InsufficientFundsOrFreeAccount";
|
|
83
99
|
RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
|
|
84
100
|
RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
|
|
85
101
|
RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
|
|
@@ -97,8 +113,7 @@ var RealtimeErrorType;
|
|
|
97
113
|
const RealtimeErrorMessages = {
|
|
98
114
|
[RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
99
115
|
[RealtimeErrorType.AuthFailed]: "Not Authorized",
|
|
100
|
-
[RealtimeErrorType.
|
|
101
|
-
[RealtimeErrorType.FreeAccount]: "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",
|
|
116
|
+
[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.",
|
|
102
117
|
[RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
|
|
103
118
|
[RealtimeErrorType.SessionExpired]: "Session has expired",
|
|
104
119
|
[RealtimeErrorType.ClosedSession]: "Session is closed",
|
|
@@ -114,94 +129,164 @@ const RealtimeErrorMessages = {
|
|
|
114
129
|
[RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
|
|
115
130
|
};
|
|
116
131
|
class RealtimeError extends Error {
|
|
117
|
-
constructor(code) {
|
|
118
|
-
const message = RealtimeErrorMessages[code];
|
|
119
|
-
super(message);
|
|
120
|
-
this.name = this.constructor.name;
|
|
121
|
-
this.code = code;
|
|
122
|
-
Error.captureStackTrace(this, this.constructor);
|
|
123
|
-
}
|
|
124
132
|
}
|
|
125
133
|
|
|
134
|
+
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
126
135
|
class RealtimeService {
|
|
127
136
|
constructor(params) {
|
|
137
|
+
var _a, _b, _c;
|
|
128
138
|
this.listeners = {};
|
|
129
|
-
this.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
this.realtimeUrl = (_a = params.realtimeUrl) !== null && _a !== void 0 ? _a : defaultRealtimeUrl;
|
|
140
|
+
this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
|
|
141
|
+
this.wordBoost = params.wordBoost;
|
|
142
|
+
this.realtimeUrl = (_c = params.realtimeUrl) !== null && _c !== void 0 ? _c : defaultRealtimeUrl;
|
|
143
|
+
if ("apiKey" in params)
|
|
144
|
+
this.apiKey = params.apiKey;
|
|
145
|
+
if ("token" in params)
|
|
146
|
+
this.token = params.token;
|
|
147
|
+
if (!(this.apiKey || this.token)) {
|
|
148
|
+
throw new Error("API key or temporary token is required.");
|
|
134
149
|
}
|
|
135
|
-
|
|
150
|
+
}
|
|
151
|
+
connectionUrl() {
|
|
152
|
+
const url = new URL(this.realtimeUrl);
|
|
136
153
|
if (url.protocol !== "wss:") {
|
|
137
154
|
throw new Error("Invalid protocol, must be wss");
|
|
138
155
|
}
|
|
139
156
|
const searchParams = new URLSearchParams();
|
|
140
|
-
|
|
141
|
-
|
|
157
|
+
if (this.token) {
|
|
158
|
+
searchParams.set("token", this.token);
|
|
159
|
+
}
|
|
160
|
+
searchParams.set("sample_rate", this.sampleRate.toString());
|
|
161
|
+
if (this.wordBoost && this.wordBoost.length > 0) {
|
|
162
|
+
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
|
|
163
|
+
}
|
|
142
164
|
url.search = searchParams.toString();
|
|
143
165
|
return url;
|
|
144
166
|
}
|
|
145
167
|
on(event, listener) {
|
|
146
168
|
this.listeners[event] = listener;
|
|
147
169
|
}
|
|
148
|
-
connect(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
headers
|
|
155
|
-
|
|
156
|
-
|
|
170
|
+
connect() {
|
|
171
|
+
return new Promise((resolve, _) => {
|
|
172
|
+
if (this.socket) {
|
|
173
|
+
throw new Error("Already connected");
|
|
174
|
+
}
|
|
175
|
+
const url = this.connectionUrl();
|
|
176
|
+
let headers;
|
|
177
|
+
if (this.token) {
|
|
178
|
+
headers = undefined;
|
|
179
|
+
}
|
|
180
|
+
else if (this.apiKey) {
|
|
181
|
+
headers = { Authorization: this.apiKey };
|
|
182
|
+
}
|
|
183
|
+
this.socket = new WebSocket(url.toString(), { headers });
|
|
184
|
+
this.socket.onclose = ({ code, reason }) => {
|
|
185
|
+
var _a, _b;
|
|
186
|
+
if (!reason) {
|
|
187
|
+
if (code in RealtimeErrorType) {
|
|
188
|
+
reason = RealtimeErrorMessages[code];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
(_b = (_a = this.listeners).close) === null || _b === void 0 ? void 0 : _b.call(_a, code, reason);
|
|
192
|
+
};
|
|
193
|
+
this.socket.onerror = (errorEvent) => {
|
|
194
|
+
var _a, _b, _c, _d;
|
|
195
|
+
if (errorEvent.error)
|
|
196
|
+
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, errorEvent.error);
|
|
197
|
+
else
|
|
198
|
+
(_d = (_c = this.listeners).error) === null || _d === void 0 ? void 0 : _d.call(_c, new Error(errorEvent.message));
|
|
199
|
+
};
|
|
200
|
+
this.socket.onmessage = ({ data }) => {
|
|
201
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
202
|
+
const message = JSON.parse(data.toString());
|
|
203
|
+
if ("error" in message) {
|
|
204
|
+
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, new RealtimeError(message.error));
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
switch (message.message_type) {
|
|
208
|
+
case "SessionBegins": {
|
|
209
|
+
const openObject = {
|
|
210
|
+
sessionId: message.session_id,
|
|
211
|
+
expiresAt: new Date(message.expires_at),
|
|
212
|
+
};
|
|
213
|
+
resolve(openObject);
|
|
214
|
+
(_d = (_c = this.listeners).open) === null || _d === void 0 ? void 0 : _d.call(_c, openObject);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case "PartialTranscript": {
|
|
218
|
+
// message.created is actually a string when coming from the socket
|
|
219
|
+
message.created = new Date(message.created);
|
|
220
|
+
(_f = (_e = this.listeners).transcript) === null || _f === void 0 ? void 0 : _f.call(_e, message);
|
|
221
|
+
(_h = (_g = this.listeners)["transcript.partial"]) === null || _h === void 0 ? void 0 : _h.call(_g, message);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "FinalTranscript": {
|
|
225
|
+
// message.created is actually a string when coming from the socket
|
|
226
|
+
message.created = new Date(message.created);
|
|
227
|
+
(_k = (_j = this.listeners).transcript) === null || _k === void 0 ? void 0 : _k.call(_j, message);
|
|
228
|
+
(_m = (_l = this.listeners)["transcript.final"]) === null || _m === void 0 ? void 0 : _m.call(_l, message);
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
case "SessionTerminated": {
|
|
232
|
+
(_o = this.sessionTerminatedResolve) === null || _o === void 0 ? void 0 : _o.call(this);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
157
237
|
});
|
|
158
|
-
this.socket.onopen = () => { var _a, _b; return (_b = (_a = this.listeners).open) === null || _b === void 0 ? void 0 : _b.call(_a); };
|
|
159
|
-
this.socket.onclose = ({ code, reason }) => { var _a, _b; return (_b = (_a = this.listeners).close) === null || _b === void 0 ? void 0 : _b.call(_a, code, reason); };
|
|
160
|
-
this.socket.onerror = (error) => {
|
|
161
|
-
var _a, _b;
|
|
162
|
-
const code = error.message;
|
|
163
|
-
const realtimeError = new RealtimeError(code);
|
|
164
|
-
(_b = (_a = this.listeners).error) === null || _b === void 0 ? void 0 : _b.call(_a, realtimeError);
|
|
165
|
-
};
|
|
166
|
-
this.socket.onmessage = ({ data }) => {
|
|
167
|
-
var _a, _b;
|
|
168
|
-
const message = JSON.parse(data.toString());
|
|
169
|
-
(_b = (_a = this.listeners).data) === null || _b === void 0 ? void 0 : _b.call(_a, message);
|
|
170
|
-
};
|
|
171
238
|
}
|
|
172
|
-
|
|
239
|
+
sendAudio(audio) {
|
|
173
240
|
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
|
|
174
241
|
throw new Error("Socket is not open for communication");
|
|
175
242
|
}
|
|
176
243
|
const payload = {
|
|
177
|
-
audio_data: Buffer.from(
|
|
244
|
+
audio_data: Buffer.from(audio).toString("base64"),
|
|
178
245
|
};
|
|
179
246
|
this.socket.send(JSON.stringify(payload));
|
|
180
247
|
}
|
|
181
|
-
|
|
182
|
-
if (this.socket) {
|
|
183
|
-
this.socket.removeAllListeners();
|
|
184
|
-
this.socket.close();
|
|
185
|
-
}
|
|
186
|
-
this.listeners = {};
|
|
187
|
-
this.socket = undefined;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
class TranscriptSubtitleService extends BaseService {
|
|
192
|
-
retrieve({ transcript_id, format, }) {
|
|
248
|
+
close(waitForSessionTermination = true) {
|
|
193
249
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
-
|
|
195
|
-
|
|
250
|
+
if (this.socket) {
|
|
251
|
+
if (this.socket.readyState === WebSocket.OPEN) {
|
|
252
|
+
const terminateSessionMessage = `{"terminate_session": true}`;
|
|
253
|
+
if (waitForSessionTermination) {
|
|
254
|
+
const sessionTerminatedPromise = new Promise((resolve, _) => {
|
|
255
|
+
this.sessionTerminatedResolve = resolve;
|
|
256
|
+
});
|
|
257
|
+
this.socket.send(terminateSessionMessage);
|
|
258
|
+
yield sessionTerminatedPromise;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
this.socket.send(terminateSessionMessage);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
this.socket.removeAllListeners();
|
|
265
|
+
this.socket.close();
|
|
266
|
+
}
|
|
267
|
+
this.listeners = {};
|
|
268
|
+
this.socket = undefined;
|
|
196
269
|
});
|
|
197
270
|
}
|
|
198
271
|
}
|
|
199
272
|
|
|
200
|
-
class
|
|
201
|
-
|
|
273
|
+
class RealtimeServiceFactory {
|
|
274
|
+
constructor(client, params) {
|
|
275
|
+
this.client = client;
|
|
276
|
+
this.params = params;
|
|
277
|
+
}
|
|
278
|
+
createService(params) {
|
|
279
|
+
if (!params)
|
|
280
|
+
params = { apiKey: this.params.apiKey };
|
|
281
|
+
else if (!("token" in params) && !params.apiKey) {
|
|
282
|
+
params.apiKey = this.params.apiKey;
|
|
283
|
+
}
|
|
284
|
+
return new RealtimeService(params);
|
|
285
|
+
}
|
|
286
|
+
createTemporaryToken(params) {
|
|
202
287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
const
|
|
204
|
-
return data;
|
|
288
|
+
const response = yield this.client.post("/v2/realtime/token", params);
|
|
289
|
+
return response.data.token;
|
|
205
290
|
});
|
|
206
291
|
}
|
|
207
292
|
}
|
|
@@ -210,13 +295,15 @@ class TranscriptService extends BaseService {
|
|
|
210
295
|
constructor(client, files) {
|
|
211
296
|
super(client);
|
|
212
297
|
this.files = files;
|
|
213
|
-
this.subtitles = new TranscriptSubtitleService(client);
|
|
214
|
-
this.redactions = new TranscriptRedactionService(client);
|
|
215
298
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
299
|
+
/**
|
|
300
|
+
* Create a transcript.
|
|
301
|
+
* @param params The parameters to create a transcript.
|
|
302
|
+
* @param options The options used for creating the new transcript.
|
|
303
|
+
* @returns A promise that resolves to the newly created transcript.
|
|
304
|
+
*/
|
|
305
|
+
create(params, options) {
|
|
306
|
+
var _a;
|
|
220
307
|
return __awaiter(this, void 0, void 0, function* () {
|
|
221
308
|
const path = getPath(params.audio_url);
|
|
222
309
|
if (path !== null) {
|
|
@@ -224,23 +311,24 @@ class TranscriptService extends BaseService {
|
|
|
224
311
|
params.audio_url = uploadUrl;
|
|
225
312
|
}
|
|
226
313
|
const res = yield this.client.post("/v2/transcript", params);
|
|
227
|
-
if (
|
|
228
|
-
return yield this.poll(res.data.id,
|
|
314
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.poll) !== null && _a !== void 0 ? _a : true) {
|
|
315
|
+
return yield this.poll(res.data.id, options);
|
|
229
316
|
}
|
|
230
317
|
return res.data;
|
|
231
318
|
});
|
|
232
319
|
}
|
|
233
|
-
poll(transcriptId,
|
|
320
|
+
poll(transcriptId, options) {
|
|
321
|
+
var _a;
|
|
234
322
|
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
const { pollingInterval, pollingTimeout, resolver = (t) => t.status === "completed" || t.status === "error", } = settings;
|
|
236
323
|
const startTime = Date.now();
|
|
237
324
|
while (true) {
|
|
238
|
-
const transcript = yield this.
|
|
239
|
-
if (
|
|
325
|
+
const transcript = yield this.get(transcriptId);
|
|
326
|
+
if (transcript.status === "completed" || transcript.status === "error") {
|
|
240
327
|
return transcript;
|
|
241
328
|
}
|
|
242
|
-
else if (Date.now() - startTime <
|
|
243
|
-
|
|
329
|
+
else if (Date.now() - startTime <
|
|
330
|
+
((_a = options === null || options === void 0 ? void 0 : options.pollingTimeout) !== null && _a !== void 0 ? _a : 180000)) {
|
|
331
|
+
yield new Promise((resolve) => { var _a; return setTimeout(resolve, (_a = options === null || options === void 0 ? void 0 : options.pollingInterval) !== null && _a !== void 0 ? _a : 3000); });
|
|
244
332
|
}
|
|
245
333
|
else {
|
|
246
334
|
throw new Error("Polling timeout");
|
|
@@ -248,22 +336,40 @@ class TranscriptService extends BaseService {
|
|
|
248
336
|
}
|
|
249
337
|
});
|
|
250
338
|
}
|
|
251
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Retrieve a transcript.
|
|
341
|
+
* @param id The identifier of the transcript.
|
|
342
|
+
* @returns A promise that resolves to the transcript.
|
|
343
|
+
*/
|
|
344
|
+
get(id) {
|
|
252
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
253
346
|
const res = yield this.client.get(`/v2/transcript/${id}`);
|
|
254
347
|
return res.data;
|
|
255
348
|
});
|
|
256
349
|
}
|
|
350
|
+
// TODO: add options overload to support list querystring parameters
|
|
351
|
+
/**
|
|
352
|
+
* Retrieves a paged list of transcript listings.
|
|
353
|
+
* @param nextUrl The URL to retrieve the transcript list from. If not provided, the first page will be retrieved.
|
|
354
|
+
* @returns
|
|
355
|
+
*/
|
|
257
356
|
list(nextUrl) {
|
|
258
357
|
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
-
const { data } = yield this.client.get(nextUrl
|
|
358
|
+
const { data } = yield this.client.get(nextUrl !== null && nextUrl !== void 0 ? nextUrl : "/v2/transcript");
|
|
260
359
|
for (const transcriptListItem of data.transcripts) {
|
|
261
360
|
transcriptListItem.created = new Date(transcriptListItem.created);
|
|
262
|
-
|
|
361
|
+
if (transcriptListItem.completed) {
|
|
362
|
+
transcriptListItem.completed = new Date(transcriptListItem.completed);
|
|
363
|
+
}
|
|
263
364
|
}
|
|
264
365
|
return data;
|
|
265
366
|
});
|
|
266
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Delete a transcript
|
|
370
|
+
* @param id The identifier of the transcript.
|
|
371
|
+
* @returns A promise that resolves to the transcript.
|
|
372
|
+
*/
|
|
267
373
|
delete(id) {
|
|
268
374
|
return __awaiter(this, void 0, void 0, function* () {
|
|
269
375
|
const res = yield this.client.delete(`/v2/transcript/${id}`);
|
|
@@ -271,35 +377,48 @@ class TranscriptService extends BaseService {
|
|
|
271
377
|
});
|
|
272
378
|
}
|
|
273
379
|
/**
|
|
274
|
-
* Retrieve all
|
|
380
|
+
* Retrieve all sentences of a transcript.
|
|
275
381
|
* @param id The identifier of the transcript.
|
|
276
|
-
* @
|
|
277
|
-
* @return A promise that resolves to the retrieved resource.
|
|
382
|
+
* @return A promise that resolves to the sentences.
|
|
278
383
|
*/
|
|
279
|
-
|
|
384
|
+
sentences(id) {
|
|
280
385
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
-
const { data } = yield this.client.get(`/v2/transcript/${id}
|
|
386
|
+
const { data } = yield this.client.get(`/v2/transcript/${id}/sentences`);
|
|
282
387
|
return data;
|
|
283
388
|
});
|
|
284
389
|
}
|
|
285
390
|
/**
|
|
286
|
-
* Retrieve all
|
|
391
|
+
* Retrieve all paragraphs of a transcript.
|
|
287
392
|
* @param id The identifier of the transcript.
|
|
288
|
-
* @return A promise that resolves to the
|
|
393
|
+
* @return A promise that resolves to the paragraphs.
|
|
289
394
|
*/
|
|
290
|
-
|
|
395
|
+
paragraphs(id) {
|
|
396
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
397
|
+
const { data } = yield this.client.get(`/v2/transcript/${id}/paragraphs`);
|
|
398
|
+
return data;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Retrieve subtitles of a transcript.
|
|
403
|
+
* @param id The identifier of the transcript.
|
|
404
|
+
* @param format The format of the subtitles.
|
|
405
|
+
* @return A promise that resolves to the subtitles text.
|
|
406
|
+
*/
|
|
407
|
+
subtitles(id, format = "srt") {
|
|
291
408
|
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
|
|
409
|
+
const { data } = yield this.client.get(`/v2/transcript/${id}/${format}`);
|
|
410
|
+
return data;
|
|
293
411
|
});
|
|
294
412
|
}
|
|
295
413
|
/**
|
|
296
|
-
* Retrieve
|
|
414
|
+
* Retrieve redactions of a transcript.
|
|
297
415
|
* @param id The identifier of the transcript.
|
|
298
|
-
* @return A promise that resolves to the
|
|
416
|
+
* @return A promise that resolves to the subtitles text.
|
|
299
417
|
*/
|
|
300
|
-
|
|
418
|
+
redactions(id) {
|
|
301
419
|
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
-
|
|
420
|
+
const { data } = yield this.client.get(`/v2/transcript/${id}/redacted-audio`);
|
|
421
|
+
return data;
|
|
303
422
|
});
|
|
304
423
|
}
|
|
305
424
|
}
|
|
@@ -325,7 +444,7 @@ class FileService extends BaseService {
|
|
|
325
444
|
*/
|
|
326
445
|
upload(path) {
|
|
327
446
|
return __awaiter(this, void 0, void 0, function* () {
|
|
328
|
-
const file = yield
|
|
447
|
+
const file = yield readFile(path);
|
|
329
448
|
const { data } = yield this.client.post("/v2/upload", file, {
|
|
330
449
|
headers: {
|
|
331
450
|
"Content-Type": "application/octet-stream",
|
|
@@ -339,40 +458,16 @@ class FileService extends BaseService {
|
|
|
339
458
|
class AssemblyAI {
|
|
340
459
|
/**
|
|
341
460
|
* Create a new AssemblyAI client.
|
|
342
|
-
* @param params The parameters for the service, including the API
|
|
461
|
+
* @param params The parameters for the service, including the API key and base URL, if any.
|
|
343
462
|
*/
|
|
344
463
|
constructor(params) {
|
|
345
464
|
params.baseUrl = params.baseUrl || "https://api.assemblyai.com";
|
|
346
|
-
const client =
|
|
465
|
+
const client = createAxiosClient(params);
|
|
347
466
|
this.files = new FileService(client);
|
|
348
467
|
this.transcripts = new TranscriptService(client, this.files);
|
|
349
|
-
this.lemur = new
|
|
350
|
-
this.realtime = (
|
|
351
|
-
if (!baseUrl) {
|
|
352
|
-
const url = new URL(params.baseUrl);
|
|
353
|
-
url.protocol = "wss:";
|
|
354
|
-
baseUrl = url.toString();
|
|
355
|
-
}
|
|
356
|
-
return new RealtimeService({
|
|
357
|
-
token: params.token,
|
|
358
|
-
baseUrl,
|
|
359
|
-
});
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
createClient(params) {
|
|
363
|
-
const client = axios.create({
|
|
364
|
-
baseURL: params.baseUrl,
|
|
365
|
-
headers: { Authorization: params.token },
|
|
366
|
-
});
|
|
367
|
-
client.interceptors.response.use(null, (error) => {
|
|
368
|
-
var _a, _b;
|
|
369
|
-
if (isAxiosError(error) && ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)) {
|
|
370
|
-
return Promise.reject(new Error(error.response.data.error));
|
|
371
|
-
}
|
|
372
|
-
return Promise.reject(error);
|
|
373
|
-
});
|
|
374
|
-
return client;
|
|
468
|
+
this.lemur = new LemurService(client);
|
|
469
|
+
this.realtime = new RealtimeServiceFactory(client, params);
|
|
375
470
|
}
|
|
376
471
|
}
|
|
377
472
|
|
|
378
|
-
export { AssemblyAI as default };
|
|
473
|
+
export { FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService, AssemblyAI as default };
|