assemblyai 4.3.0 → 4.3.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/CHANGELOG.md +12 -0
- package/README.md +161 -86
- package/dist/assemblyai.umd.js +65 -59
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +60 -54
- package/dist/deno.mjs +60 -54
- package/dist/index.cjs +65 -59
- package/dist/index.mjs +65 -59
- package/dist/node.cjs +60 -54
- package/dist/node.mjs +60 -54
- package/dist/services/base.d.ts +1 -1
- package/dist/services/files/index.d.ts +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/lemur/index.d.ts +1 -1
- package/dist/services/realtime/service.d.ts +3 -3
- package/dist/services/transcripts/index.d.ts +26 -26
- package/dist/types/asyncapi.generated.d.ts +60 -39
- package/dist/types/openapi.generated.d.ts +722 -329
- package/dist/types/realtime/index.d.ts +2 -2
- package/dist/types/services/index.d.ts +0 -1
- package/dist/types/transcripts/index.d.ts +14 -5
- package/package.json +2 -1
- package/src/services/base.ts +1 -1
- package/src/services/files/index.ts +2 -2
- package/src/services/index.ts +1 -1
- package/src/services/lemur/index.ts +1 -1
- package/src/services/realtime/service.ts +7 -8
- package/src/services/transcripts/index.ts +47 -54
- package/src/types/asyncapi.generated.ts +62 -40
- package/src/types/openapi.generated.ts +726 -330
- package/src/types/realtime/index.ts +2 -2
- package/src/types/services/index.ts +0 -1
- package/src/types/transcripts/index.ts +17 -7
- package/dist/types/services/abstractions.d.ts +0 -52
- package/src/types/services/abstractions.ts +0 -56
package/dist/index.cjs
CHANGED
|
@@ -52,14 +52,14 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
52
52
|
class BaseService {
|
|
53
53
|
/**
|
|
54
54
|
* Create a new service.
|
|
55
|
-
* @param params The parameters to use for the service.
|
|
55
|
+
* @param params - The parameters to use for the service.
|
|
56
56
|
*/
|
|
57
57
|
constructor(params) {
|
|
58
58
|
this.params = params;
|
|
59
59
|
}
|
|
60
60
|
fetch(input, init) {
|
|
61
|
-
var _a;
|
|
62
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
var _a;
|
|
63
63
|
init = init !== null && init !== void 0 ? init : {};
|
|
64
64
|
init.headers = (_a = init.headers) !== null && _a !== void 0 ? _a : {};
|
|
65
65
|
init.headers = Object.assign({ Authorization: this.params.apiKey, "Content-Type": "application/json" }, init.headers);
|
|
@@ -120,7 +120,7 @@ class LemurService extends BaseService {
|
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
122
|
* Delete the data for a previously submitted LeMUR request.
|
|
123
|
-
* @param id ID of the LeMUR request
|
|
123
|
+
* @param id - ID of the LeMUR request
|
|
124
124
|
*/
|
|
125
125
|
purgeRequestData(id) {
|
|
126
126
|
return this.fetchJson(`/lemur/v3/${id}`, {
|
|
@@ -187,8 +187,7 @@ class RealtimeTranscriber {
|
|
|
187
187
|
this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
|
|
188
188
|
this.wordBoost = params.wordBoost;
|
|
189
189
|
this.encoding = params.encoding;
|
|
190
|
-
this.
|
|
191
|
-
params.end_utterance_silence_threshold;
|
|
190
|
+
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
192
191
|
if ("token" in params && params.token)
|
|
193
192
|
this.token = params.token;
|
|
194
193
|
if ("apiKey" in params && params.apiKey)
|
|
@@ -236,11 +235,11 @@ class RealtimeTranscriber {
|
|
|
236
235
|
}
|
|
237
236
|
this.socket.binaryType = "arraybuffer";
|
|
238
237
|
this.socket.onopen = () => {
|
|
239
|
-
if (this.
|
|
240
|
-
this.
|
|
238
|
+
if (this.endUtteranceSilenceThreshold === undefined ||
|
|
239
|
+
this.endUtteranceSilenceThreshold === null) {
|
|
241
240
|
return;
|
|
242
241
|
}
|
|
243
|
-
this.configureEndUtteranceSilenceThreshold(this.
|
|
242
|
+
this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold);
|
|
244
243
|
};
|
|
245
244
|
this.socket.onclose = ({ code, reason }) => {
|
|
246
245
|
var _a, _b;
|
|
@@ -315,8 +314,8 @@ class RealtimeTranscriber {
|
|
|
315
314
|
}
|
|
316
315
|
/**
|
|
317
316
|
* Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
|
|
318
|
-
* @param threshold The duration of the end utterance silence threshold in milliseconds
|
|
319
|
-
*
|
|
317
|
+
* @param threshold - The duration of the end utterance silence threshold in milliseconds.
|
|
318
|
+
* This value must be an integer between 0 and 20_000.
|
|
320
319
|
*/
|
|
321
320
|
configureEndUtteranceSilenceThreshold(threshold) {
|
|
322
321
|
this.send(`{"end_utterance_silence_threshold":${threshold}}`);
|
|
@@ -327,8 +326,8 @@ class RealtimeTranscriber {
|
|
|
327
326
|
}
|
|
328
327
|
this.socket.send(data);
|
|
329
328
|
}
|
|
330
|
-
close(
|
|
331
|
-
return __awaiter(this,
|
|
329
|
+
close() {
|
|
330
|
+
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
332
331
|
if (this.socket) {
|
|
333
332
|
if (this.socket.readyState === WebSocket.OPEN) {
|
|
334
333
|
if (waitForSessionTermination) {
|
|
@@ -410,8 +409,8 @@ class TranscriptService extends BaseService {
|
|
|
410
409
|
}
|
|
411
410
|
/**
|
|
412
411
|
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
|
|
413
|
-
* @param params The parameters to transcribe an audio file.
|
|
414
|
-
* @param options The options to transcribe an audio file.
|
|
412
|
+
* @param params - The parameters to transcribe an audio file.
|
|
413
|
+
* @param options - The options to transcribe an audio file.
|
|
415
414
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
416
415
|
*/
|
|
417
416
|
transcribe(params, options) {
|
|
@@ -422,45 +421,52 @@ class TranscriptService extends BaseService {
|
|
|
422
421
|
}
|
|
423
422
|
/**
|
|
424
423
|
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
|
|
425
|
-
* @param params The parameters to start the transcription of an audio file.
|
|
424
|
+
* @param params - The parameters to start the transcription of an audio file.
|
|
426
425
|
* @returns A promise that resolves to the queued transcript.
|
|
427
426
|
*/
|
|
428
427
|
submit(params) {
|
|
429
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
-
const { audio } = params, createParams = __rest(params, ["audio"]);
|
|
431
429
|
let audioUrl;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
430
|
+
let transcriptParams = undefined;
|
|
431
|
+
if ("audio" in params) {
|
|
432
|
+
const { audio } = params, audioTranscriptParams = __rest(params, ["audio"]);
|
|
433
|
+
if (typeof audio === "string") {
|
|
434
|
+
const path = getPath(audio);
|
|
435
|
+
if (path !== null) {
|
|
436
|
+
// audio is local path, upload local file
|
|
437
|
+
audioUrl = yield this.files.upload(path);
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
// audio is not a local path, assume it's a URL
|
|
441
|
+
audioUrl = audio;
|
|
442
|
+
}
|
|
437
443
|
}
|
|
438
444
|
else {
|
|
439
|
-
// audio is
|
|
440
|
-
audioUrl = audio;
|
|
445
|
+
// audio is of uploadable type
|
|
446
|
+
audioUrl = yield this.files.upload(audio);
|
|
441
447
|
}
|
|
448
|
+
transcriptParams = Object.assign(Object.assign({}, audioTranscriptParams), { audio_url: audioUrl });
|
|
442
449
|
}
|
|
443
450
|
else {
|
|
444
|
-
|
|
445
|
-
audioUrl = yield this.files.upload(audio);
|
|
451
|
+
transcriptParams = params;
|
|
446
452
|
}
|
|
447
453
|
const data = yield this.fetchJson("/v2/transcript", {
|
|
448
454
|
method: "POST",
|
|
449
|
-
body: JSON.stringify(
|
|
455
|
+
body: JSON.stringify(transcriptParams),
|
|
450
456
|
});
|
|
451
457
|
return data;
|
|
452
458
|
});
|
|
453
459
|
}
|
|
454
460
|
/**
|
|
455
461
|
* Create a transcript.
|
|
456
|
-
* @param params The parameters to create a transcript.
|
|
457
|
-
* @param options The options used for creating the new transcript.
|
|
462
|
+
* @param params - The parameters to create a transcript.
|
|
463
|
+
* @param options - The options used for creating the new transcript.
|
|
458
464
|
* @returns A promise that resolves to the transcript.
|
|
459
465
|
* @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
|
|
460
466
|
*/
|
|
461
467
|
create(params, options) {
|
|
462
|
-
var _a;
|
|
463
468
|
return __awaiter(this, void 0, void 0, function* () {
|
|
469
|
+
var _a;
|
|
464
470
|
const path = getPath(params.audio_url);
|
|
465
471
|
if (path !== null) {
|
|
466
472
|
const uploadUrl = yield this.files.upload(path);
|
|
@@ -478,13 +484,13 @@ class TranscriptService extends BaseService {
|
|
|
478
484
|
}
|
|
479
485
|
/**
|
|
480
486
|
* Wait until the transcript ready, either the status is "completed" or "error".
|
|
481
|
-
* @param transcriptId The ID of the transcript.
|
|
482
|
-
* @param options The options to wait until the transcript is ready.
|
|
487
|
+
* @param transcriptId - The ID of the transcript.
|
|
488
|
+
* @param options - The options to wait until the transcript is ready.
|
|
483
489
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
484
490
|
*/
|
|
485
491
|
waitUntilReady(transcriptId, options) {
|
|
486
|
-
var _a, _b;
|
|
487
492
|
return __awaiter(this, void 0, void 0, function* () {
|
|
493
|
+
var _a, _b;
|
|
488
494
|
const pollingInterval = (_a = options === null || options === void 0 ? void 0 : options.pollingInterval) !== null && _a !== void 0 ? _a : 3000;
|
|
489
495
|
const pollingTimeout = (_b = options === null || options === void 0 ? void 0 : options.pollingTimeout) !== null && _b !== void 0 ? _b : -1;
|
|
490
496
|
const startTime = Date.now();
|
|
@@ -506,7 +512,7 @@ class TranscriptService extends BaseService {
|
|
|
506
512
|
}
|
|
507
513
|
/**
|
|
508
514
|
* Retrieve a transcript.
|
|
509
|
-
* @param id The identifier of the transcript.
|
|
515
|
+
* @param id - The identifier of the transcript.
|
|
510
516
|
* @returns A promise that resolves to the transcript.
|
|
511
517
|
*/
|
|
512
518
|
get(id) {
|
|
@@ -514,20 +520,20 @@ class TranscriptService extends BaseService {
|
|
|
514
520
|
}
|
|
515
521
|
/**
|
|
516
522
|
* Retrieves a page of transcript listings.
|
|
517
|
-
* @param
|
|
523
|
+
* @param params - The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
518
524
|
*/
|
|
519
|
-
list(
|
|
525
|
+
list(params) {
|
|
520
526
|
return __awaiter(this, void 0, void 0, function* () {
|
|
521
527
|
let url = "/v2/transcript";
|
|
522
|
-
if (typeof
|
|
523
|
-
url =
|
|
528
|
+
if (typeof params === "string") {
|
|
529
|
+
url = params;
|
|
524
530
|
}
|
|
525
|
-
else if (
|
|
526
|
-
url = `${url}?${new URLSearchParams(Object.keys(
|
|
531
|
+
else if (params) {
|
|
532
|
+
url = `${url}?${new URLSearchParams(Object.keys(params).map((key) => {
|
|
527
533
|
var _a;
|
|
528
534
|
return [
|
|
529
535
|
key,
|
|
530
|
-
((_a =
|
|
536
|
+
((_a = params[key]) === null || _a === void 0 ? void 0 : _a.toString()) || "",
|
|
531
537
|
];
|
|
532
538
|
}))}`;
|
|
533
539
|
}
|
|
@@ -543,7 +549,7 @@ class TranscriptService extends BaseService {
|
|
|
543
549
|
}
|
|
544
550
|
/**
|
|
545
551
|
* Delete a transcript
|
|
546
|
-
* @param id The identifier of the transcript.
|
|
552
|
+
* @param id - The identifier of the transcript.
|
|
547
553
|
* @returns A promise that resolves to the transcript.
|
|
548
554
|
*/
|
|
549
555
|
delete(id) {
|
|
@@ -552,9 +558,9 @@ class TranscriptService extends BaseService {
|
|
|
552
558
|
/**
|
|
553
559
|
* Search through the transcript for a specific set of keywords.
|
|
554
560
|
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
555
|
-
* @param id The identifier of the transcript.
|
|
556
|
-
* @param words Keywords to search for.
|
|
557
|
-
* @
|
|
561
|
+
* @param id - The identifier of the transcript.
|
|
562
|
+
* @param words - Keywords to search for.
|
|
563
|
+
* @returns A promise that resolves to the sentences.
|
|
558
564
|
*/
|
|
559
565
|
wordSearch(id, words) {
|
|
560
566
|
const params = new URLSearchParams({ words: words.join(",") });
|
|
@@ -562,29 +568,29 @@ class TranscriptService extends BaseService {
|
|
|
562
568
|
}
|
|
563
569
|
/**
|
|
564
570
|
* Retrieve all sentences of a transcript.
|
|
565
|
-
* @param id The identifier of the transcript.
|
|
566
|
-
* @
|
|
571
|
+
* @param id - The identifier of the transcript.
|
|
572
|
+
* @returns A promise that resolves to the sentences.
|
|
567
573
|
*/
|
|
568
574
|
sentences(id) {
|
|
569
575
|
return this.fetchJson(`/v2/transcript/${id}/sentences`);
|
|
570
576
|
}
|
|
571
577
|
/**
|
|
572
578
|
* Retrieve all paragraphs of a transcript.
|
|
573
|
-
* @param id The identifier of the transcript.
|
|
574
|
-
* @
|
|
579
|
+
* @param id - The identifier of the transcript.
|
|
580
|
+
* @returns A promise that resolves to the paragraphs.
|
|
575
581
|
*/
|
|
576
582
|
paragraphs(id) {
|
|
577
583
|
return this.fetchJson(`/v2/transcript/${id}/paragraphs`);
|
|
578
584
|
}
|
|
579
585
|
/**
|
|
580
586
|
* Retrieve subtitles of a transcript.
|
|
581
|
-
* @param id The identifier of the transcript.
|
|
582
|
-
* @param format The format of the subtitles.
|
|
583
|
-
* @param chars_per_caption The maximum number of characters per caption.
|
|
584
|
-
* @
|
|
587
|
+
* @param id - The identifier of the transcript.
|
|
588
|
+
* @param format - The format of the subtitles.
|
|
589
|
+
* @param chars_per_caption - The maximum number of characters per caption.
|
|
590
|
+
* @returns A promise that resolves to the subtitles text.
|
|
585
591
|
*/
|
|
586
|
-
subtitles(
|
|
587
|
-
return __awaiter(this,
|
|
592
|
+
subtitles(id_1) {
|
|
593
|
+
return __awaiter(this, arguments, void 0, function* (id, format = "srt", chars_per_caption) {
|
|
588
594
|
let url = `/v2/transcript/${id}/${format}`;
|
|
589
595
|
if (chars_per_caption) {
|
|
590
596
|
const params = new URLSearchParams();
|
|
@@ -597,8 +603,8 @@ class TranscriptService extends BaseService {
|
|
|
597
603
|
}
|
|
598
604
|
/**
|
|
599
605
|
* Retrieve redactions of a transcript.
|
|
600
|
-
* @param id The identifier of the transcript.
|
|
601
|
-
* @
|
|
606
|
+
* @param id - The identifier of the transcript.
|
|
607
|
+
* @returns A promise that resolves to the subtitles text.
|
|
602
608
|
*/
|
|
603
609
|
redactions(id) {
|
|
604
610
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
@@ -616,8 +622,8 @@ path) {
|
|
|
616
622
|
class FileService extends BaseService {
|
|
617
623
|
/**
|
|
618
624
|
* Upload a local file to AssemblyAI.
|
|
619
|
-
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
620
|
-
* @
|
|
625
|
+
* @param input - The local file path to upload, or a stream or buffer of the file to upload.
|
|
626
|
+
* @returns A promise that resolves to the uploaded file URL.
|
|
621
627
|
*/
|
|
622
628
|
upload(input) {
|
|
623
629
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -643,7 +649,7 @@ const defaultBaseUrl = "https://api.assemblyai.com";
|
|
|
643
649
|
class AssemblyAI {
|
|
644
650
|
/**
|
|
645
651
|
* Create a new AssemblyAI client.
|
|
646
|
-
* @param params The parameters for the service, including the API key and base URL, if any.
|
|
652
|
+
* @param params - The parameters for the service, including the API key and base URL, if any.
|
|
647
653
|
*/
|
|
648
654
|
constructor(params) {
|
|
649
655
|
params.baseUrl = params.baseUrl || defaultBaseUrl;
|
package/dist/index.mjs
CHANGED
|
@@ -50,14 +50,14 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
50
50
|
class BaseService {
|
|
51
51
|
/**
|
|
52
52
|
* Create a new service.
|
|
53
|
-
* @param params The parameters to use for the service.
|
|
53
|
+
* @param params - The parameters to use for the service.
|
|
54
54
|
*/
|
|
55
55
|
constructor(params) {
|
|
56
56
|
this.params = params;
|
|
57
57
|
}
|
|
58
58
|
fetch(input, init) {
|
|
59
|
-
var _a;
|
|
60
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
var _a;
|
|
61
61
|
init = init !== null && init !== void 0 ? init : {};
|
|
62
62
|
init.headers = (_a = init.headers) !== null && _a !== void 0 ? _a : {};
|
|
63
63
|
init.headers = Object.assign({ Authorization: this.params.apiKey, "Content-Type": "application/json" }, init.headers);
|
|
@@ -118,7 +118,7 @@ class LemurService extends BaseService {
|
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Delete the data for a previously submitted LeMUR request.
|
|
121
|
-
* @param id ID of the LeMUR request
|
|
121
|
+
* @param id - ID of the LeMUR request
|
|
122
122
|
*/
|
|
123
123
|
purgeRequestData(id) {
|
|
124
124
|
return this.fetchJson(`/lemur/v3/${id}`, {
|
|
@@ -185,8 +185,7 @@ class RealtimeTranscriber {
|
|
|
185
185
|
this.sampleRate = (_b = params.sampleRate) !== null && _b !== void 0 ? _b : 16000;
|
|
186
186
|
this.wordBoost = params.wordBoost;
|
|
187
187
|
this.encoding = params.encoding;
|
|
188
|
-
this.
|
|
189
|
-
params.end_utterance_silence_threshold;
|
|
188
|
+
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
190
189
|
if ("token" in params && params.token)
|
|
191
190
|
this.token = params.token;
|
|
192
191
|
if ("apiKey" in params && params.apiKey)
|
|
@@ -234,11 +233,11 @@ class RealtimeTranscriber {
|
|
|
234
233
|
}
|
|
235
234
|
this.socket.binaryType = "arraybuffer";
|
|
236
235
|
this.socket.onopen = () => {
|
|
237
|
-
if (this.
|
|
238
|
-
this.
|
|
236
|
+
if (this.endUtteranceSilenceThreshold === undefined ||
|
|
237
|
+
this.endUtteranceSilenceThreshold === null) {
|
|
239
238
|
return;
|
|
240
239
|
}
|
|
241
|
-
this.configureEndUtteranceSilenceThreshold(this.
|
|
240
|
+
this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold);
|
|
242
241
|
};
|
|
243
242
|
this.socket.onclose = ({ code, reason }) => {
|
|
244
243
|
var _a, _b;
|
|
@@ -313,8 +312,8 @@ class RealtimeTranscriber {
|
|
|
313
312
|
}
|
|
314
313
|
/**
|
|
315
314
|
* Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
|
|
316
|
-
* @param threshold The duration of the end utterance silence threshold in milliseconds
|
|
317
|
-
*
|
|
315
|
+
* @param threshold - The duration of the end utterance silence threshold in milliseconds.
|
|
316
|
+
* This value must be an integer between 0 and 20_000.
|
|
318
317
|
*/
|
|
319
318
|
configureEndUtteranceSilenceThreshold(threshold) {
|
|
320
319
|
this.send(`{"end_utterance_silence_threshold":${threshold}}`);
|
|
@@ -325,8 +324,8 @@ class RealtimeTranscriber {
|
|
|
325
324
|
}
|
|
326
325
|
this.socket.send(data);
|
|
327
326
|
}
|
|
328
|
-
close(
|
|
329
|
-
return __awaiter(this,
|
|
327
|
+
close() {
|
|
328
|
+
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
330
329
|
if (this.socket) {
|
|
331
330
|
if (this.socket.readyState === WebSocket.OPEN) {
|
|
332
331
|
if (waitForSessionTermination) {
|
|
@@ -408,8 +407,8 @@ class TranscriptService extends BaseService {
|
|
|
408
407
|
}
|
|
409
408
|
/**
|
|
410
409
|
* Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
|
|
411
|
-
* @param params The parameters to transcribe an audio file.
|
|
412
|
-
* @param options The options to transcribe an audio file.
|
|
410
|
+
* @param params - The parameters to transcribe an audio file.
|
|
411
|
+
* @param options - The options to transcribe an audio file.
|
|
413
412
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
414
413
|
*/
|
|
415
414
|
transcribe(params, options) {
|
|
@@ -420,45 +419,52 @@ class TranscriptService extends BaseService {
|
|
|
420
419
|
}
|
|
421
420
|
/**
|
|
422
421
|
* Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
|
|
423
|
-
* @param params The parameters to start the transcription of an audio file.
|
|
422
|
+
* @param params - The parameters to start the transcription of an audio file.
|
|
424
423
|
* @returns A promise that resolves to the queued transcript.
|
|
425
424
|
*/
|
|
426
425
|
submit(params) {
|
|
427
426
|
return __awaiter(this, void 0, void 0, function* () {
|
|
428
|
-
const { audio } = params, createParams = __rest(params, ["audio"]);
|
|
429
427
|
let audioUrl;
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
428
|
+
let transcriptParams = undefined;
|
|
429
|
+
if ("audio" in params) {
|
|
430
|
+
const { audio } = params, audioTranscriptParams = __rest(params, ["audio"]);
|
|
431
|
+
if (typeof audio === "string") {
|
|
432
|
+
const path = getPath(audio);
|
|
433
|
+
if (path !== null) {
|
|
434
|
+
// audio is local path, upload local file
|
|
435
|
+
audioUrl = yield this.files.upload(path);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
// audio is not a local path, assume it's a URL
|
|
439
|
+
audioUrl = audio;
|
|
440
|
+
}
|
|
435
441
|
}
|
|
436
442
|
else {
|
|
437
|
-
// audio is
|
|
438
|
-
audioUrl = audio;
|
|
443
|
+
// audio is of uploadable type
|
|
444
|
+
audioUrl = yield this.files.upload(audio);
|
|
439
445
|
}
|
|
446
|
+
transcriptParams = Object.assign(Object.assign({}, audioTranscriptParams), { audio_url: audioUrl });
|
|
440
447
|
}
|
|
441
448
|
else {
|
|
442
|
-
|
|
443
|
-
audioUrl = yield this.files.upload(audio);
|
|
449
|
+
transcriptParams = params;
|
|
444
450
|
}
|
|
445
451
|
const data = yield this.fetchJson("/v2/transcript", {
|
|
446
452
|
method: "POST",
|
|
447
|
-
body: JSON.stringify(
|
|
453
|
+
body: JSON.stringify(transcriptParams),
|
|
448
454
|
});
|
|
449
455
|
return data;
|
|
450
456
|
});
|
|
451
457
|
}
|
|
452
458
|
/**
|
|
453
459
|
* Create a transcript.
|
|
454
|
-
* @param params The parameters to create a transcript.
|
|
455
|
-
* @param options The options used for creating the new transcript.
|
|
460
|
+
* @param params - The parameters to create a transcript.
|
|
461
|
+
* @param options - The options used for creating the new transcript.
|
|
456
462
|
* @returns A promise that resolves to the transcript.
|
|
457
463
|
* @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
|
|
458
464
|
*/
|
|
459
465
|
create(params, options) {
|
|
460
|
-
var _a;
|
|
461
466
|
return __awaiter(this, void 0, void 0, function* () {
|
|
467
|
+
var _a;
|
|
462
468
|
const path = getPath(params.audio_url);
|
|
463
469
|
if (path !== null) {
|
|
464
470
|
const uploadUrl = yield this.files.upload(path);
|
|
@@ -476,13 +482,13 @@ class TranscriptService extends BaseService {
|
|
|
476
482
|
}
|
|
477
483
|
/**
|
|
478
484
|
* Wait until the transcript ready, either the status is "completed" or "error".
|
|
479
|
-
* @param transcriptId The ID of the transcript.
|
|
480
|
-
* @param options The options to wait until the transcript is ready.
|
|
485
|
+
* @param transcriptId - The ID of the transcript.
|
|
486
|
+
* @param options - The options to wait until the transcript is ready.
|
|
481
487
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
482
488
|
*/
|
|
483
489
|
waitUntilReady(transcriptId, options) {
|
|
484
|
-
var _a, _b;
|
|
485
490
|
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
+
var _a, _b;
|
|
486
492
|
const pollingInterval = (_a = options === null || options === void 0 ? void 0 : options.pollingInterval) !== null && _a !== void 0 ? _a : 3000;
|
|
487
493
|
const pollingTimeout = (_b = options === null || options === void 0 ? void 0 : options.pollingTimeout) !== null && _b !== void 0 ? _b : -1;
|
|
488
494
|
const startTime = Date.now();
|
|
@@ -504,7 +510,7 @@ class TranscriptService extends BaseService {
|
|
|
504
510
|
}
|
|
505
511
|
/**
|
|
506
512
|
* Retrieve a transcript.
|
|
507
|
-
* @param id The identifier of the transcript.
|
|
513
|
+
* @param id - The identifier of the transcript.
|
|
508
514
|
* @returns A promise that resolves to the transcript.
|
|
509
515
|
*/
|
|
510
516
|
get(id) {
|
|
@@ -512,20 +518,20 @@ class TranscriptService extends BaseService {
|
|
|
512
518
|
}
|
|
513
519
|
/**
|
|
514
520
|
* Retrieves a page of transcript listings.
|
|
515
|
-
* @param
|
|
521
|
+
* @param params - The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
|
|
516
522
|
*/
|
|
517
|
-
list(
|
|
523
|
+
list(params) {
|
|
518
524
|
return __awaiter(this, void 0, void 0, function* () {
|
|
519
525
|
let url = "/v2/transcript";
|
|
520
|
-
if (typeof
|
|
521
|
-
url =
|
|
526
|
+
if (typeof params === "string") {
|
|
527
|
+
url = params;
|
|
522
528
|
}
|
|
523
|
-
else if (
|
|
524
|
-
url = `${url}?${new URLSearchParams(Object.keys(
|
|
529
|
+
else if (params) {
|
|
530
|
+
url = `${url}?${new URLSearchParams(Object.keys(params).map((key) => {
|
|
525
531
|
var _a;
|
|
526
532
|
return [
|
|
527
533
|
key,
|
|
528
|
-
((_a =
|
|
534
|
+
((_a = params[key]) === null || _a === void 0 ? void 0 : _a.toString()) || "",
|
|
529
535
|
];
|
|
530
536
|
}))}`;
|
|
531
537
|
}
|
|
@@ -541,7 +547,7 @@ class TranscriptService extends BaseService {
|
|
|
541
547
|
}
|
|
542
548
|
/**
|
|
543
549
|
* Delete a transcript
|
|
544
|
-
* @param id The identifier of the transcript.
|
|
550
|
+
* @param id - The identifier of the transcript.
|
|
545
551
|
* @returns A promise that resolves to the transcript.
|
|
546
552
|
*/
|
|
547
553
|
delete(id) {
|
|
@@ -550,9 +556,9 @@ class TranscriptService extends BaseService {
|
|
|
550
556
|
/**
|
|
551
557
|
* Search through the transcript for a specific set of keywords.
|
|
552
558
|
* You can search for individual words, numbers, or phrases containing up to five words or numbers.
|
|
553
|
-
* @param id The identifier of the transcript.
|
|
554
|
-
* @param words Keywords to search for.
|
|
555
|
-
* @
|
|
559
|
+
* @param id - The identifier of the transcript.
|
|
560
|
+
* @param words - Keywords to search for.
|
|
561
|
+
* @returns A promise that resolves to the sentences.
|
|
556
562
|
*/
|
|
557
563
|
wordSearch(id, words) {
|
|
558
564
|
const params = new URLSearchParams({ words: words.join(",") });
|
|
@@ -560,29 +566,29 @@ class TranscriptService extends BaseService {
|
|
|
560
566
|
}
|
|
561
567
|
/**
|
|
562
568
|
* Retrieve all sentences of a transcript.
|
|
563
|
-
* @param id The identifier of the transcript.
|
|
564
|
-
* @
|
|
569
|
+
* @param id - The identifier of the transcript.
|
|
570
|
+
* @returns A promise that resolves to the sentences.
|
|
565
571
|
*/
|
|
566
572
|
sentences(id) {
|
|
567
573
|
return this.fetchJson(`/v2/transcript/${id}/sentences`);
|
|
568
574
|
}
|
|
569
575
|
/**
|
|
570
576
|
* Retrieve all paragraphs of a transcript.
|
|
571
|
-
* @param id The identifier of the transcript.
|
|
572
|
-
* @
|
|
577
|
+
* @param id - The identifier of the transcript.
|
|
578
|
+
* @returns A promise that resolves to the paragraphs.
|
|
573
579
|
*/
|
|
574
580
|
paragraphs(id) {
|
|
575
581
|
return this.fetchJson(`/v2/transcript/${id}/paragraphs`);
|
|
576
582
|
}
|
|
577
583
|
/**
|
|
578
584
|
* Retrieve subtitles of a transcript.
|
|
579
|
-
* @param id The identifier of the transcript.
|
|
580
|
-
* @param format The format of the subtitles.
|
|
581
|
-
* @param chars_per_caption The maximum number of characters per caption.
|
|
582
|
-
* @
|
|
585
|
+
* @param id - The identifier of the transcript.
|
|
586
|
+
* @param format - The format of the subtitles.
|
|
587
|
+
* @param chars_per_caption - The maximum number of characters per caption.
|
|
588
|
+
* @returns A promise that resolves to the subtitles text.
|
|
583
589
|
*/
|
|
584
|
-
subtitles(
|
|
585
|
-
return __awaiter(this,
|
|
590
|
+
subtitles(id_1) {
|
|
591
|
+
return __awaiter(this, arguments, void 0, function* (id, format = "srt", chars_per_caption) {
|
|
586
592
|
let url = `/v2/transcript/${id}/${format}`;
|
|
587
593
|
if (chars_per_caption) {
|
|
588
594
|
const params = new URLSearchParams();
|
|
@@ -595,8 +601,8 @@ class TranscriptService extends BaseService {
|
|
|
595
601
|
}
|
|
596
602
|
/**
|
|
597
603
|
* Retrieve redactions of a transcript.
|
|
598
|
-
* @param id The identifier of the transcript.
|
|
599
|
-
* @
|
|
604
|
+
* @param id - The identifier of the transcript.
|
|
605
|
+
* @returns A promise that resolves to the subtitles text.
|
|
600
606
|
*/
|
|
601
607
|
redactions(id) {
|
|
602
608
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
@@ -614,8 +620,8 @@ path) {
|
|
|
614
620
|
class FileService extends BaseService {
|
|
615
621
|
/**
|
|
616
622
|
* Upload a local file to AssemblyAI.
|
|
617
|
-
* @param input The local file path to upload, or a stream or buffer of the file to upload.
|
|
618
|
-
* @
|
|
623
|
+
* @param input - The local file path to upload, or a stream or buffer of the file to upload.
|
|
624
|
+
* @returns A promise that resolves to the uploaded file URL.
|
|
619
625
|
*/
|
|
620
626
|
upload(input) {
|
|
621
627
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -641,7 +647,7 @@ const defaultBaseUrl = "https://api.assemblyai.com";
|
|
|
641
647
|
class AssemblyAI {
|
|
642
648
|
/**
|
|
643
649
|
* Create a new AssemblyAI client.
|
|
644
|
-
* @param params The parameters for the service, including the API key and base URL, if any.
|
|
650
|
+
* @param params - The parameters for the service, including the API key and base URL, if any.
|
|
645
651
|
*/
|
|
646
652
|
constructor(params) {
|
|
647
653
|
params.baseUrl = params.baseUrl || defaultBaseUrl;
|