assemblyai 4.3.3 → 4.4.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/CHANGELOG.md +34 -0
- package/README.md +12 -7
- package/dist/assemblyai.umd.js +24 -2
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/bun.mjs +22 -0
- package/dist/deno.mjs +22 -0
- package/dist/index.cjs +24 -2
- package/dist/index.mjs +24 -2
- package/dist/node.cjs +22 -0
- package/dist/node.mjs +22 -0
- package/dist/services/realtime/service.d.ts +4 -1
- package/dist/types/asyncapi.generated.d.ts +36 -3
- package/dist/types/openapi.generated.d.ts +121 -31
- package/dist/types/realtime/index.d.ts +27 -2
- package/package.json +8 -4
- package/src/services/realtime/service.ts +26 -0
- package/src/services/transcripts/index.ts +13 -0
- package/src/types/asyncapi.generated.ts +37 -1
- package/src/types/openapi.generated.ts +121 -31
- package/src/types/realtime/index.ts +27 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData } from "../..";
|
|
1
|
+
import { RealtimeTranscriberParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData, AudioData, SessionInformation } from "../..";
|
|
2
2
|
export declare class RealtimeTranscriber {
|
|
3
3
|
private realtimeUrl;
|
|
4
4
|
private sampleRate;
|
|
@@ -7,6 +7,8 @@ export declare class RealtimeTranscriber {
|
|
|
7
7
|
private apiKey?;
|
|
8
8
|
private token?;
|
|
9
9
|
private endUtteranceSilenceThreshold?;
|
|
10
|
+
private enableExtraSessionInformation?;
|
|
11
|
+
private disablePartialTranscripts?;
|
|
10
12
|
private socket?;
|
|
11
13
|
private listeners;
|
|
12
14
|
private sessionTerminatedResolve?;
|
|
@@ -16,6 +18,7 @@ export declare class RealtimeTranscriber {
|
|
|
16
18
|
on(event: "transcript", listener: (transcript: RealtimeTranscript) => void): void;
|
|
17
19
|
on(event: "transcript.partial", listener: (transcript: PartialTranscript) => void): void;
|
|
18
20
|
on(event: "transcript.final", listener: (transcript: FinalTranscript) => void): void;
|
|
21
|
+
on(event: "session_information", listener: (info: SessionInformation) => void): void;
|
|
19
22
|
on(event: "error", listener: (error: Error) => void): void;
|
|
20
23
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
21
24
|
connect(): Promise<SessionBeginsEventData>;
|
|
@@ -16,6 +16,9 @@ export type ConfigureEndUtteranceSilenceThreshold = {
|
|
|
16
16
|
*/
|
|
17
17
|
end_utterance_silence_threshold: number;
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Transcript text at the end of an utterance with punctuation and casing.
|
|
21
|
+
*/
|
|
19
22
|
export type FinalTranscript = RealtimeBaseTranscript & {
|
|
20
23
|
/**
|
|
21
24
|
* Describes the type of message
|
|
@@ -39,7 +42,10 @@ export type ForceEndUtterance = {
|
|
|
39
42
|
*/
|
|
40
43
|
force_end_utterance: boolean;
|
|
41
44
|
};
|
|
42
|
-
export type MessageType = "SessionBegins" | "PartialTranscript" | "FinalTranscript" | "SessionTerminated";
|
|
45
|
+
export type MessageType = "SessionBegins" | "PartialTranscript" | "FinalTranscript" | "SessionInformation" | "SessionTerminated";
|
|
46
|
+
/**
|
|
47
|
+
* As you send audio data to the API, the API immediately starts responding with Partial Transcript results.
|
|
48
|
+
*/
|
|
43
49
|
export type PartialTranscript = RealtimeBaseTranscript & {
|
|
44
50
|
/**
|
|
45
51
|
* Describes the type of message
|
|
@@ -79,12 +85,18 @@ export type RealtimeBaseTranscript = {
|
|
|
79
85
|
*/
|
|
80
86
|
words: Word[];
|
|
81
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Error message
|
|
90
|
+
*/
|
|
82
91
|
export type RealtimeError = {
|
|
83
92
|
error: string;
|
|
84
93
|
};
|
|
85
|
-
export type RealtimeMessage = SessionBegins | PartialTranscript | FinalTranscript | SessionTerminated | RealtimeError;
|
|
94
|
+
export type RealtimeMessage = SessionBegins | PartialTranscript | FinalTranscript | SessionInformation | SessionTerminated | RealtimeError;
|
|
86
95
|
export type RealtimeTranscript = PartialTranscript | FinalTranscript;
|
|
87
96
|
export type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript";
|
|
97
|
+
/**
|
|
98
|
+
* Session start
|
|
99
|
+
*/
|
|
88
100
|
export type SessionBegins = RealtimeBaseMessage & {
|
|
89
101
|
/**
|
|
90
102
|
* Timestamp when this session will expire
|
|
@@ -99,15 +111,36 @@ export type SessionBegins = RealtimeBaseMessage & {
|
|
|
99
111
|
*/
|
|
100
112
|
session_id: string;
|
|
101
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Information about the session
|
|
116
|
+
* Information about the session that is concluding.
|
|
117
|
+
* This message is sent at the end of the session, before the SessionTerminated message.
|
|
118
|
+
*/
|
|
119
|
+
export type SessionInformation = RealtimeBaseMessage & {
|
|
120
|
+
/**
|
|
121
|
+
* The total duration of the audio in seconds
|
|
122
|
+
*/
|
|
123
|
+
audio_duration_seconds: number;
|
|
124
|
+
/**
|
|
125
|
+
* Describes the type of the message
|
|
126
|
+
*/
|
|
127
|
+
message_type: "SessionInformation";
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Session terminated
|
|
131
|
+
*/
|
|
102
132
|
export type SessionTerminated = RealtimeBaseMessage & {
|
|
103
133
|
/**
|
|
104
134
|
* Describes the type of the message
|
|
105
135
|
*/
|
|
106
136
|
message_type: "SessionTerminated";
|
|
107
137
|
};
|
|
138
|
+
/**
|
|
139
|
+
* Terminate session
|
|
140
|
+
*/
|
|
108
141
|
export type TerminateSession = {
|
|
109
142
|
/**
|
|
110
|
-
* Set to true to end your
|
|
143
|
+
* Set to true to end your streaming session forever
|
|
111
144
|
*/
|
|
112
145
|
terminate_session: boolean;
|
|
113
146
|
};
|
|
@@ -258,6 +258,10 @@ export type AutoHighlightsResult = {
|
|
|
258
258
|
* A temporally-sequential array of Key Phrases
|
|
259
259
|
*/
|
|
260
260
|
results: AutoHighlightResult[];
|
|
261
|
+
/**
|
|
262
|
+
* The status of the Key Phrases model. Either success, or unavailable in the rare case that the model failed.
|
|
263
|
+
*/
|
|
264
|
+
status: AudioIntelligenceModelStatus;
|
|
261
265
|
};
|
|
262
266
|
/**
|
|
263
267
|
* Chapter of the audio file
|
|
@@ -532,7 +536,8 @@ export type LemurActionItemsResponse = LemurBaseResponse & {
|
|
|
532
536
|
* ```js
|
|
533
537
|
* {
|
|
534
538
|
* "transcript_ids": [
|
|
535
|
-
* "
|
|
539
|
+
* "85f9b381-e90c-46ed-beca-7d76245d375e",
|
|
540
|
+
* "7c3acd18-df4d-4432-88f5-1e89f8827eea"
|
|
536
541
|
* ],
|
|
537
542
|
* "context": "This is an interview about wildfires.",
|
|
538
543
|
* "final_model": "default",
|
|
@@ -761,12 +766,12 @@ export type LemurSummaryResponse = LemurBaseResponse & {
|
|
|
761
766
|
* }
|
|
762
767
|
* ```
|
|
763
768
|
*/
|
|
764
|
-
export type LemurTaskParams =
|
|
769
|
+
export type LemurTaskParams = {
|
|
765
770
|
/**
|
|
766
771
|
* Your text to prompt the model to produce a desired output, including any context you want to pass into the model.
|
|
767
772
|
*/
|
|
768
773
|
prompt: string;
|
|
769
|
-
};
|
|
774
|
+
} & LemurBaseParams;
|
|
770
775
|
/**
|
|
771
776
|
* @example
|
|
772
777
|
* ```js
|
|
@@ -776,12 +781,12 @@ export type LemurTaskParams = LemurBaseParams & {
|
|
|
776
781
|
* }
|
|
777
782
|
* ```
|
|
778
783
|
*/
|
|
779
|
-
export type LemurTaskResponse =
|
|
784
|
+
export type LemurTaskResponse = {
|
|
780
785
|
/**
|
|
781
786
|
* The response generated by LeMUR.
|
|
782
787
|
*/
|
|
783
788
|
response: string;
|
|
784
|
-
};
|
|
789
|
+
} & LemurBaseResponse;
|
|
785
790
|
/**
|
|
786
791
|
* @example
|
|
787
792
|
* ```js
|
|
@@ -823,6 +828,8 @@ export type ListTranscriptParams = {
|
|
|
823
828
|
throttled_only?: boolean;
|
|
824
829
|
};
|
|
825
830
|
/**
|
|
831
|
+
* Details of the transcript page.
|
|
832
|
+
* Details of the transcript page. Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts.
|
|
826
833
|
* @example
|
|
827
834
|
* ```js
|
|
828
835
|
* {
|
|
@@ -835,10 +842,27 @@ export type ListTranscriptParams = {
|
|
|
835
842
|
* ```
|
|
836
843
|
*/
|
|
837
844
|
export type PageDetails = {
|
|
845
|
+
/**
|
|
846
|
+
* The URL used to retrieve the current page of transcripts
|
|
847
|
+
*/
|
|
838
848
|
current_url: string;
|
|
849
|
+
/**
|
|
850
|
+
* The number of results this page is limited to
|
|
851
|
+
*/
|
|
839
852
|
limit: number;
|
|
840
|
-
|
|
841
|
-
|
|
853
|
+
/**
|
|
854
|
+
* The URL to the next page of transcripts
|
|
855
|
+
* The URL to the next page of transcripts. The next URL always points to a page with newer transcripts.
|
|
856
|
+
*/
|
|
857
|
+
next_url: string | null;
|
|
858
|
+
/**
|
|
859
|
+
* The URL to the previous page of transcripts
|
|
860
|
+
* The URL to the next page of transcripts. The previous URL always points to a page with older transcripts.
|
|
861
|
+
*/
|
|
862
|
+
prev_url: string | null;
|
|
863
|
+
/**
|
|
864
|
+
* The actual number of results in the page
|
|
865
|
+
*/
|
|
842
866
|
result_count: number;
|
|
843
867
|
};
|
|
844
868
|
/**
|
|
@@ -959,7 +983,7 @@ export type PurgeLemurRequestDataResponse = {
|
|
|
959
983
|
*/
|
|
960
984
|
export type RealtimeTemporaryTokenResponse = {
|
|
961
985
|
/**
|
|
962
|
-
* The temporary authentication token for
|
|
986
|
+
* The temporary authentication token for Streaming Speech-to-Text
|
|
963
987
|
*/
|
|
964
988
|
token: string;
|
|
965
989
|
};
|
|
@@ -1157,11 +1181,11 @@ export type SeverityScoreSummary = {
|
|
|
1157
1181
|
/**
|
|
1158
1182
|
* The speech model to use for the transcription.
|
|
1159
1183
|
*/
|
|
1160
|
-
export type SpeechModel = "nano" | "conformer-2";
|
|
1184
|
+
export type SpeechModel = "best" | "nano" | "conformer-2";
|
|
1161
1185
|
/**
|
|
1162
|
-
* The replacement logic for detected PII, can be "
|
|
1186
|
+
* The replacement logic for detected PII, can be "entity_name" or "hash". See {@link https://www.assemblyai.com/docs/models/pii-redaction | PII redaction } for more details.
|
|
1163
1187
|
*/
|
|
1164
|
-
export type SubstitutionPolicy = "
|
|
1188
|
+
export type SubstitutionPolicy = "entity_name" | "hash";
|
|
1165
1189
|
/**
|
|
1166
1190
|
* Format of the subtitles
|
|
1167
1191
|
*/
|
|
@@ -1609,7 +1633,7 @@ export type TopicDetectionResult = {
|
|
|
1609
1633
|
* "punctuate": true,
|
|
1610
1634
|
* "format_text": true,
|
|
1611
1635
|
* "dual_channel": false,
|
|
1612
|
-
* "webhook_url": "https://your-webhook-url/path",
|
|
1636
|
+
* "webhook_url": "https://your-webhook-url.tld/path",
|
|
1613
1637
|
* "webhook_status_code": 200,
|
|
1614
1638
|
* "webhook_auth": true,
|
|
1615
1639
|
* "webhook_auth_header_name": "webhook-secret",
|
|
@@ -2336,32 +2360,45 @@ export type TranscriptCustomSpelling = {
|
|
|
2336
2360
|
*/
|
|
2337
2361
|
export type TranscriptLanguageCode = "en" | "en_au" | "en_uk" | "en_us" | "es" | "fr" | "de" | "it" | "pt" | "nl" | "hi" | "ja" | "zh" | "fi" | "ko" | "pl" | "ru" | "tr" | "uk" | "vi";
|
|
2338
2362
|
/**
|
|
2363
|
+
* A list of transcripts
|
|
2364
|
+
* A list of transcripts. Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts.
|
|
2339
2365
|
* @example
|
|
2340
2366
|
* ```js
|
|
2341
2367
|
* {
|
|
2342
2368
|
* "page_details": {
|
|
2343
|
-
* "limit":
|
|
2344
|
-
* "result_count":
|
|
2345
|
-
* "current_url": "https://api.assemblyai.com/v2/transcript?limit=
|
|
2346
|
-
* "prev_url": "https://api.assemblyai.com/v2/transcript?limit=
|
|
2347
|
-
* "next_url": "https://api.assemblyai.com/v2/transcript?limit=
|
|
2369
|
+
* "limit": 3",
|
|
2370
|
+
* "result_count": 3,
|
|
2371
|
+
* "current_url": "https://api.assemblyai.com/v2/transcript?limit=3",
|
|
2372
|
+
* "prev_url": "https://api.assemblyai.com/v2/transcript?limit=3&before_id=28a73d01-98db-41dd-9e98-2533ba0af117",
|
|
2373
|
+
* "next_url": "https://api.assemblyai.com/v2/transcript?limit=3&after_id=b33f4691-85b7-4f31-be12-a87cef1c1229"
|
|
2348
2374
|
* },
|
|
2349
2375
|
* "transcripts": [
|
|
2350
2376
|
* {
|
|
2351
|
-
* "id": "
|
|
2352
|
-
* "resource_url": "https://api.assemblyai.com/v2/transcript/
|
|
2377
|
+
* "id": "b33f4691-85b7-4f31-be12-a87cef1c1229",
|
|
2378
|
+
* "resource_url": "https://api.assemblyai.com/v2/transcript/b33f4691-85b7-4f31-be12-a87cef1c1229",
|
|
2353
2379
|
* "status": "completed",
|
|
2354
|
-
* "created": "
|
|
2355
|
-
* "completed": "
|
|
2356
|
-
* "audio_url": "
|
|
2380
|
+
* "created": "2024-03-11T21:29:59.936851",
|
|
2381
|
+
* "completed": "2024-03-11T21:30:07.314223",
|
|
2382
|
+
* "audio_url": "http://deleted_by_user",
|
|
2383
|
+
* "error": null
|
|
2384
|
+
* },
|
|
2385
|
+
* {
|
|
2386
|
+
* "id": "ce522f10-d204-42e8-a838-6b95098145cc",
|
|
2387
|
+
* "resource_url": "https://api.assemblyai.com/v2/transcript/ce522f10-d204-42e8-a838-6b95098145cc",
|
|
2388
|
+
* "status": "error",
|
|
2389
|
+
* "created": "2024-03-11T21:23:59.979420",
|
|
2390
|
+
* "completed": null,
|
|
2391
|
+
* "audio_url": "https://storage.googleapis.com/client-docs-samples/nbc.mp3",
|
|
2392
|
+
* "error": "Download error, unable to download https://storage.googleapis.com/client-docs-samples/nbc.mp3. Please make sure the file exists and is accessible from the internet."
|
|
2357
2393
|
* },
|
|
2358
2394
|
* {
|
|
2359
|
-
* "id": "
|
|
2360
|
-
* "resource_url": "https://api.assemblyai.com/v2/transcript/
|
|
2395
|
+
* "id": "28a73d01-98db-41dd-9e98-2533ba0af117",
|
|
2396
|
+
* "resource_url": "https://api.assemblyai.com/v2/transcript/28a73d01-98db-41dd-9e98-2533ba0af117",
|
|
2361
2397
|
* "status": "completed",
|
|
2362
|
-
* "created": "
|
|
2363
|
-
* "completed": "
|
|
2364
|
-
* "audio_url": "
|
|
2398
|
+
* "created": "2024-03-11T21:12:57.372215",
|
|
2399
|
+
* "completed": "2024-03-11T21:13:03.267020",
|
|
2400
|
+
* "audio_url": "https://storage.googleapis.com/aai-docs-samples/nbc.mp3",
|
|
2401
|
+
* "error": null
|
|
2365
2402
|
* }
|
|
2366
2403
|
* ]
|
|
2367
2404
|
* }
|
|
@@ -2380,7 +2417,8 @@ export type TranscriptList = {
|
|
|
2380
2417
|
* "status": "completed",
|
|
2381
2418
|
* "created": "2023-11-02T21:49:25.586965",
|
|
2382
2419
|
* "completed": "2023-11-02T21:49:25.586965",
|
|
2383
|
-
* "audio_url": "https://github.com/AssemblyAI-Examples/audio-examples/raw/main/20230607_me_canadian_wildfires.mp3"
|
|
2420
|
+
* "audio_url": "https://github.com/AssemblyAI-Examples/audio-examples/raw/main/20230607_me_canadian_wildfires.mp3",
|
|
2421
|
+
* "error": null
|
|
2384
2422
|
* }
|
|
2385
2423
|
* ```
|
|
2386
2424
|
*/
|
|
@@ -2388,6 +2426,10 @@ export type TranscriptListItem = {
|
|
|
2388
2426
|
audio_url: string;
|
|
2389
2427
|
completed: Date | null;
|
|
2390
2428
|
created: Date;
|
|
2429
|
+
/**
|
|
2430
|
+
* Error message of why the transcript failed
|
|
2431
|
+
*/
|
|
2432
|
+
error: string | null;
|
|
2391
2433
|
id: string;
|
|
2392
2434
|
resource_url: string;
|
|
2393
2435
|
status: TranscriptStatus;
|
|
@@ -2402,7 +2444,7 @@ export type TranscriptListItem = {
|
|
|
2402
2444
|
* "punctuate": true,
|
|
2403
2445
|
* "format_text": true,
|
|
2404
2446
|
* "dual_channel": true,
|
|
2405
|
-
* "webhook_url": "https://your-webhook-url/path",
|
|
2447
|
+
* "webhook_url": "https://your-webhook-url.tld/path",
|
|
2406
2448
|
* "webhook_auth_header_name": "webhook-secret",
|
|
2407
2449
|
* "webhook_auth_header_value": "webhook-secret-value",
|
|
2408
2450
|
* "auto_highlights": true,
|
|
@@ -2653,13 +2695,61 @@ export type TranscriptParagraph = {
|
|
|
2653
2695
|
};
|
|
2654
2696
|
/**
|
|
2655
2697
|
* The parameters for creating a transcript
|
|
2698
|
+
* @example
|
|
2699
|
+
* ```js
|
|
2700
|
+
* {
|
|
2701
|
+
* "speech_model": null,
|
|
2702
|
+
* "language_code": "en_us",
|
|
2703
|
+
* "audio_url": "https://github.com/AssemblyAI-Examples/audio-examples/raw/main/20230607_me_canadian_wildfires.mp3",
|
|
2704
|
+
* "punctuate": true,
|
|
2705
|
+
* "format_text": true,
|
|
2706
|
+
* "dual_channel": true,
|
|
2707
|
+
* "webhook_url": "https://your-webhook-url/path",
|
|
2708
|
+
* "webhook_auth_header_name": "webhook-secret",
|
|
2709
|
+
* "webhook_auth_header_value": "webhook-secret-value",
|
|
2710
|
+
* "auto_highlights": true,
|
|
2711
|
+
* "audio_start_from": 10,
|
|
2712
|
+
* "audio_end_at": 280,
|
|
2713
|
+
* "word_boost": [
|
|
2714
|
+
* "aws",
|
|
2715
|
+
* "azure",
|
|
2716
|
+
* "google cloud"
|
|
2717
|
+
* ],
|
|
2718
|
+
* "boost_param": "high",
|
|
2719
|
+
* "filter_profanity": true,
|
|
2720
|
+
* "redact_pii": true,
|
|
2721
|
+
* "redact_pii_audio": true,
|
|
2722
|
+
* "redact_pii_audio_quality": "mp3",
|
|
2723
|
+
* "redact_pii_policies": [
|
|
2724
|
+
* "us_social_security_number",
|
|
2725
|
+
* "credit_card_number"
|
|
2726
|
+
* ],
|
|
2727
|
+
* "redact_pii_sub": "hash",
|
|
2728
|
+
* "speaker_labels": true,
|
|
2729
|
+
* "speakers_expected": 2,
|
|
2730
|
+
* "content_safety": true,
|
|
2731
|
+
* "iab_categories": true,
|
|
2732
|
+
* "language_detection": false,
|
|
2733
|
+
* "custom_spelling": [],
|
|
2734
|
+
* "disfluencies": false,
|
|
2735
|
+
* "sentiment_analysis": true,
|
|
2736
|
+
* "auto_chapters": true,
|
|
2737
|
+
* "entity_detection": true,
|
|
2738
|
+
* "speech_threshold": 0.5,
|
|
2739
|
+
* "summarization": true,
|
|
2740
|
+
* "summary_model": "informative",
|
|
2741
|
+
* "summary_type": "bullets",
|
|
2742
|
+
* "custom_topics": true,
|
|
2743
|
+
* "topics": []
|
|
2744
|
+
* }
|
|
2745
|
+
* ```
|
|
2656
2746
|
*/
|
|
2657
|
-
export type TranscriptParams =
|
|
2747
|
+
export type TranscriptParams = {
|
|
2658
2748
|
/**
|
|
2659
2749
|
* The URL of the audio or video file to transcribe.
|
|
2660
2750
|
*/
|
|
2661
2751
|
audio_url: string;
|
|
2662
|
-
};
|
|
2752
|
+
} & TranscriptOptionalParams;
|
|
2663
2753
|
/**
|
|
2664
2754
|
* The notification when the transcript status is completed or error.
|
|
2665
2755
|
* @example
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AudioEncoding, FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType } from "../asyncapi.generated";
|
|
1
|
+
import { AudioEncoding, FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType, SessionInformation } from "../asyncapi.generated";
|
|
2
2
|
type CreateRealtimeTranscriberParams = {
|
|
3
3
|
/**
|
|
4
4
|
* The WebSocket URL that the RealtimeTranscriber connects to
|
|
@@ -20,6 +20,18 @@ type CreateRealtimeTranscriberParams = {
|
|
|
20
20
|
* The duration of the end utterance silence threshold in milliseconds
|
|
21
21
|
*/
|
|
22
22
|
endUtteranceSilenceThreshold?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Disable partial transcripts.
|
|
25
|
+
* Set to `true` to not receive partial transcripts. Defaults to `false`.
|
|
26
|
+
* @defaultValue false
|
|
27
|
+
*/
|
|
28
|
+
disablePartialTranscripts?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Enable extra session information.
|
|
31
|
+
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
|
|
32
|
+
* @defaultValue false
|
|
33
|
+
*/
|
|
34
|
+
enableExtraSessionInformation?: boolean;
|
|
23
35
|
} & ({
|
|
24
36
|
/**
|
|
25
37
|
* The API key used to authenticate the RealtimeTranscriber
|
|
@@ -57,6 +69,18 @@ type RealtimeTranscriberParams = {
|
|
|
57
69
|
* The duration of the end utterance silence threshold in milliseconds
|
|
58
70
|
*/
|
|
59
71
|
endUtteranceSilenceThreshold?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Disable partial transcripts.
|
|
74
|
+
* Set to `true` to not receive partial transcripts. Defaults to `false`.
|
|
75
|
+
* @defaultValue false
|
|
76
|
+
*/
|
|
77
|
+
disablePartialTranscripts?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Enable extra session information.
|
|
80
|
+
* Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
|
|
81
|
+
* @defaultValue false
|
|
82
|
+
*/
|
|
83
|
+
enableExtraSessionInformation?: boolean;
|
|
60
84
|
} & ({
|
|
61
85
|
/**
|
|
62
86
|
* The API key used to authenticate the RealtimeTranscriber.
|
|
@@ -73,7 +97,7 @@ type RealtimeTranscriberParams = {
|
|
|
73
97
|
* @deprecated Use RealtimeTranscriberParams instead
|
|
74
98
|
*/
|
|
75
99
|
type RealtimeServiceParams = RealtimeTranscriberParams;
|
|
76
|
-
type RealtimeEvents = "open" | "close" | "transcript" | "transcript.partial" | "transcript.final" | "error";
|
|
100
|
+
type RealtimeEvents = "open" | "close" | "transcript" | "transcript.partial" | "transcript.final" | "session_information" | "error";
|
|
77
101
|
type SessionBeginsEventData = {
|
|
78
102
|
sessionId: string;
|
|
79
103
|
expiresAt: Date;
|
|
@@ -84,6 +108,7 @@ type RealtimeListeners = {
|
|
|
84
108
|
transcript?: (transcript: RealtimeTranscript) => void;
|
|
85
109
|
"transcript.partial"?: (transcript: PartialTranscript) => void;
|
|
86
110
|
"transcript.final"?: (transcript: FinalTranscript) => void;
|
|
111
|
+
session_information?: (info: SessionInformation) => void;
|
|
87
112
|
error?: (error: Error) => void;
|
|
88
113
|
};
|
|
89
114
|
type RealtimeTokenParams = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
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"
|
|
@@ -69,9 +69,12 @@
|
|
|
69
69
|
"build": "pnpm clean && pnpm rollup -c",
|
|
70
70
|
"clean": "rimraf dist/* && rimraf temp/* && rimraf temp-docs/*",
|
|
71
71
|
"lint": "eslint -c .eslintrc.json '{src,tests}/**/*.{js,ts}' && publint && tsc --noEmit -p tsconfig.json",
|
|
72
|
-
"test": "
|
|
72
|
+
"test": "pnpm run test:unit && pnpm run test:integration",
|
|
73
|
+
"test:unit": "jest --config jest.unit.config.js",
|
|
74
|
+
"test:integration": "jest --config jest.integration.config.js --testTimeout 360000",
|
|
73
75
|
"format": "prettier '**/*' --write",
|
|
74
|
-
"generate
|
|
76
|
+
"generate:types": "tsx ./scripts/generate-types.ts && prettier 'src/types/*.generated.ts' --write",
|
|
77
|
+
"generate:reference": "typedoc",
|
|
75
78
|
"copybara:dry-run": "./copybara.sh dry_run --init-history",
|
|
76
79
|
"copybara:pr": "./copybara.sh sync_out --init-history"
|
|
77
80
|
},
|
|
@@ -125,7 +128,8 @@
|
|
|
125
128
|
"ts-jest": "^29.1.2",
|
|
126
129
|
"tslib": "^2.5.3",
|
|
127
130
|
"typescript": "^5.4.2",
|
|
128
|
-
"typedoc": "^0.25.12"
|
|
131
|
+
"typedoc": "^0.25.12",
|
|
132
|
+
"typedoc-plugin-extras": "^3.0.0"
|
|
129
133
|
},
|
|
130
134
|
"dependencies": {
|
|
131
135
|
"ws": "^8.16.0"
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
SessionBeginsEventData,
|
|
13
13
|
AudioEncoding,
|
|
14
14
|
AudioData,
|
|
15
|
+
SessionInformation,
|
|
15
16
|
} from "../..";
|
|
16
17
|
import {
|
|
17
18
|
RealtimeError,
|
|
@@ -49,6 +50,9 @@ export class RealtimeTranscriber {
|
|
|
49
50
|
private apiKey?: string;
|
|
50
51
|
private token?: string;
|
|
51
52
|
private endUtteranceSilenceThreshold?: number;
|
|
53
|
+
private enableExtraSessionInformation?: boolean;
|
|
54
|
+
private disablePartialTranscripts?: boolean;
|
|
55
|
+
|
|
52
56
|
private socket?: WebSocket;
|
|
53
57
|
private listeners: RealtimeListeners = {};
|
|
54
58
|
private sessionTerminatedResolve?: () => void;
|
|
@@ -59,6 +63,8 @@ export class RealtimeTranscriber {
|
|
|
59
63
|
this.wordBoost = params.wordBoost;
|
|
60
64
|
this.encoding = params.encoding;
|
|
61
65
|
this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
|
|
66
|
+
this.enableExtraSessionInformation = params.enableExtraSessionInformation;
|
|
67
|
+
this.disablePartialTranscripts = params.disablePartialTranscripts;
|
|
62
68
|
if ("token" in params && params.token) this.token = params.token;
|
|
63
69
|
if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
|
|
64
70
|
|
|
@@ -85,6 +91,18 @@ export class RealtimeTranscriber {
|
|
|
85
91
|
if (this.encoding) {
|
|
86
92
|
searchParams.set("encoding", this.encoding);
|
|
87
93
|
}
|
|
94
|
+
if (this.enableExtraSessionInformation) {
|
|
95
|
+
searchParams.set(
|
|
96
|
+
"enable_extra_session_information",
|
|
97
|
+
this.enableExtraSessionInformation.toString(),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (this.disablePartialTranscripts) {
|
|
101
|
+
searchParams.set(
|
|
102
|
+
"disable_partial_transcripts",
|
|
103
|
+
this.disablePartialTranscripts.toString(),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
88
106
|
url.search = searchParams.toString();
|
|
89
107
|
|
|
90
108
|
return url;
|
|
@@ -103,6 +121,10 @@ export class RealtimeTranscriber {
|
|
|
103
121
|
event: "transcript.final",
|
|
104
122
|
listener: (transcript: FinalTranscript) => void,
|
|
105
123
|
): void;
|
|
124
|
+
on(
|
|
125
|
+
event: "session_information",
|
|
126
|
+
listener: (info: SessionInformation) => void,
|
|
127
|
+
): void;
|
|
106
128
|
on(event: "error", listener: (error: Error) => void): void;
|
|
107
129
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
108
130
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -183,6 +205,10 @@ export class RealtimeTranscriber {
|
|
|
183
205
|
this.listeners["transcript.final"]?.(message);
|
|
184
206
|
break;
|
|
185
207
|
}
|
|
208
|
+
case "SessionInformation": {
|
|
209
|
+
this.listeners.session_information?.(message);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
186
212
|
case "SessionTerminated": {
|
|
187
213
|
this.sessionTerminatedResolve?.();
|
|
188
214
|
break;
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
TranscribeParams,
|
|
16
16
|
TranscribeOptions,
|
|
17
17
|
SubmitParams,
|
|
18
|
+
SpeechModel,
|
|
18
19
|
} from "../..";
|
|
19
20
|
import { FileService } from "../files";
|
|
20
21
|
import { getPath } from "../../utils/path";
|
|
@@ -37,6 +38,7 @@ export class TranscriptService extends BaseService {
|
|
|
37
38
|
params: TranscribeParams,
|
|
38
39
|
options?: TranscribeOptions,
|
|
39
40
|
): Promise<Transcript> {
|
|
41
|
+
deprecateConformer2(params);
|
|
40
42
|
const transcript = await this.submit(params);
|
|
41
43
|
return await this.waitUntilReady(transcript.id, options);
|
|
42
44
|
}
|
|
@@ -47,6 +49,7 @@ export class TranscriptService extends BaseService {
|
|
|
47
49
|
* @returns A promise that resolves to the queued transcript.
|
|
48
50
|
*/
|
|
49
51
|
async submit(params: SubmitParams): Promise<Transcript> {
|
|
52
|
+
deprecateConformer2(params);
|
|
50
53
|
let audioUrl;
|
|
51
54
|
let transcriptParams: TranscriptParams | undefined = undefined;
|
|
52
55
|
if ("audio" in params) {
|
|
@@ -87,6 +90,7 @@ export class TranscriptService extends BaseService {
|
|
|
87
90
|
params: TranscriptParams,
|
|
88
91
|
options?: CreateTranscriptOptions,
|
|
89
92
|
): Promise<Transcript> {
|
|
93
|
+
deprecateConformer2(params);
|
|
90
94
|
const path = getPath(params.audio_url);
|
|
91
95
|
if (path !== null) {
|
|
92
96
|
const uploadUrl = await this.files.upload(path);
|
|
@@ -246,3 +250,12 @@ export class TranscriptService extends BaseService {
|
|
|
246
250
|
);
|
|
247
251
|
}
|
|
248
252
|
}
|
|
253
|
+
|
|
254
|
+
function deprecateConformer2(params: { speech_model?: SpeechModel | null }) {
|
|
255
|
+
if (!params) return;
|
|
256
|
+
if (params.speech_model === "conformer-2") {
|
|
257
|
+
console.warn(
|
|
258
|
+
"The speech_model conformer-2 option is deprecated and will stop working in the near future. Use best or nano instead.",
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -37,6 +37,9 @@ export type ConfigureEndUtteranceSilenceThreshold = {
|
|
|
37
37
|
end_utterance_silence_threshold: number;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Transcript text at the end of an utterance with punctuation and casing.
|
|
42
|
+
*/
|
|
40
43
|
export type FinalTranscript = RealtimeBaseTranscript & {
|
|
41
44
|
/**
|
|
42
45
|
* Describes the type of message
|
|
@@ -66,8 +69,12 @@ export type MessageType =
|
|
|
66
69
|
| "SessionBegins"
|
|
67
70
|
| "PartialTranscript"
|
|
68
71
|
| "FinalTranscript"
|
|
72
|
+
| "SessionInformation"
|
|
69
73
|
| "SessionTerminated";
|
|
70
74
|
|
|
75
|
+
/**
|
|
76
|
+
* As you send audio data to the API, the API immediately starts responding with Partial Transcript results.
|
|
77
|
+
*/
|
|
71
78
|
export type PartialTranscript = RealtimeBaseTranscript & {
|
|
72
79
|
/**
|
|
73
80
|
* Describes the type of message
|
|
@@ -110,6 +117,9 @@ export type RealtimeBaseTranscript = {
|
|
|
110
117
|
words: Word[];
|
|
111
118
|
};
|
|
112
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Error message
|
|
122
|
+
*/
|
|
113
123
|
export type RealtimeError = {
|
|
114
124
|
error: string;
|
|
115
125
|
};
|
|
@@ -118,6 +128,7 @@ export type RealtimeMessage =
|
|
|
118
128
|
| SessionBegins
|
|
119
129
|
| PartialTranscript
|
|
120
130
|
| FinalTranscript
|
|
131
|
+
| SessionInformation
|
|
121
132
|
| SessionTerminated
|
|
122
133
|
| RealtimeError;
|
|
123
134
|
|
|
@@ -125,6 +136,9 @@ export type RealtimeTranscript = PartialTranscript | FinalTranscript;
|
|
|
125
136
|
|
|
126
137
|
export type RealtimeTranscriptType = "PartialTranscript" | "FinalTranscript";
|
|
127
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Session start
|
|
141
|
+
*/
|
|
128
142
|
export type SessionBegins = RealtimeBaseMessage & {
|
|
129
143
|
/**
|
|
130
144
|
* Timestamp when this session will expire
|
|
@@ -140,6 +154,25 @@ export type SessionBegins = RealtimeBaseMessage & {
|
|
|
140
154
|
session_id: string;
|
|
141
155
|
};
|
|
142
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Information about the session
|
|
159
|
+
* Information about the session that is concluding.
|
|
160
|
+
* This message is sent at the end of the session, before the SessionTerminated message.
|
|
161
|
+
*/
|
|
162
|
+
export type SessionInformation = RealtimeBaseMessage & {
|
|
163
|
+
/**
|
|
164
|
+
* The total duration of the audio in seconds
|
|
165
|
+
*/
|
|
166
|
+
audio_duration_seconds: number;
|
|
167
|
+
/**
|
|
168
|
+
* Describes the type of the message
|
|
169
|
+
*/
|
|
170
|
+
message_type: "SessionInformation";
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Session terminated
|
|
175
|
+
*/
|
|
143
176
|
export type SessionTerminated = RealtimeBaseMessage & {
|
|
144
177
|
/**
|
|
145
178
|
* Describes the type of the message
|
|
@@ -147,9 +180,12 @@ export type SessionTerminated = RealtimeBaseMessage & {
|
|
|
147
180
|
message_type: "SessionTerminated";
|
|
148
181
|
};
|
|
149
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Terminate session
|
|
185
|
+
*/
|
|
150
186
|
export type TerminateSession = {
|
|
151
187
|
/**
|
|
152
|
-
* Set to true to end your
|
|
188
|
+
* Set to true to end your streaming session forever
|
|
153
189
|
*/
|
|
154
190
|
terminate_session: boolean;
|
|
155
191
|
};
|