assemblyai 1.0.0 → 2.0.0-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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -66
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.esm.js +378 -0
  5. package/dist/index.js +380 -0
  6. package/dist/services/base.d.ts +15 -0
  7. package/dist/services/files/index.d.ts +9 -0
  8. package/dist/services/index.d.ts +31 -0
  9. package/dist/services/lemur/index.d.ts +8 -0
  10. package/dist/services/realtime/index.d.ts +16 -0
  11. package/dist/services/transcripts/index.d.ts +42 -0
  12. package/dist/services/transcripts/redactions.d.ts +14 -0
  13. package/dist/services/transcripts/subtitles.d.ts +12 -0
  14. package/dist/types/core/index.d.ts +2 -0
  15. package/dist/types/core/params.d.ts +2 -0
  16. package/dist/types/core/segments.d.ts +28 -0
  17. package/dist/types/core/transcript.d.ts +113 -0
  18. package/dist/types/index.d.ts +6 -0
  19. package/dist/types/lemur/index.d.ts +79 -0
  20. package/dist/types/models/auto_chapter.d.ts +8 -0
  21. package/dist/types/models/auto_highlights.d.ts +11 -0
  22. package/dist/types/models/content_safety.d.ts +25 -0
  23. package/dist/types/models/entity_detection.d.ts +7 -0
  24. package/dist/types/models/index.d.ts +8 -0
  25. package/dist/types/models/pii.d.ts +3 -0
  26. package/dist/types/models/sentiment_analysis.d.ts +9 -0
  27. package/dist/types/models/shared.d.ts +3 -0
  28. package/dist/types/models/summarization.d.ts +3 -0
  29. package/dist/types/models/topic_detection.d.ts +17 -0
  30. package/dist/types/realtime/index.d.ts +17 -0
  31. package/dist/types/services/abstractions.d.ts +80 -0
  32. package/dist/types/services/index.d.ts +9 -0
  33. package/dist/types/shared/index.d.ts +2 -0
  34. package/dist/types/shared/pagination.d.ts +7 -0
  35. package/dist/types/shared/timestamp.d.ts +5 -0
  36. package/dist/utils/errors/index.d.ts +1 -0
  37. package/dist/utils/errors/realtime.d.ts +26 -0
  38. package/package.json +55 -21
  39. package/src/index.ts +2 -0
  40. package/src/services/base.ts +16 -0
  41. package/src/services/files/index.ts +22 -0
  42. package/src/services/index.ts +66 -0
  43. package/src/services/lemur/index.ts +45 -0
  44. package/src/services/realtime/index.ts +106 -0
  45. package/src/services/transcripts/index.ts +156 -0
  46. package/src/services/transcripts/redactions.ts +27 -0
  47. package/src/services/transcripts/subtitles.ts +26 -0
  48. package/src/types/core/index.ts +2 -0
  49. package/src/types/core/params.ts +3 -0
  50. package/src/types/core/segments.ts +29 -0
  51. package/src/types/core/transcript.ts +159 -0
  52. package/src/types/index.ts +6 -0
  53. package/src/types/lemur/index.ts +97 -0
  54. package/src/types/models/auto_chapter.ts +9 -0
  55. package/src/types/models/auto_highlights.ts +14 -0
  56. package/src/types/models/content_safety.ts +34 -0
  57. package/src/types/models/entity_detection.ts +8 -0
  58. package/src/types/models/index.ts +8 -0
  59. package/src/types/models/pii.ts +32 -0
  60. package/src/types/models/sentiment_analysis.ts +11 -0
  61. package/src/types/models/shared.ts +4 -0
  62. package/src/types/models/summarization.ts +10 -0
  63. package/src/types/models/topic_detection.ts +21 -0
  64. package/src/types/realtime/index.ts +28 -0
  65. package/src/types/services/abstractions.ts +88 -0
  66. package/src/types/services/index.ts +11 -0
  67. package/src/types/shared/index.ts +2 -0
  68. package/src/types/shared/pagination.ts +8 -0
  69. package/src/types/shared/timestamp.ts +6 -0
  70. package/src/utils/.gitkeep +0 -0
  71. package/src/utils/errors/index.ts +5 -0
  72. package/src/utils/errors/realtime.ts +58 -0
  73. package/.eslintrc.json +0 -3
  74. package/index.js +0 -15
  75. package/src/Client.js +0 -28
  76. package/src/api/Http/Request.js +0 -108
  77. package/src/api/Http/Response.js +0 -23
  78. package/src/api/Model.js +0 -17
  79. package/src/api/Transcript.js +0 -16
  80. package/src/api/Upload.js +0 -41
  81. package/src/api/util.js +0 -44
