assemblyai 4.2.0 → 4.2.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 +17 -0
- package/README.md +5 -5
- package/dist/assemblyai.umd.js +34 -17
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +33 -18
- package/dist/deno.mjs +33 -18
- package/dist/index.cjs +34 -17
- package/dist/index.mjs +33 -18
- package/dist/node.cjs +34 -17
- package/dist/node.mjs +33 -18
- package/dist/services/index.d.ts +3 -3
- package/dist/services/realtime/factory.d.ts +12 -3
- package/dist/services/realtime/service.d.ts +10 -5
- package/dist/types/asyncapi.generated.d.ts +5 -4
- package/dist/types/openapi.generated.d.ts +20 -4
- package/dist/types/realtime/index.d.ts +11 -3
- package/dist/utils/path.d.ts +1 -0
- package/docs/compat.md +5 -5
- package/package.json +1 -1
- package/src/services/index.ts +10 -3
- package/src/services/realtime/factory.ts +18 -5
- package/src/services/realtime/service.ts +13 -7
- package/src/services/transcripts/index.ts +1 -11
- package/src/types/asyncapi.generated.ts +5 -4
- package/src/types/openapi.generated.ts +21 -4
- package/src/types/realtime/index.ts +14 -2
- package/src/utils/path.ts +7 -0
package/dist/node.cjs
CHANGED
|
@@ -129,7 +129,7 @@ class RealtimeError extends Error {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
132
|
-
class
|
|
132
|
+
class RealtimeTranscriber {
|
|
133
133
|
constructor(params) {
|
|
134
134
|
this.listeners = {};
|
|
135
135
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -270,18 +270,29 @@ class RealtimeService {
|
|
|
270
270
|
this.socket = undefined;
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
275
|
+
*/
|
|
276
|
+
class RealtimeService extends RealtimeTranscriber {
|
|
277
|
+
}
|
|
273
278
|
|
|
274
|
-
class
|
|
279
|
+
class RealtimeTranscriberFactory extends BaseService {
|
|
275
280
|
constructor(params) {
|
|
276
281
|
super(params);
|
|
277
282
|
this.rtFactoryParams = params;
|
|
278
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* @deprecated Use transcriber(...) instead
|
|
286
|
+
*/
|
|
279
287
|
createService(params) {
|
|
288
|
+
return this.transcriber(params);
|
|
289
|
+
}
|
|
290
|
+
transcriber(params) {
|
|
280
291
|
const serviceParams = { ...params };
|
|
281
292
|
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
282
293
|
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
283
294
|
}
|
|
284
|
-
return new
|
|
295
|
+
return new RealtimeTranscriber(serviceParams);
|
|
285
296
|
}
|
|
286
297
|
async createTemporaryToken(params) {
|
|
287
298
|
const data = await this.fetchJson("/v2/realtime/token", {
|
|
@@ -291,6 +302,23 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
291
302
|
return data.token;
|
|
292
303
|
}
|
|
293
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
307
|
+
*/
|
|
308
|
+
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function getPath(path) {
|
|
312
|
+
if (path.startsWith("http"))
|
|
313
|
+
return null;
|
|
314
|
+
if (path.startsWith("https"))
|
|
315
|
+
return null;
|
|
316
|
+
if (path.startsWith("file://"))
|
|
317
|
+
return path.substring(7);
|
|
318
|
+
if (path.startsWith("file:"))
|
|
319
|
+
return path.substring(5);
|
|
320
|
+
return path;
|
|
321
|
+
}
|
|
294
322
|
|
|
295
323
|
class TranscriptService extends BaseService {
|
|
296
324
|
constructor(params, files) {
|
|
@@ -476,19 +504,6 @@ class TranscriptService extends BaseService {
|
|
|
476
504
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
477
505
|
}
|
|
478
506
|
}
|
|
479
|
-
function getPath(path) {
|
|
480
|
-
let url;
|
|
481
|
-
try {
|
|
482
|
-
url = new URL(path);
|
|
483
|
-
if (url.protocol === "file:")
|
|
484
|
-
return url.pathname;
|
|
485
|
-
else
|
|
486
|
-
return null;
|
|
487
|
-
}
|
|
488
|
-
catch {
|
|
489
|
-
return path;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
507
|
|
|
493
508
|
const readFile = async (path) => stream.Readable.toWeb(fs.createReadStream(path));
|
|
494
509
|
|
|
@@ -529,7 +544,7 @@ class AssemblyAI {
|
|
|
529
544
|
this.files = new FileService(params);
|
|
530
545
|
this.transcripts = new TranscriptService(params, this.files);
|
|
531
546
|
this.lemur = new LemurService(params);
|
|
532
|
-
this.realtime = new
|
|
547
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
533
548
|
}
|
|
534
549
|
}
|
|
535
550
|
|
|
@@ -538,4 +553,6 @@ exports.FileService = FileService;
|
|
|
538
553
|
exports.LemurService = LemurService;
|
|
539
554
|
exports.RealtimeService = RealtimeService;
|
|
540
555
|
exports.RealtimeServiceFactory = RealtimeServiceFactory;
|
|
556
|
+
exports.RealtimeTranscriber = RealtimeTranscriber;
|
|
557
|
+
exports.RealtimeTranscriberFactory = RealtimeTranscriberFactory;
|
|
541
558
|
exports.TranscriptService = TranscriptService;
|
package/dist/node.mjs
CHANGED
|
@@ -127,7 +127,7 @@ class RealtimeError extends Error {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
130
|
-
class
|
|
130
|
+
class RealtimeTranscriber {
|
|
131
131
|
constructor(params) {
|
|
132
132
|
this.listeners = {};
|
|
133
133
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
@@ -268,18 +268,29 @@ class RealtimeService {
|
|
|
268
268
|
this.socket = undefined;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
273
|
+
*/
|
|
274
|
+
class RealtimeService extends RealtimeTranscriber {
|
|
275
|
+
}
|
|
271
276
|
|
|
272
|
-
class
|
|
277
|
+
class RealtimeTranscriberFactory extends BaseService {
|
|
273
278
|
constructor(params) {
|
|
274
279
|
super(params);
|
|
275
280
|
this.rtFactoryParams = params;
|
|
276
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* @deprecated Use transcriber(...) instead
|
|
284
|
+
*/
|
|
277
285
|
createService(params) {
|
|
286
|
+
return this.transcriber(params);
|
|
287
|
+
}
|
|
288
|
+
transcriber(params) {
|
|
278
289
|
const serviceParams = { ...params };
|
|
279
290
|
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
280
291
|
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
281
292
|
}
|
|
282
|
-
return new
|
|
293
|
+
return new RealtimeTranscriber(serviceParams);
|
|
283
294
|
}
|
|
284
295
|
async createTemporaryToken(params) {
|
|
285
296
|
const data = await this.fetchJson("/v2/realtime/token", {
|
|
@@ -289,6 +300,23 @@ class RealtimeServiceFactory extends BaseService {
|
|
|
289
300
|
return data.token;
|
|
290
301
|
}
|
|
291
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
305
|
+
*/
|
|
306
|
+
class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function getPath(path) {
|
|
310
|
+
if (path.startsWith("http"))
|
|
311
|
+
return null;
|
|
312
|
+
if (path.startsWith("https"))
|
|
313
|
+
return null;
|
|
314
|
+
if (path.startsWith("file://"))
|
|
315
|
+
return path.substring(7);
|
|
316
|
+
if (path.startsWith("file:"))
|
|
317
|
+
return path.substring(5);
|
|
318
|
+
return path;
|
|
319
|
+
}
|
|
292
320
|
|
|
293
321
|
class TranscriptService extends BaseService {
|
|
294
322
|
constructor(params, files) {
|
|
@@ -474,19 +502,6 @@ class TranscriptService extends BaseService {
|
|
|
474
502
|
return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
|
|
475
503
|
}
|
|
476
504
|
}
|
|
477
|
-
function getPath(path) {
|
|
478
|
-
let url;
|
|
479
|
-
try {
|
|
480
|
-
url = new URL(path);
|
|
481
|
-
if (url.protocol === "file:")
|
|
482
|
-
return url.pathname;
|
|
483
|
-
else
|
|
484
|
-
return null;
|
|
485
|
-
}
|
|
486
|
-
catch {
|
|
487
|
-
return path;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
505
|
|
|
491
506
|
const readFile = async (path) => Readable.toWeb(createReadStream(path));
|
|
492
507
|
|
|
@@ -527,8 +542,8 @@ class AssemblyAI {
|
|
|
527
542
|
this.files = new FileService(params);
|
|
528
543
|
this.transcripts = new TranscriptService(params, this.files);
|
|
529
544
|
this.lemur = new LemurService(params);
|
|
530
|
-
this.realtime = new
|
|
545
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
531
546
|
}
|
|
532
547
|
}
|
|
533
548
|
|
|
534
|
-
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
|
|
549
|
+
export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, RealtimeTranscriber, RealtimeTranscriberFactory, TranscriptService };
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseServiceParams } from "..";
|
|
2
2
|
import { LemurService } from "./lemur";
|
|
3
|
-
import { RealtimeService, RealtimeServiceFactory } from "./realtime";
|
|
3
|
+
import { RealtimeTranscriber, RealtimeTranscriberFactory, RealtimeService, RealtimeServiceFactory } from "./realtime";
|
|
4
4
|
import { TranscriptService } from "./transcripts";
|
|
5
5
|
import { FileService } from "./files";
|
|
6
6
|
declare class AssemblyAI {
|
|
@@ -19,11 +19,11 @@ declare class AssemblyAI {
|
|
|
19
19
|
/**
|
|
20
20
|
* The realtime service.
|
|
21
21
|
*/
|
|
22
|
-
realtime:
|
|
22
|
+
realtime: RealtimeTranscriberFactory;
|
|
23
23
|
/**
|
|
24
24
|
* Create a new AssemblyAI client.
|
|
25
25
|
* @param params The parameters for the service, including the API key and base URL, if any.
|
|
26
26
|
*/
|
|
27
27
|
constructor(params: BaseServiceParams);
|
|
28
28
|
}
|
|
29
|
-
export { AssemblyAI, LemurService, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };
|
|
29
|
+
export { AssemblyAI, LemurService, RealtimeTranscriberFactory, RealtimeTranscriber, RealtimeServiceFactory, RealtimeService, TranscriptService, FileService, };
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import { BaseServiceParams, RealtimeTokenParams, CreateRealtimeServiceParams } from "../..";
|
|
2
|
-
import { RealtimeService } from "./service";
|
|
1
|
+
import { BaseServiceParams, RealtimeTokenParams, CreateRealtimeTranscriberParams, CreateRealtimeServiceParams } from "../..";
|
|
2
|
+
import { RealtimeService, RealtimeTranscriber } from "./service";
|
|
3
3
|
import { BaseService } from "../base";
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class RealtimeTranscriberFactory extends BaseService {
|
|
5
5
|
private rtFactoryParams;
|
|
6
6
|
constructor(params: BaseServiceParams);
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use transcriber(...) instead
|
|
9
|
+
*/
|
|
7
10
|
createService(params?: CreateRealtimeServiceParams): RealtimeService;
|
|
11
|
+
transcriber(params?: CreateRealtimeTranscriberParams): RealtimeTranscriber;
|
|
8
12
|
createTemporaryToken(params: RealtimeTokenParams): Promise<string>;
|
|
9
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
16
|
+
*/
|
|
17
|
+
export declare class RealtimeServiceFactory extends RealtimeTranscriberFactory {
|
|
18
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class
|
|
1
|
+
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData } from "../..";
|
|
2
|
+
export declare class RealtimeTranscriber {
|
|
3
3
|
private realtimeUrl;
|
|
4
4
|
private sampleRate;
|
|
5
5
|
private wordBoost?;
|
|
@@ -9,7 +9,7 @@ export declare class RealtimeService {
|
|
|
9
9
|
private socket?;
|
|
10
10
|
private listeners;
|
|
11
11
|
private sessionTerminatedResolve?;
|
|
12
|
-
constructor(params:
|
|
12
|
+
constructor(params: RealtimeTranscriberParams);
|
|
13
13
|
private connectionUrl;
|
|
14
14
|
on(event: "open", listener: (event: SessionBeginsEventData) => void): void;
|
|
15
15
|
on(event: "transcript", listener: (transcript: RealtimeTranscript) => void): void;
|
|
@@ -18,7 +18,12 @@ export declare class RealtimeService {
|
|
|
18
18
|
on(event: "error", listener: (error: Error) => void): void;
|
|
19
19
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
20
20
|
connect(): Promise<SessionBeginsEventData>;
|
|
21
|
-
sendAudio(audio:
|
|
22
|
-
stream(): WritableStream<
|
|
21
|
+
sendAudio(audio: AudioData): void;
|
|
22
|
+
stream(): WritableStream<AudioData>;
|
|
23
23
|
close(waitForSessionTermination?: boolean): Promise<void>;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
27
|
+
*/
|
|
28
|
+
export declare class RealtimeService extends RealtimeTranscriber {
|
|
29
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Format: binary
|
|
3
|
+
* @description Binary audio data
|
|
4
|
+
*/
|
|
5
|
+
export type AudioData = ArrayBufferLike;
|
|
5
6
|
/**
|
|
6
7
|
* @description The encoding of the audio data
|
|
7
8
|
* @default pcm_s16le
|
|
@@ -425,12 +425,21 @@ export type Error = {
|
|
|
425
425
|
* "64nygnr62k-405c-4ae8-8a6b-d90b40ff3cce"
|
|
426
426
|
* ],
|
|
427
427
|
* "context": "This is an interview about wildfires.",
|
|
428
|
+
* "answer_format": "Bullet Points",
|
|
428
429
|
* "final_model": "default",
|
|
429
430
|
* "temperature": 0,
|
|
430
431
|
* "max_output_size": 3000
|
|
431
432
|
* }
|
|
432
433
|
*/
|
|
433
|
-
export type LemurActionItemsParams = LemurBaseParams
|
|
434
|
+
export type LemurActionItemsParams = LemurBaseParams & {
|
|
435
|
+
/**
|
|
436
|
+
* @description How you want the action items to be returned. This can be any text.
|
|
437
|
+
* Defaults to "Bullet Points".
|
|
438
|
+
*
|
|
439
|
+
* @default Bullet Points
|
|
440
|
+
*/
|
|
441
|
+
answer_format?: string;
|
|
442
|
+
};
|
|
434
443
|
/**
|
|
435
444
|
* @example {
|
|
436
445
|
* "request_id": "5e1b27c2-691f-4414-8bc5-f14678442f9e",
|
|
@@ -825,6 +834,13 @@ export type RedactedAudioResponse = {
|
|
|
825
834
|
* @enum {string}
|
|
826
835
|
*/
|
|
827
836
|
export type RedactedAudioStatus = "redacted_audio_ready";
|
|
837
|
+
/**
|
|
838
|
+
* @description Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
|
|
839
|
+
* @default mp3
|
|
840
|
+
* @example mp3
|
|
841
|
+
* @enum {string}
|
|
842
|
+
*/
|
|
843
|
+
export type RedactPiiAudioQuality = "mp3" | "wav";
|
|
828
844
|
/**
|
|
829
845
|
* @example {
|
|
830
846
|
* "sentences": [
|
|
@@ -1954,7 +1970,7 @@ export type Transcript = {
|
|
|
1954
1970
|
* @description The audio quality of the PII-redacted audio file, if redact_pii_audio is enabled.
|
|
1955
1971
|
* See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more information.
|
|
1956
1972
|
*/
|
|
1957
|
-
redact_pii_audio_quality?:
|
|
1973
|
+
redact_pii_audio_quality?: RedactPiiAudioQuality | null;
|
|
1958
1974
|
/**
|
|
1959
1975
|
* @description The list of PII Redaction policies that were enabled, if PII Redaction is enabled.
|
|
1960
1976
|
* See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more information.
|
|
@@ -2097,7 +2113,7 @@ export type TranscriptList = {
|
|
|
2097
2113
|
*/
|
|
2098
2114
|
export type TranscriptListItem = {
|
|
2099
2115
|
audio_url: string;
|
|
2100
|
-
completed
|
|
2116
|
+
completed: Date | null;
|
|
2101
2117
|
created: Date;
|
|
2102
2118
|
/** Format: uuid */
|
|
2103
2119
|
id: string;
|
|
@@ -2198,7 +2214,7 @@ export type TranscriptOptionalParams = {
|
|
|
2198
2214
|
* @description Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
|
|
2199
2215
|
* @default mp3
|
|
2200
2216
|
*/
|
|
2201
|
-
redact_pii_audio_quality?:
|
|
2217
|
+
redact_pii_audio_quality?: RedactPiiAudioQuality;
|
|
2202
2218
|
/** @description The list of PII Redaction policies to enable. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details. */
|
|
2203
2219
|
redact_pii_policies?: PiiPolicy[];
|
|
2204
2220
|
/** @description The replacement logic for detected PII, can be "entity_type" or "hash". See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AudioEncoding, FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType } from "../asyncapi.generated";
|
|
2
|
-
type
|
|
2
|
+
type CreateRealtimeTranscriberParams = {
|
|
3
3
|
realtimeUrl?: string;
|
|
4
4
|
sampleRate?: number;
|
|
5
5
|
wordBoost?: string[];
|
|
@@ -9,7 +9,11 @@ type CreateRealtimeServiceParams = {
|
|
|
9
9
|
} | {
|
|
10
10
|
token: string;
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use CreateRealtimeTranscriberParams instead
|
|
14
|
+
*/
|
|
15
|
+
type CreateRealtimeServiceParams = CreateRealtimeTranscriberParams;
|
|
16
|
+
type RealtimeTranscriberParams = {
|
|
13
17
|
realtimeUrl?: string;
|
|
14
18
|
sampleRate?: number;
|
|
15
19
|
wordBoost?: string[];
|
|
@@ -19,6 +23,10 @@ type RealtimeServiceParams = {
|
|
|
19
23
|
} | {
|
|
20
24
|
token: string;
|
|
21
25
|
});
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use RealtimeTranscriberParams instead
|
|
28
|
+
*/
|
|
29
|
+
type RealtimeServiceParams = RealtimeTranscriberParams;
|
|
22
30
|
type RealtimeEvents = "open" | "close" | "transcript" | "transcript.partial" | "transcript.final" | "error";
|
|
23
31
|
type SessionBeginsEventData = {
|
|
24
32
|
sessionId: string;
|
|
@@ -35,4 +43,4 @@ type RealtimeListeners = {
|
|
|
35
43
|
type RealtimeTokenParams = {
|
|
36
44
|
expires_in: number;
|
|
37
45
|
};
|
|
38
|
-
export type { CreateRealtimeServiceParams, RealtimeServiceParams, RealtimeEvents, RealtimeTranscriptType, SessionBeginsEventData, RealtimeListeners, RealtimeTokenParams, };
|
|
46
|
+
export type { CreateRealtimeTranscriberParams, RealtimeTranscriberParams, CreateRealtimeServiceParams, RealtimeServiceParams, RealtimeEvents, RealtimeTranscriptType, SessionBeginsEventData, RealtimeListeners, RealtimeTokenParams, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPath(path: string): string | null;
|
package/docs/compat.md
CHANGED
|
@@ -13,7 +13,7 @@ If you do use an older version of Node.js like version 16, you'll need to polyfi
|
|
|
13
13
|
To make the SDK compatible with the browser, the SDK aims to use web standards as much as possible.
|
|
14
14
|
However, there are still incompatibilities between Node.js and the browser.
|
|
15
15
|
|
|
16
|
-
- `
|
|
16
|
+
- `RealtimeTranscriber` doesn't support the AssemblyAI API key in the browser.
|
|
17
17
|
Instead, you have to generate a temporary auth token using `client.realtime.createTemporaryToken`, and pass in the resulting token to the real-time transcriber.
|
|
18
18
|
|
|
19
19
|
Generate a temporary auth token on the server.
|
|
@@ -31,16 +31,16 @@ However, there are still incompatibilities between Node.js and the browser.
|
|
|
31
31
|
> If you embed the API key on the client, everyone can see it and use it for themselves.
|
|
32
32
|
|
|
33
33
|
Then pass the token via an API to the client.
|
|
34
|
-
On the client, create an instance of `
|
|
34
|
+
On the client, create an instance of `RealtimeTranscriber` using the token.
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
|
-
import {
|
|
37
|
+
import { RealtimeTranscriber } from "assemblyai";
|
|
38
38
|
// or the following if you're using UMD
|
|
39
|
-
// const {
|
|
39
|
+
// const { RealtimeTranscriber } = assemblyai;
|
|
40
40
|
|
|
41
41
|
const token = getToken(); // getToken is a function for you to implement
|
|
42
42
|
|
|
43
|
-
const rt = new
|
|
43
|
+
const rt = new RealtimeTranscriber({
|
|
44
44
|
token: token,
|
|
45
45
|
});
|
|
46
46
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"description": "The AssemblyAI JavaScript 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
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
package/src/services/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { BaseServiceParams } from "..";
|
|
2
2
|
import { LemurService } from "./lemur";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
RealtimeTranscriber,
|
|
5
|
+
RealtimeTranscriberFactory,
|
|
6
|
+
RealtimeService,
|
|
7
|
+
RealtimeServiceFactory,
|
|
8
|
+
} from "./realtime";
|
|
4
9
|
import { TranscriptService } from "./transcripts";
|
|
5
10
|
import { FileService } from "./files";
|
|
6
11
|
|
|
@@ -25,7 +30,7 @@ class AssemblyAI {
|
|
|
25
30
|
/**
|
|
26
31
|
* The realtime service.
|
|
27
32
|
*/
|
|
28
|
-
public realtime:
|
|
33
|
+
public realtime: RealtimeTranscriberFactory;
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* Create a new AssemblyAI client.
|
|
@@ -38,13 +43,15 @@ class AssemblyAI {
|
|
|
38
43
|
this.files = new FileService(params);
|
|
39
44
|
this.transcripts = new TranscriptService(params, this.files);
|
|
40
45
|
this.lemur = new LemurService(params);
|
|
41
|
-
this.realtime = new
|
|
46
|
+
this.realtime = new RealtimeTranscriberFactory(params);
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export {
|
|
46
51
|
AssemblyAI,
|
|
47
52
|
LemurService,
|
|
53
|
+
RealtimeTranscriberFactory,
|
|
54
|
+
RealtimeTranscriber,
|
|
48
55
|
RealtimeServiceFactory,
|
|
49
56
|
RealtimeService,
|
|
50
57
|
TranscriptService,
|
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseServiceParams,
|
|
3
3
|
RealtimeTokenParams,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
CreateRealtimeTranscriberParams,
|
|
5
|
+
RealtimeTranscriberParams,
|
|
6
6
|
RealtimeTemporaryTokenResponse,
|
|
7
|
+
CreateRealtimeServiceParams,
|
|
7
8
|
} from "../..";
|
|
8
|
-
import { RealtimeService } from "./service";
|
|
9
|
+
import { RealtimeService, RealtimeTranscriber } from "./service";
|
|
9
10
|
import { BaseService } from "../base";
|
|
10
11
|
|
|
11
|
-
export class
|
|
12
|
+
export class RealtimeTranscriberFactory extends BaseService {
|
|
12
13
|
private rtFactoryParams: BaseServiceParams;
|
|
13
14
|
constructor(params: BaseServiceParams) {
|
|
14
15
|
super(params);
|
|
15
16
|
this.rtFactoryParams = params;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use transcriber(...) instead
|
|
21
|
+
*/
|
|
18
22
|
createService(params?: CreateRealtimeServiceParams): RealtimeService {
|
|
23
|
+
return this.transcriber(params);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
transcriber(params?: CreateRealtimeTranscriberParams): RealtimeTranscriber {
|
|
19
27
|
const serviceParams = { ...params } as Record<string, unknown>;
|
|
20
28
|
if (!serviceParams.token && !serviceParams.apiKey) {
|
|
21
29
|
serviceParams.apiKey = this.rtFactoryParams.apiKey;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
return new
|
|
32
|
+
return new RealtimeTranscriber(serviceParams as RealtimeTranscriberParams);
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
async createTemporaryToken(params: RealtimeTokenParams) {
|
|
@@ -35,3 +43,8 @@ export class RealtimeServiceFactory extends BaseService {
|
|
|
35
43
|
return data.token;
|
|
36
44
|
}
|
|
37
45
|
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use RealtimeTranscriberFactory instead
|
|
49
|
+
*/
|
|
50
|
+
export class RealtimeServiceFactory extends RealtimeTranscriberFactory {}
|
|
@@ -4,13 +4,14 @@ import { ErrorEvent, MessageEvent, CloseEvent } from "ws";
|
|
|
4
4
|
import {
|
|
5
5
|
RealtimeEvents,
|
|
6
6
|
RealtimeListeners,
|
|
7
|
-
|
|
7
|
+
RealtimeTranscriberParams,
|
|
8
8
|
RealtimeMessage,
|
|
9
9
|
RealtimeTranscript,
|
|
10
10
|
PartialTranscript,
|
|
11
11
|
FinalTranscript,
|
|
12
12
|
SessionBeginsEventData,
|
|
13
13
|
AudioEncoding,
|
|
14
|
+
AudioData,
|
|
14
15
|
} from "../..";
|
|
15
16
|
import {
|
|
16
17
|
RealtimeError,
|
|
@@ -20,7 +21,7 @@ import {
|
|
|
20
21
|
|
|
21
22
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
22
23
|
|
|
23
|
-
export class
|
|
24
|
+
export class RealtimeTranscriber {
|
|
24
25
|
private realtimeUrl: string;
|
|
25
26
|
private sampleRate: number;
|
|
26
27
|
private wordBoost?: string[];
|
|
@@ -31,7 +32,7 @@ export class RealtimeService {
|
|
|
31
32
|
private listeners: RealtimeListeners = {};
|
|
32
33
|
private sessionTerminatedResolve?: () => void;
|
|
33
34
|
|
|
34
|
-
constructor(params:
|
|
35
|
+
constructor(params: RealtimeTranscriberParams) {
|
|
35
36
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
36
37
|
this.sampleRate = params.sampleRate ?? 16_000;
|
|
37
38
|
this.wordBoost = params.wordBoost;
|
|
@@ -157,16 +158,16 @@ export class RealtimeService {
|
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
sendAudio(audio:
|
|
161
|
+
sendAudio(audio: AudioData) {
|
|
161
162
|
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
|
|
162
163
|
throw new Error("Socket is not open for communication");
|
|
163
164
|
}
|
|
164
165
|
this.socket.send(audio);
|
|
165
166
|
}
|
|
166
167
|
|
|
167
|
-
stream(): WritableStream<
|
|
168
|
-
return new WritableStream<
|
|
169
|
-
write: (chunk:
|
|
168
|
+
stream(): WritableStream<AudioData> {
|
|
169
|
+
return new WritableStream<AudioData>({
|
|
170
|
+
write: (chunk: AudioData) => {
|
|
170
171
|
this.sendAudio(chunk);
|
|
171
172
|
},
|
|
172
173
|
});
|
|
@@ -194,3 +195,8 @@ export class RealtimeService {
|
|
|
194
195
|
this.socket = undefined;
|
|
195
196
|
}
|
|
196
197
|
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @deprecated Use RealtimeTranscriber instead
|
|
201
|
+
*/
|
|
202
|
+
export class RealtimeService extends RealtimeTranscriber {}
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
SubmitParams,
|
|
22
22
|
} from "../..";
|
|
23
23
|
import { FileService } from "../files";
|
|
24
|
+
import { getPath } from "../../utils/path";
|
|
24
25
|
|
|
25
26
|
export class TranscriptService
|
|
26
27
|
extends BaseService
|
|
@@ -249,14 +250,3 @@ export class TranscriptService
|
|
|
249
250
|
);
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
|
-
|
|
253
|
-
function getPath(path: string) {
|
|
254
|
-
let url: URL;
|
|
255
|
-
try {
|
|
256
|
-
url = new URL(path);
|
|
257
|
-
if (url.protocol === "file:") return url.pathname;
|
|
258
|
-
else return null;
|
|
259
|
-
} catch {
|
|
260
|
-
return path;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
@@ -15,10 +15,11 @@ type OneOf<T extends any[]> = T extends [infer Only]
|
|
|
15
15
|
? OneOf<[XOR<A, B>, ...Rest]>
|
|
16
16
|
: never;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Format: binary
|
|
20
|
+
* @description Binary audio data
|
|
21
|
+
*/
|
|
22
|
+
export type AudioData = ArrayBufferLike;
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @description The encoding of the audio data
|