assemblyai 4.6.1 → 4.7.0-alpha
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 +5 -0
- package/README.internal.md +100 -0
- package/dist/assemblyai.streaming.umd.js +37 -23
- package/dist/assemblyai.streaming.umd.min.js +1 -1
- package/dist/assemblyai.umd.js +38 -24
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +38 -24
- package/dist/bun.mjs +38 -24
- package/dist/deno.mjs +38 -24
- package/dist/index.cjs +38 -24
- package/dist/index.mjs +38 -24
- package/dist/node.cjs +38 -24
- package/dist/node.mjs +38 -24
- package/dist/streaming.browser.mjs +37 -23
- package/dist/streaming.cjs +37 -23
- package/dist/streaming.mjs +37 -23
- package/dist/types/openapi.generated.d.ts +19 -3
- package/dist/utils/errors/realtime.d.ts +34 -20
- package/dist/workerd.mjs +38 -24
- package/package.json +2 -2
- package/src/services/realtime/service.ts +4 -7
- package/src/types/openapi.generated.ts +19 -3
- package/src/utils/errors/realtime.ts +49 -24
package/dist/streaming.cjs
CHANGED
|
@@ -42,30 +42,42 @@ const { WritableStream } = typeof window !== "undefined"
|
|
|
42
42
|
|
|
43
43
|
const factory = (url, params) => new ws(url, params);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
45
|
+
const RealtimeErrorType = {
|
|
46
|
+
BadSampleRate: 4000,
|
|
47
|
+
AuthFailed: 4001,
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use InsufficientFunds or FreeTierUser instead
|
|
50
|
+
*/
|
|
51
|
+
InsufficientFundsOrFreeAccount: 4002,
|
|
52
|
+
InsufficientFunds: 4002,
|
|
53
|
+
FreeTierUser: 4003,
|
|
54
|
+
NonexistentSessionId: 4004,
|
|
55
|
+
SessionExpired: 4008,
|
|
56
|
+
ClosedSession: 4010,
|
|
57
|
+
RateLimited: 4029,
|
|
58
|
+
UniqueSessionViolation: 4030,
|
|
59
|
+
SessionTimeout: 4031,
|
|
60
|
+
AudioTooShort: 4032,
|
|
61
|
+
AudioTooLong: 4033,
|
|
62
|
+
AudioTooSmallToTranscode: 4034,
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated Don't use
|
|
65
|
+
*/
|
|
66
|
+
BadJson: 4100,
|
|
67
|
+
BadSchema: 4101,
|
|
68
|
+
TooManyStreams: 4102,
|
|
69
|
+
Reconnected: 4103,
|
|
70
|
+
/**
|
|
71
|
+
* @deprecated Don't use
|
|
72
|
+
*/
|
|
73
|
+
ReconnectAttemptsExhausted: 1013,
|
|
74
|
+
WordBoostParameterParsingFailed: 4104,
|
|
75
|
+
};
|
|
65
76
|
const RealtimeErrorMessages = {
|
|
66
77
|
[RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
67
78
|
[RealtimeErrorType.AuthFailed]: "Not Authorized",
|
|
68
|
-
[RealtimeErrorType.
|
|
79
|
+
[RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
|
|
80
|
+
[RealtimeErrorType.FreeTierUser]: "This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",
|
|
69
81
|
[RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
|
|
70
82
|
[RealtimeErrorType.SessionExpired]: "Session has expired",
|
|
71
83
|
[RealtimeErrorType.ClosedSession]: "Session is closed",
|
|
@@ -74,11 +86,13 @@ const RealtimeErrorMessages = {
|
|
|
74
86
|
[RealtimeErrorType.SessionTimeout]: "Session Timeout",
|
|
75
87
|
[RealtimeErrorType.AudioTooShort]: "Audio too short",
|
|
76
88
|
[RealtimeErrorType.AudioTooLong]: "Audio too long",
|
|
89
|
+
[RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
|
|
77
90
|
[RealtimeErrorType.BadJson]: "Bad JSON",
|
|
78
91
|
[RealtimeErrorType.BadSchema]: "Bad schema",
|
|
79
92
|
[RealtimeErrorType.TooManyStreams]: "Too many streams",
|
|
80
|
-
[RealtimeErrorType.Reconnected]: "
|
|
93
|
+
[RealtimeErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
|
|
81
94
|
[RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
|
|
95
|
+
[RealtimeErrorType.WordBoostParameterParsingFailed]: "Could not parse word boost parameter",
|
|
82
96
|
};
|
|
83
97
|
class RealtimeError extends Error {
|
|
84
98
|
}
|
|
@@ -172,7 +186,7 @@ class RealtimeTranscriber {
|
|
|
172
186
|
this.socket.onclose = ({ code, reason }) => {
|
|
173
187
|
var _a, _b;
|
|
174
188
|
if (!reason) {
|
|
175
|
-
if (code in
|
|
189
|
+
if (code in RealtimeErrorMessages) {
|
|
176
190
|
reason = RealtimeErrorMessages[code];
|
|
177
191
|
}
|
|
178
192
|
}
|
package/dist/streaming.mjs
CHANGED
|
@@ -40,30 +40,42 @@ const { WritableStream } = typeof window !== "undefined"
|
|
|
40
40
|
|
|
41
41
|
const factory = (url, params) => new ws(url, params);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
const RealtimeErrorType = {
|
|
44
|
+
BadSampleRate: 4000,
|
|
45
|
+
AuthFailed: 4001,
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use InsufficientFunds or FreeTierUser instead
|
|
48
|
+
*/
|
|
49
|
+
InsufficientFundsOrFreeAccount: 4002,
|
|
50
|
+
InsufficientFunds: 4002,
|
|
51
|
+
FreeTierUser: 4003,
|
|
52
|
+
NonexistentSessionId: 4004,
|
|
53
|
+
SessionExpired: 4008,
|
|
54
|
+
ClosedSession: 4010,
|
|
55
|
+
RateLimited: 4029,
|
|
56
|
+
UniqueSessionViolation: 4030,
|
|
57
|
+
SessionTimeout: 4031,
|
|
58
|
+
AudioTooShort: 4032,
|
|
59
|
+
AudioTooLong: 4033,
|
|
60
|
+
AudioTooSmallToTranscode: 4034,
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Don't use
|
|
63
|
+
*/
|
|
64
|
+
BadJson: 4100,
|
|
65
|
+
BadSchema: 4101,
|
|
66
|
+
TooManyStreams: 4102,
|
|
67
|
+
Reconnected: 4103,
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Don't use
|
|
70
|
+
*/
|
|
71
|
+
ReconnectAttemptsExhausted: 1013,
|
|
72
|
+
WordBoostParameterParsingFailed: 4104,
|
|
73
|
+
};
|
|
63
74
|
const RealtimeErrorMessages = {
|
|
64
75
|
[RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
65
76
|
[RealtimeErrorType.AuthFailed]: "Not Authorized",
|
|
66
|
-
[RealtimeErrorType.
|
|
77
|
+
[RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
|
|
78
|
+
[RealtimeErrorType.FreeTierUser]: "This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",
|
|
67
79
|
[RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
|
|
68
80
|
[RealtimeErrorType.SessionExpired]: "Session has expired",
|
|
69
81
|
[RealtimeErrorType.ClosedSession]: "Session is closed",
|
|
@@ -72,11 +84,13 @@ const RealtimeErrorMessages = {
|
|
|
72
84
|
[RealtimeErrorType.SessionTimeout]: "Session Timeout",
|
|
73
85
|
[RealtimeErrorType.AudioTooShort]: "Audio too short",
|
|
74
86
|
[RealtimeErrorType.AudioTooLong]: "Audio too long",
|
|
87
|
+
[RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
|
|
75
88
|
[RealtimeErrorType.BadJson]: "Bad JSON",
|
|
76
89
|
[RealtimeErrorType.BadSchema]: "Bad schema",
|
|
77
90
|
[RealtimeErrorType.TooManyStreams]: "Too many streams",
|
|
78
|
-
[RealtimeErrorType.Reconnected]: "
|
|
91
|
+
[RealtimeErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
|
|
79
92
|
[RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
|
|
93
|
+
[RealtimeErrorType.WordBoostParameterParsingFailed]: "Could not parse word boost parameter",
|
|
80
94
|
};
|
|
81
95
|
class RealtimeError extends Error {
|
|
82
96
|
}
|
|
@@ -170,7 +184,7 @@ class RealtimeTranscriber {
|
|
|
170
184
|
this.socket.onclose = ({ code, reason }) => {
|
|
171
185
|
var _a, _b;
|
|
172
186
|
if (!reason) {
|
|
173
|
-
if (code in
|
|
187
|
+
if (code in RealtimeErrorMessages) {
|
|
174
188
|
reason = RealtimeErrorMessages[code];
|
|
175
189
|
}
|
|
176
190
|
}
|
|
@@ -2239,6 +2239,16 @@ export type Transcript = {
|
|
|
2239
2239
|
* The default value is 'en_us'.
|
|
2240
2240
|
*/
|
|
2241
2241
|
language_code?: LiteralUnion<TranscriptLanguageCode, string>;
|
|
2242
|
+
/**
|
|
2243
|
+
* The confidence score for the detected language, between 0.0 (low confidence) and 1.0 (high confidence)
|
|
2244
|
+
*/
|
|
2245
|
+
language_confidence: number | null;
|
|
2246
|
+
/**
|
|
2247
|
+
* The confidence threshold for the automatically detected language.
|
|
2248
|
+
* An error will be returned if the langauge confidence is below this threshold.
|
|
2249
|
+
* Defaults to 0.
|
|
2250
|
+
*/
|
|
2251
|
+
language_confidence_threshold: number | null;
|
|
2242
2252
|
/**
|
|
2243
2253
|
* Whether {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection } is enabled, either true or false
|
|
2244
2254
|
*/
|
|
@@ -2374,7 +2384,7 @@ export type Transcript = {
|
|
|
2374
2384
|
words?: TranscriptWord[] | null;
|
|
2375
2385
|
};
|
|
2376
2386
|
/**
|
|
2377
|
-
*
|
|
2387
|
+
* How much to boost specified words
|
|
2378
2388
|
*/
|
|
2379
2389
|
export type TranscriptBoostParam = "low" | "default" | "high";
|
|
2380
2390
|
/**
|
|
@@ -2548,7 +2558,7 @@ export type TranscriptOptionalParams = {
|
|
|
2548
2558
|
*/
|
|
2549
2559
|
auto_highlights?: boolean;
|
|
2550
2560
|
/**
|
|
2551
|
-
*
|
|
2561
|
+
* How much to boost specified words
|
|
2552
2562
|
*/
|
|
2553
2563
|
boost_param?: TranscriptBoostParam;
|
|
2554
2564
|
/**
|
|
@@ -2596,6 +2606,12 @@ export type TranscriptOptionalParams = {
|
|
|
2596
2606
|
* The default value is 'en_us'.
|
|
2597
2607
|
*/
|
|
2598
2608
|
language_code?: LiteralUnion<TranscriptLanguageCode, string> | null;
|
|
2609
|
+
/**
|
|
2610
|
+
* The confidence threshold for the automatically detected language.
|
|
2611
|
+
* An error will be returned if the langauge confidence is below this threshold.
|
|
2612
|
+
* Defaults to 0.
|
|
2613
|
+
*/
|
|
2614
|
+
language_confidence_threshold?: number;
|
|
2599
2615
|
/**
|
|
2600
2616
|
* Enable {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection }, either true or false.
|
|
2601
2617
|
*/
|
|
@@ -2639,7 +2655,7 @@ export type TranscriptOptionalParams = {
|
|
|
2639
2655
|
*/
|
|
2640
2656
|
speakers_expected?: number | null;
|
|
2641
2657
|
/**
|
|
2642
|
-
* The speech model to use for the transcription. When `null`, the
|
|
2658
|
+
* The speech model to use for the transcription. When `null`, the "best" model is used.
|
|
2643
2659
|
* @defaultValue null
|
|
2644
2660
|
*/
|
|
2645
2661
|
speech_model?: SpeechModel | null;
|
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
declare
|
|
2
|
-
BadSampleRate
|
|
3
|
-
AuthFailed
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
declare const RealtimeErrorType: {
|
|
2
|
+
readonly BadSampleRate: 4000;
|
|
3
|
+
readonly AuthFailed: 4001;
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use InsufficientFunds or FreeTierUser instead
|
|
6
|
+
*/
|
|
7
|
+
readonly InsufficientFundsOrFreeAccount: 4002;
|
|
8
|
+
readonly InsufficientFunds: 4002;
|
|
9
|
+
readonly FreeTierUser: 4003;
|
|
10
|
+
readonly NonexistentSessionId: 4004;
|
|
11
|
+
readonly SessionExpired: 4008;
|
|
12
|
+
readonly ClosedSession: 4010;
|
|
13
|
+
readonly RateLimited: 4029;
|
|
14
|
+
readonly UniqueSessionViolation: 4030;
|
|
15
|
+
readonly SessionTimeout: 4031;
|
|
16
|
+
readonly AudioTooShort: 4032;
|
|
17
|
+
readonly AudioTooLong: 4033;
|
|
18
|
+
readonly AudioTooSmallToTranscode: 4034;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Don't use
|
|
21
|
+
*/
|
|
22
|
+
readonly BadJson: 4100;
|
|
23
|
+
readonly BadSchema: 4101;
|
|
24
|
+
readonly TooManyStreams: 4102;
|
|
25
|
+
readonly Reconnected: 4103;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Don't use
|
|
28
|
+
*/
|
|
29
|
+
readonly ReconnectAttemptsExhausted: 1013;
|
|
30
|
+
readonly WordBoostParameterParsingFailed: 4104;
|
|
31
|
+
};
|
|
32
|
+
type RealtimeErrorTypeCodes = (typeof RealtimeErrorType)[keyof typeof RealtimeErrorType];
|
|
33
|
+
declare const RealtimeErrorMessages: Record<RealtimeErrorTypeCodes, string>;
|
|
20
34
|
declare class RealtimeError extends Error {
|
|
21
35
|
}
|
|
22
|
-
export { RealtimeError, RealtimeErrorType, RealtimeErrorMessages };
|
|
36
|
+
export { RealtimeError, RealtimeErrorType, RealtimeErrorTypeCodes, RealtimeErrorMessages, };
|
package/dist/workerd.mjs
CHANGED
|
@@ -15,7 +15,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
15
15
|
defaultUserAgentString += navigator.userAgent;
|
|
16
16
|
}
|
|
17
17
|
const defaultUserAgent = {
|
|
18
|
-
sdk: { name: "JavaScript", version: "4.6.
|
|
18
|
+
sdk: { name: "JavaScript", version: "4.6.2" },
|
|
19
19
|
};
|
|
20
20
|
if (typeof process !== "undefined") {
|
|
21
21
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -147,30 +147,42 @@ const { WritableStream } = typeof window !== "undefined"
|
|
|
147
147
|
|
|
148
148
|
const factory = (url, params) => new ws(url, params);
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
150
|
+
const RealtimeErrorType = {
|
|
151
|
+
BadSampleRate: 4000,
|
|
152
|
+
AuthFailed: 4001,
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated Use InsufficientFunds or FreeTierUser instead
|
|
155
|
+
*/
|
|
156
|
+
InsufficientFundsOrFreeAccount: 4002,
|
|
157
|
+
InsufficientFunds: 4002,
|
|
158
|
+
FreeTierUser: 4003,
|
|
159
|
+
NonexistentSessionId: 4004,
|
|
160
|
+
SessionExpired: 4008,
|
|
161
|
+
ClosedSession: 4010,
|
|
162
|
+
RateLimited: 4029,
|
|
163
|
+
UniqueSessionViolation: 4030,
|
|
164
|
+
SessionTimeout: 4031,
|
|
165
|
+
AudioTooShort: 4032,
|
|
166
|
+
AudioTooLong: 4033,
|
|
167
|
+
AudioTooSmallToTranscode: 4034,
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated Don't use
|
|
170
|
+
*/
|
|
171
|
+
BadJson: 4100,
|
|
172
|
+
BadSchema: 4101,
|
|
173
|
+
TooManyStreams: 4102,
|
|
174
|
+
Reconnected: 4103,
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated Don't use
|
|
177
|
+
*/
|
|
178
|
+
ReconnectAttemptsExhausted: 1013,
|
|
179
|
+
WordBoostParameterParsingFailed: 4104,
|
|
180
|
+
};
|
|
170
181
|
const RealtimeErrorMessages = {
|
|
171
182
|
[RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
172
183
|
[RealtimeErrorType.AuthFailed]: "Not Authorized",
|
|
173
|
-
[RealtimeErrorType.
|
|
184
|
+
[RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
|
|
185
|
+
[RealtimeErrorType.FreeTierUser]: "This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",
|
|
174
186
|
[RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
|
|
175
187
|
[RealtimeErrorType.SessionExpired]: "Session has expired",
|
|
176
188
|
[RealtimeErrorType.ClosedSession]: "Session is closed",
|
|
@@ -179,11 +191,13 @@ const RealtimeErrorMessages = {
|
|
|
179
191
|
[RealtimeErrorType.SessionTimeout]: "Session Timeout",
|
|
180
192
|
[RealtimeErrorType.AudioTooShort]: "Audio too short",
|
|
181
193
|
[RealtimeErrorType.AudioTooLong]: "Audio too long",
|
|
194
|
+
[RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
|
|
182
195
|
[RealtimeErrorType.BadJson]: "Bad JSON",
|
|
183
196
|
[RealtimeErrorType.BadSchema]: "Bad schema",
|
|
184
197
|
[RealtimeErrorType.TooManyStreams]: "Too many streams",
|
|
185
|
-
[RealtimeErrorType.Reconnected]: "
|
|
198
|
+
[RealtimeErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
|
|
186
199
|
[RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
|
|
200
|
+
[RealtimeErrorType.WordBoostParameterParsingFailed]: "Could not parse word boost parameter",
|
|
187
201
|
};
|
|
188
202
|
class RealtimeError extends Error {
|
|
189
203
|
}
|
|
@@ -275,7 +289,7 @@ class RealtimeTranscriber {
|
|
|
275
289
|
};
|
|
276
290
|
this.socket.onclose = ({ code, reason }) => {
|
|
277
291
|
if (!reason) {
|
|
278
|
-
if (code in
|
|
292
|
+
if (code in RealtimeErrorMessages) {
|
|
279
293
|
reason = RealtimeErrorMessages[code];
|
|
280
294
|
}
|
|
281
295
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0-alpha",
|
|
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"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"url": "git+https://github.com/AssemblyAI/assemblyai-node-sdk.git"
|
|
72
72
|
},
|
|
73
73
|
"publishConfig": {
|
|
74
|
-
"tag": "
|
|
74
|
+
"tag": "alpha",
|
|
75
75
|
"access": "public",
|
|
76
76
|
"registry": "https://registry.npmjs.org/"
|
|
77
77
|
},
|
|
@@ -17,11 +17,8 @@ import {
|
|
|
17
17
|
AudioData,
|
|
18
18
|
SessionInformation,
|
|
19
19
|
} from "../..";
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
RealtimeErrorMessages,
|
|
23
|
-
RealtimeErrorType,
|
|
24
|
-
} from "../../utils/errors";
|
|
20
|
+
import { RealtimeError, RealtimeErrorMessages } from "../../utils/errors";
|
|
21
|
+
import { RealtimeErrorTypeCodes } from "../../utils/errors/realtime";
|
|
25
22
|
|
|
26
23
|
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
|
|
27
24
|
const forceEndOfUtteranceMessage = `{"force_end_utterance":true}`;
|
|
@@ -213,8 +210,8 @@ export class RealtimeTranscriber {
|
|
|
213
210
|
|
|
214
211
|
this.socket!.onclose = ({ code, reason }: CloseEvent) => {
|
|
215
212
|
if (!reason) {
|
|
216
|
-
if (code in
|
|
217
|
-
reason = RealtimeErrorMessages[code as
|
|
213
|
+
if (code in RealtimeErrorMessages) {
|
|
214
|
+
reason = RealtimeErrorMessages[code as RealtimeErrorTypeCodes];
|
|
218
215
|
}
|
|
219
216
|
}
|
|
220
217
|
this.listeners.close?.(code, reason);
|
|
@@ -2406,6 +2406,16 @@ export type Transcript = {
|
|
|
2406
2406
|
* The default value is 'en_us'.
|
|
2407
2407
|
*/
|
|
2408
2408
|
language_code?: LiteralUnion<TranscriptLanguageCode, string>;
|
|
2409
|
+
/**
|
|
2410
|
+
* The confidence score for the detected language, between 0.0 (low confidence) and 1.0 (high confidence)
|
|
2411
|
+
*/
|
|
2412
|
+
language_confidence: number | null;
|
|
2413
|
+
/**
|
|
2414
|
+
* The confidence threshold for the automatically detected language.
|
|
2415
|
+
* An error will be returned if the langauge confidence is below this threshold.
|
|
2416
|
+
* Defaults to 0.
|
|
2417
|
+
*/
|
|
2418
|
+
language_confidence_threshold: number | null;
|
|
2409
2419
|
/**
|
|
2410
2420
|
* Whether {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection } is enabled, either true or false
|
|
2411
2421
|
*/
|
|
@@ -2542,7 +2552,7 @@ export type Transcript = {
|
|
|
2542
2552
|
};
|
|
2543
2553
|
|
|
2544
2554
|
/**
|
|
2545
|
-
*
|
|
2555
|
+
* How much to boost specified words
|
|
2546
2556
|
*/
|
|
2547
2557
|
export type TranscriptBoostParam = "low" | "default" | "high";
|
|
2548
2558
|
|
|
@@ -2823,7 +2833,7 @@ export type TranscriptOptionalParams = {
|
|
|
2823
2833
|
*/
|
|
2824
2834
|
auto_highlights?: boolean;
|
|
2825
2835
|
/**
|
|
2826
|
-
*
|
|
2836
|
+
* How much to boost specified words
|
|
2827
2837
|
*/
|
|
2828
2838
|
boost_param?: TranscriptBoostParam;
|
|
2829
2839
|
/**
|
|
@@ -2871,6 +2881,12 @@ export type TranscriptOptionalParams = {
|
|
|
2871
2881
|
* The default value is 'en_us'.
|
|
2872
2882
|
*/
|
|
2873
2883
|
language_code?: LiteralUnion<TranscriptLanguageCode, string> | null;
|
|
2884
|
+
/**
|
|
2885
|
+
* The confidence threshold for the automatically detected language.
|
|
2886
|
+
* An error will be returned if the langauge confidence is below this threshold.
|
|
2887
|
+
* Defaults to 0.
|
|
2888
|
+
*/
|
|
2889
|
+
language_confidence_threshold?: number;
|
|
2874
2890
|
/**
|
|
2875
2891
|
* Enable {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection }, either true or false.
|
|
2876
2892
|
*/
|
|
@@ -2914,7 +2930,7 @@ export type TranscriptOptionalParams = {
|
|
|
2914
2930
|
*/
|
|
2915
2931
|
speakers_expected?: number | null;
|
|
2916
2932
|
/**
|
|
2917
|
-
* The speech model to use for the transcription. When `null`, the
|
|
2933
|
+
* The speech model to use for the transcription. When `null`, the "best" model is used.
|
|
2918
2934
|
* @defaultValue null
|
|
2919
2935
|
*/
|
|
2920
2936
|
speech_model?: SpeechModel | null;
|
|
@@ -1,28 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
BadSampleRate
|
|
3
|
-
AuthFailed
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
const RealtimeErrorType = {
|
|
2
|
+
BadSampleRate: 4000,
|
|
3
|
+
AuthFailed: 4001,
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use InsufficientFunds or FreeTierUser instead
|
|
6
|
+
*/
|
|
7
|
+
InsufficientFundsOrFreeAccount: 4002,
|
|
8
|
+
InsufficientFunds: 4002,
|
|
9
|
+
FreeTierUser: 4003,
|
|
10
|
+
NonexistentSessionId: 4004,
|
|
11
|
+
SessionExpired: 4008,
|
|
12
|
+
ClosedSession: 4010,
|
|
13
|
+
RateLimited: 4029,
|
|
14
|
+
UniqueSessionViolation: 4030,
|
|
15
|
+
SessionTimeout: 4031,
|
|
16
|
+
AudioTooShort: 4032,
|
|
17
|
+
AudioTooLong: 4033,
|
|
18
|
+
AudioTooSmallToTranscode: 4034,
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Don't use
|
|
21
|
+
*/
|
|
22
|
+
BadJson: 4100,
|
|
23
|
+
BadSchema: 4101,
|
|
24
|
+
TooManyStreams: 4102,
|
|
25
|
+
Reconnected: 4103,
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Don't use
|
|
28
|
+
*/
|
|
29
|
+
ReconnectAttemptsExhausted: 1013,
|
|
30
|
+
WordBoostParameterParsingFailed: 4104,
|
|
31
|
+
} as const;
|
|
20
32
|
|
|
21
|
-
|
|
33
|
+
type RealtimeErrorTypeCodes =
|
|
34
|
+
(typeof RealtimeErrorType)[keyof typeof RealtimeErrorType];
|
|
35
|
+
|
|
36
|
+
const RealtimeErrorMessages: Record<RealtimeErrorTypeCodes, string> = {
|
|
22
37
|
[RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
23
38
|
[RealtimeErrorType.AuthFailed]: "Not Authorized",
|
|
24
|
-
[RealtimeErrorType.
|
|
25
|
-
|
|
39
|
+
[RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
|
|
40
|
+
[RealtimeErrorType.FreeTierUser]:
|
|
41
|
+
"This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",
|
|
26
42
|
[RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
|
|
27
43
|
[RealtimeErrorType.SessionExpired]: "Session has expired",
|
|
28
44
|
[RealtimeErrorType.ClosedSession]: "Session is closed",
|
|
@@ -31,14 +47,23 @@ const RealtimeErrorMessages: Record<RealtimeErrorType, string> = {
|
|
|
31
47
|
[RealtimeErrorType.SessionTimeout]: "Session Timeout",
|
|
32
48
|
[RealtimeErrorType.AudioTooShort]: "Audio too short",
|
|
33
49
|
[RealtimeErrorType.AudioTooLong]: "Audio too long",
|
|
50
|
+
[RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
|
|
34
51
|
[RealtimeErrorType.BadJson]: "Bad JSON",
|
|
35
52
|
[RealtimeErrorType.BadSchema]: "Bad schema",
|
|
36
53
|
[RealtimeErrorType.TooManyStreams]: "Too many streams",
|
|
37
|
-
[RealtimeErrorType.Reconnected]:
|
|
54
|
+
[RealtimeErrorType.Reconnected]:
|
|
55
|
+
"This session has been reconnected. This WebSocket is no longer valid.",
|
|
38
56
|
[RealtimeErrorType.ReconnectAttemptsExhausted]:
|
|
39
57
|
"Reconnect attempts exhausted",
|
|
58
|
+
[RealtimeErrorType.WordBoostParameterParsingFailed]:
|
|
59
|
+
"Could not parse word boost parameter",
|
|
40
60
|
};
|
|
41
61
|
|
|
42
62
|
class RealtimeError extends Error {}
|
|
43
63
|
|
|
44
|
-
export {
|
|
64
|
+
export {
|
|
65
|
+
RealtimeError,
|
|
66
|
+
RealtimeErrorType,
|
|
67
|
+
RealtimeErrorTypeCodes,
|
|
68
|
+
RealtimeErrorMessages,
|
|
69
|
+
};
|