package/dist/index.js ADDED
@@ -0,0 +1,380 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+ var WebSocket = require('ws');
5
+ var fs = require('fs/promises');
6
+
7
+ /******************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise, SuppressedError, Symbol */
22
+
23
+
24
+ function __awaiter(thisArg, _arguments, P, generator) {
25
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
+ return new (P || (P = Promise))(function (resolve, reject) {
27
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
31
+ });
32
+ }
33
+
34
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
+ var e = new Error(message);
36
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
+ };
38
+
39
+ /**
40
+ * Base class for services that communicate with the API.
41
+ */
42
+ class BaseService {
43
+ /**
44
+ * Create a new service.
45
+ * @param params The AxiosInstance to send HTTP requests to the API.
46
+ */
47
+ constructor(client) {
48
+ this.client = client;
49
+ }
50
+ }
51
+
52
+ class LeMURService extends BaseService {
53
+ summary(params) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const { data } = yield this.client.post("/lemur/v3/generate/summary", params);
56
+ return data;
57
+ });
58
+ }
59
+ questionAnswer(params) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const { data } = yield this.client.post("/lemur/v3/generate/question-answer", params);
62
+ return data;
63
+ });
64
+ }
65
+ actionItems(params) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const { data } = yield this.client.post("/lemur/v3/generate/action-items", params);
68
+ return data;
69
+ });
70
+ }
71
+ task(params) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const { data } = yield this.client.post("/lemur/v3/generate/task", params);
74
+ return data;
75
+ });
76
+ }
77
+ }
78
+
79
+ var RealtimeErrorType;
80
+ (function (RealtimeErrorType) {
81
+ RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
82
+ RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
83
+ RealtimeErrorType[RealtimeErrorType["InsufficientFunds"] = 4002] = "InsufficientFunds";
84
+ RealtimeErrorType[RealtimeErrorType["FreeAccount"] = 4003] = "FreeAccount";
85
+ RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
86
+ RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
87
+ RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
88
+ RealtimeErrorType[RealtimeErrorType["RateLimited"] = 4029] = "RateLimited";
89
+ RealtimeErrorType[RealtimeErrorType["UniqueSessionViolation"] = 4030] = "UniqueSessionViolation";
90
+ RealtimeErrorType[RealtimeErrorType["SessionTimeout"] = 4031] = "SessionTimeout";
91
+ RealtimeErrorType[RealtimeErrorType["AudioTooShort"] = 4032] = "AudioTooShort";
92
+ RealtimeErrorType[RealtimeErrorType["AudioTooLong"] = 4033] = "AudioTooLong";
93
+ RealtimeErrorType[RealtimeErrorType["BadJson"] = 4100] = "BadJson";
94
+ RealtimeErrorType[RealtimeErrorType["BadSchema"] = 4101] = "BadSchema";
95
+ RealtimeErrorType[RealtimeErrorType["TooManyStreams"] = 4102] = "TooManyStreams";
96
+ RealtimeErrorType[RealtimeErrorType["Reconnected"] = 4103] = "Reconnected";
97
+ RealtimeErrorType[RealtimeErrorType["ReconnectAttemptsExhausted"] = 1013] = "ReconnectAttemptsExhausted";
98
+ })(RealtimeErrorType || (RealtimeErrorType = {}));
99
+ const RealtimeErrorMessages = {
100
+ [RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
101
+ [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",
104
+ [RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
105
+ [RealtimeErrorType.SessionExpired]: "Session has expired",
106
+ [RealtimeErrorType.ClosedSession]: "Session is closed",
107
+ [RealtimeErrorType.RateLimited]: "Rate limited",
108
+ [RealtimeErrorType.UniqueSessionViolation]: "Unique session violation",
109
+ [RealtimeErrorType.SessionTimeout]: "Session Timeout",
110
+ [RealtimeErrorType.AudioTooShort]: "Audio too short",
111
+ [RealtimeErrorType.AudioTooLong]: "Audio too long",
112
+ [RealtimeErrorType.BadJson]: "Bad JSON",
113
+ [RealtimeErrorType.BadSchema]: "Bad schema",
114
+ [RealtimeErrorType.TooManyStreams]: "Too many streams",
115
+ [RealtimeErrorType.Reconnected]: "Reconnected",
116
+ [RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
117
+ };
118
+ 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
+ }
127
+
128
+ class RealtimeService {
129
+ constructor(params) {
130
+ this.listeners = {};
131
+ this.params = params;
132
+ }
133
+ connectionUrl(connectionParams) {
134
+ if (!this.params.baseUrl) {
135
+ throw new Error("Missing base URL");
136
+ }
137
+ const url = new URL(this.params.baseUrl);
138
+ if (url.protocol !== "wss:") {
139
+ throw new Error("Invalid protocol, must be wss");
140
+ }
141
+ const searchParams = new URLSearchParams();
142
+ searchParams.set("sample_rate", connectionParams.sampleRate.toString());
143
+ searchParams.set("word_boost", connectionParams.wordBoost.join(","));
144
+ url.search = searchParams.toString();
145
+ return url;
146
+ }
147
+ on(event, listener) {
148
+ this.listeners[event] = listener;
149
+ }
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
+ },
159
+ });
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
+ }
174
+ send(data) {
175
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
176
+ throw new Error("Socket is not open for communication");
177
+ }
178
+ const payload = {
179
+ audio_data: Buffer.from(data).toString("base64"),
180
+ };
181
+ this.socket.send(JSON.stringify(payload));
182
+ }
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, }) {
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ const { data } = yield this.client.get(`/v2/transcript/${transcript_id}/${format}`);
197
+ return data;
198
+ });
199
+ }
200
+ }
201
+
202
+ class TranscriptRedactionService extends BaseService {
203
+ retrieve(params) {
204
+ 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;
207
+ });
208
+ }
209
+ }
210
+
211
+ class TranscriptService extends BaseService {
212
+ constructor(client, files) {
213
+ super(client);
214
+ this.files = files;
215
+ this.subtitles = new TranscriptSubtitleService(client);
216
+ this.redactions = new TranscriptRedactionService(client);
217
+ }
218
+ create(params, settings = {
219
+ pollingInterval: 3000,
220
+ pollingTimeout: 180000,
221
+ }) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ const path = getPath(params.audio_url);
224
+ if (path !== null) {
225
+ const uploadUrl = yield this.files.upload(path);
226
+ params.audio_url = uploadUrl;
227
+ }
228
+ const res = yield this.client.post("/v2/transcript", params);
229
+ if (settings && settings.pollingInterval) {
230
+ return yield this.poll(res.data.id, settings);
231
+ }
232
+ return res.data;
233
+ });
234
+ }
235
+ poll(transcriptId, settings) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ const { pollingInterval, pollingTimeout, resolver = (t) => t.status === "completed" || t.status === "error", } = settings;
238
+ const startTime = Date.now();
239
+ while (true) {
240
+ const transcript = yield this.retrieve(transcriptId);
241
+ if (resolver(transcript)) {
242
+ return transcript;
243
+ }
244
+ else if (Date.now() - startTime < pollingTimeout) {
245
+ yield new Promise((resolve) => setTimeout(resolve, pollingInterval));
246
+ }
247
+ else {
248
+ throw new Error("Polling timeout");
249
+ }
250
+ }
251
+ });
252
+ }
253
+ retrieve(id) {
254
+ return __awaiter(this, void 0, void 0, function* () {
255
+ const res = yield this.client.get(`/v2/transcript/${id}`);
256
+ return res.data;
257
+ });
258
+ }
259
+ list(nextUrl) {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ const { data } = yield this.client.get(nextUrl || "/v2/transcript");
262
+ for (const transcriptListItem of data.transcripts) {
263
+ transcriptListItem.created = new Date(transcriptListItem.created);
264
+ transcriptListItem.completed = new Date(transcriptListItem.completed);
265
+ }
266
+ return data;
267
+ });
268
+ }
269
+ delete(id) {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ const res = yield this.client.delete(`/v2/transcript/${id}`);
272
+ return res.data;
273
+ });
274
+ }
275
+ /**
276
+ * Retrieve all segments of a transcript.
277
+ * @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.
280
+ */
281
+ segments(id, type) {
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ const { data } = yield this.client.get(`/v2/transcript/${id}/${type}`);
284
+ return data;
285
+ });
286
+ }
287
+ /**
288
+ * Retrieve all sentences of a transcript.
289
+ * @param id The identifier of the transcript.
290
+ * @return A promise that resolves to the sentences.
291
+ */
292
+ sentences(id) {
293
+ return __awaiter(this, void 0, void 0, function* () {
294
+ return this.segments(id, "sentences");
295
+ });
296
+ }
297
+ /**
298
+ * Retrieve all paragraphs of a transcript.
299
+ * @param id The identifier of the transcript.
300
+ * @return A promise that resolves to the paragraphs.
301
+ */
302
+ paragraphs(id) {
303
+ return __awaiter(this, void 0, void 0, function* () {
304
+ return this.segments(id, "paragraphs");
305
+ });
306
+ }
307
+ }
308
+ function getPath(path) {
309
+ let url;
310
+ try {
311
+ url = new URL(path);
312
+ if (url.protocol === "file:")
313
+ return url.pathname;
314
+ else
315
+ return null;
316
+ }
317
+ catch (_a) {
318
+ return path;
319
+ }
320
+ }
321
+
322
+ class FileService extends BaseService {
323
+ /**
324
+ * Upload a local file to AssemblyAI.
325
+ * @param path The local file to upload.
326
+ * @return A promise that resolves to the uploaded file URL.
327
+ */
328
+ upload(path) {
329
+ return __awaiter(this, void 0, void 0, function* () {
330
+ const file = yield fs.readFile(path);
331
+ const { data } = yield this.client.post("/v2/upload", file, {
332
+ headers: {
333
+ "Content-Type": "application/octet-stream",
334
+ },
335
+ });
336
+ return data.upload_url;
337
+ });
338
+ }
339
+ }
340
+
341
+ class AssemblyAI {
342
+ /**
343
+ * Create a new AssemblyAI client.
344
+ * @param params The parameters for the service, including the API token and base URL, if any.
345
+ */
346
+ constructor(params) {
347
+ params.baseUrl = params.baseUrl || "https://api.assemblyai.com";
348
+ const client = this.createClient(params);
349
+ this.files = new FileService(client);
350
+ 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;
377
+ }
378
+ }
379
+
380
+ module.exports = AssemblyAI;
@@ -0,0 +1,15 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { BaseServiceParams } from "@/types";
3
+ /**
4
+ * Base class for services that communicate with the API.
5
+ */
6
+ declare abstract class BaseService {
7
+ protected client: AxiosInstance;
8
+ /**
9
+ * Create a new service.
10
+ * @param params The AxiosInstance to send HTTP requests to the API.
11
+ */
12
+ constructor(client: AxiosInstance);
13
+ }
14
+ export type { BaseServiceParams };
15
+ export default BaseService;
@@ -0,0 +1,9 @@
1
+ import BaseService from "@/services/base";
2
+ export default class FileService extends BaseService {
3
+ /**
4
+ * Upload a local file to AssemblyAI.
5
+ * @param path The local file to upload.
6
+ * @return A promise that resolves to the uploaded file URL.
7
+ */
8
+ upload(path: string): Promise<string>;
9
+ }
@@ -0,0 +1,31 @@
1
+ import { BaseServiceParams } from "./base";
2
+ import LeMURService from "./lemur";
3
+ import RealtimeService from "./realtime";
4
+ import TranscriptService from "./transcripts";
5
+ import FileService from "./files";
6
+ export default class AssemblyAI {
7
+ /**
8
+ * The files service.
9
+ */
10
+ files: FileService;
11
+ /**
12
+ * The transcripts service.
13
+ */
14
+ transcripts: TranscriptService;
15
+ /**
16
+ * The LeMUR service.
17
+ */
18
+ lemur: LeMURService;
19
+ /**
20
+ * The realtime service.
21
+ */
22
+ realtime: (params?: {
23
+ baseUrl: string;
24
+ }) => RealtimeService;
25
+ /**
26
+ * Create a new AssemblyAI client.
27
+ * @param params The parameters for the service, including the API token and base URL, if any.
28
+ */
29
+ constructor(params: BaseServiceParams);
30
+ private createClient;
31
+ }
@@ -0,0 +1,8 @@
1
+ import { LeMURResponse, SummaryParams, QuestionAnswerParams, ActionItemsParams, TaskParams, LeMURQuestionAnswerResponse } from "@/types";
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>;
8
+ }
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,42 @@
1
+ import BaseService from "@/services/base";
2
+ import TranscriptSubtitleService from "./subtitles";
3
+ import { ParagraphsBody, SentencesBody, Transcript, TranscriptList, TranscriptParams, TranscriptPollingSettings, Createable, Deletable, Listable, Retrieveable } from "@/types";
4
+ import TranscriptRedactionService from "./redactions";
5
+ import { AxiosInstance } from "axios";
6
+ import FileService from "../files";
7
+ export default class TranscriptService extends BaseService implements Createable<Transcript, TranscriptParams, TranscriptPollingSettings>, Retrieveable<Transcript>, Deletable<Transcript>, Listable<TranscriptList> {
8
+ private files;
9
+ /**
10
+ * The subtitles service.
11
+ */
12
+ subtitles: TranscriptSubtitleService;
13
+ /**
14
+ * The redactions service.
15
+ */
16
+ redactions: TranscriptRedactionService;
17
+ constructor(client: AxiosInstance, files: FileService);
18
+ create(params: TranscriptParams, settings?: TranscriptPollingSettings | null): Promise<Transcript>;
19
+ private poll;
20
+ retrieve(id: string): Promise<Transcript>;
21
+ list(nextUrl?: string): Promise<TranscriptList>;
22
+ delete(id: string): Promise<Transcript>;
23
+ /**
24
+ * Retrieve all segments of a transcript.
25
+ * @param id The identifier of the transcript.
26
+ * @param type The type of segment to retrieve.
27
+ * @return A promise that resolves to the retrieved resource.
28
+ */
29
+ private segments;
30
+ /**
31
+ * Retrieve all sentences of a transcript.
32
+ * @param id The identifier of the transcript.
33
+ * @return A promise that resolves to the sentences.
34
+ */
35
+ sentences(id: string): Promise<SentencesBody>;
36
+ /**
37
+ * Retrieve all paragraphs of a transcript.
38
+ * @param id The identifier of the transcript.
39
+ * @return A promise that resolves to the paragraphs.
40
+ */
41
+ paragraphs(id: string): Promise<ParagraphsBody>;
42
+ }
@@ -0,0 +1,14 @@
1
+ import BaseService from "@/services/base";
2
+ import { Retrieveable } from "@/types";
3
+ type TranscriptRedactionParams = {
4
+ transcript_id: string;
5
+ path: string;
6
+ };
7
+ type TranscriptRedactionResponse = {
8
+ status: "redacted_audio_ready";
9
+ redacted_audio_url: string;
10
+ };
11
+ export default class TranscriptRedactionService extends BaseService implements Retrieveable<TranscriptRedactionResponse, TranscriptRedactionParams> {
12
+ retrieve(params: TranscriptRedactionParams): Promise<TranscriptRedactionResponse>;
13
+ }
14
+ export {};
@@ -0,0 +1,12 @@
1
+ import BaseService from "@/services/base";
2
+ import { Retrieveable } from "@/types";
3
+ type Subtitle = string;
4
+ type SubtitleFormat = "vtt" | "srt";
5
+ type TranscriptionSubtitleParams = {
6
+ transcript_id: string;
7
+ format: SubtitleFormat;
8
+ };
9
+ export default class TranscriptSubtitleService extends BaseService implements Retrieveable<Subtitle, TranscriptionSubtitleParams> {
10
+ retrieve({ transcript_id, format, }: TranscriptionSubtitleParams): Promise<Subtitle>;
11
+ }
12
+ export {};
@@ -0,0 +1,2 @@
1
+ export type * from "./transcript";
2
+ export type * from "./segments";
@@ -0,0 +1,2 @@
1
+ type WordBoostWeight = "low" | "default" | "high";
2
+ export type { WordBoostWeight };
@@ -0,0 +1,28 @@
1
+ type SegmentType = "paragraphs" | "sentences";
2
+ type Segment<T> = T & {
3
+ id: string;
4
+ confidence: number;
5
+ audio_duration: number;
6
+ };
7
+ type ParagraphsBody = Segment<{
8
+ paragraphs: Utterance[];
9
+ }>;
10
+ type SentencesBody = Segment<{
11
+ sentences: Utterance[];
12
+ }>;
13
+ type Word = {
14
+ text: string;
15
+ start: number;
16
+ end: number;
17
+ confidence: number;
18
+ speaker?: string | null;
19
+ };
20
+ type Utterance = {
21
+ start: number;
22
+ end: number;
23
+ confidence: number;
24
+ speaker?: string;
25
+ text: string;
26
+ words: Word[];
27
+ };
28
+ export type { Word, Utterance, ParagraphsBody, SentencesBody, SegmentType };
@@ -0,0 +1,113 @@
1
+ import { AutoChapter, AutoHighlights, ContentSafetyLabels, Entity, PIIAudioQuality, PIIRedactionPolicies, SentimentAnalysis, SummaryModel, SummaryType, TopicDetection } from "@/types/models";
2
+ import { PageDetails } from "@/types/shared";
3
+ import { Utterance, Word } from "./segments";
4
+ import { WordBoostWeight } from "./params";
5
+ type TranscriptStatus = "queued" | "processing" | "completed" | "error";
6
+ type TranscriptBase = {
7
+ status?: TranscriptStatus | null;
8
+ audio_url: string;
9
+ audio_start_from?: number | null;
10
+ audio_end_at?: number | null;
11
+ filter_profanity?: boolean;
12
+ custom_spelling?: null;
13
+ disfluencies?: boolean;
14
+ dual_channel?: boolean | null;
15
+ punctuate?: boolean;
16
+ speaker_labels?: boolean;
17
+ format_text?: boolean;
18
+ auto_chapters?: boolean;
19
+ content_safety?: boolean;
20
+ entity_detection?: boolean;
21
+ language_code?: string;
22
+ language_detection?: boolean;
23
+ iab_categories?: boolean;
24
+ auto_highlights?: boolean;
25
+ summarization?: boolean;
26
+ summary_type?: SummaryType;
27
+ summary_model?: SummaryModel;
28
+ redact_pii?: boolean;
29
+ redact_pii_sub?: string;
30
+ redact_pii_audio_quality?: PIIAudioQuality;
31
+ redact_pii_audio?: boolean;
32
+ redact_pii_policies?: PIIRedactionPolicies[];
33
+ sentiment_analysis?: boolean;
34
+ webhook_auth_header_name?: null;
35
+ webhook_auth?: boolean;
36
+ webhook_status_code?: null | number;
37
+ webhook_url?: null | string;
38
+ word_boost?: string[];
39
+ boost_param?: WordBoostWeight;
40
+ };
41
+ type TranscriptParams = Omit<TranscriptBase, "status">;
42
+ type TranscriptQueued = TranscriptBase & {
43
+ id: string;
44
+ status: "queued";
45
+ };
46
+ type TranscriptProcessing = TranscriptBase & {
47
+ id: string;
48
+ status: "processing";
49
+ };
50
+ type TranscriptCompleted = TranscriptBase & {
51
+ status: "completed";
52
+ id: string;
53
+ audio_duration?: number;
54
+ words?: Word[];
55
+ utterances?: Utterance[];
56
+ text?: string;
57
+ confidence?: number;
58
+ chapters?: AutoChapter[] | null;
59
+ content_safety_labels?: ContentSafetyLabels;
60
+ entities?: Entity[];
61
+ iab_categories_result?: TopicDetection;
62
+ auto_highlights_result?: AutoHighlights;
63
+ summary?: string;
64
+ sentiment_analysis_results?: SentimentAnalysis[];
65
+ /**
66
+ * @deprecated Acoustic Model is deprecated and will be removed in a future release
67
+ */
68
+ acoustic_model?: unknown;
69
+ /**
70
+ * @deprecated Speed Boost is deprecated and will be removed in a future release
71
+ */
72
+ speed_boost?: boolean;
73
+ /**
74
+ * @deprecated Language Model is deprecated and will be removed in a future release
75
+ */
76
+ language_model?: unknown;
77
+ };
78
+ type TranscriptFailed = TranscriptBase & {
79
+ status: "error";
80
+ id: string;
81
+ error?: string;
82
+ };
83
+ type Transcript = Readonly<TranscriptQueued> | Readonly<TranscriptProcessing> | Readonly<TranscriptCompleted> | Readonly<TranscriptFailed>;
84
+ type TranscriptPollingSettings = {
85
+ pollingInterval: number;
86
+ pollingTimeout: number;
87
+ resolver?: (transcript: Transcript) => boolean;
88
+ };
89
+ type TranscriptListInternal = {
90
+ page_details: PageDetails;
91
+ transcripts: TranscriptListItemInternal[];
92
+ };
93
+ type TranscriptListItemInternal = {
94
+ id: string;
95
+ resource_url: string;
96
+ status: TranscriptStatus;
97
+ created: string;
98
+ completed: string;
99
+ audio_url: string;
100
+ };
101
+ type TranscriptList = {
102
+ page_details: PageDetails;
103
+ transcripts: TranscriptListItem[];
104
+ };
105
+ type TranscriptListItem = {
106
+ id: string;
107
+ resource_url: string;
108
+ status: TranscriptStatus;
109
+ created: Date;
110
+ completed: Date;
111
+ audio_url: string;
112
+ };
113
+ export type { Transcript, TranscriptStatus, TranscriptParams, TranscriptList, TranscriptListItem, TranscriptListInternal, TranscriptListItemInternal, TranscriptPollingSettings, };