assemblyai 2.0.2-beta → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -6
- package/dist/index.d.ts +1 -3
- package/dist/index.esm.js +61 -26
- package/dist/index.js +60 -28
- package/dist/services/files/index.d.ts +3 -2
- package/dist/services/lemur/index.d.ts +6 -1
- package/dist/services/realtime/service.d.ts +3 -0
- package/dist/services/transcripts/index.d.ts +12 -5
- package/dist/types/files/index.d.ts +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/openapi.generated.d.ts +21 -0
- package/dist/utils/axios.d.ts +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -6
- package/src/services/files/index.ts +18 -10
- package/src/services/lemur/index.ts +12 -0
- package/src/services/realtime/service.ts +11 -0
- package/src/services/transcripts/index.ts +36 -8
- package/src/types/files/index.ts +10 -0
- package/src/types/index.ts +1 -0
- package/src/types/openapi.generated.ts +22 -0
- package/src/utils/axios.ts +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
[
|
|
11
11
|
](https://discord.gg/5aQNZyq3)
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
# AssemblyAI Node.js SDK
|
|
15
14
|
|
|
16
15
|
The AssemblyAI Node.js SDK provides an easy-to-use interface for interacting with the AssemblyAI API,
|
|
@@ -41,7 +40,7 @@ bun add assemblyai
|
|
|
41
40
|
Import the AssemblyAI package and create an AssemblyAI object with your API key:
|
|
42
41
|
|
|
43
42
|
```javascript
|
|
44
|
-
import AssemblyAI from "assemblyai";
|
|
43
|
+
import { AssemblyAI } from "assemblyai";
|
|
45
44
|
|
|
46
45
|
const client = new AssemblyAI({
|
|
47
46
|
apiKey: process.env.ASSEMBLYAI_API_KEY,
|
|
@@ -95,7 +94,7 @@ const transcript = await client.transcripts.get(transcript.id)
|
|
|
95
94
|
|
|
96
95
|
## List transcripts
|
|
97
96
|
|
|
98
|
-
This will return a
|
|
97
|
+
This will return a page of transcripts that you have transcript.
|
|
99
98
|
|
|
100
99
|
```javascript
|
|
101
100
|
const page = await client.transcripts.list()
|
|
@@ -165,13 +164,13 @@ const { response } = await client.lemur.task({
|
|
|
165
164
|
Create the real-time service.
|
|
166
165
|
|
|
167
166
|
```typescript
|
|
168
|
-
const
|
|
167
|
+
const rt = client.realtime.createService();
|
|
169
168
|
```
|
|
170
169
|
|
|
171
170
|
You can also pass in the following options.
|
|
172
171
|
|
|
173
172
|
```typescript
|
|
174
|
-
const
|
|
173
|
+
const rt = client.realtime.createService({
|
|
175
174
|
realtimeUrl: 'wss://localhost/override',
|
|
176
175
|
apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,
|
|
177
176
|
sampleRate: 16_000,
|
|
@@ -209,7 +208,7 @@ After configuring your events, connect to the server.
|
|
|
209
208
|
await rt.connect();
|
|
210
209
|
```
|
|
211
210
|
|
|
212
|
-
Send audio data.
|
|
211
|
+
Send audio data via chunks.
|
|
213
212
|
|
|
214
213
|
```typescript
|
|
215
214
|
// Pseudo code for getting audio
|
|
@@ -217,6 +216,11 @@ getAudio((chunk) => {
|
|
|
217
216
|
rt.sendAudio(chunk);
|
|
218
217
|
});
|
|
219
218
|
```
|
|
219
|
+
Or send audio data via a stream by piping to the realtime stream.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
audioStream.pipe(rt.stream());
|
|
223
|
+
```
|
|
220
224
|
|
|
221
225
|
Close the connection when you're finished.
|
|
222
226
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios, { isAxiosError } from 'axios';
|
|
2
2
|
import WebSocket from 'ws';
|
|
3
|
-
import {
|
|
3
|
+
import { Writable } from 'stream';
|
|
4
|
+
import fs from 'fs';
|
|
4
5
|
|
|
5
6
|
function createAxiosClient(params) {
|
|
6
7
|
const client = axios.create({
|
|
@@ -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;
|
|
@@ -246,6 +257,15 @@ class RealtimeService {
|
|
|
246
257
|
};
|
|
247
258
|
this.socket.send(JSON.stringify(payload));
|
|
248
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
|
+
}
|
|
249
269
|
close(waitForSessionTermination = true) {
|
|
250
270
|
return __awaiter(this, void 0, void 0, function* () {
|
|
251
271
|
if (this.socket) {
|
|
@@ -349,15 +369,23 @@ class TranscriptService extends BaseService {
|
|
|
349
369
|
return res.data;
|
|
350
370
|
});
|
|
351
371
|
}
|
|
352
|
-
// TODO: add options overload to support list querystring parameters
|
|
353
372
|
/**
|
|
354
|
-
* Retrieves a
|
|
355
|
-
* @param
|
|
356
|
-
* @returns
|
|
373
|
+
* Retrieves a page of transcript listings.
|
|
374
|
+
* @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
357
375
|
*/
|
|
358
|
-
list(
|
|
376
|
+
list(parameters) {
|
|
359
377
|
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
-
|
|
378
|
+
let url = "/v2/transcript";
|
|
379
|
+
let query;
|
|
380
|
+
if (typeof parameters === "string") {
|
|
381
|
+
url = parameters;
|
|
382
|
+
}
|
|
383
|
+
else if (parameters) {
|
|
384
|
+
query = parameters;
|
|
385
|
+
}
|
|
386
|
+
const { data } = yield this.client.get(url, {
|
|
387
|
+
params: query,
|
|
388
|
+
});
|
|
361
389
|
for (const transcriptListItem of data.transcripts) {
|
|
362
390
|
transcriptListItem.created = new Date(transcriptListItem.created);
|
|
363
391
|
if (transcriptListItem.completed) {
|
|
@@ -378,6 +406,23 @@ class TranscriptService extends BaseService {
|
|
|
378
406
|
return res.data;
|
|
379
407
|
});
|
|
380
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Search through the transcript for a specific set of keywords.
|
|
411
|
+
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
412
|
+
* @param id The identifier of the transcript.
|
|
413
|
+
* @param id Keywords to search for.
|
|
414
|
+
* @return A promise that resolves to the sentences.
|
|
415
|
+
*/
|
|
416
|
+
wordSearch(id, words) {
|
|
417
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
418
|
+
const { data } = yield this.client.get(`/v2/transcript/${id}/word-search`, {
|
|
419
|
+
params: {
|
|
420
|
+
words: JSON.stringify(words),
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
return data;
|
|
424
|
+
});
|
|
425
|
+
}
|
|
381
426
|
/**
|
|
382
427
|
* Retrieve all sentences of a transcript.
|
|
383
428
|
* @param id The identifier of the transcript.
|
|
@@ -441,13 +486,17 @@ function getPath(path) {
|
|
|
441
486
|
class FileService extends BaseService {
|
|
442
487
|
/**
|
|
443
488
|
* Upload a local file to AssemblyAI.
|
|
444
|
-
* @param
|
|
489
|
+
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
445
490
|
* @return A promise that resolves to the uploaded file URL.
|
|
446
491
|
*/
|
|
447
|
-
upload(
|
|
492
|
+
upload(input) {
|
|
448
493
|
return __awaiter(this, void 0, void 0, function* () {
|
|
449
|
-
|
|
450
|
-
|
|
494
|
+
let fileData;
|
|
495
|
+
if (typeof input === "string")
|
|
496
|
+
fileData = fs.createReadStream(input);
|
|
497
|
+
else
|
|
498
|
+
fileData = input;
|
|
499
|
+
const { data } = yield this.client.post("/v2/upload", fileData, {
|
|
451
500
|
headers: {
|
|
452
501
|
"Content-Type": "application/octet-stream",
|
|
453
502
|
},
|
|
@@ -472,18 +521,4 @@ class AssemblyAI {
|
|
|
472
521
|
}
|
|
473
522
|
}
|
|
474
523
|
|
|
475
|
-
|
|
476
|
-
__proto__: null,
|
|
477
|
-
AssemblyAI: AssemblyAI,
|
|
478
|
-
FileService: FileService,
|
|
479
|
-
LemurService: LemurService,
|
|
480
|
-
RealtimeService: RealtimeService,
|
|
481
|
-
RealtimeServiceFactory: RealtimeServiceFactory,
|
|
482
|
-
TranscriptService: TranscriptService
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
class AssemblyAIExports extends AssemblyAI {
|
|
486
|
-
}
|
|
487
|
-
module.exports = Object.assign(AssemblyAIExports, services);
|
|
488
|
-
|
|
489
|
-
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService, AssemblyAI as default };
|
|
524
|
+
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var axios = require('axios');
|
|
6
4
|
var WebSocket = require('ws');
|
|
7
|
-
var
|
|
5
|
+
var stream = require('stream');
|
|
6
|
+
var fs = require('fs');
|
|
8
7
|
|
|
9
8
|
function createAxiosClient(params) {
|
|
10
9
|
const client = axios.create({
|
|
@@ -92,6 +91,16 @@ class LemurService extends BaseService {
|
|
|
92
91
|
return data;
|
|
93
92
|
});
|
|
94
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Delete the data for a previously submitted LeMUR request.
|
|
96
|
+
* @param id ID of the LeMUR request
|
|
97
|
+
*/
|
|
98
|
+
purgeRequestData(id) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const { data } = yield this.client.delete(`/lemur/v3/${id}`);
|
|
101
|
+
return data;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
var RealtimeErrorType;
|
|
@@ -250,6 +259,15 @@ class RealtimeService {
|
|
|
250
259
|
};
|
|
251
260
|
this.socket.send(JSON.stringify(payload));
|
|
252
261
|
}
|
|
262
|
+
stream() {
|
|
263
|
+
const stream$1 = new stream.Writable({
|
|
264
|
+
write: (chunk, encoding, next) => {
|
|
265
|
+
this.sendAudio(chunk);
|
|
266
|
+
next();
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
return stream$1;
|
|
270
|
+
}
|
|
253
271
|
close(waitForSessionTermination = true) {
|
|
254
272
|
return __awaiter(this, void 0, void 0, function* () {
|
|
255
273
|
if (this.socket) {
|
|
@@ -353,15 +371,23 @@ class TranscriptService extends BaseService {
|
|
|
353
371
|
return res.data;
|
|
354
372
|
});
|
|
355
373
|
}
|
|
356
|
-
// TODO: add options overload to support list querystring parameters
|
|
357
374
|
/**
|
|
358
|
-
* Retrieves a
|
|
359
|
-
* @param
|
|
360
|
-
* @returns
|
|
375
|
+
* Retrieves a page of transcript listings.
|
|
376
|
+
* @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
361
377
|
*/
|
|
362
|
-
list(
|
|
378
|
+
list(parameters) {
|
|
363
379
|
return __awaiter(this, void 0, void 0, function* () {
|
|
364
|
-
|
|
380
|
+
let url = "/v2/transcript";
|
|
381
|
+
let query;
|
|
382
|
+
if (typeof parameters === "string") {
|
|
383
|
+
url = parameters;
|
|
384
|
+
}
|
|
385
|
+
else if (parameters) {
|
|
386
|
+
query = parameters;
|
|
387
|
+
}
|
|
388
|
+
const { data } = yield this.client.get(url, {
|
|
389
|
+
params: query,
|
|
390
|
+
});
|
|
365
391
|
for (const transcriptListItem of data.transcripts) {
|
|
366
392
|
transcriptListItem.created = new Date(transcriptListItem.created);
|
|
367
393
|
if (transcriptListItem.completed) {
|
|
@@ -382,6 +408,23 @@ class TranscriptService extends BaseService {
|
|
|
382
408
|
return res.data;
|
|
383
409
|
});
|
|
384
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Search through the transcript for a specific set of keywords.
|
|
413
|
+
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
414
|
+
* @param id The identifier of the transcript.
|
|
415
|
+
* @param id Keywords to search for.
|
|
416
|
+
* @return A promise that resolves to the sentences.
|
|
417
|
+
*/
|
|
418
|
+
wordSearch(id, words) {
|
|
419
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
const { data } = yield this.client.get(`/v2/transcript/${id}/word-search`, {
|
|
421
|
+
params: {
|
|
422
|
+
words: JSON.stringify(words),
|
|
423
|
+
},
|
|
424
|
+
});
|
|
425
|
+
return data;
|
|
426
|
+
});
|
|
427
|
+
}
|
|
385
428
|
/**
|
|
386
429
|
* Retrieve all sentences of a transcript.
|
|
387
430
|
* @param id The identifier of the transcript.
|
|
@@ -445,13 +488,17 @@ function getPath(path) {
|
|
|
445
488
|
class FileService extends BaseService {
|
|
446
489
|
/**
|
|
447
490
|
* Upload a local file to AssemblyAI.
|
|
448
|
-
* @param
|
|
491
|
+
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
449
492
|
* @return A promise that resolves to the uploaded file URL.
|
|
450
493
|
*/
|
|
451
|
-
upload(
|
|
494
|
+
upload(input) {
|
|
452
495
|
return __awaiter(this, void 0, void 0, function* () {
|
|
453
|
-
|
|
454
|
-
|
|
496
|
+
let fileData;
|
|
497
|
+
if (typeof input === "string")
|
|
498
|
+
fileData = fs.createReadStream(input);
|
|
499
|
+
else
|
|
500
|
+
fileData = input;
|
|
501
|
+
const { data } = yield this.client.post("/v2/upload", fileData, {
|
|
455
502
|
headers: {
|
|
456
503
|
"Content-Type": "application/octet-stream",
|
|
457
504
|
},
|
|
@@ -476,24 +523,9 @@ class AssemblyAI {
|
|
|
476
523
|
}
|
|
477
524
|
}
|
|
478
525
|
|
|
479
|
-
var services = /*#__PURE__*/Object.freeze({
|
|
480
|
-
__proto__: null,
|
|
481
|
-
AssemblyAI: AssemblyAI,
|
|
482
|
-
FileService: FileService,
|
|
483
|
-
LemurService: LemurService,
|
|
484
|
-
RealtimeService: RealtimeService,
|
|
485
|
-
RealtimeServiceFactory: RealtimeServiceFactory,
|
|
486
|
-
TranscriptService: TranscriptService
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
class AssemblyAIExports extends AssemblyAI {
|
|
490
|
-
}
|
|
491
|
-
module.exports = Object.assign(AssemblyAIExports, services);
|
|
492
|
-
|
|
493
526
|
exports.AssemblyAI = AssemblyAI;
|
|
494
527
|
exports.FileService = FileService;
|
|
495
528
|
exports.LemurService = LemurService;
|
|
496
529
|
exports.RealtimeService = RealtimeService;
|
|
497
530
|
exports.RealtimeServiceFactory = RealtimeServiceFactory;
|
|
498
531
|
exports.TranscriptService = TranscriptService;
|
|
499
|
-
exports.default = AssemblyAI;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BaseService } from "@/services/base";
|
|
2
|
+
import { FileUploadParameters } from "@/types";
|
|
2
3
|
export declare class FileService extends BaseService {
|
|
3
4
|
/**
|
|
4
5
|
* Upload a local file to AssemblyAI.
|
|
5
|
-
* @param
|
|
6
|
+
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
6
7
|
* @return A promise that resolves to the uploaded file URL.
|
|
7
8
|
*/
|
|
8
|
-
upload(
|
|
9
|
+
upload(input: FileUploadParameters): Promise<string>;
|
|
9
10
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { LemurSummaryParameters, LemurActionItemsParameters, LemurQuestionAnswerParameters, LemurTaskParameters, LemurSummaryResponse, LemurQuestionAnswerResponse, LemurActionItemsResponse, LemurTaskResponse } from "@/types";
|
|
1
|
+
import { LemurSummaryParameters, LemurActionItemsParameters, LemurQuestionAnswerParameters, LemurTaskParameters, LemurSummaryResponse, LemurQuestionAnswerResponse, LemurActionItemsResponse, LemurTaskResponse, PurgeLemurRequestDataResponse } from "@/types";
|
|
2
2
|
import { BaseService } from "@/services/base";
|
|
3
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,5 +1,5 @@
|
|
|
1
1
|
import { BaseService } from "@/services/base";
|
|
2
|
-
import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse } from "@/types";
|
|
2
|
+
import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse, TranscriptListParameters, WordSearchResponse } from "@/types";
|
|
3
3
|
import { AxiosInstance } from "axios";
|
|
4
4
|
import { FileService } from "../files";
|
|
5
5
|
export declare class TranscriptService extends BaseService implements Createable<Transcript, CreateTranscriptParameters, CreateTranscriptOptions>, Retrieveable<Transcript>, Deletable<Transcript>, Listable<TranscriptList> {
|
|
@@ -20,17 +20,24 @@ export declare class TranscriptService extends BaseService implements Createable
|
|
|
20
20
|
*/
|
|
21
21
|
get(id: string): Promise<Transcript>;
|
|
22
22
|
/**
|
|
23
|
-
* Retrieves a
|
|
24
|
-
* @param
|
|
25
|
-
* @returns
|
|
23
|
+
* Retrieves a page of transcript listings.
|
|
24
|
+
* @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
26
25
|
*/
|
|
27
|
-
list(
|
|
26
|
+
list(parameters?: TranscriptListParameters | string): Promise<TranscriptList>;
|
|
28
27
|
/**
|
|
29
28
|
* Delete a transcript
|
|
30
29
|
* @param id The identifier of the transcript.
|
|
31
30
|
* @returns A promise that resolves to the transcript.
|
|
32
31
|
*/
|
|
33
32
|
delete(id: string): Promise<Transcript>;
|
|
33
|
+
/**
|
|
34
|
+
* Search through the transcript for a specific set of keywords.
|
|
35
|
+
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
36
|
+
* @param id The identifier of the transcript.
|
|
37
|
+
* @param id Keywords to search for.
|
|
38
|
+
* @return A promise that resolves to the sentences.
|
|
39
|
+
*/
|
|
40
|
+
wordSearch(id: string, words: string[]): Promise<WordSearchResponse>;
|
|
34
41
|
/**
|
|
35
42
|
* Retrieve all sentences of a transcript.
|
|
36
43
|
* @param id The identifier of the transcript.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
type FileUploadParameters = string | FileUploadData;
|
|
4
|
+
type FileUploadData = NodeJS.ReadableStream | ReadableStream | Buffer | ArrayBufferView | ArrayBufferLike | Uint8Array;
|
|
5
|
+
export type { FileUploadParameters, FileUploadData };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -620,6 +620,27 @@ export type TranscriptListItem = {
|
|
|
620
620
|
resource_url: string;
|
|
621
621
|
status: TranscriptStatus;
|
|
622
622
|
};
|
|
623
|
+
export type TranscriptListParameters = {
|
|
624
|
+
/** @description Get transcripts that were created after this transcript ID */
|
|
625
|
+
after_id?: string;
|
|
626
|
+
/** @description Get transcripts that were created before this transcript ID */
|
|
627
|
+
before_id?: string;
|
|
628
|
+
/**
|
|
629
|
+
* Format: date
|
|
630
|
+
* @description Only get transcripts created on this date
|
|
631
|
+
*/
|
|
632
|
+
created_on?: string;
|
|
633
|
+
/**
|
|
634
|
+
* Format: int64
|
|
635
|
+
* @description Maximum amount of transcripts to retrieve
|
|
636
|
+
* @default 10
|
|
637
|
+
*/
|
|
638
|
+
limit?: number;
|
|
639
|
+
/** @description Filter by transcript status */
|
|
640
|
+
status?: TranscriptStatus;
|
|
641
|
+
/** @description Only get throttled transcripts, overrides the status filter */
|
|
642
|
+
throttled_only?: boolean;
|
|
643
|
+
};
|
|
623
644
|
export type TranscriptParagraph = {
|
|
624
645
|
/** Format: double */
|
|
625
646
|
confidence: number;
|
package/dist/utils/axios.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "git+https://github.com/AssemblyAI/assemblyai-node-sdk.git"
|
|
12
12
|
},
|
|
13
13
|
"publishConfig": {
|
|
14
|
-
"tag": "
|
|
14
|
+
"tag": "latest",
|
|
15
15
|
"access": "public",
|
|
16
16
|
"registry": "https://registry.npmjs.org/"
|
|
17
17
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import * as services from "./services";
|
|
2
|
-
import { AssemblyAI } from "./services";
|
|
3
|
-
export * from "./services";
|
|
4
1
|
export type * from "./types";
|
|
5
|
-
export
|
|
6
|
-
class AssemblyAIExports extends AssemblyAI {}
|
|
7
|
-
module.exports = Object.assign(AssemblyAIExports, services);
|
|
2
|
+
export * from "./services";
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
// import the fs module instead if specific named exports
|
|
2
|
+
// to keep the assemblyai module more compatible. Some fs polyfills don't include `createReadStream`.
|
|
3
|
+
import fs from "fs";
|
|
2
4
|
import { BaseService } from "@/services/base";
|
|
3
|
-
import { UploadedFile } from "@/types";
|
|
5
|
+
import { UploadedFile, FileUploadParameters, FileUploadData } from "@/types";
|
|
4
6
|
|
|
5
7
|
export class FileService extends BaseService {
|
|
6
8
|
/**
|
|
7
9
|
* Upload a local file to AssemblyAI.
|
|
8
|
-
* @param
|
|
10
|
+
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
9
11
|
* @return A promise that resolves to the uploaded file URL.
|
|
10
12
|
*/
|
|
11
|
-
async upload(
|
|
12
|
-
|
|
13
|
+
async upload(input: FileUploadParameters): Promise<string> {
|
|
14
|
+
let fileData: FileUploadData;
|
|
15
|
+
if (typeof input === "string") fileData = fs.createReadStream(input);
|
|
16
|
+
else fileData = input;
|
|
13
17
|
|
|
14
|
-
const { data } = await this.client.post<UploadedFile>(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const { data } = await this.client.post<UploadedFile>(
|
|
19
|
+
"/v2/upload",
|
|
20
|
+
fileData,
|
|
21
|
+
{
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/octet-stream",
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
);
|
|
19
27
|
|
|
20
28
|
return data.upload_url;
|
|
21
29
|
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
LemurQuestionAnswerResponse,
|
|
8
8
|
LemurActionItemsResponse,
|
|
9
9
|
LemurTaskResponse,
|
|
10
|
+
PurgeLemurRequestDataResponse,
|
|
10
11
|
} from "@/types";
|
|
11
12
|
import { BaseService } from "@/services/base";
|
|
12
13
|
|
|
@@ -46,4 +47,15 @@ export 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
|
|
|
@@ -161,6 +162,16 @@ export class RealtimeService {
|
|
|
161
162
|
this.socket.send(JSON.stringify(payload));
|
|
162
163
|
}
|
|
163
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
|
+
|
|
164
175
|
async close(waitForSessionTermination = true) {
|
|
165
176
|
if (this.socket) {
|
|
166
177
|
if (this.socket.readyState === WebSocket.OPEN) {
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
Retrieveable,
|
|
13
13
|
SubtitleFormat,
|
|
14
14
|
RedactedAudioResponse,
|
|
15
|
+
TranscriptListParameters,
|
|
16
|
+
WordSearchResponse,
|
|
15
17
|
} from "@/types";
|
|
16
18
|
import { AxiosInstance } from "axios";
|
|
17
19
|
import { FileService } from "../files";
|
|
@@ -86,16 +88,23 @@ export class TranscriptService
|
|
|
86
88
|
return res.data;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
// TODO: add options overload to support list querystring parameters
|
|
90
91
|
/**
|
|
91
|
-
* Retrieves a
|
|
92
|
-
* @param
|
|
93
|
-
* @returns
|
|
92
|
+
* Retrieves a page of transcript listings.
|
|
93
|
+
* @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
94
94
|
*/
|
|
95
|
-
async list(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
async list(
|
|
96
|
+
parameters?: TranscriptListParameters | string
|
|
97
|
+
): Promise<TranscriptList> {
|
|
98
|
+
let url = "/v2/transcript";
|
|
99
|
+
let query: TranscriptListParameters | undefined;
|
|
100
|
+
if (typeof parameters === "string") {
|
|
101
|
+
url = parameters;
|
|
102
|
+
} else if (parameters) {
|
|
103
|
+
query = parameters;
|
|
104
|
+
}
|
|
105
|
+
const { data } = await this.client.get<TranscriptList>(url, {
|
|
106
|
+
params: query,
|
|
107
|
+
});
|
|
99
108
|
for (const transcriptListItem of data.transcripts) {
|
|
100
109
|
transcriptListItem.created = new Date(transcriptListItem.created);
|
|
101
110
|
if (transcriptListItem.completed) {
|
|
@@ -116,6 +125,25 @@ export class TranscriptService
|
|
|
116
125
|
return res.data;
|
|
117
126
|
}
|
|
118
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Search through the transcript for a specific set of keywords.
|
|
130
|
+
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
131
|
+
* @param id The identifier of the transcript.
|
|
132
|
+
* @param id Keywords to search for.
|
|
133
|
+
* @return A promise that resolves to the sentences.
|
|
134
|
+
*/
|
|
135
|
+
async wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
|
|
136
|
+
const { data } = await this.client.get<WordSearchResponse>(
|
|
137
|
+
`/v2/transcript/${id}/word-search`,
|
|
138
|
+
{
|
|
139
|
+
params: {
|
|
140
|
+
words: JSON.stringify(words),
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
return data;
|
|
145
|
+
}
|
|
146
|
+
|
|
119
147
|
/**
|
|
120
148
|
* Retrieve all sentences of a transcript.
|
|
121
149
|
* @param id The identifier of the transcript.
|
package/src/types/index.ts
CHANGED
|
@@ -762,6 +762,28 @@ export type TranscriptListItem = {
|
|
|
762
762
|
status: TranscriptStatus;
|
|
763
763
|
};
|
|
764
764
|
|
|
765
|
+
export type TranscriptListParameters = {
|
|
766
|
+
/** @description Get transcripts that were created after this transcript ID */
|
|
767
|
+
after_id?: string;
|
|
768
|
+
/** @description Get transcripts that were created before this transcript ID */
|
|
769
|
+
before_id?: string;
|
|
770
|
+
/**
|
|
771
|
+
* Format: date
|
|
772
|
+
* @description Only get transcripts created on this date
|
|
773
|
+
*/
|
|
774
|
+
created_on?: string;
|
|
775
|
+
/**
|
|
776
|
+
* Format: int64
|
|
777
|
+
* @description Maximum amount of transcripts to retrieve
|
|
778
|
+
* @default 10
|
|
779
|
+
*/
|
|
780
|
+
limit?: number;
|
|
781
|
+
/** @description Filter by transcript status */
|
|
782
|
+
status?: TranscriptStatus;
|
|
783
|
+
/** @description Only get throttled transcripts, overrides the status filter */
|
|
784
|
+
throttled_only?: boolean;
|
|
785
|
+
};
|
|
786
|
+
|
|
765
787
|
export type TranscriptParagraph = {
|
|
766
788
|
/** Format: double */
|
|
767
789
|
confidence: number;
|
package/src/utils/axios.ts
CHANGED