assemblyai 2.0.1 → 2.0.2
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 +16 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +56 -3
- package/dist/index.js +56 -2
- package/dist/services/base.d.ts +1 -2
- package/dist/services/files/index.d.ts +2 -2
- package/dist/services/index.d.ts +5 -5
- package/dist/services/lemur/index.d.ts +8 -3
- package/dist/services/realtime/service.d.ts +3 -0
- package/dist/services/transcripts/index.d.ts +12 -4
- package/dist/types/services/abstractions.d.ts +1 -1
- package/dist/utils/errors/index.d.ts +1 -1
- package/dist/utils/errors/realtime.d.ts +1 -2
- package/package.json +4 -4
- package/src/index.ts +4 -2
- package/src/services/base.ts +1 -3
- package/src/services/files/index.ts +2 -2
- package/src/services/index.ts +5 -4
- package/src/services/lemur/index.ts +14 -2
- package/src/services/realtime/service.ts +14 -2
- package/src/services/transcripts/index.ts +24 -3
- package/src/types/services/abstractions.ts +1 -1
- package/src/utils/errors/index.ts +1 -1
- package/src/utils/errors/realtime.ts +1 -2
package/README.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
[](https://www.npmjs.com/package/assemblyai)
|
|
6
|
+
[](https://github.com/AssemblyAI/assemblyai-node-sdk/actions/workflows/test.yml)
|
|
7
|
+
[](https://github.com/AssemblyAI/assemblyai-node-sdk/blob/master/LICENSE)
|
|
8
|
+
[](https://twitter.com/AssemblyAI)
|
|
9
|
+
[](https://www.youtube.com/@AssemblyAI)
|
|
10
|
+
[
|
|
11
|
+
](https://discord.gg/5aQNZyq3)
|
|
12
|
+
|
|
5
13
|
# AssemblyAI Node.js SDK
|
|
6
14
|
|
|
7
15
|
The AssemblyAI Node.js SDK provides an easy-to-use interface for interacting with the AssemblyAI API,
|
|
@@ -156,13 +164,13 @@ const { response } = await client.lemur.task({
|
|
|
156
164
|
Create the real-time service.
|
|
157
165
|
|
|
158
166
|
```typescript
|
|
159
|
-
const
|
|
167
|
+
const rt = client.realtime.createService();
|
|
160
168
|
```
|
|
161
169
|
|
|
162
170
|
You can also pass in the following options.
|
|
163
171
|
|
|
164
172
|
```typescript
|
|
165
|
-
const
|
|
173
|
+
const rt = client.realtime.createService({
|
|
166
174
|
realtimeUrl: 'wss://localhost/override',
|
|
167
175
|
apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,
|
|
168
176
|
sampleRate: 16_000,
|
|
@@ -200,7 +208,7 @@ After configuring your events, connect to the server.
|
|
|
200
208
|
await rt.connect();
|
|
201
209
|
```
|
|
202
210
|
|
|
203
|
-
Send audio data.
|
|
211
|
+
Send audio data via chunks.
|
|
204
212
|
|
|
205
213
|
```typescript
|
|
206
214
|
// Pseudo code for getting audio
|
|
@@ -208,6 +216,11 @@ getAudio((chunk) => {
|
|
|
208
216
|
rt.sendAudio(chunk);
|
|
209
217
|
});
|
|
210
218
|
```
|
|
219
|
+
Or send audio data via a stream by piping to the realtime stream.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
audioStream.pipe(rt.stream());
|
|
223
|
+
```
|
|
211
224
|
|
|
212
225
|
Close the connection when you're finished.
|
|
213
226
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios, { isAxiosError } from 'axios';
|
|
2
2
|
import WebSocket from 'ws';
|
|
3
|
+
import { Writable } from 'stream';
|
|
3
4
|
import { readFile } from 'fs/promises';
|
|
4
5
|
|
|
5
6
|
function createAxiosClient(params) {
|
|
@@ -88,6 +89,16 @@ class LemurService extends BaseService {
|
|
|
88
89
|
return data;
|
|
89
90
|
});
|
|
90
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Delete the data for a previously submitted LeMUR request.
|
|
94
|
+
* @param id ID of the LeMUR request
|
|
95
|
+
*/
|
|
96
|
+
purgeRequestData(id) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const { data } = yield this.client.delete(`/lemur/v3/${id}`);
|
|
99
|
+
return data;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
91
102
|
}
|
|
92
103
|
|
|
93
104
|
var RealtimeErrorType;
|
|
@@ -164,11 +175,12 @@ class RealtimeService {
|
|
|
164
175
|
url.search = searchParams.toString();
|
|
165
176
|
return url;
|
|
166
177
|
}
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
179
|
on(event, listener) {
|
|
168
180
|
this.listeners[event] = listener;
|
|
169
181
|
}
|
|
170
182
|
connect() {
|
|
171
|
-
return new Promise((resolve
|
|
183
|
+
return new Promise((resolve) => {
|
|
172
184
|
if (this.socket) {
|
|
173
185
|
throw new Error("Already connected");
|
|
174
186
|
}
|
|
@@ -245,13 +257,22 @@ class RealtimeService {
|
|
|
245
257
|
};
|
|
246
258
|
this.socket.send(JSON.stringify(payload));
|
|
247
259
|
}
|
|
260
|
+
stream() {
|
|
261
|
+
const stream = new Writable({
|
|
262
|
+
write: (chunk, encoding, next) => {
|
|
263
|
+
this.sendAudio(chunk);
|
|
264
|
+
next();
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
return stream;
|
|
268
|
+
}
|
|
248
269
|
close(waitForSessionTermination = true) {
|
|
249
270
|
return __awaiter(this, void 0, void 0, function* () {
|
|
250
271
|
if (this.socket) {
|
|
251
272
|
if (this.socket.readyState === WebSocket.OPEN) {
|
|
252
273
|
const terminateSessionMessage = `{"terminate_session": true}`;
|
|
253
274
|
if (waitForSessionTermination) {
|
|
254
|
-
const sessionTerminatedPromise = new Promise((resolve
|
|
275
|
+
const sessionTerminatedPromise = new Promise((resolve) => {
|
|
255
276
|
this.sessionTerminatedResolve = resolve;
|
|
256
277
|
});
|
|
257
278
|
this.socket.send(terminateSessionMessage);
|
|
@@ -321,6 +342,7 @@ class TranscriptService extends BaseService {
|
|
|
321
342
|
var _a;
|
|
322
343
|
return __awaiter(this, void 0, void 0, function* () {
|
|
323
344
|
const startTime = Date.now();
|
|
345
|
+
// eslint-disable-next-line no-constant-condition
|
|
324
346
|
while (true) {
|
|
325
347
|
const transcript = yield this.get(transcriptId);
|
|
326
348
|
if (transcript.status === "completed" || transcript.status === "error") {
|
|
@@ -376,6 +398,23 @@ class TranscriptService extends BaseService {
|
|
|
376
398
|
return res.data;
|
|
377
399
|
});
|
|
378
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Search through the transcript for a specific set of keywords.
|
|
403
|
+
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
404
|
+
* @param id The identifier of the transcript.
|
|
405
|
+
* @param id Keywords to search for.
|
|
406
|
+
* @return A promise that resolves to the sentences.
|
|
407
|
+
*/
|
|
408
|
+
wordSearch(id, words) {
|
|
409
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
410
|
+
const { data } = yield this.client.get(`/v2/transcript/${id}/word-search`, {
|
|
411
|
+
params: {
|
|
412
|
+
words: JSON.stringify(words),
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
return data;
|
|
416
|
+
});
|
|
417
|
+
}
|
|
379
418
|
/**
|
|
380
419
|
* Retrieve all sentences of a transcript.
|
|
381
420
|
* @param id The identifier of the transcript.
|
|
@@ -470,4 +509,18 @@ class AssemblyAI {
|
|
|
470
509
|
}
|
|
471
510
|
}
|
|
472
511
|
|
|
473
|
-
|
|
512
|
+
var services = /*#__PURE__*/Object.freeze({
|
|
513
|
+
__proto__: null,
|
|
514
|
+
AssemblyAI: AssemblyAI,
|
|
515
|
+
FileService: FileService,
|
|
516
|
+
LemurService: LemurService,
|
|
517
|
+
RealtimeService: RealtimeService,
|
|
518
|
+
RealtimeServiceFactory: RealtimeServiceFactory,
|
|
519
|
+
TranscriptService: TranscriptService
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
class AssemblyAIExports extends AssemblyAI {
|
|
523
|
+
}
|
|
524
|
+
module.exports = Object.assign(AssemblyAIExports, services);
|
|
525
|
+
|
|
526
|
+
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService, AssemblyAI as default };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var axios = require('axios');
|
|
6
6
|
var WebSocket = require('ws');
|
|
7
|
+
var stream = require('stream');
|
|
7
8
|
var promises = require('fs/promises');
|
|
8
9
|
|
|
9
10
|
function createAxiosClient(params) {
|
|
@@ -92,6 +93,16 @@ class LemurService extends BaseService {
|
|
|
92
93
|
return data;
|
|
93
94
|
});
|
|
94
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Delete the data for a previously submitted LeMUR request.
|
|
98
|
+
* @param id ID of the LeMUR request
|
|
99
|
+
*/
|
|
100
|
+
purgeRequestData(id) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const { data } = yield this.client.delete(`/lemur/v3/${id}`);
|
|
103
|
+
return data;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
var RealtimeErrorType;
|
|
@@ -168,11 +179,12 @@ class RealtimeService {
|
|
|
168
179
|
url.search = searchParams.toString();
|
|
169
180
|
return url;
|
|
170
181
|
}
|
|
182
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
171
183
|
on(event, listener) {
|
|
172
184
|
this.listeners[event] = listener;
|
|
173
185
|
}
|
|
174
186
|
connect() {
|
|
175
|
-
return new Promise((resolve
|
|
187
|
+
return new Promise((resolve) => {
|
|
176
188
|
if (this.socket) {
|
|
177
189
|
throw new Error("Already connected");
|
|
178
190
|
}
|
|
@@ -249,13 +261,22 @@ class RealtimeService {
|
|
|
249
261
|
};
|
|
250
262
|
this.socket.send(JSON.stringify(payload));
|
|
251
263
|
}
|
|
264
|
+
stream() {
|
|
265
|
+
const stream$1 = new stream.Writable({
|
|
266
|
+
write: (chunk, encoding, next) => {
|
|
267
|
+
this.sendAudio(chunk);
|
|
268
|
+
next();
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
return stream$1;
|
|
272
|
+
}
|
|
252
273
|
close(waitForSessionTermination = true) {
|
|
253
274
|
return __awaiter(this, void 0, void 0, function* () {
|
|
254
275
|
if (this.socket) {
|
|
255
276
|
if (this.socket.readyState === WebSocket.OPEN) {
|
|
256
277
|
const terminateSessionMessage = `{"terminate_session": true}`;
|
|
257
278
|
if (waitForSessionTermination) {
|
|
258
|
-
const sessionTerminatedPromise = new Promise((resolve
|
|
279
|
+
const sessionTerminatedPromise = new Promise((resolve) => {
|
|
259
280
|
this.sessionTerminatedResolve = resolve;
|
|
260
281
|
});
|
|
261
282
|
this.socket.send(terminateSessionMessage);
|
|
@@ -325,6 +346,7 @@ class TranscriptService extends BaseService {
|
|
|
325
346
|
var _a;
|
|
326
347
|
return __awaiter(this, void 0, void 0, function* () {
|
|
327
348
|
const startTime = Date.now();
|
|
349
|
+
// eslint-disable-next-line no-constant-condition
|
|
328
350
|
while (true) {
|
|
329
351
|
const transcript = yield this.get(transcriptId);
|
|
330
352
|
if (transcript.status === "completed" || transcript.status === "error") {
|
|
@@ -380,6 +402,23 @@ class TranscriptService extends BaseService {
|
|
|
380
402
|
return res.data;
|
|
381
403
|
});
|
|
382
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Search through the transcript for a specific set of keywords.
|
|
407
|
+
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
408
|
+
* @param id The identifier of the transcript.
|
|
409
|
+
* @param id Keywords to search for.
|
|
410
|
+
* @return A promise that resolves to the sentences.
|
|
411
|
+
*/
|
|
412
|
+
wordSearch(id, words) {
|
|
413
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
414
|
+
const { data } = yield this.client.get(`/v2/transcript/${id}/word-search`, {
|
|
415
|
+
params: {
|
|
416
|
+
words: JSON.stringify(words),
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
return data;
|
|
420
|
+
});
|
|
421
|
+
}
|
|
383
422
|
/**
|
|
384
423
|
* Retrieve all sentences of a transcript.
|
|
385
424
|
* @param id The identifier of the transcript.
|
|
@@ -474,6 +513,21 @@ class AssemblyAI {
|
|
|
474
513
|
}
|
|
475
514
|
}
|
|
476
515
|
|
|
516
|
+
var services = /*#__PURE__*/Object.freeze({
|
|
517
|
+
__proto__: null,
|
|
518
|
+
AssemblyAI: AssemblyAI,
|
|
519
|
+
FileService: FileService,
|
|
520
|
+
LemurService: LemurService,
|
|
521
|
+
RealtimeService: RealtimeService,
|
|
522
|
+
RealtimeServiceFactory: RealtimeServiceFactory,
|
|
523
|
+
TranscriptService: TranscriptService
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
class AssemblyAIExports extends AssemblyAI {
|
|
527
|
+
}
|
|
528
|
+
module.exports = Object.assign(AssemblyAIExports, services);
|
|
529
|
+
|
|
530
|
+
exports.AssemblyAI = AssemblyAI;
|
|
477
531
|
exports.FileService = FileService;
|
|
478
532
|
exports.LemurService = LemurService;
|
|
479
533
|
exports.RealtimeService = RealtimeService;
|
package/dist/services/base.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AxiosInstance } from "axios";
|
|
|
2
2
|
/**
|
|
3
3
|
* Base class for services that communicate with the API.
|
|
4
4
|
*/
|
|
5
|
-
declare abstract class BaseService {
|
|
5
|
+
export declare abstract class BaseService {
|
|
6
6
|
protected client: AxiosInstance;
|
|
7
7
|
/**
|
|
8
8
|
* Create a new service.
|
|
@@ -10,4 +10,3 @@ declare abstract class BaseService {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor(client: AxiosInstance);
|
|
12
12
|
}
|
|
13
|
-
export default BaseService;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import BaseService from "@/services/base";
|
|
2
|
-
export
|
|
1
|
+
import { BaseService } from "@/services/base";
|
|
2
|
+
export declare class FileService extends BaseService {
|
|
3
3
|
/**
|
|
4
4
|
* Upload a local file to AssemblyAI.
|
|
5
5
|
* @param path The local file to upload.
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseServiceParams } from "@/types";
|
|
2
|
-
import LemurService from "./lemur";
|
|
2
|
+
import { LemurService } from "./lemur";
|
|
3
3
|
import { RealtimeService, RealtimeServiceFactory } from "./realtime";
|
|
4
|
-
import TranscriptService from "./transcripts";
|
|
5
|
-
import FileService from "./files";
|
|
6
|
-
|
|
4
|
+
import { TranscriptService } from "./transcripts";
|
|
5
|
+
import { FileService } from "./files";
|
|
6
|
+
declare class AssemblyAI {
|
|
7
7
|
/**
|
|
8
8
|
* The files service.
|
|
9
9
|
*/
|
|
@@ -26,4 +26,4 @@ export default class AssemblyAI {
|
|
|
26
26
|
*/
|
|
27
27
|
constructor(params: BaseServiceParams);
|
|
28
28
|
}
|
|
29
|
-
export { LemurService, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };
|
|
29
|
+
export { AssemblyAI, LemurService, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { LemurSummaryParameters, LemurActionItemsParameters, LemurQuestionAnswerParameters, LemurTaskParameters, LemurSummaryResponse, LemurQuestionAnswerResponse, LemurActionItemsResponse, LemurTaskResponse } from "@/types";
|
|
2
|
-
import BaseService from "@/services/base";
|
|
3
|
-
export
|
|
1
|
+
import { LemurSummaryParameters, LemurActionItemsParameters, LemurQuestionAnswerParameters, LemurTaskParameters, LemurSummaryResponse, LemurQuestionAnswerResponse, LemurActionItemsResponse, LemurTaskResponse, PurgeLemurRequestDataResponse } from "@/types";
|
|
2
|
+
import { BaseService } from "@/services/base";
|
|
3
|
+
export declare class LemurService extends BaseService {
|
|
4
4
|
summary(params: LemurSummaryParameters): Promise<LemurSummaryResponse>;
|
|
5
5
|
questionAnswer(params: LemurQuestionAnswerParameters): Promise<LemurQuestionAnswerResponse>;
|
|
6
6
|
actionItems(params: LemurActionItemsParameters): Promise<LemurActionItemsResponse>;
|
|
7
7
|
task(params: LemurTaskParameters): Promise<LemurTaskResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Delete the data for a previously submitted LeMUR request.
|
|
10
|
+
* @param id ID of the LeMUR request
|
|
11
|
+
*/
|
|
12
|
+
purgeRequestData(id: string): Promise<PurgeLemurRequestDataResponse>;
|
|
8
13
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { RealtimeServiceParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData } from "@/types";
|
|
3
|
+
import { Writable } from "stream";
|
|
2
4
|
export declare class RealtimeService {
|
|
3
5
|
private realtimeUrl;
|
|
4
6
|
private sampleRate;
|
|
@@ -18,5 +20,6 @@ export declare class RealtimeService {
|
|
|
18
20
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
19
21
|
connect(): Promise<SessionBeginsEventData>;
|
|
20
22
|
sendAudio(audio: ArrayBuffer): void;
|
|
23
|
+
stream(): Writable;
|
|
21
24
|
close(waitForSessionTermination?: boolean): Promise<void>;
|
|
22
25
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import BaseService from "@/services/base";
|
|
2
|
-
import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse } from "@/types";
|
|
1
|
+
import { BaseService } from "@/services/base";
|
|
2
|
+
import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse, WordSearchResponse } from "@/types";
|
|
3
3
|
import { AxiosInstance } from "axios";
|
|
4
|
-
import FileService from "../files";
|
|
5
|
-
export
|
|
4
|
+
import { FileService } from "../files";
|
|
5
|
+
export declare class TranscriptService extends BaseService implements Createable<Transcript, CreateTranscriptParameters, CreateTranscriptOptions>, Retrieveable<Transcript>, Deletable<Transcript>, Listable<TranscriptList> {
|
|
6
6
|
private files;
|
|
7
7
|
constructor(client: AxiosInstance, files: FileService);
|
|
8
8
|
/**
|
|
@@ -31,6 +31,14 @@ export default class TranscriptService extends BaseService implements Createable
|
|
|
31
31
|
* @returns A promise that resolves to the transcript.
|
|
32
32
|
*/
|
|
33
33
|
delete(id: string): Promise<Transcript>;
|
|
34
|
+
/**
|
|
35
|
+
* Search through the transcript for a specific set of keywords.
|
|
36
|
+
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
37
|
+
* @param id The identifier of the transcript.
|
|
38
|
+
* @param id Keywords to search for.
|
|
39
|
+
* @return A promise that resolves to the sentences.
|
|
40
|
+
*/
|
|
41
|
+
wordSearch(id: string, words: string[]): Promise<WordSearchResponse>;
|
|
34
42
|
/**
|
|
35
43
|
* Retrieve all sentences of a transcript.
|
|
36
44
|
* @param id The identifier of the transcript.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @template T The type of the resource.
|
|
4
4
|
* @template Parameters The type of the parameters required to create the resource.
|
|
5
5
|
*/
|
|
6
|
-
interface Createable<T, Parameters, Options = Record<string,
|
|
6
|
+
interface Createable<T, Parameters, Options = Record<string, unknown>> {
|
|
7
7
|
/**
|
|
8
8
|
* Create a new resource.
|
|
9
9
|
* @param params The parameters of the new resource.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { RealtimeError, RealtimeErrorType, RealtimeErrorMessages, } from "./realtime";
|
|
@@ -19,5 +19,4 @@ declare enum RealtimeErrorType {
|
|
|
19
19
|
declare const RealtimeErrorMessages: Record<RealtimeErrorType, string>;
|
|
20
20
|
declare class RealtimeError extends Error {
|
|
21
21
|
}
|
|
22
|
-
export { RealtimeErrorType, RealtimeErrorMessages };
|
|
23
|
-
export default RealtimeError;
|
|
22
|
+
export { RealtimeError, RealtimeErrorType, RealtimeErrorMessages };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "The AssemblyAI Node.js SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "pnpm clean && pnpm rollup -c",
|
|
20
20
|
"clean": "rimraf dist",
|
|
21
|
-
"lint": "
|
|
21
|
+
"lint": "eslint -c .eslintrc.json 'src/**/*'",
|
|
22
22
|
"test": "pnpm lint && pnpm test:unit",
|
|
23
23
|
"test:unit": "jest --config jest.config.rollup.ts",
|
|
24
24
|
"format": "prettier --write 'src/**/*.ts'",
|
|
@@ -45,8 +45,9 @@
|
|
|
45
45
|
"@types/jest": "^29.5.5",
|
|
46
46
|
"@types/node": "^20.5.7",
|
|
47
47
|
"@types/ws": "^8.5.5",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
48
49
|
"dotenv": "^16.3.1",
|
|
49
|
-
"eslint": "^8.
|
|
50
|
+
"eslint": "^8.48.0",
|
|
50
51
|
"i": "^0.3.7",
|
|
51
52
|
"jest": "^29.5.0",
|
|
52
53
|
"jest-cli": "^29.5.0",
|
|
@@ -63,7 +64,6 @@
|
|
|
63
64
|
"ts-jest": "^29.1.0",
|
|
64
65
|
"ts-node": "^10.9.1",
|
|
65
66
|
"tslib": "^2.5.3",
|
|
66
|
-
"tslint": "^6.1.3",
|
|
67
67
|
"typescript": "^5.2.2"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as services from "./services";
|
|
2
|
+
import { AssemblyAI } from "./services";
|
|
3
3
|
export * from "./services";
|
|
4
4
|
export type * from "./types";
|
|
5
5
|
export default AssemblyAI;
|
|
6
|
+
class AssemblyAIExports extends AssemblyAI {}
|
|
7
|
+
module.exports = Object.assign(AssemblyAIExports, services);
|
package/src/services/base.ts
CHANGED
|
@@ -3,12 +3,10 @@ import { AxiosInstance } from "axios";
|
|
|
3
3
|
/**
|
|
4
4
|
* Base class for services that communicate with the API.
|
|
5
5
|
*/
|
|
6
|
-
abstract class BaseService {
|
|
6
|
+
export abstract class BaseService {
|
|
7
7
|
/**
|
|
8
8
|
* Create a new service.
|
|
9
9
|
* @param params The AxiosInstance to send HTTP requests to the API.
|
|
10
10
|
*/
|
|
11
11
|
constructor(protected client: AxiosInstance) {}
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
export default BaseService;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFile } from "fs/promises";
|
|
2
|
-
import BaseService from "@/services/base";
|
|
2
|
+
import { BaseService } from "@/services/base";
|
|
3
3
|
import { UploadedFile } from "@/types";
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export class FileService extends BaseService {
|
|
6
6
|
/**
|
|
7
7
|
* Upload a local file to AssemblyAI.
|
|
8
8
|
* @param path The local file to upload.
|
package/src/services/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createAxiosClient } from "@/utils/axios";
|
|
2
2
|
import { BaseServiceParams } from "@/types";
|
|
3
|
-
import LemurService from "./lemur";
|
|
3
|
+
import { LemurService } from "./lemur";
|
|
4
4
|
import { RealtimeService, RealtimeServiceFactory } from "./realtime";
|
|
5
|
-
import TranscriptService from "./transcripts";
|
|
6
|
-
import FileService from "./files";
|
|
5
|
+
import { TranscriptService } from "./transcripts";
|
|
6
|
+
import { FileService } from "./files";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
class AssemblyAI {
|
|
9
9
|
/**
|
|
10
10
|
* The files service.
|
|
11
11
|
*/
|
|
@@ -41,6 +41,7 @@ export default class AssemblyAI {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export {
|
|
44
|
+
AssemblyAI,
|
|
44
45
|
LemurService,
|
|
45
46
|
RealtimeServiceFactory,
|
|
46
47
|
RealtimeService,
|
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
LemurQuestionAnswerResponse,
|
|
8
8
|
LemurActionItemsResponse,
|
|
9
9
|
LemurTaskResponse,
|
|
10
|
+
PurgeLemurRequestDataResponse,
|
|
10
11
|
} from "@/types";
|
|
11
|
-
import BaseService from "@/services/base";
|
|
12
|
+
import { BaseService } from "@/services/base";
|
|
12
13
|
|
|
13
|
-
export
|
|
14
|
+
export class LemurService extends BaseService {
|
|
14
15
|
async summary(params: LemurSummaryParameters): Promise<LemurSummaryResponse> {
|
|
15
16
|
const { data } = await this.client.post<LemurSummaryResponse>(
|
|
16
17
|
"/lemur/v3/generate/summary",
|
|
@@ -46,4 +47,15 @@ export default class LemurService extends BaseService {
|
|
|
46
47
|
);
|
|
47
48
|
return data;
|
|
48
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Delete the data for a previously submitted LeMUR request.
|
|
53
|
+
* @param id ID of the LeMUR request
|
|
54
|
+
*/
|
|
55
|
+
async purgeRequestData(id: string): Promise<PurgeLemurRequestDataResponse> {
|
|
56
|
+
const { data } = await this.client.delete<PurgeLemurRequestDataResponse>(
|
|
57
|
+
`/lemur/v3/${id}`
|
|
58
|
+
);
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
49
61
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
RealtimeErrorMessages,
|
|
15
15
|
RealtimeErrorType,
|
|
16
16
|
} from "@/utils/errors";
|
|
17
|
+
import { Writable } from "stream";
|
|
17
18
|
|
|
18
19
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
19
20
|
|
|
@@ -75,12 +76,13 @@ export class RealtimeService {
|
|
|
75
76
|
): void;
|
|
76
77
|
on(event: "error", listener: (error: Error) => void): void;
|
|
77
78
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
80
|
on(event: RealtimeEvents, listener: (...args: any[]) => void) {
|
|
79
81
|
this.listeners[event] = listener;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
connect() {
|
|
83
|
-
return new Promise<SessionBeginsEventData>((resolve
|
|
85
|
+
return new Promise<SessionBeginsEventData>((resolve) => {
|
|
84
86
|
if (this.socket) {
|
|
85
87
|
throw new Error("Already connected");
|
|
86
88
|
}
|
|
@@ -160,12 +162,22 @@ export class RealtimeService {
|
|
|
160
162
|
this.socket.send(JSON.stringify(payload));
|
|
161
163
|
}
|
|
162
164
|
|
|
165
|
+
stream(): Writable {
|
|
166
|
+
const stream = new Writable({
|
|
167
|
+
write: (chunk: Buffer, encoding, next) => {
|
|
168
|
+
this.sendAudio(chunk);
|
|
169
|
+
next();
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
return stream;
|
|
173
|
+
}
|
|
174
|
+
|
|
163
175
|
async close(waitForSessionTermination = true) {
|
|
164
176
|
if (this.socket) {
|
|
165
177
|
if (this.socket.readyState === WebSocket.OPEN) {
|
|
166
178
|
const terminateSessionMessage = `{"terminate_session": true}`;
|
|
167
179
|
if (waitForSessionTermination) {
|
|
168
|
-
const sessionTerminatedPromise = new Promise<void>((resolve
|
|
180
|
+
const sessionTerminatedPromise = new Promise<void>((resolve) => {
|
|
169
181
|
this.sessionTerminatedResolve = resolve;
|
|
170
182
|
});
|
|
171
183
|
this.socket.send(terminateSessionMessage);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BaseService from "@/services/base";
|
|
1
|
+
import { BaseService } from "@/services/base";
|
|
2
2
|
import {
|
|
3
3
|
ParagraphsResponse,
|
|
4
4
|
SentencesResponse,
|
|
@@ -12,11 +12,12 @@ import {
|
|
|
12
12
|
Retrieveable,
|
|
13
13
|
SubtitleFormat,
|
|
14
14
|
RedactedAudioResponse,
|
|
15
|
+
WordSearchResponse,
|
|
15
16
|
} from "@/types";
|
|
16
17
|
import { AxiosInstance } from "axios";
|
|
17
|
-
import FileService from "../files";
|
|
18
|
+
import { FileService } from "../files";
|
|
18
19
|
|
|
19
|
-
export
|
|
20
|
+
export class TranscriptService
|
|
20
21
|
extends BaseService
|
|
21
22
|
implements
|
|
22
23
|
Createable<Transcript, CreateTranscriptParameters, CreateTranscriptOptions>,
|
|
@@ -58,6 +59,7 @@ export default class TranscriptService
|
|
|
58
59
|
options?: CreateTranscriptOptions
|
|
59
60
|
): Promise<Transcript> {
|
|
60
61
|
const startTime = Date.now();
|
|
62
|
+
// eslint-disable-next-line no-constant-condition
|
|
61
63
|
while (true) {
|
|
62
64
|
const transcript = await this.get(transcriptId);
|
|
63
65
|
if (transcript.status === "completed" || transcript.status === "error") {
|
|
@@ -115,6 +117,25 @@ export default class TranscriptService
|
|
|
115
117
|
return res.data;
|
|
116
118
|
}
|
|
117
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Search through the transcript for a specific set of keywords.
|
|
122
|
+
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
123
|
+
* @param id The identifier of the transcript.
|
|
124
|
+
* @param id Keywords to search for.
|
|
125
|
+
* @return A promise that resolves to the sentences.
|
|
126
|
+
*/
|
|
127
|
+
async wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
|
|
128
|
+
const { data } = await this.client.get<WordSearchResponse>(
|
|
129
|
+
`/v2/transcript/${id}/word-search`,
|
|
130
|
+
{
|
|
131
|
+
params: {
|
|
132
|
+
words: JSON.stringify(words),
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
|
|
118
139
|
/**
|
|
119
140
|
* Retrieve all sentences of a transcript.
|
|
120
141
|
* @param id The identifier of the transcript.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @template T The type of the resource.
|
|
4
4
|
* @template Parameters The type of the parameters required to create the resource.
|
|
5
5
|
*/
|
|
6
|
-
interface Createable<T, Parameters, Options = Record<string,
|
|
6
|
+
interface Createable<T, Parameters, Options = Record<string, unknown>> {
|
|
7
7
|
/**
|
|
8
8
|
* Create a new resource.
|
|
9
9
|
* @param params The parameters of the new resource.
|
|
@@ -41,5 +41,4 @@ const RealtimeErrorMessages: Record<RealtimeErrorType, string> = {
|
|
|
41
41
|
|
|
42
42
|
class RealtimeError extends Error {}
|
|
43
43
|
|
|
44
|
-
export { RealtimeErrorType, RealtimeErrorMessages };
|
|
45
|
-
export default RealtimeError;
|
|
44
|
+
export { RealtimeError, RealtimeErrorType, RealtimeErrorMessages };
|