assemblyai 2.0.0-beta → 2.0.1

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