assemblyai 4.5.0 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/assemblyai.streaming.umd.js +29 -0
- package/dist/assemblyai.umd.js +30 -11
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +30 -11
- package/dist/bun.mjs +30 -11
- package/dist/deno.mjs +30 -11
- package/dist/index.cjs +30 -11
- package/dist/index.mjs +30 -11
- package/dist/node.cjs +30 -11
- package/dist/node.mjs +30 -11
- package/dist/services/realtime/service.d.ts +60 -0
- package/dist/streaming.browser.mjs +29 -0
- package/dist/streaming.cjs +29 -0
- package/dist/streaming.mjs +29 -0
- package/dist/types/openapi.generated.d.ts +41 -28
- package/dist/workerd.mjs +30 -11
- package/package.json +27 -15
- package/src/services/realtime/service.ts +65 -0
- package/src/services/transcripts/index.ts +0 -13
- package/src/types/openapi.generated.ts +53 -33
package/dist/index.cjs
CHANGED
|
@@ -63,7 +63,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
63
63
|
defaultUserAgentString += navigator.userAgent;
|
|
64
64
|
}
|
|
65
65
|
const defaultUserAgent = {
|
|
66
|
-
sdk: { name: "JavaScript", version: "4.
|
|
66
|
+
sdk: { name: "JavaScript", version: "4.6.1" },
|
|
67
67
|
};
|
|
68
68
|
if (typeof process !== "undefined") {
|
|
69
69
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -243,7 +243,14 @@ class RealtimeError extends Error {
|
|
|
243
243
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
244
244
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
245
245
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
246
|
+
/**
|
|
247
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
248
|
+
*/
|
|
246
249
|
class RealtimeTranscriber {
|
|
250
|
+
/**
|
|
251
|
+
* Create a new RealtimeTranscriber.
|
|
252
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
253
|
+
*/
|
|
247
254
|
constructor(params) {
|
|
248
255
|
var _a, _b;
|
|
249
256
|
this.listeners = {};
|
|
@@ -284,10 +291,19 @@ class RealtimeTranscriber {
|
|
|
284
291
|
url.search = searchParams.toString();
|
|
285
292
|
return url;
|
|
286
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Add a listener for an event.
|
|
296
|
+
* @param event - The event to listen for.
|
|
297
|
+
* @param listener - The function to call when the event is emitted.
|
|
298
|
+
*/
|
|
287
299
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
288
300
|
on(event, listener) {
|
|
289
301
|
this.listeners[event] = listener;
|
|
290
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Connect to the server and begin a new session.
|
|
305
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
306
|
+
*/
|
|
291
307
|
connect() {
|
|
292
308
|
return new Promise((resolve) => {
|
|
293
309
|
if (this.socket) {
|
|
@@ -369,9 +385,17 @@ class RealtimeTranscriber {
|
|
|
369
385
|
};
|
|
370
386
|
});
|
|
371
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Send audio data to the server.
|
|
390
|
+
* @param audio - The audio data to send to the server.
|
|
391
|
+
*/
|
|
372
392
|
sendAudio(audio) {
|
|
373
393
|
this.send(audio);
|
|
374
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
397
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
398
|
+
*/
|
|
375
399
|
stream() {
|
|
376
400
|
return new WritableStream({
|
|
377
401
|
write: (chunk) => {
|
|
@@ -399,6 +423,11 @@ class RealtimeTranscriber {
|
|
|
399
423
|
}
|
|
400
424
|
this.socket.send(data);
|
|
401
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Close the connection to the server.
|
|
428
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
429
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
430
|
+
*/
|
|
402
431
|
close() {
|
|
403
432
|
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
404
433
|
var _a;
|
|
@@ -491,7 +520,6 @@ class TranscriptService extends BaseService {
|
|
|
491
520
|
*/
|
|
492
521
|
transcribe(params, options) {
|
|
493
522
|
return __awaiter(this, void 0, void 0, function* () {
|
|
494
|
-
deprecateConformer2(params);
|
|
495
523
|
const transcript = yield this.submit(params);
|
|
496
524
|
return yield this.waitUntilReady(transcript.id, options);
|
|
497
525
|
});
|
|
@@ -503,7 +531,6 @@ class TranscriptService extends BaseService {
|
|
|
503
531
|
*/
|
|
504
532
|
submit(params) {
|
|
505
533
|
return __awaiter(this, void 0, void 0, function* () {
|
|
506
|
-
deprecateConformer2(params);
|
|
507
534
|
let audioUrl;
|
|
508
535
|
let transcriptParams = undefined;
|
|
509
536
|
if ("audio" in params) {
|
|
@@ -550,7 +577,6 @@ class TranscriptService extends BaseService {
|
|
|
550
577
|
create(params, options) {
|
|
551
578
|
return __awaiter(this, void 0, void 0, function* () {
|
|
552
579
|
var _a;
|
|
553
|
-
deprecateConformer2(params);
|
|
554
580
|
const path = getPath(params.audio_url);
|
|
555
581
|
if (path !== null) {
|
|
556
582
|
const uploadUrl = yield this.files.upload(path);
|
|
@@ -726,13 +752,6 @@ class TranscriptService extends BaseService {
|
|
|
726
752
|
});
|
|
727
753
|
}
|
|
728
754
|
}
|
|
729
|
-
function deprecateConformer2(params) {
|
|
730
|
-
if (!params)
|
|
731
|
-
return;
|
|
732
|
-
if (params.speech_model === "conformer-2") {
|
|
733
|
-
console.warn("The speech_model conformer-2 option is deprecated and will stop working in the near future. Use best or nano instead.");
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
755
|
|
|
737
756
|
const readFile = function (
|
|
738
757
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
package/dist/index.mjs
CHANGED
|
@@ -61,7 +61,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
61
61
|
defaultUserAgentString += navigator.userAgent;
|
|
62
62
|
}
|
|
63
63
|
const defaultUserAgent = {
|
|
64
|
-
sdk: { name: "JavaScript", version: "4.
|
|
64
|
+
sdk: { name: "JavaScript", version: "4.6.1" },
|
|
65
65
|
};
|
|
66
66
|
if (typeof process !== "undefined") {
|
|
67
67
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -241,7 +241,14 @@ class RealtimeError extends Error {
|
|
|
241
241
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
242
242
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
243
243
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
244
|
+
/**
|
|
245
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
246
|
+
*/
|
|
244
247
|
class RealtimeTranscriber {
|
|
248
|
+
/**
|
|
249
|
+
* Create a new RealtimeTranscriber.
|
|
250
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
251
|
+
*/
|
|
245
252
|
constructor(params) {
|
|
246
253
|
var _a, _b;
|
|
247
254
|
this.listeners = {};
|
|
@@ -282,10 +289,19 @@ class RealtimeTranscriber {
|
|
|
282
289
|
url.search = searchParams.toString();
|
|
283
290
|
return url;
|
|
284
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Add a listener for an event.
|
|
294
|
+
* @param event - The event to listen for.
|
|
295
|
+
* @param listener - The function to call when the event is emitted.
|
|
296
|
+
*/
|
|
285
297
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
286
298
|
on(event, listener) {
|
|
287
299
|
this.listeners[event] = listener;
|
|
288
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Connect to the server and begin a new session.
|
|
303
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
304
|
+
*/
|
|
289
305
|
connect() {
|
|
290
306
|
return new Promise((resolve) => {
|
|
291
307
|
if (this.socket) {
|
|
@@ -367,9 +383,17 @@ class RealtimeTranscriber {
|
|
|
367
383
|
};
|
|
368
384
|
});
|
|
369
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Send audio data to the server.
|
|
388
|
+
* @param audio - The audio data to send to the server.
|
|
389
|
+
*/
|
|
370
390
|
sendAudio(audio) {
|
|
371
391
|
this.send(audio);
|
|
372
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
395
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
396
|
+
*/
|
|
373
397
|
stream() {
|
|
374
398
|
return new WritableStream({
|
|
375
399
|
write: (chunk) => {
|
|
@@ -397,6 +421,11 @@ class RealtimeTranscriber {
|
|
|
397
421
|
}
|
|
398
422
|
this.socket.send(data);
|
|
399
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* Close the connection to the server.
|
|
426
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
427
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
428
|
+
*/
|
|
400
429
|
close() {
|
|
401
430
|
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
402
431
|
var _a;
|
|
@@ -489,7 +518,6 @@ class TranscriptService extends BaseService {
|
|
|
489
518
|
*/
|
|
490
519
|
transcribe(params, options) {
|
|
491
520
|
return __awaiter(this, void 0, void 0, function* () {
|
|
492
|
-
deprecateConformer2(params);
|
|
493
521
|
const transcript = yield this.submit(params);
|
|
494
522
|
return yield this.waitUntilReady(transcript.id, options);
|
|
495
523
|
});
|
|
@@ -501,7 +529,6 @@ class TranscriptService extends BaseService {
|
|
|
501
529
|
*/
|
|
502
530
|
submit(params) {
|
|
503
531
|
return __awaiter(this, void 0, void 0, function* () {
|
|
504
|
-
deprecateConformer2(params);
|
|
505
532
|
let audioUrl;
|
|
506
533
|
let transcriptParams = undefined;
|
|
507
534
|
if ("audio" in params) {
|
|
@@ -548,7 +575,6 @@ class TranscriptService extends BaseService {
|
|
|
548
575
|
create(params, options) {
|
|
549
576
|
return __awaiter(this, void 0, void 0, function* () {
|
|
550
577
|
var _a;
|
|
551
|
-
deprecateConformer2(params);
|
|
552
578
|
const path = getPath(params.audio_url);
|
|
553
579
|
if (path !== null) {
|
|
554
580
|
const uploadUrl = yield this.files.upload(path);
|
|
@@ -724,13 +750,6 @@ class TranscriptService extends BaseService {
|
|
|
724
750
|
});
|
|
725
751
|
}
|
|
726
752
|
}
|
|
727
|
-
function deprecateConformer2(params) {
|
|
728
|
-
if (!params)
|
|
729
|
-
return;
|
|
730
|
-
if (params.speech_model === "conformer-2") {
|
|
731
|
-
console.warn("The speech_model conformer-2 option is deprecated and will stop working in the near future. Use best or nano instead.");
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
753
|
|
|
735
754
|
const readFile = function (
|
|
736
755
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
package/dist/node.cjs
CHANGED
|
@@ -22,7 +22,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
22
22
|
defaultUserAgentString += navigator.userAgent;
|
|
23
23
|
}
|
|
24
24
|
const defaultUserAgent = {
|
|
25
|
-
sdk: { name: "JavaScript", version: "4.
|
|
25
|
+
sdk: { name: "JavaScript", version: "4.6.1" },
|
|
26
26
|
};
|
|
27
27
|
if (typeof process !== "undefined") {
|
|
28
28
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -192,7 +192,14 @@ class RealtimeError extends Error {
|
|
|
192
192
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
193
193
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
194
194
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
195
|
+
/**
|
|
196
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
197
|
+
*/
|
|
195
198
|
class RealtimeTranscriber {
|
|
199
|
+
/**
|
|
200
|
+
* Create a new RealtimeTranscriber.
|
|
201
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
202
|
+
*/
|
|
196
203
|
constructor(params) {
|
|
197
204
|
this.listeners = {};
|
|
198
205
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -232,10 +239,19 @@ class RealtimeTranscriber {
|
|
|
232
239
|
url.search = searchParams.toString();
|
|
233
240
|
return url;
|
|
234
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Add a listener for an event.
|
|
244
|
+
* @param event - The event to listen for.
|
|
245
|
+
* @param listener - The function to call when the event is emitted.
|
|
246
|
+
*/
|
|
235
247
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
236
248
|
on(event, listener) {
|
|
237
249
|
this.listeners[event] = listener;
|
|
238
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Connect to the server and begin a new session.
|
|
253
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
254
|
+
*/
|
|
239
255
|
connect() {
|
|
240
256
|
return new Promise((resolve) => {
|
|
241
257
|
if (this.socket) {
|
|
@@ -314,9 +330,17 @@ class RealtimeTranscriber {
|
|
|
314
330
|
};
|
|
315
331
|
});
|
|
316
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Send audio data to the server.
|
|
335
|
+
* @param audio - The audio data to send to the server.
|
|
336
|
+
*/
|
|
317
337
|
sendAudio(audio) {
|
|
318
338
|
this.send(audio);
|
|
319
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
342
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
343
|
+
*/
|
|
320
344
|
stream() {
|
|
321
345
|
return new web.WritableStream({
|
|
322
346
|
write: (chunk) => {
|
|
@@ -344,6 +368,11 @@ class RealtimeTranscriber {
|
|
|
344
368
|
}
|
|
345
369
|
this.socket.send(data);
|
|
346
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Close the connection to the server.
|
|
373
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
374
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
375
|
+
*/
|
|
347
376
|
async close(waitForSessionTermination = true) {
|
|
348
377
|
if (this.socket) {
|
|
349
378
|
if (this.socket.readyState === this.socket.OPEN) {
|
|
@@ -430,7 +459,6 @@ class TranscriptService extends BaseService {
|
|
|
430
459
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
431
460
|
*/
|
|
432
461
|
async transcribe(params, options) {
|
|
433
|
-
deprecateConformer2(params);
|
|
434
462
|
const transcript = await this.submit(params);
|
|
435
463
|
return await this.waitUntilReady(transcript.id, options);
|
|
436
464
|
}
|
|
@@ -440,7 +468,6 @@ class TranscriptService extends BaseService {
|
|
|
440
468
|
* @returns A promise that resolves to the queued transcript.
|
|
441
469
|
*/
|
|
442
470
|
async submit(params) {
|
|
443
|
-
deprecateConformer2(params);
|
|
444
471
|
let audioUrl;
|
|
445
472
|
let transcriptParams = undefined;
|
|
446
473
|
if ("audio" in params) {
|
|
@@ -484,7 +511,6 @@ class TranscriptService extends BaseService {
|
|
|
484
511
|
* @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
|
|
485
512
|
*/
|
|
486
513
|
async create(params, options) {
|
|
487
|
-
deprecateConformer2(params);
|
|
488
514
|
const path = getPath(params.audio_url);
|
|
489
515
|
if (path !== null) {
|
|
490
516
|
const uploadUrl = await this.files.upload(path);
|
|
@@ -647,13 +673,6 @@ class TranscriptService extends BaseService {
|
|
|
647
673
|
};
|
|
648
674
|
}
|
|
649
675
|
}
|
|
650
|
-
function deprecateConformer2(params) {
|
|
651
|
-
if (!params)
|
|
652
|
-
return;
|
|
653
|
-
if (params.speech_model === "conformer-2") {
|
|
654
|
-
console.warn("The speech_model conformer-2 option is deprecated and will stop working in the near future. Use best or nano instead.");
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
676
|
|
|
658
677
|
const readFile = async (path) => stream.Readable.toWeb(fs.createReadStream(path));
|
|
659
678
|
|
package/dist/node.mjs
CHANGED
|
@@ -20,7 +20,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
20
20
|
defaultUserAgentString += navigator.userAgent;
|
|
21
21
|
}
|
|
22
22
|
const defaultUserAgent = {
|
|
23
|
-
sdk: { name: "JavaScript", version: "4.
|
|
23
|
+
sdk: { name: "JavaScript", version: "4.6.1" },
|
|
24
24
|
};
|
|
25
25
|
if (typeof process !== "undefined") {
|
|
26
26
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -190,7 +190,14 @@ class RealtimeError extends Error {
|
|
|
190
190
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
191
191
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
192
192
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
193
|
+
/**
|
|
194
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
195
|
+
*/
|
|
193
196
|
class RealtimeTranscriber {
|
|
197
|
+
/**
|
|
198
|
+
* Create a new RealtimeTranscriber.
|
|
199
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
200
|
+
*/
|
|
194
201
|
constructor(params) {
|
|
195
202
|
this.listeners = {};
|
|
196
203
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -230,10 +237,19 @@ class RealtimeTranscriber {
|
|
|
230
237
|
url.search = searchParams.toString();
|
|
231
238
|
return url;
|
|
232
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Add a listener for an event.
|
|
242
|
+
* @param event - The event to listen for.
|
|
243
|
+
* @param listener - The function to call when the event is emitted.
|
|
244
|
+
*/
|
|
233
245
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
234
246
|
on(event, listener) {
|
|
235
247
|
this.listeners[event] = listener;
|
|
236
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Connect to the server and begin a new session.
|
|
251
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
252
|
+
*/
|
|
237
253
|
connect() {
|
|
238
254
|
return new Promise((resolve) => {
|
|
239
255
|
if (this.socket) {
|
|
@@ -312,9 +328,17 @@ class RealtimeTranscriber {
|
|
|
312
328
|
};
|
|
313
329
|
});
|
|
314
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Send audio data to the server.
|
|
333
|
+
* @param audio - The audio data to send to the server.
|
|
334
|
+
*/
|
|
315
335
|
sendAudio(audio) {
|
|
316
336
|
this.send(audio);
|
|
317
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
340
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
341
|
+
*/
|
|
318
342
|
stream() {
|
|
319
343
|
return new WritableStream({
|
|
320
344
|
write: (chunk) => {
|
|
@@ -342,6 +366,11 @@ class RealtimeTranscriber {
|
|
|
342
366
|
}
|
|
343
367
|
this.socket.send(data);
|
|
344
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Close the connection to the server.
|
|
371
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
372
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
373
|
+
*/
|
|
345
374
|
async close(waitForSessionTermination = true) {
|
|
346
375
|
if (this.socket) {
|
|
347
376
|
if (this.socket.readyState === this.socket.OPEN) {
|
|
@@ -428,7 +457,6 @@ class TranscriptService extends BaseService {
|
|
|
428
457
|
* @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
|
|
429
458
|
*/
|
|
430
459
|
async transcribe(params, options) {
|
|
431
|
-
deprecateConformer2(params);
|
|
432
460
|
const transcript = await this.submit(params);
|
|
433
461
|
return await this.waitUntilReady(transcript.id, options);
|
|
434
462
|
}
|
|
@@ -438,7 +466,6 @@ class TranscriptService extends BaseService {
|
|
|
438
466
|
* @returns A promise that resolves to the queued transcript.
|
|
439
467
|
*/
|
|
440
468
|
async submit(params) {
|
|
441
|
-
deprecateConformer2(params);
|
|
442
469
|
let audioUrl;
|
|
443
470
|
let transcriptParams = undefined;
|
|
444
471
|
if ("audio" in params) {
|
|
@@ -482,7 +509,6 @@ class TranscriptService extends BaseService {
|
|
|
482
509
|
* @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
|
|
483
510
|
*/
|
|
484
511
|
async create(params, options) {
|
|
485
|
-
deprecateConformer2(params);
|
|
486
512
|
const path = getPath(params.audio_url);
|
|
487
513
|
if (path !== null) {
|
|
488
514
|
const uploadUrl = await this.files.upload(path);
|
|
@@ -645,13 +671,6 @@ class TranscriptService extends BaseService {
|
|
|
645
671
|
};
|
|
646
672
|
}
|
|
647
673
|
}
|
|
648
|
-
function deprecateConformer2(params) {
|
|
649
|
-
if (!params)
|
|
650
|
-
return;
|
|
651
|
-
if (params.speech_model === "conformer-2") {
|
|
652
|
-
console.warn("The speech_model conformer-2 option is deprecated and will stop working in the near future. Use best or nano instead.");
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
674
|
|
|
656
675
|
const readFile = async (path) => Readable.toWeb(createReadStream(path));
|
|
657
676
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData, SessionInformation } from "../..";
|
|
2
|
+
/**
|
|
3
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
4
|
+
*/
|
|
2
5
|
export declare class RealtimeTranscriber {
|
|
3
6
|
private realtimeUrl;
|
|
4
7
|
private sampleRate;
|
|
@@ -11,17 +14,69 @@ export declare class RealtimeTranscriber {
|
|
|
11
14
|
private socket?;
|
|
12
15
|
private listeners;
|
|
13
16
|
private sessionTerminatedResolve?;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new RealtimeTranscriber.
|
|
19
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
20
|
+
*/
|
|
14
21
|
constructor(params: RealtimeTranscriberParams);
|
|
15
22
|
private connectionUrl;
|
|
23
|
+
/**
|
|
24
|
+
* Listen for the open event which is emitted when the connection is established and the session begins.
|
|
25
|
+
* @param event - The open event.
|
|
26
|
+
* @param listener - The function to call when the event is emitted.
|
|
27
|
+
*/
|
|
16
28
|
on(event: "open", listener: (event: SessionBeginsEventData) => void): void;
|
|
29
|
+
/**
|
|
30
|
+
* Listen for the transcript event which is emitted when a partian or final transcript is received.
|
|
31
|
+
* @param event - The transcript event.
|
|
32
|
+
* @param listener - The function to call when the event is emitted.
|
|
33
|
+
*/
|
|
17
34
|
on(event: "transcript", listener: (transcript: RealtimeTranscript) => void): void;
|
|
35
|
+
/**
|
|
36
|
+
* Listen for the partial transcript event which is emitted when a partial transcript is received.
|
|
37
|
+
* @param event - The partial transcript event.
|
|
38
|
+
* @param listener - The function to call when the event is emitted.
|
|
39
|
+
*/
|
|
18
40
|
on(event: "transcript.partial", listener: (transcript: PartialTranscript) => void): void;
|
|
41
|
+
/**
|
|
42
|
+
* Listen for the final transcript event which is emitted when a final transcript is received.
|
|
43
|
+
* @param event - The final transcript event.
|
|
44
|
+
* @param listener - The function to call when the event is emitted.
|
|
45
|
+
*/
|
|
19
46
|
on(event: "transcript.final", listener: (transcript: FinalTranscript) => void): void;
|
|
47
|
+
/**
|
|
48
|
+
* Listen for the session information event which is emitted when session information is received.
|
|
49
|
+
* The session information is sent right before the session is terminated.
|
|
50
|
+
* @param event - The session information event.
|
|
51
|
+
* @param listener - The function to call when the event is emitted.
|
|
52
|
+
*/
|
|
20
53
|
on(event: "session_information", listener: (info: SessionInformation) => void): void;
|
|
54
|
+
/**
|
|
55
|
+
* Listen for the error event which is emitted when an error occurs.
|
|
56
|
+
* @param event - The error event.
|
|
57
|
+
* @param listener - The function to call when the event is emitted.
|
|
58
|
+
*/
|
|
21
59
|
on(event: "error", listener: (error: Error) => void): void;
|
|
60
|
+
/**
|
|
61
|
+
* Listen for the close event which is emitted when the connection is closed.
|
|
62
|
+
* @param event - The close event.
|
|
63
|
+
* @param listener - The function to call when the event is emitted.
|
|
64
|
+
*/
|
|
22
65
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
66
|
+
/**
|
|
67
|
+
* Connect to the server and begin a new session.
|
|
68
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
69
|
+
*/
|
|
23
70
|
connect(): Promise<SessionBeginsEventData>;
|
|
71
|
+
/**
|
|
72
|
+
* Send audio data to the server.
|
|
73
|
+
* @param audio - The audio data to send to the server.
|
|
74
|
+
*/
|
|
24
75
|
sendAudio(audio: AudioData): void;
|
|
76
|
+
/**
|
|
77
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
78
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
79
|
+
*/
|
|
25
80
|
stream(): WritableStream<AudioData>;
|
|
26
81
|
/**
|
|
27
82
|
* Manually end an utterance
|
|
@@ -34,6 +89,11 @@ export declare class RealtimeTranscriber {
|
|
|
34
89
|
*/
|
|
35
90
|
configureEndUtteranceSilenceThreshold(threshold: number): void;
|
|
36
91
|
private send;
|
|
92
|
+
/**
|
|
93
|
+
* Close the connection to the server.
|
|
94
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
95
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
96
|
+
*/
|
|
37
97
|
close(waitForSessionTermination?: boolean): Promise<void>;
|
|
38
98
|
}
|
|
39
99
|
/**
|
|
@@ -56,7 +56,14 @@ class RealtimeError extends Error {
|
|
|
56
56
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
57
57
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
58
58
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
59
|
+
/**
|
|
60
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
61
|
+
*/
|
|
59
62
|
class RealtimeTranscriber {
|
|
63
|
+
/**
|
|
64
|
+
* Create a new RealtimeTranscriber.
|
|
65
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
66
|
+
*/
|
|
60
67
|
constructor(params) {
|
|
61
68
|
this.listeners = {};
|
|
62
69
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -96,10 +103,19 @@ class RealtimeTranscriber {
|
|
|
96
103
|
url.search = searchParams.toString();
|
|
97
104
|
return url;
|
|
98
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Add a listener for an event.
|
|
108
|
+
* @param event - The event to listen for.
|
|
109
|
+
* @param listener - The function to call when the event is emitted.
|
|
110
|
+
*/
|
|
99
111
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
112
|
on(event, listener) {
|
|
101
113
|
this.listeners[event] = listener;
|
|
102
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Connect to the server and begin a new session.
|
|
117
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
118
|
+
*/
|
|
103
119
|
connect() {
|
|
104
120
|
return new Promise((resolve) => {
|
|
105
121
|
if (this.socket) {
|
|
@@ -178,9 +194,17 @@ class RealtimeTranscriber {
|
|
|
178
194
|
};
|
|
179
195
|
});
|
|
180
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Send audio data to the server.
|
|
199
|
+
* @param audio - The audio data to send to the server.
|
|
200
|
+
*/
|
|
181
201
|
sendAudio(audio) {
|
|
182
202
|
this.send(audio);
|
|
183
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
206
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
207
|
+
*/
|
|
184
208
|
stream() {
|
|
185
209
|
return new WritableStream({
|
|
186
210
|
write: (chunk) => {
|
|
@@ -208,6 +232,11 @@ class RealtimeTranscriber {
|
|
|
208
232
|
}
|
|
209
233
|
this.socket.send(data);
|
|
210
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Close the connection to the server.
|
|
237
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
238
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
239
|
+
*/
|
|
211
240
|
async close(waitForSessionTermination = true) {
|
|
212
241
|
if (this.socket) {
|
|
213
242
|
if (this.socket.readyState === this.socket.OPEN) {
|
package/dist/streaming.cjs
CHANGED
|
@@ -86,7 +86,14 @@ class RealtimeError extends Error {
|
|
|
86
86
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
87
87
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
88
88
|
const terminateSessionMessage = `{"terminate_session":true}`;
|
|
89
|
+
/**
|
|
90
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
91
|
+
*/
|
|
89
92
|
class RealtimeTranscriber {
|
|
93
|
+
/**
|
|
94
|
+
* Create a new RealtimeTranscriber.
|
|
95
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
96
|
+
*/
|
|
90
97
|
constructor(params) {
|
|
91
98
|
var _a, _b;
|
|
92
99
|
this.listeners = {};
|
|
@@ -127,10 +134,19 @@ class RealtimeTranscriber {
|
|
|
127
134
|
url.search = searchParams.toString();
|
|
128
135
|
return url;
|
|
129
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Add a listener for an event.
|
|
139
|
+
* @param event - The event to listen for.
|
|
140
|
+
* @param listener - The function to call when the event is emitted.
|
|
141
|
+
*/
|
|
130
142
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
131
143
|
on(event, listener) {
|
|
132
144
|
this.listeners[event] = listener;
|
|
133
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Connect to the server and begin a new session.
|
|
148
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
149
|
+
*/
|
|
134
150
|
connect() {
|
|
135
151
|
return new Promise((resolve) => {
|
|
136
152
|
if (this.socket) {
|
|
@@ -212,9 +228,17 @@ class RealtimeTranscriber {
|
|
|
212
228
|
};
|
|
213
229
|
});
|
|
214
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Send audio data to the server.
|
|
233
|
+
* @param audio - The audio data to send to the server.
|
|
234
|
+
*/
|
|
215
235
|
sendAudio(audio) {
|
|
216
236
|
this.send(audio);
|
|
217
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
240
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
241
|
+
*/
|
|
218
242
|
stream() {
|
|
219
243
|
return new WritableStream({
|
|
220
244
|
write: (chunk) => {
|
|
@@ -242,6 +266,11 @@ class RealtimeTranscriber {
|
|
|
242
266
|
}
|
|
243
267
|
this.socket.send(data);
|
|
244
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Close the connection to the server.
|
|
271
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
272
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
273
|
+
*/
|
|
245
274
|
close() {
|
|
246
275
|
return __awaiter(this, arguments, void 0, function* (waitForSessionTermination = true) {
|
|
247
276
|
var _a;
|