assemblyai 4.5.0 → 4.6.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 +7 -0
- package/dist/assemblyai.streaming.umd.js +29 -0
- package/dist/assemblyai.umd.js +30 -1
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +30 -1
- package/dist/bun.mjs +30 -1
- package/dist/deno.mjs +30 -1
- package/dist/index.cjs +30 -1
- package/dist/index.mjs +30 -1
- package/dist/node.cjs +30 -1
- package/dist/node.mjs +30 -1
- 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 +17 -8
- package/dist/workerd.mjs +30 -1
- package/package.json +27 -15
- package/src/services/realtime/service.ts +65 -0
- package/src/types/openapi.generated.ts +28 -9
|
@@ -45,6 +45,9 @@ type BufferLike =
|
|
|
45
45
|
| { valueOf(): string }
|
|
46
46
|
| { [Symbol.toPrimitive](hint: string): string };
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* RealtimeTranscriber connects to the Streaming Speech-to-Text API and lets you transcribe audio in real-time.
|
|
50
|
+
*/
|
|
48
51
|
export class RealtimeTranscriber {
|
|
49
52
|
private realtimeUrl: string;
|
|
50
53
|
private sampleRate: number;
|
|
@@ -59,6 +62,10 @@ export class RealtimeTranscriber {
|
|
|
59
62
|
private listeners: RealtimeListeners = {};
|
|
60
63
|
private sessionTerminatedResolve?: () => void;
|
|
61
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Create a new RealtimeTranscriber.
|
|
67
|
+
* @param params - Parameters to configure the RealtimeTranscriber
|
|
68
|
+
*/
|
|
62
69
|
constructor(params: RealtimeTranscriberParams) {
|
|
63
70
|
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
|
|
64
71
|
this.sampleRate = params.sampleRate ?? 16_000;
|
|
@@ -106,30 +113,75 @@ export class RealtimeTranscriber {
|
|
|
106
113
|
return url;
|
|
107
114
|
}
|
|
108
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Listen for the open event which is emitted when the connection is established and the session begins.
|
|
118
|
+
* @param event - The open event.
|
|
119
|
+
* @param listener - The function to call when the event is emitted.
|
|
120
|
+
*/
|
|
109
121
|
on(event: "open", listener: (event: SessionBeginsEventData) => void): void;
|
|
122
|
+
/**
|
|
123
|
+
* Listen for the transcript event which is emitted when a partian or final transcript is received.
|
|
124
|
+
* @param event - The transcript event.
|
|
125
|
+
* @param listener - The function to call when the event is emitted.
|
|
126
|
+
*/
|
|
110
127
|
on(
|
|
111
128
|
event: "transcript",
|
|
112
129
|
listener: (transcript: RealtimeTranscript) => void,
|
|
113
130
|
): void;
|
|
131
|
+
/**
|
|
132
|
+
* Listen for the partial transcript event which is emitted when a partial transcript is received.
|
|
133
|
+
* @param event - The partial transcript event.
|
|
134
|
+
* @param listener - The function to call when the event is emitted.
|
|
135
|
+
*/
|
|
114
136
|
on(
|
|
115
137
|
event: "transcript.partial",
|
|
116
138
|
listener: (transcript: PartialTranscript) => void,
|
|
117
139
|
): void;
|
|
140
|
+
/**
|
|
141
|
+
* Listen for the final transcript event which is emitted when a final transcript is received.
|
|
142
|
+
* @param event - The final transcript event.
|
|
143
|
+
* @param listener - The function to call when the event is emitted.
|
|
144
|
+
*/
|
|
118
145
|
on(
|
|
119
146
|
event: "transcript.final",
|
|
120
147
|
listener: (transcript: FinalTranscript) => void,
|
|
121
148
|
): void;
|
|
149
|
+
/**
|
|
150
|
+
* Listen for the session information event which is emitted when session information is received.
|
|
151
|
+
* The session information is sent right before the session is terminated.
|
|
152
|
+
* @param event - The session information event.
|
|
153
|
+
* @param listener - The function to call when the event is emitted.
|
|
154
|
+
*/
|
|
122
155
|
on(
|
|
123
156
|
event: "session_information",
|
|
124
157
|
listener: (info: SessionInformation) => void,
|
|
125
158
|
): void;
|
|
159
|
+
/**
|
|
160
|
+
* Listen for the error event which is emitted when an error occurs.
|
|
161
|
+
* @param event - The error event.
|
|
162
|
+
* @param listener - The function to call when the event is emitted.
|
|
163
|
+
*/
|
|
126
164
|
on(event: "error", listener: (error: Error) => void): void;
|
|
165
|
+
/**
|
|
166
|
+
* Listen for the close event which is emitted when the connection is closed.
|
|
167
|
+
* @param event - The close event.
|
|
168
|
+
* @param listener - The function to call when the event is emitted.
|
|
169
|
+
*/
|
|
127
170
|
on(event: "close", listener: (code: number, reason: string) => void): void;
|
|
171
|
+
/**
|
|
172
|
+
* Add a listener for an event.
|
|
173
|
+
* @param event - The event to listen for.
|
|
174
|
+
* @param listener - The function to call when the event is emitted.
|
|
175
|
+
*/
|
|
128
176
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
177
|
on(event: RealtimeEvents, listener: (...args: any[]) => void) {
|
|
130
178
|
this.listeners[event] = listener;
|
|
131
179
|
}
|
|
132
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Connect to the server and begin a new session.
|
|
183
|
+
* @returns A promise that resolves when the connection is established and the session begins.
|
|
184
|
+
*/
|
|
133
185
|
connect() {
|
|
134
186
|
return new Promise<SessionBeginsEventData>((resolve) => {
|
|
135
187
|
if (this.socket) {
|
|
@@ -216,10 +268,18 @@ export class RealtimeTranscriber {
|
|
|
216
268
|
});
|
|
217
269
|
}
|
|
218
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Send audio data to the server.
|
|
273
|
+
* @param audio - The audio data to send to the server.
|
|
274
|
+
*/
|
|
219
275
|
sendAudio(audio: AudioData) {
|
|
220
276
|
this.send(audio);
|
|
221
277
|
}
|
|
222
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Create a writable stream that can be used to send audio data to the server.
|
|
281
|
+
* @returns A writable stream that can be used to send audio data to the server.
|
|
282
|
+
*/
|
|
223
283
|
stream(): WritableStream<AudioData> {
|
|
224
284
|
return new WritableStream<AudioData>({
|
|
225
285
|
write: (chunk: AudioData) => {
|
|
@@ -251,6 +311,11 @@ export class RealtimeTranscriber {
|
|
|
251
311
|
this.socket.send(data);
|
|
252
312
|
}
|
|
253
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Close the connection to the server.
|
|
316
|
+
* @param waitForSessionTermination - If true, the method will wait for the session to be terminated before closing the connection.
|
|
317
|
+
* While waiting for the session to be terminated, you will receive the final transcript and session information.
|
|
318
|
+
*/
|
|
254
319
|
async close(waitForSessionTermination = true) {
|
|
255
320
|
if (this.socket) {
|
|
256
321
|
if (this.socket.readyState === this.socket.OPEN) {
|
|
@@ -632,7 +632,6 @@ export type LemurBaseParams = {
|
|
|
632
632
|
>;
|
|
633
633
|
/**
|
|
634
634
|
* The model that is used for the final prompt after compression is performed.
|
|
635
|
-
* Defaults to "default".
|
|
636
635
|
*
|
|
637
636
|
* @defaultValue "default
|
|
638
637
|
*/
|
|
@@ -687,10 +686,16 @@ export type LemurBaseResponse = {
|
|
|
687
686
|
*
|
|
688
687
|
*/
|
|
689
688
|
export type LemurModel =
|
|
689
|
+
| "anthropic/claude-3-5-sonnet"
|
|
690
|
+
| "anthropic/claude-3-opus"
|
|
691
|
+
| "anthropic/claude-3-haiku"
|
|
692
|
+
| "anthropic/claude-3-sonnet"
|
|
693
|
+
| "anthropic/claude-2-1"
|
|
694
|
+
| "anthropic/claude-2"
|
|
690
695
|
| "default"
|
|
696
|
+
| "anthropic/claude-instant-1-2"
|
|
691
697
|
| "basic"
|
|
692
|
-
| "assemblyai/mistral-7b"
|
|
693
|
-
| "anthropic/claude-2-1";
|
|
698
|
+
| "assemblyai/mistral-7b";
|
|
694
699
|
|
|
695
700
|
/**
|
|
696
701
|
* @example
|
|
@@ -1168,6 +1173,11 @@ export type RealtimeTemporaryTokenResponse = {
|
|
|
1168
1173
|
token: string;
|
|
1169
1174
|
};
|
|
1170
1175
|
|
|
1176
|
+
/**
|
|
1177
|
+
* The notification when the redacted audio is ready.
|
|
1178
|
+
*/
|
|
1179
|
+
export type RedactedAudioNotification = RedactedAudioResponse;
|
|
1180
|
+
|
|
1171
1181
|
/**
|
|
1172
1182
|
* @example
|
|
1173
1183
|
* ```js
|
|
@@ -2506,15 +2516,17 @@ export type Transcript = {
|
|
|
2506
2516
|
*/
|
|
2507
2517
|
webhook_auth: boolean;
|
|
2508
2518
|
/**
|
|
2509
|
-
* The header name
|
|
2519
|
+
* The header name to be sent with the transcript completed or failed webhook requests
|
|
2510
2520
|
*/
|
|
2511
2521
|
webhook_auth_header_name?: string | null;
|
|
2512
2522
|
/**
|
|
2513
|
-
* The status code we received from your server when delivering
|
|
2523
|
+
* The status code we received from your server when delivering the transcript completed or failed webhook request, if a webhook URL was provided
|
|
2514
2524
|
*/
|
|
2515
2525
|
webhook_status_code?: number | null;
|
|
2516
2526
|
/**
|
|
2517
|
-
* The URL to which we send
|
|
2527
|
+
* The URL to which we send webhook requests.
|
|
2528
|
+
* We sends two different types of webhook requests.
|
|
2529
|
+
* One request when a transcript is completed or failed, and one request when the redacted audio is ready if redact_pii_audio is enabled.
|
|
2518
2530
|
*/
|
|
2519
2531
|
webhook_url?: string | null;
|
|
2520
2532
|
/**
|
|
@@ -2931,17 +2943,17 @@ export type TranscriptOptionalParams = {
|
|
|
2931
2943
|
*/
|
|
2932
2944
|
topics?: string[];
|
|
2933
2945
|
/**
|
|
2934
|
-
* The header name
|
|
2946
|
+
* The header name to be sent with the transcript completed or failed webhook requests
|
|
2935
2947
|
* @defaultValue null
|
|
2936
2948
|
*/
|
|
2937
2949
|
webhook_auth_header_name?: string | null;
|
|
2938
2950
|
/**
|
|
2939
|
-
*
|
|
2951
|
+
* The header value to send back with the transcript completed or failed webhook requests for added security
|
|
2940
2952
|
* @defaultValue null
|
|
2941
2953
|
*/
|
|
2942
2954
|
webhook_auth_header_value?: string | null;
|
|
2943
2955
|
/**
|
|
2944
|
-
* The URL to which
|
|
2956
|
+
* The URL to which we send webhook requests. We sends two different types of webhook requests. One request when a transcript is completed or failed, and one request when the redacted audio is ready if redact_pii_audio is enabled.
|
|
2945
2957
|
*/
|
|
2946
2958
|
webhook_url?: string;
|
|
2947
2959
|
/**
|
|
@@ -3292,6 +3304,13 @@ export type TranscriptUtterance = {
|
|
|
3292
3304
|
words: TranscriptWord[];
|
|
3293
3305
|
};
|
|
3294
3306
|
|
|
3307
|
+
/**
|
|
3308
|
+
* The notifications sent to the webhook URL.
|
|
3309
|
+
*/
|
|
3310
|
+
export type TranscriptWebhookNotification =
|
|
3311
|
+
| TranscriptReadyNotification
|
|
3312
|
+
| RedactedAudioNotification;
|
|
3313
|
+
|
|
3295
3314
|
/**
|
|
3296
3315
|
* @example
|
|
3297
3316
|
* ```js
|