assemblyai 4.6.1 → 4.7.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.7.0]
4
+
5
+ - Add `language_confidence_threshold` to `Transcript`, `TranscriptParams`, and `TranscriptOptionalParams`.
6
+ > The confidence threshold for the automatically detected language.
7
+ > An error will be returned if the langauge confidence is below this threshold.
8
+ - Add `language_confidence` to `Transcript`
9
+ > The confidence score for the detected language, between 0.0 (low confidence) and 1.0 (high confidence)
10
+
11
+ Using these new fields you can determine the confidence of the language detection model (enable by setting `language_detection` to `true`), and fail the transcript if it doesn't meet your desired threshold.
12
+
13
+ [Learn more about the new automatic language detection model and feature improvements on our blog.](https://www.assemblyai.com/blog/ald-improvements)
14
+
15
+ ## [4.6.2]
16
+
17
+ - Change `RealtimeErrorType` from enum to const object.
18
+ - Add `RealtimeErrorTypeCodes` which is a union of `RealtimeErrorType` values
19
+
3
20
  ## [4.6.1]
4
21
 
5
22
  - Remove `conformer-2` from `SpeechModel` union type.
@@ -51,30 +51,42 @@
51
51
  return new PolyfillWebSocket(url);
52
52
  };
53
53
 
54
- var RealtimeErrorType;
55
- (function (RealtimeErrorType) {
56
- RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
57
- RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
58
- // Both InsufficientFunds and FreeAccount error use 4002
59
- RealtimeErrorType[RealtimeErrorType["InsufficientFundsOrFreeAccount"] = 4002] = "InsufficientFundsOrFreeAccount";
60
- RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
61
- RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
62
- RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
63
- RealtimeErrorType[RealtimeErrorType["RateLimited"] = 4029] = "RateLimited";
64
- RealtimeErrorType[RealtimeErrorType["UniqueSessionViolation"] = 4030] = "UniqueSessionViolation";
65
- RealtimeErrorType[RealtimeErrorType["SessionTimeout"] = 4031] = "SessionTimeout";
66
- RealtimeErrorType[RealtimeErrorType["AudioTooShort"] = 4032] = "AudioTooShort";
67
- RealtimeErrorType[RealtimeErrorType["AudioTooLong"] = 4033] = "AudioTooLong";
68
- RealtimeErrorType[RealtimeErrorType["BadJson"] = 4100] = "BadJson";
69
- RealtimeErrorType[RealtimeErrorType["BadSchema"] = 4101] = "BadSchema";
70
- RealtimeErrorType[RealtimeErrorType["TooManyStreams"] = 4102] = "TooManyStreams";
71
- RealtimeErrorType[RealtimeErrorType["Reconnected"] = 4103] = "Reconnected";
72
- RealtimeErrorType[RealtimeErrorType["ReconnectAttemptsExhausted"] = 1013] = "ReconnectAttemptsExhausted";
73
- })(RealtimeErrorType || (RealtimeErrorType = {}));
54
+ const RealtimeErrorType = {
55
+ BadSampleRate: 4000,
56
+ AuthFailed: 4001,
57
+ /**
58
+ * @deprecated Use InsufficientFunds or FreeTierUser instead
59
+ */
60
+ InsufficientFundsOrFreeAccount: 4002,
61
+ InsufficientFunds: 4002,
62
+ FreeTierUser: 4003,
63
+ NonexistentSessionId: 4004,
64
+ SessionExpired: 4008,
65
+ ClosedSession: 4010,
66
+ RateLimited: 4029,
67
+ UniqueSessionViolation: 4030,
68
+ SessionTimeout: 4031,
69
+ AudioTooShort: 4032,
70
+ AudioTooLong: 4033,
71
+ AudioTooSmallToTranscode: 4034,
72
+ /**
73
+ * @deprecated Don't use
74
+ */
75
+ BadJson: 4100,
76
+ BadSchema: 4101,
77
+ TooManyStreams: 4102,
78
+ Reconnected: 4103,
79
+ /**
80
+ * @deprecated Don't use
81
+ */
82
+ ReconnectAttemptsExhausted: 1013,
83
+ WordBoostParameterParsingFailed: 4104,
84
+ };
74
85
  const RealtimeErrorMessages = {
75
86
  [RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
76
87
  [RealtimeErrorType.AuthFailed]: "Not Authorized",
77
- [RealtimeErrorType.InsufficientFundsOrFreeAccount]: "Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",
88
+ [RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
89
+ [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.",
78
90
  [RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
79
91
  [RealtimeErrorType.SessionExpired]: "Session has expired",
80
92
  [RealtimeErrorType.ClosedSession]: "Session is closed",
@@ -83,11 +95,13 @@
83
95
  [RealtimeErrorType.SessionTimeout]: "Session Timeout",
84
96
  [RealtimeErrorType.AudioTooShort]: "Audio too short",
85
97
  [RealtimeErrorType.AudioTooLong]: "Audio too long",
98
+ [RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
86
99
  [RealtimeErrorType.BadJson]: "Bad JSON",
87
100
  [RealtimeErrorType.BadSchema]: "Bad schema",
88
101
  [RealtimeErrorType.TooManyStreams]: "Too many streams",
89
- [RealtimeErrorType.Reconnected]: "Reconnected",
102
+ [RealtimeErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
90
103
  [RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
104
+ [RealtimeErrorType.WordBoostParameterParsingFailed]: "Could not parse word boost parameter",
91
105
  };
92
106
  class RealtimeError extends Error {
93
107
  }
@@ -181,7 +195,7 @@
181
195
  this.socket.onclose = ({ code, reason }) => {
182
196
  var _a, _b;
183
197
  if (!reason) {
184
- if (code in RealtimeErrorType) {
198
+ if (code in RealtimeErrorMessages) {
185
199
  reason = RealtimeErrorMessages[code];
186
200
  }
187
201
  }
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t,s,i){return new(s||(s=Promise))((function(o,n){function r(e){try{l(i.next(e))}catch(e){n(e)}}function a(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{WritableStream:s}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var i,o;const n=null!==(o=null!==(i=null!==WebSocket&&void 0!==WebSocket?WebSocket:null===global||void 0===global?void 0:global.WebSocket)&&void 0!==i?i:null===window||void 0===window?void 0:window.WebSocket)&&void 0!==o?o:null===self||void 0===self?void 0:self.WebSocket,r=(e,t)=>t?new n(e,t):new n(e);var a;!function(e){e[e.BadSampleRate=4e3]="BadSampleRate",e[e.AuthFailed=4001]="AuthFailed",e[e.InsufficientFundsOrFreeAccount=4002]="InsufficientFundsOrFreeAccount",e[e.NonexistentSessionId=4004]="NonexistentSessionId",e[e.SessionExpired=4008]="SessionExpired",e[e.ClosedSession=4010]="ClosedSession",e[e.RateLimited=4029]="RateLimited",e[e.UniqueSessionViolation=4030]="UniqueSessionViolation",e[e.SessionTimeout=4031]="SessionTimeout",e[e.AudioTooShort=4032]="AudioTooShort",e[e.AudioTooLong=4033]="AudioTooLong",e[e.BadJson=4100]="BadJson",e[e.BadSchema=4101]="BadSchema",e[e.TooManyStreams=4102]="TooManyStreams",e[e.Reconnected=4103]="Reconnected",e[e.ReconnectAttemptsExhausted=1013]="ReconnectAttemptsExhausted"}(a||(a={}));const l={[a.BadSampleRate]:"Sample rate must be a positive integer",[a.AuthFailed]:"Not Authorized",[a.InsufficientFundsOrFreeAccount]:"Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",[a.NonexistentSessionId]:"Session ID does not exist",[a.SessionExpired]:"Session has expired",[a.ClosedSession]:"Session is closed",[a.RateLimited]:"Rate limited",[a.UniqueSessionViolation]:"Unique session violation",[a.SessionTimeout]:"Session Timeout",[a.AudioTooShort]:"Audio too short",[a.AudioTooLong]:"Audio too long",[a.BadJson]:"Bad JSON",[a.BadSchema]:"Bad schema",[a.TooManyStreams]:"Too many streams",[a.Reconnected]:"Reconnected",[a.ReconnectAttemptsExhausted]:"Reconnect attempts exhausted"};class c extends Error{}const d='{"terminate_session":true}';class h{constructor(e){var t,s;if(this.listeners={},this.realtimeUrl=null!==(t=e.realtimeUrl)&&void 0!==t?t:"wss://api.assemblyai.com/v2/realtime/ws",this.sampleRate=null!==(s=e.sampleRate)&&void 0!==s?s:16e3,this.wordBoost=e.wordBoost,this.encoding=e.encoding,this.endUtteranceSilenceThreshold=e.endUtteranceSilenceThreshold,this.disablePartialTranscripts=e.disablePartialTranscripts,"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){const e=new URL(this.realtimeUrl);if("wss:"!==e.protocol)throw new Error("Invalid protocol, must be wss");const t=new URLSearchParams;return this.token&&t.set("token",this.token),t.set("sample_rate",this.sampleRate.toString()),this.wordBoost&&this.wordBoost.length>0&&t.set("word_boost",JSON.stringify(this.wordBoost)),this.encoding&&t.set("encoding",this.encoding),t.set("enable_extra_session_information","true"),this.disablePartialTranscripts&&t.set("disable_partial_transcripts",this.disablePartialTranscripts.toString()),e.search=t.toString(),e}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=r(t.toString()):this.socket=r(t.toString(),{headers:{Authorization:this.apiKey}}),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{void 0!==this.endUtteranceSilenceThreshold&&null!==this.endUtteranceSilenceThreshold&&this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold)},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in a&&(t=l[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,o;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(o=(i=this.listeners).error)||void 0===o||o.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,o,n,r,a,l,d,h,u,p,m,S,f,v;const w=JSON.parse(t.toString());if("error"in w)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new c(w.error));else switch(w.message_type){case"SessionBegins":{const t={sessionId:w.session_id,expiresAt:new Date(w.expires_at)};e(t),null===(n=(o=this.listeners).open)||void 0===n||n.call(o,t);break}case"PartialTranscript":w.created=new Date(w.created),null===(a=(r=this.listeners).transcript)||void 0===a||a.call(r,w),null===(d=(l=this.listeners)["transcript.partial"])||void 0===d||d.call(l,w);break;case"FinalTranscript":w.created=new Date(w.created),null===(u=(h=this.listeners).transcript)||void 0===u||u.call(h,w),null===(m=(p=this.listeners)["transcript.final"])||void 0===m||m.call(p,w);break;case"SessionInformation":null===(f=(S=this.listeners).session_information)||void 0===f||f.call(S,w);break;case"SessionTerminated":null===(v=this.sessionTerminatedResolve)||void 0===v||v.call(this)}}}))}sendAudio(e){this.send(e)}stream(){return new s({write:e=>{this.sendAudio(e)}})}forceEndUtterance(){this.send('{"force_end_utterance":true}')}configureEndUtteranceSilenceThreshold(e){this.send(`{"end_utterance_silence_threshold":${e}}`)}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(d),yield e}else this.socket.send(d);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}e.RealtimeService=class extends h{},e.RealtimeTranscriber=h}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t,s,i){return new(s||(s=Promise))((function(o,n){function r(e){try{l(i.next(e))}catch(e){n(e)}}function a(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{WritableStream:s}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var i,o;const n=null!==(o=null!==(i=null!==WebSocket&&void 0!==WebSocket?WebSocket:null===global||void 0===global?void 0:global.WebSocket)&&void 0!==i?i:null===window||void 0===window?void 0:window.WebSocket)&&void 0!==o?o:null===self||void 0===self?void 0:self.WebSocket,r=(e,t)=>t?new n(e,t):new n(e),a={[4e3]:"Sample rate must be a positive integer",[4001]:"Not Authorized",[4002]:"Insufficient funds",[4003]:"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.",[4004]:"Session ID does not exist",[4008]:"Session has expired",[4010]:"Session is closed",[4029]:"Rate limited",[4030]:"Unique session violation",[4031]:"Session Timeout",[4032]:"Audio too short",[4033]:"Audio too long",[4034]:"Audio too small to transcode",[4100]:"Bad JSON",[4101]:"Bad schema",[4102]:"Too many streams",[4103]:"This session has been reconnected. This WebSocket is no longer valid.",[1013]:"Reconnect attempts exhausted",[4104]:"Could not parse word boost parameter"};class l extends Error{}const c='{"terminate_session":true}';class d{constructor(e){var t,s;if(this.listeners={},this.realtimeUrl=null!==(t=e.realtimeUrl)&&void 0!==t?t:"wss://api.assemblyai.com/v2/realtime/ws",this.sampleRate=null!==(s=e.sampleRate)&&void 0!==s?s:16e3,this.wordBoost=e.wordBoost,this.encoding=e.encoding,this.endUtteranceSilenceThreshold=e.endUtteranceSilenceThreshold,this.disablePartialTranscripts=e.disablePartialTranscripts,"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){const e=new URL(this.realtimeUrl);if("wss:"!==e.protocol)throw new Error("Invalid protocol, must be wss");const t=new URLSearchParams;return this.token&&t.set("token",this.token),t.set("sample_rate",this.sampleRate.toString()),this.wordBoost&&this.wordBoost.length>0&&t.set("word_boost",JSON.stringify(this.wordBoost)),this.encoding&&t.set("encoding",this.encoding),t.set("enable_extra_session_information","true"),this.disablePartialTranscripts&&t.set("disable_partial_transcripts",this.disablePartialTranscripts.toString()),e.search=t.toString(),e}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=r(t.toString()):this.socket=r(t.toString(),{headers:{Authorization:this.apiKey}}),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{void 0!==this.endUtteranceSilenceThreshold&&null!==this.endUtteranceSilenceThreshold&&this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold)},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in a&&(t=a[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,o;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(o=(i=this.listeners).error)||void 0===o||o.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,o,n,r,a,c,d,h,u,p,f,m,v,w;const k=JSON.parse(t.toString());if("error"in k)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new l(k.error));else switch(k.message_type){case"SessionBegins":{const t={sessionId:k.session_id,expiresAt:new Date(k.expires_at)};e(t),null===(n=(o=this.listeners).open)||void 0===n||n.call(o,t);break}case"PartialTranscript":k.created=new Date(k.created),null===(a=(r=this.listeners).transcript)||void 0===a||a.call(r,k),null===(d=(c=this.listeners)["transcript.partial"])||void 0===d||d.call(c,k);break;case"FinalTranscript":k.created=new Date(k.created),null===(u=(h=this.listeners).transcript)||void 0===u||u.call(h,k),null===(f=(p=this.listeners)["transcript.final"])||void 0===f||f.call(p,k);break;case"SessionInformation":null===(v=(m=this.listeners).session_information)||void 0===v||v.call(m,k);break;case"SessionTerminated":null===(w=this.sessionTerminatedResolve)||void 0===w||w.call(this)}}}))}sendAudio(e){this.send(e)}stream(){return new s({write:e=>{this.sendAudio(e)}})}forceEndUtterance(){this.send('{"force_end_utterance":true}')}configureEndUtteranceSilenceThreshold(e){this.send(`{"end_utterance_silence_threshold":${e}}`)}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(c),yield e}else this.socket.send(c);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}e.RealtimeService=class extends d{},e.RealtimeTranscriber=d}));
@@ -65,7 +65,7 @@
65
65
  defaultUserAgentString += navigator.userAgent;
66
66
  }
67
67
  const defaultUserAgent = {
68
- sdk: { name: "JavaScript", version: "4.6.1" },
68
+ sdk: { name: "JavaScript", version: "4.7.0" },
69
69
  };
70
70
  if (typeof process !== "undefined") {
71
71
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -208,30 +208,42 @@
208
208
  return new PolyfillWebSocket(url);
209
209
  };
210
210
 
211
- var RealtimeErrorType;
212
- (function (RealtimeErrorType) {
213
- RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
214
- RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
215
- // Both InsufficientFunds and FreeAccount error use 4002
216
- RealtimeErrorType[RealtimeErrorType["InsufficientFundsOrFreeAccount"] = 4002] = "InsufficientFundsOrFreeAccount";
217
- RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
218
- RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
219
- RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
220
- RealtimeErrorType[RealtimeErrorType["RateLimited"] = 4029] = "RateLimited";
221
- RealtimeErrorType[RealtimeErrorType["UniqueSessionViolation"] = 4030] = "UniqueSessionViolation";
222
- RealtimeErrorType[RealtimeErrorType["SessionTimeout"] = 4031] = "SessionTimeout";
223
- RealtimeErrorType[RealtimeErrorType["AudioTooShort"] = 4032] = "AudioTooShort";
224
- RealtimeErrorType[RealtimeErrorType["AudioTooLong"] = 4033] = "AudioTooLong";
225
- RealtimeErrorType[RealtimeErrorType["BadJson"] = 4100] = "BadJson";
226
- RealtimeErrorType[RealtimeErrorType["BadSchema"] = 4101] = "BadSchema";
227
- RealtimeErrorType[RealtimeErrorType["TooManyStreams"] = 4102] = "TooManyStreams";
228
- RealtimeErrorType[RealtimeErrorType["Reconnected"] = 4103] = "Reconnected";
229
- RealtimeErrorType[RealtimeErrorType["ReconnectAttemptsExhausted"] = 1013] = "ReconnectAttemptsExhausted";
230
- })(RealtimeErrorType || (RealtimeErrorType = {}));
211
+ const RealtimeErrorType = {
212
+ BadSampleRate: 4000,
213
+ AuthFailed: 4001,
214
+ /**
215
+ * @deprecated Use InsufficientFunds or FreeTierUser instead
216
+ */
217
+ InsufficientFundsOrFreeAccount: 4002,
218
+ InsufficientFunds: 4002,
219
+ FreeTierUser: 4003,
220
+ NonexistentSessionId: 4004,
221
+ SessionExpired: 4008,
222
+ ClosedSession: 4010,
223
+ RateLimited: 4029,
224
+ UniqueSessionViolation: 4030,
225
+ SessionTimeout: 4031,
226
+ AudioTooShort: 4032,
227
+ AudioTooLong: 4033,
228
+ AudioTooSmallToTranscode: 4034,
229
+ /**
230
+ * @deprecated Don't use
231
+ */
232
+ BadJson: 4100,
233
+ BadSchema: 4101,
234
+ TooManyStreams: 4102,
235
+ Reconnected: 4103,
236
+ /**
237
+ * @deprecated Don't use
238
+ */
239
+ ReconnectAttemptsExhausted: 1013,
240
+ WordBoostParameterParsingFailed: 4104,
241
+ };
231
242
  const RealtimeErrorMessages = {
232
243
  [RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
233
244
  [RealtimeErrorType.AuthFailed]: "Not Authorized",
234
- [RealtimeErrorType.InsufficientFundsOrFreeAccount]: "Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",
245
+ [RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
246
+ [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.",
235
247
  [RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
236
248
  [RealtimeErrorType.SessionExpired]: "Session has expired",
237
249
  [RealtimeErrorType.ClosedSession]: "Session is closed",
@@ -240,11 +252,13 @@
240
252
  [RealtimeErrorType.SessionTimeout]: "Session Timeout",
241
253
  [RealtimeErrorType.AudioTooShort]: "Audio too short",
242
254
  [RealtimeErrorType.AudioTooLong]: "Audio too long",
255
+ [RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
243
256
  [RealtimeErrorType.BadJson]: "Bad JSON",
244
257
  [RealtimeErrorType.BadSchema]: "Bad schema",
245
258
  [RealtimeErrorType.TooManyStreams]: "Too many streams",
246
- [RealtimeErrorType.Reconnected]: "Reconnected",
259
+ [RealtimeErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
247
260
  [RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
261
+ [RealtimeErrorType.WordBoostParameterParsingFailed]: "Could not parse word boost parameter",
248
262
  };
249
263
  class RealtimeError extends Error {
250
264
  }
@@ -338,7 +352,7 @@
338
352
  this.socket.onclose = ({ code, reason }) => {
339
353
  var _a, _b;
340
354
  if (!reason) {
341
- if (code in RealtimeErrorType) {
355
+ if (code in RealtimeErrorMessages) {
342
356
  reason = RealtimeErrorMessages[code];
343
357
  }
344
358
  }
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t,s,i){return new(s||(s=Promise))((function(n,o){function r(e){try{d(i.next(e))}catch(e){o(e)}}function a(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}d((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s={cache:"no-store"};let i="";"undefined"!=typeof navigator&&navigator.userAgent&&(i+=navigator.userAgent);const n={sdk:{name:"JavaScript",version:"4.6.1"}};"undefined"!=typeof process&&(process.versions.node&&-1===i.indexOf("Node")&&(n.runtime_env={name:"Node",version:process.versions.node}),process.versions.bun&&-1===i.indexOf("Bun")&&(n.runtime_env={name:"Bun",version:process.versions.bun})),"undefined"!=typeof Deno&&process.versions.bun&&-1===i.indexOf("Deno")&&(n.runtime_env={name:"Deno",version:Deno.version.deno});class o{constructor(e){var t;this.params=e,!1===e.userAgent?this.userAgent=void 0:this.userAgent=(t=e.userAgent||{},i+(!1===t?"":" AssemblyAI/1.0 ("+Object.entries(Object.assign(Object.assign({},n),t)).map((([e,t])=>t?`${e}=${t.name}/${t.version}`:"")).join(" ")+")"))}fetch(e,i){return t(this,void 0,void 0,(function*(){i=Object.assign(Object.assign({},s),i);let t={Authorization:this.params.apiKey,"Content-Type":"application/json"};(null==s?void 0:s.headers)&&(t=Object.assign(Object.assign({},t),s.headers)),(null==i?void 0:i.headers)&&(t=Object.assign(Object.assign({},t),i.headers)),this.userAgent&&(t["User-Agent"]=this.userAgent,"undefined"!=typeof window&&"chrome"in window&&(t["AssemblyAI-Agent"]=this.userAgent)),i.headers=t,e.startsWith("http")||(e=this.params.baseUrl+e);const n=yield fetch(e,i);if(n.status>=400){let e;const t=yield n.text();if(t){try{e=JSON.parse(t)}catch(e){}if(null==e?void 0:e.error)throw new Error(e.error);throw new Error(t)}throw new Error(`HTTP Error: ${n.status} ${n.statusText}`)}return n}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class r extends o{summary(e){return this.fetchJson("/lemur/v3/generate/summary",{method:"POST",body:JSON.stringify(e)})}questionAnswer(e){return this.fetchJson("/lemur/v3/generate/question-answer",{method:"POST",body:JSON.stringify(e)})}actionItems(e){return this.fetchJson("/lemur/v3/generate/action-items",{method:"POST",body:JSON.stringify(e)})}task(e){return this.fetchJson("/lemur/v3/generate/task",{method:"POST",body:JSON.stringify(e)})}getResponse(e){return this.fetchJson(`/lemur/v3/${e}`)}purgeRequestData(e){return this.fetchJson(`/lemur/v3/${e}`,{method:"DELETE"})}}const{WritableStream:a}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var d,c;const l=null!==(c=null!==(d=null!==WebSocket&&void 0!==WebSocket?WebSocket:null===global||void 0===global?void 0:global.WebSocket)&&void 0!==d?d:null===window||void 0===window?void 0:window.WebSocket)&&void 0!==c?c:null===self||void 0===self?void 0:self.WebSocket,u=(e,t)=>t?new l(e,t):new l(e);var h;!function(e){e[e.BadSampleRate=4e3]="BadSampleRate",e[e.AuthFailed=4001]="AuthFailed",e[e.InsufficientFundsOrFreeAccount=4002]="InsufficientFundsOrFreeAccount",e[e.NonexistentSessionId=4004]="NonexistentSessionId",e[e.SessionExpired=4008]="SessionExpired",e[e.ClosedSession=4010]="ClosedSession",e[e.RateLimited=4029]="RateLimited",e[e.UniqueSessionViolation=4030]="UniqueSessionViolation",e[e.SessionTimeout=4031]="SessionTimeout",e[e.AudioTooShort=4032]="AudioTooShort",e[e.AudioTooLong=4033]="AudioTooLong",e[e.BadJson=4100]="BadJson",e[e.BadSchema=4101]="BadSchema",e[e.TooManyStreams=4102]="TooManyStreams",e[e.Reconnected=4103]="Reconnected",e[e.ReconnectAttemptsExhausted=1013]="ReconnectAttemptsExhausted"}(h||(h={}));const f={[h.BadSampleRate]:"Sample rate must be a positive integer",[h.AuthFailed]:"Not Authorized",[h.InsufficientFundsOrFreeAccount]:"Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",[h.NonexistentSessionId]:"Session ID does not exist",[h.SessionExpired]:"Session has expired",[h.ClosedSession]:"Session is closed",[h.RateLimited]:"Rate limited",[h.UniqueSessionViolation]:"Unique session violation",[h.SessionTimeout]:"Session Timeout",[h.AudioTooShort]:"Audio too short",[h.AudioTooLong]:"Audio too long",[h.BadJson]:"Bad JSON",[h.BadSchema]:"Bad schema",[h.TooManyStreams]:"Too many streams",[h.Reconnected]:"Reconnected",[h.ReconnectAttemptsExhausted]:"Reconnect attempts exhausted"};class p extends Error{}const m='{"terminate_session":true}';class v{constructor(e){var t,s;if(this.listeners={},this.realtimeUrl=null!==(t=e.realtimeUrl)&&void 0!==t?t:"wss://api.assemblyai.com/v2/realtime/ws",this.sampleRate=null!==(s=e.sampleRate)&&void 0!==s?s:16e3,this.wordBoost=e.wordBoost,this.encoding=e.encoding,this.endUtteranceSilenceThreshold=e.endUtteranceSilenceThreshold,this.disablePartialTranscripts=e.disablePartialTranscripts,"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){const e=new URL(this.realtimeUrl);if("wss:"!==e.protocol)throw new Error("Invalid protocol, must be wss");const t=new URLSearchParams;return this.token&&t.set("token",this.token),t.set("sample_rate",this.sampleRate.toString()),this.wordBoost&&this.wordBoost.length>0&&t.set("word_boost",JSON.stringify(this.wordBoost)),this.encoding&&t.set("encoding",this.encoding),t.set("enable_extra_session_information","true"),this.disablePartialTranscripts&&t.set("disable_partial_transcripts",this.disablePartialTranscripts.toString()),e.search=t.toString(),e}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=u(t.toString()):this.socket=u(t.toString(),{headers:{Authorization:this.apiKey}}),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{void 0!==this.endUtteranceSilenceThreshold&&null!==this.endUtteranceSilenceThreshold&&this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold)},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in h&&(t=f[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,n;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(n=(i=this.listeners).error)||void 0===n||n.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,n,o,r,a,d,c,l,u,h,f,m,v,y;const b=JSON.parse(t.toString());if("error"in b)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new p(b.error));else switch(b.message_type){case"SessionBegins":{const t={sessionId:b.session_id,expiresAt:new Date(b.expires_at)};e(t),null===(o=(n=this.listeners).open)||void 0===o||o.call(n,t);break}case"PartialTranscript":b.created=new Date(b.created),null===(a=(r=this.listeners).transcript)||void 0===a||a.call(r,b),null===(c=(d=this.listeners)["transcript.partial"])||void 0===c||c.call(d,b);break;case"FinalTranscript":b.created=new Date(b.created),null===(u=(l=this.listeners).transcript)||void 0===u||u.call(l,b),null===(f=(h=this.listeners)["transcript.final"])||void 0===f||f.call(h,b);break;case"SessionInformation":null===(v=(m=this.listeners).session_information)||void 0===v||v.call(m,b);break;case"SessionTerminated":null===(y=this.sessionTerminatedResolve)||void 0===y||y.call(this)}}}))}sendAudio(e){this.send(e)}stream(){return new a({write:e=>{this.sendAudio(e)}})}forceEndUtterance(){this.send('{"force_end_utterance":true}')}configureEndUtteranceSilenceThreshold(e){this.send(`{"end_utterance_silence_threshold":${e}}`)}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(m),yield e}else this.socket.send(m);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class y extends o{constructor(e){super(e),this.rtFactoryParams=e}createService(e){return this.transcriber(e)}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.rtFactoryParams.apiKey),new v(t)}createTemporaryToken(e){return t(this,void 0,void 0,(function*(){return(yield this.fetchJson("/v2/realtime/token",{method:"POST",body:JSON.stringify(e)})).token}))}}function b(e){return e.startsWith("http")||e.startsWith("https")||e.startsWith("data:")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class S extends o{constructor(e,t){super(e),this.files=t}transcribe(e,s){return t(this,void 0,void 0,(function*(){const t=yield this.submit(e);return yield this.waitUntilReady(t.id,s)}))}submit(e){return t(this,void 0,void 0,(function*(){let t,s;if("audio"in e){const{audio:i}=e,n=function(e,t){var s={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(s[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(s[i[n]]=e[i[n]])}return s}(e,["audio"]);if("string"==typeof i){const e=b(i);t=null!==e?yield this.files.upload(e):i.startsWith("data:")?yield this.files.upload(i):i}else t=yield this.files.upload(i);s=Object.assign(Object.assign({},n),{audio_url:t})}else s=e;return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(s)})}))}create(e,s){return t(this,void 0,void 0,(function*(){var t;const i=b(e.audio_url);if(null!==i){const t=yield this.files.upload(i);e.audio_url=t}const n=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(t=null==s?void 0:s.poll)||void 0===t||t?yield this.waitUntilReady(n.id,s):n}))}waitUntilReady(e,s){return t(this,void 0,void 0,(function*(){var t,i;const n=null!==(t=null==s?void 0:s.pollingInterval)&&void 0!==t?t:3e3,o=null!==(i=null==s?void 0:s.pollingTimeout)&&void 0!==i?i:-1,r=Date.now();for(;;){const t=yield this.get(e);if("completed"===t.status||"error"===t.status)return t;if(o>0&&Date.now()-r>o)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,n)))}}))}get(e){return this.fetchJson(`/v2/transcript/${e}`)}list(e){return t(this,void 0,void 0,(function*(){let t="/v2/transcript";"string"==typeof e?t=e:e&&(t=`${t}?${new URLSearchParams(Object.keys(e).map((t=>{var s;return[t,(null===(s=e[t])||void 0===s?void 0:s.toString())||""]})))}`);const s=yield this.fetchJson(t);for(const e of s.transcripts)e.created=new Date(e.created),e.completed&&(e.completed=new Date(e.completed));return s}))}delete(e){return this.fetchJson(`/v2/transcript/${e}`,{method:"DELETE"})}wordSearch(e,t){const s=new URLSearchParams({words:t.join(",")});return this.fetchJson(`/v2/transcript/${e}/word-search?${s.toString()}`)}sentences(e){return this.fetchJson(`/v2/transcript/${e}/sentences`)}paragraphs(e){return this.fetchJson(`/v2/transcript/${e}/paragraphs`)}subtitles(e){return t(this,arguments,void 0,(function*(e,t="srt",s){let i=`/v2/transcript/${e}/${t}`;if(s){const e=new URLSearchParams;e.set("chars_per_caption",s.toString()),i+=`?${e.toString()}`}const n=yield this.fetch(i);return yield n.text()}))}redactions(e){return this.redactedAudio(e)}redactedAudio(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}redactedAudioFile(e){return t(this,void 0,void 0,(function*(){const{redacted_audio_url:t,status:s}=yield this.redactedAudio(e);if("redacted_audio_ready"!==s)throw new Error(`Redacted audio status is ${s}`);const i=yield fetch(t);if(!i.ok)throw new Error(`Failed to fetch redacted audio: ${i.statusText}`);return{arrayBuffer:i.arrayBuffer.bind(i),blob:i.blob.bind(i),body:i.body,bodyUsed:i.bodyUsed}}))}}class g extends o{upload(e){return t(this,void 0,void 0,(function*(){let s;s="string"==typeof e?e.startsWith("data:")?function(e){const t=e.split(","),s=t[0].match(/:(.*?);/)[1],i=atob(t[1]);let n=i.length;const o=new Uint8Array(n);for(;n--;)o[n]=i.charCodeAt(n);return new Blob([o],{type:s})}(e):yield function(e){return t(this,void 0,void 0,(function*(){throw new Error("Interacting with the file system is not supported in this environment.")}))}():e;return(yield this.fetchJson("/v2/upload",{method:"POST",body:s,headers:{"Content-Type":"application/octet-stream"},duplex:"half"})).upload_url}))}}e.AssemblyAI=class{constructor(e){e.baseUrl=e.baseUrl||"https://api.assemblyai.com",e.baseUrl&&e.baseUrl.endsWith("/")&&(e.baseUrl=e.baseUrl.slice(0,-1)),this.files=new g(e),this.transcripts=new S(e,this.files),this.lemur=new r(e),this.realtime=new y(e)}},e.FileService=g,e.LemurService=r,e.RealtimeService=class extends v{},e.RealtimeServiceFactory=class extends y{},e.RealtimeTranscriber=v,e.RealtimeTranscriberFactory=y,e.TranscriptService=S}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).assemblyai={})}(this,(function(e){"use strict";function t(e,t,s,i){return new(s||(s=Promise))((function(r,n){function o(e){try{l(i.next(e))}catch(e){n(e)}}function a(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s={cache:"no-store"};let i="";"undefined"!=typeof navigator&&navigator.userAgent&&(i+=navigator.userAgent);const r={sdk:{name:"JavaScript",version:"4.7.0"}};"undefined"!=typeof process&&(process.versions.node&&-1===i.indexOf("Node")&&(r.runtime_env={name:"Node",version:process.versions.node}),process.versions.bun&&-1===i.indexOf("Bun")&&(r.runtime_env={name:"Bun",version:process.versions.bun})),"undefined"!=typeof Deno&&process.versions.bun&&-1===i.indexOf("Deno")&&(r.runtime_env={name:"Deno",version:Deno.version.deno});class n{constructor(e){var t;this.params=e,!1===e.userAgent?this.userAgent=void 0:this.userAgent=(t=e.userAgent||{},i+(!1===t?"":" AssemblyAI/1.0 ("+Object.entries(Object.assign(Object.assign({},r),t)).map((([e,t])=>t?`${e}=${t.name}/${t.version}`:"")).join(" ")+")"))}fetch(e,i){return t(this,void 0,void 0,(function*(){i=Object.assign(Object.assign({},s),i);let t={Authorization:this.params.apiKey,"Content-Type":"application/json"};(null==s?void 0:s.headers)&&(t=Object.assign(Object.assign({},t),s.headers)),(null==i?void 0:i.headers)&&(t=Object.assign(Object.assign({},t),i.headers)),this.userAgent&&(t["User-Agent"]=this.userAgent,"undefined"!=typeof window&&"chrome"in window&&(t["AssemblyAI-Agent"]=this.userAgent)),i.headers=t,e.startsWith("http")||(e=this.params.baseUrl+e);const r=yield fetch(e,i);if(r.status>=400){let e;const t=yield r.text();if(t){try{e=JSON.parse(t)}catch(e){}if(null==e?void 0:e.error)throw new Error(e.error);throw new Error(t)}throw new Error(`HTTP Error: ${r.status} ${r.statusText}`)}return r}))}fetchJson(e,s){return t(this,void 0,void 0,(function*(){return(yield this.fetch(e,s)).json()}))}}class o extends n{summary(e){return this.fetchJson("/lemur/v3/generate/summary",{method:"POST",body:JSON.stringify(e)})}questionAnswer(e){return this.fetchJson("/lemur/v3/generate/question-answer",{method:"POST",body:JSON.stringify(e)})}actionItems(e){return this.fetchJson("/lemur/v3/generate/action-items",{method:"POST",body:JSON.stringify(e)})}task(e){return this.fetchJson("/lemur/v3/generate/task",{method:"POST",body:JSON.stringify(e)})}getResponse(e){return this.fetchJson(`/lemur/v3/${e}`)}purgeRequestData(e){return this.fetchJson(`/lemur/v3/${e}`,{method:"DELETE"})}}const{WritableStream:a}="undefined"!=typeof window?window:"undefined"!=typeof global?global:globalThis;var l,c;const d=null!==(c=null!==(l=null!==WebSocket&&void 0!==WebSocket?WebSocket:null===global||void 0===global?void 0:global.WebSocket)&&void 0!==l?l:null===window||void 0===window?void 0:window.WebSocket)&&void 0!==c?c:null===self||void 0===self?void 0:self.WebSocket,h=(e,t)=>t?new d(e,t):new d(e),u={[4e3]:"Sample rate must be a positive integer",[4001]:"Not Authorized",[4002]:"Insufficient funds",[4003]:"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.",[4004]:"Session ID does not exist",[4008]:"Session has expired",[4010]:"Session is closed",[4029]:"Rate limited",[4030]:"Unique session violation",[4031]:"Session Timeout",[4032]:"Audio too short",[4033]:"Audio too long",[4034]:"Audio too small to transcode",[4100]:"Bad JSON",[4101]:"Bad schema",[4102]:"Too many streams",[4103]:"This session has been reconnected. This WebSocket is no longer valid.",[1013]:"Reconnect attempts exhausted",[4104]:"Could not parse word boost parameter"};class f extends Error{}const p='{"terminate_session":true}';class v{constructor(e){var t,s;if(this.listeners={},this.realtimeUrl=null!==(t=e.realtimeUrl)&&void 0!==t?t:"wss://api.assemblyai.com/v2/realtime/ws",this.sampleRate=null!==(s=e.sampleRate)&&void 0!==s?s:16e3,this.wordBoost=e.wordBoost,this.encoding=e.encoding,this.endUtteranceSilenceThreshold=e.endUtteranceSilenceThreshold,this.disablePartialTranscripts=e.disablePartialTranscripts,"token"in e&&e.token&&(this.token=e.token),"apiKey"in e&&e.apiKey&&(this.apiKey=e.apiKey),!this.token&&!this.apiKey)throw new Error("API key or temporary token is required.")}connectionUrl(){const e=new URL(this.realtimeUrl);if("wss:"!==e.protocol)throw new Error("Invalid protocol, must be wss");const t=new URLSearchParams;return this.token&&t.set("token",this.token),t.set("sample_rate",this.sampleRate.toString()),this.wordBoost&&this.wordBoost.length>0&&t.set("word_boost",JSON.stringify(this.wordBoost)),this.encoding&&t.set("encoding",this.encoding),t.set("enable_extra_session_information","true"),this.disablePartialTranscripts&&t.set("disable_partial_transcripts",this.disablePartialTranscripts.toString()),e.search=t.toString(),e}on(e,t){this.listeners[e]=t}connect(){return new Promise((e=>{if(this.socket)throw new Error("Already connected");const t=this.connectionUrl();this.token?this.socket=h(t.toString()):this.socket=h(t.toString(),{headers:{Authorization:this.apiKey}}),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{void 0!==this.endUtteranceSilenceThreshold&&null!==this.endUtteranceSilenceThreshold&&this.configureEndUtteranceSilenceThreshold(this.endUtteranceSilenceThreshold)},this.socket.onclose=({code:e,reason:t})=>{var s,i;t||e in u&&(t=u[e]),null===(i=(s=this.listeners).close)||void 0===i||i.call(s,e,t)},this.socket.onerror=e=>{var t,s,i,r;e.error?null===(s=(t=this.listeners).error)||void 0===s||s.call(t,e.error):null===(r=(i=this.listeners).error)||void 0===r||r.call(i,new Error(e.message))},this.socket.onmessage=({data:t})=>{var s,i,r,n,o,a,l,c,d,h,u,p,v,m,y;const b=JSON.parse(t.toString());if("error"in b)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new f(b.error));else switch(b.message_type){case"SessionBegins":{const t={sessionId:b.session_id,expiresAt:new Date(b.expires_at)};e(t),null===(n=(r=this.listeners).open)||void 0===n||n.call(r,t);break}case"PartialTranscript":b.created=new Date(b.created),null===(a=(o=this.listeners).transcript)||void 0===a||a.call(o,b),null===(c=(l=this.listeners)["transcript.partial"])||void 0===c||c.call(l,b);break;case"FinalTranscript":b.created=new Date(b.created),null===(h=(d=this.listeners).transcript)||void 0===h||h.call(d,b),null===(p=(u=this.listeners)["transcript.final"])||void 0===p||p.call(u,b);break;case"SessionInformation":null===(m=(v=this.listeners).session_information)||void 0===m||m.call(v,b);break;case"SessionTerminated":null===(y=this.sessionTerminatedResolve)||void 0===y||y.call(this)}}}))}sendAudio(e){this.send(e)}stream(){return new a({write:e=>{this.sendAudio(e)}})}forceEndUtterance(){this.send('{"force_end_utterance":true}')}configureEndUtteranceSilenceThreshold(e){this.send(`{"end_utterance_silence_threshold":${e}}`)}send(e){if(!this.socket||this.socket.readyState!==this.socket.OPEN)throw new Error("Socket is not open for communication");this.socket.send(e)}close(){return t(this,arguments,void 0,(function*(e=!0){var t;if(this.socket){if(this.socket.readyState===this.socket.OPEN)if(e){const e=new Promise((e=>{this.sessionTerminatedResolve=e}));this.socket.send(p),yield e}else this.socket.send(p);(null===(t=this.socket)||void 0===t?void 0:t.removeAllListeners)&&this.socket.removeAllListeners(),this.socket.close()}this.listeners={},this.socket=void 0}))}}class m extends n{constructor(e){super(e),this.rtFactoryParams=e}createService(e){return this.transcriber(e)}transcriber(e){const t=Object.assign({},e);return t.token||t.apiKey||(t.apiKey=this.rtFactoryParams.apiKey),new v(t)}createTemporaryToken(e){return t(this,void 0,void 0,(function*(){return(yield this.fetchJson("/v2/realtime/token",{method:"POST",body:JSON.stringify(e)})).token}))}}function y(e){return e.startsWith("http")||e.startsWith("https")||e.startsWith("data:")?null:e.startsWith("file://")?e.substring(7):e.startsWith("file:")?e.substring(5):e}class b extends n{constructor(e,t){super(e),this.files=t}transcribe(e,s){return t(this,void 0,void 0,(function*(){const t=yield this.submit(e);return yield this.waitUntilReady(t.id,s)}))}submit(e){return t(this,void 0,void 0,(function*(){let t,s;if("audio"in e){const{audio:i}=e,r=function(e,t){var s={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(s[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(s[i[r]]=e[i[r]])}return s}(e,["audio"]);if("string"==typeof i){const e=y(i);t=null!==e?yield this.files.upload(e):i.startsWith("data:")?yield this.files.upload(i):i}else t=yield this.files.upload(i);s=Object.assign(Object.assign({},r),{audio_url:t})}else s=e;return yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(s)})}))}create(e,s){return t(this,void 0,void 0,(function*(){var t;const i=y(e.audio_url);if(null!==i){const t=yield this.files.upload(i);e.audio_url=t}const r=yield this.fetchJson("/v2/transcript",{method:"POST",body:JSON.stringify(e)});return null===(t=null==s?void 0:s.poll)||void 0===t||t?yield this.waitUntilReady(r.id,s):r}))}waitUntilReady(e,s){return t(this,void 0,void 0,(function*(){var t,i;const r=null!==(t=null==s?void 0:s.pollingInterval)&&void 0!==t?t:3e3,n=null!==(i=null==s?void 0:s.pollingTimeout)&&void 0!==i?i:-1,o=Date.now();for(;;){const t=yield this.get(e);if("completed"===t.status||"error"===t.status)return t;if(n>0&&Date.now()-o>n)throw new Error("Polling timeout");yield new Promise((e=>setTimeout(e,r)))}}))}get(e){return this.fetchJson(`/v2/transcript/${e}`)}list(e){return t(this,void 0,void 0,(function*(){let t="/v2/transcript";"string"==typeof e?t=e:e&&(t=`${t}?${new URLSearchParams(Object.keys(e).map((t=>{var s;return[t,(null===(s=e[t])||void 0===s?void 0:s.toString())||""]})))}`);const s=yield this.fetchJson(t);for(const e of s.transcripts)e.created=new Date(e.created),e.completed&&(e.completed=new Date(e.completed));return s}))}delete(e){return this.fetchJson(`/v2/transcript/${e}`,{method:"DELETE"})}wordSearch(e,t){const s=new URLSearchParams({words:t.join(",")});return this.fetchJson(`/v2/transcript/${e}/word-search?${s.toString()}`)}sentences(e){return this.fetchJson(`/v2/transcript/${e}/sentences`)}paragraphs(e){return this.fetchJson(`/v2/transcript/${e}/paragraphs`)}subtitles(e){return t(this,arguments,void 0,(function*(e,t="srt",s){let i=`/v2/transcript/${e}/${t}`;if(s){const e=new URLSearchParams;e.set("chars_per_caption",s.toString()),i+=`?${e.toString()}`}const r=yield this.fetch(i);return yield r.text()}))}redactions(e){return this.redactedAudio(e)}redactedAudio(e){return this.fetchJson(`/v2/transcript/${e}/redacted-audio`)}redactedAudioFile(e){return t(this,void 0,void 0,(function*(){const{redacted_audio_url:t,status:s}=yield this.redactedAudio(e);if("redacted_audio_ready"!==s)throw new Error(`Redacted audio status is ${s}`);const i=yield fetch(t);if(!i.ok)throw new Error(`Failed to fetch redacted audio: ${i.statusText}`);return{arrayBuffer:i.arrayBuffer.bind(i),blob:i.blob.bind(i),body:i.body,bodyUsed:i.bodyUsed}}))}}class w extends n{upload(e){return t(this,void 0,void 0,(function*(){let s;s="string"==typeof e?e.startsWith("data:")?function(e){const t=e.split(","),s=t[0].match(/:(.*?);/)[1],i=atob(t[1]);let r=i.length;const n=new Uint8Array(r);for(;r--;)n[r]=i.charCodeAt(r);return new Blob([n],{type:s})}(e):yield function(e){return t(this,void 0,void 0,(function*(){throw new Error("Interacting with the file system is not supported in this environment.")}))}():e;return(yield this.fetchJson("/v2/upload",{method:"POST",body:s,headers:{"Content-Type":"application/octet-stream"},duplex:"half"})).upload_url}))}}e.AssemblyAI=class{constructor(e){e.baseUrl=e.baseUrl||"https://api.assemblyai.com",e.baseUrl&&e.baseUrl.endsWith("/")&&(e.baseUrl=e.baseUrl.slice(0,-1)),this.files=new w(e),this.transcripts=new b(e,this.files),this.lemur=new o(e),this.realtime=new m(e)}},e.FileService=w,e.LemurService=o,e.RealtimeService=class extends v{},e.RealtimeServiceFactory=class extends m{},e.RealtimeTranscriber=v,e.RealtimeTranscriberFactory=m,e.TranscriptService=b}));
package/dist/browser.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.1" },
18
+ sdk: { name: "JavaScript", version: "4.7.0" },
19
19
  };
20
20
  if (typeof process !== "undefined") {
21
21
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -153,30 +153,42 @@ const factory = (url, params) => {
153
153
  return new PolyfillWebSocket(url);
154
154
  };
155
155
 
156
- var RealtimeErrorType;
157
- (function (RealtimeErrorType) {
158
- RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
159
- RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
160
- // Both InsufficientFunds and FreeAccount error use 4002
161
- RealtimeErrorType[RealtimeErrorType["InsufficientFundsOrFreeAccount"] = 4002] = "InsufficientFundsOrFreeAccount";
162
- RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
163
- RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
164
- RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
165
- RealtimeErrorType[RealtimeErrorType["RateLimited"] = 4029] = "RateLimited";
166
- RealtimeErrorType[RealtimeErrorType["UniqueSessionViolation"] = 4030] = "UniqueSessionViolation";
167
- RealtimeErrorType[RealtimeErrorType["SessionTimeout"] = 4031] = "SessionTimeout";
168
- RealtimeErrorType[RealtimeErrorType["AudioTooShort"] = 4032] = "AudioTooShort";
169
- RealtimeErrorType[RealtimeErrorType["AudioTooLong"] = 4033] = "AudioTooLong";
170
- RealtimeErrorType[RealtimeErrorType["BadJson"] = 4100] = "BadJson";
171
- RealtimeErrorType[RealtimeErrorType["BadSchema"] = 4101] = "BadSchema";
172
- RealtimeErrorType[RealtimeErrorType["TooManyStreams"] = 4102] = "TooManyStreams";
173
- RealtimeErrorType[RealtimeErrorType["Reconnected"] = 4103] = "Reconnected";
174
- RealtimeErrorType[RealtimeErrorType["ReconnectAttemptsExhausted"] = 1013] = "ReconnectAttemptsExhausted";
175
- })(RealtimeErrorType || (RealtimeErrorType = {}));
156
+ const RealtimeErrorType = {
157
+ BadSampleRate: 4000,
158
+ AuthFailed: 4001,
159
+ /**
160
+ * @deprecated Use InsufficientFunds or FreeTierUser instead
161
+ */
162
+ InsufficientFundsOrFreeAccount: 4002,
163
+ InsufficientFunds: 4002,
164
+ FreeTierUser: 4003,
165
+ NonexistentSessionId: 4004,
166
+ SessionExpired: 4008,
167
+ ClosedSession: 4010,
168
+ RateLimited: 4029,
169
+ UniqueSessionViolation: 4030,
170
+ SessionTimeout: 4031,
171
+ AudioTooShort: 4032,
172
+ AudioTooLong: 4033,
173
+ AudioTooSmallToTranscode: 4034,
174
+ /**
175
+ * @deprecated Don't use
176
+ */
177
+ BadJson: 4100,
178
+ BadSchema: 4101,
179
+ TooManyStreams: 4102,
180
+ Reconnected: 4103,
181
+ /**
182
+ * @deprecated Don't use
183
+ */
184
+ ReconnectAttemptsExhausted: 1013,
185
+ WordBoostParameterParsingFailed: 4104,
186
+ };
176
187
  const RealtimeErrorMessages = {
177
188
  [RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
178
189
  [RealtimeErrorType.AuthFailed]: "Not Authorized",
179
- [RealtimeErrorType.InsufficientFundsOrFreeAccount]: "Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",
190
+ [RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
191
+ [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.",
180
192
  [RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
181
193
  [RealtimeErrorType.SessionExpired]: "Session has expired",
182
194
  [RealtimeErrorType.ClosedSession]: "Session is closed",
@@ -185,11 +197,13 @@ const RealtimeErrorMessages = {
185
197
  [RealtimeErrorType.SessionTimeout]: "Session Timeout",
186
198
  [RealtimeErrorType.AudioTooShort]: "Audio too short",
187
199
  [RealtimeErrorType.AudioTooLong]: "Audio too long",
200
+ [RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
188
201
  [RealtimeErrorType.BadJson]: "Bad JSON",
189
202
  [RealtimeErrorType.BadSchema]: "Bad schema",
190
203
  [RealtimeErrorType.TooManyStreams]: "Too many streams",
191
- [RealtimeErrorType.Reconnected]: "Reconnected",
204
+ [RealtimeErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
192
205
  [RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
206
+ [RealtimeErrorType.WordBoostParameterParsingFailed]: "Could not parse word boost parameter",
193
207
  };
194
208
  class RealtimeError extends Error {
195
209
  }
@@ -281,7 +295,7 @@ class RealtimeTranscriber {
281
295
  };
282
296
  this.socket.onclose = ({ code, reason }) => {
283
297
  if (!reason) {
284
- if (code in RealtimeErrorType) {
298
+ if (code in RealtimeErrorMessages) {
285
299
  reason = RealtimeErrorMessages[code];
286
300
  }
287
301
  }
package/dist/bun.mjs CHANGED
@@ -17,7 +17,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
17
17
  defaultUserAgentString += navigator.userAgent;
18
18
  }
19
19
  const defaultUserAgent = {
20
- sdk: { name: "JavaScript", version: "4.6.1" },
20
+ sdk: { name: "JavaScript", version: "4.7.0" },
21
21
  };
22
22
  if (typeof process !== "undefined") {
23
23
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -149,30 +149,42 @@ const { WritableStream } = typeof window !== "undefined"
149
149
 
150
150
  const factory = (url, params) => new ws(url, params);
151
151
 
152
- var RealtimeErrorType;
153
- (function (RealtimeErrorType) {
154
- RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
155
- RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
156
- // Both InsufficientFunds and FreeAccount error use 4002
157
- RealtimeErrorType[RealtimeErrorType["InsufficientFundsOrFreeAccount"] = 4002] = "InsufficientFundsOrFreeAccount";
158
- RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
159
- RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
160
- RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
161
- RealtimeErrorType[RealtimeErrorType["RateLimited"] = 4029] = "RateLimited";
162
- RealtimeErrorType[RealtimeErrorType["UniqueSessionViolation"] = 4030] = "UniqueSessionViolation";
163
- RealtimeErrorType[RealtimeErrorType["SessionTimeout"] = 4031] = "SessionTimeout";
164
- RealtimeErrorType[RealtimeErrorType["AudioTooShort"] = 4032] = "AudioTooShort";
165
- RealtimeErrorType[RealtimeErrorType["AudioTooLong"] = 4033] = "AudioTooLong";
166
- RealtimeErrorType[RealtimeErrorType["BadJson"] = 4100] = "BadJson";
167
- RealtimeErrorType[RealtimeErrorType["BadSchema"] = 4101] = "BadSchema";
168
- RealtimeErrorType[RealtimeErrorType["TooManyStreams"] = 4102] = "TooManyStreams";
169
- RealtimeErrorType[RealtimeErrorType["Reconnected"] = 4103] = "Reconnected";
170
- RealtimeErrorType[RealtimeErrorType["ReconnectAttemptsExhausted"] = 1013] = "ReconnectAttemptsExhausted";
171
- })(RealtimeErrorType || (RealtimeErrorType = {}));
152
+ const RealtimeErrorType = {
153
+ BadSampleRate: 4000,
154
+ AuthFailed: 4001,
155
+ /**
156
+ * @deprecated Use InsufficientFunds or FreeTierUser instead
157
+ */
158
+ InsufficientFundsOrFreeAccount: 4002,
159
+ InsufficientFunds: 4002,
160
+ FreeTierUser: 4003,
161
+ NonexistentSessionId: 4004,
162
+ SessionExpired: 4008,
163
+ ClosedSession: 4010,
164
+ RateLimited: 4029,
165
+ UniqueSessionViolation: 4030,
166
+ SessionTimeout: 4031,
167
+ AudioTooShort: 4032,
168
+ AudioTooLong: 4033,
169
+ AudioTooSmallToTranscode: 4034,
170
+ /**
171
+ * @deprecated Don't use
172
+ */
173
+ BadJson: 4100,
174
+ BadSchema: 4101,
175
+ TooManyStreams: 4102,
176
+ Reconnected: 4103,
177
+ /**
178
+ * @deprecated Don't use
179
+ */
180
+ ReconnectAttemptsExhausted: 1013,
181
+ WordBoostParameterParsingFailed: 4104,
182
+ };
172
183
  const RealtimeErrorMessages = {
173
184
  [RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
174
185
  [RealtimeErrorType.AuthFailed]: "Not Authorized",
175
- [RealtimeErrorType.InsufficientFundsOrFreeAccount]: "Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",
186
+ [RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
187
+ [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.",
176
188
  [RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
177
189
  [RealtimeErrorType.SessionExpired]: "Session has expired",
178
190
  [RealtimeErrorType.ClosedSession]: "Session is closed",
@@ -181,11 +193,13 @@ const RealtimeErrorMessages = {
181
193
  [RealtimeErrorType.SessionTimeout]: "Session Timeout",
182
194
  [RealtimeErrorType.AudioTooShort]: "Audio too short",
183
195
  [RealtimeErrorType.AudioTooLong]: "Audio too long",
196
+ [RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
184
197
  [RealtimeErrorType.BadJson]: "Bad JSON",
185
198
  [RealtimeErrorType.BadSchema]: "Bad schema",
186
199
  [RealtimeErrorType.TooManyStreams]: "Too many streams",
187
- [RealtimeErrorType.Reconnected]: "Reconnected",
200
+ [RealtimeErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
188
201
  [RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
202
+ [RealtimeErrorType.WordBoostParameterParsingFailed]: "Could not parse word boost parameter",
189
203
  };
190
204
  class RealtimeError extends Error {
191
205
  }
@@ -277,7 +291,7 @@ class RealtimeTranscriber {
277
291
  };
278
292
  this.socket.onclose = ({ code, reason }) => {
279
293
  if (!reason) {
280
- if (code in RealtimeErrorType) {
294
+ if (code in RealtimeErrorMessages) {
281
295
  reason = RealtimeErrorMessages[code];
282
296
  }
283
297
  }
package/dist/deno.mjs CHANGED
@@ -17,7 +17,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
17
17
  defaultUserAgentString += navigator.userAgent;
18
18
  }
19
19
  const defaultUserAgent = {
20
- sdk: { name: "JavaScript", version: "4.6.1" },
20
+ sdk: { name: "JavaScript", version: "4.7.0" },
21
21
  };
22
22
  if (typeof process !== "undefined") {
23
23
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -149,30 +149,42 @@ const { WritableStream } = typeof window !== "undefined"
149
149
 
150
150
  const factory = (url, params) => new ws(url, params);
151
151
 
152
- var RealtimeErrorType;
153
- (function (RealtimeErrorType) {
154
- RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
155
- RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
156
- // Both InsufficientFunds and FreeAccount error use 4002
157
- RealtimeErrorType[RealtimeErrorType["InsufficientFundsOrFreeAccount"] = 4002] = "InsufficientFundsOrFreeAccount";
158
- RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
159
- RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
160
- RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
161
- RealtimeErrorType[RealtimeErrorType["RateLimited"] = 4029] = "RateLimited";
162
- RealtimeErrorType[RealtimeErrorType["UniqueSessionViolation"] = 4030] = "UniqueSessionViolation";
163
- RealtimeErrorType[RealtimeErrorType["SessionTimeout"] = 4031] = "SessionTimeout";
164
- RealtimeErrorType[RealtimeErrorType["AudioTooShort"] = 4032] = "AudioTooShort";
165
- RealtimeErrorType[RealtimeErrorType["AudioTooLong"] = 4033] = "AudioTooLong";
166
- RealtimeErrorType[RealtimeErrorType["BadJson"] = 4100] = "BadJson";
167
- RealtimeErrorType[RealtimeErrorType["BadSchema"] = 4101] = "BadSchema";
168
- RealtimeErrorType[RealtimeErrorType["TooManyStreams"] = 4102] = "TooManyStreams";
169
- RealtimeErrorType[RealtimeErrorType["Reconnected"] = 4103] = "Reconnected";
170
- RealtimeErrorType[RealtimeErrorType["ReconnectAttemptsExhausted"] = 1013] = "ReconnectAttemptsExhausted";
171
- })(RealtimeErrorType || (RealtimeErrorType = {}));
152
+ const RealtimeErrorType = {
153
+ BadSampleRate: 4000,
154
+ AuthFailed: 4001,
155
+ /**
156
+ * @deprecated Use InsufficientFunds or FreeTierUser instead
157
+ */
158
+ InsufficientFundsOrFreeAccount: 4002,
159
+ InsufficientFunds: 4002,
160
+ FreeTierUser: 4003,
161
+ NonexistentSessionId: 4004,
162
+ SessionExpired: 4008,
163
+ ClosedSession: 4010,
164
+ RateLimited: 4029,
165
+ UniqueSessionViolation: 4030,
166
+ SessionTimeout: 4031,
167
+ AudioTooShort: 4032,
168
+ AudioTooLong: 4033,
169
+ AudioTooSmallToTranscode: 4034,
170
+ /**
171
+ * @deprecated Don't use
172
+ */
173
+ BadJson: 4100,
174
+ BadSchema: 4101,
175
+ TooManyStreams: 4102,
176
+ Reconnected: 4103,
177
+ /**
178
+ * @deprecated Don't use
179
+ */
180
+ ReconnectAttemptsExhausted: 1013,
181
+ WordBoostParameterParsingFailed: 4104,
182
+ };
172
183
  const RealtimeErrorMessages = {
173
184
  [RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
174
185
  [RealtimeErrorType.AuthFailed]: "Not Authorized",
175
- [RealtimeErrorType.InsufficientFundsOrFreeAccount]: "Insufficient funds or you are using a free account. This feature is paid-only and requires you to add a credit card. Please visit https://assemblyai.com/dashboard/ to add a credit card to your account.",
186
+ [RealtimeErrorType.InsufficientFunds]: "Insufficient funds",
187
+ [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.",
176
188
  [RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
177
189
  [RealtimeErrorType.SessionExpired]: "Session has expired",
178
190
  [RealtimeErrorType.ClosedSession]: "Session is closed",
@@ -181,11 +193,13 @@ const RealtimeErrorMessages = {
181
193
  [RealtimeErrorType.SessionTimeout]: "Session Timeout",
182
194
  [RealtimeErrorType.AudioTooShort]: "Audio too short",
183
195
  [RealtimeErrorType.AudioTooLong]: "Audio too long",
196
+ [RealtimeErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
184
197
  [RealtimeErrorType.BadJson]: "Bad JSON",
185
198
  [RealtimeErrorType.BadSchema]: "Bad schema",
186
199
  [RealtimeErrorType.TooManyStreams]: "Too many streams",
187
- [RealtimeErrorType.Reconnected]: "Reconnected",
200
+ [RealtimeErrorType.Reconnected]: "This session has been reconnected. This WebSocket is no longer valid.",
188
201
  [RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
202
+ [RealtimeErrorType.WordBoostParameterParsingFailed]: "Could not parse word boost parameter",
189
203
  };
190
204
  class RealtimeError extends Error {
191
205
  }
@@ -277,7 +291,7 @@ class RealtimeTranscriber {
277
291
  };
278
292
  this.socket.onclose = ({ code, reason }) => {
279
293
  if (!reason) {
280
- if (code in RealtimeErrorType) {
294
+ if (code in RealtimeErrorMessages) {
281
295
  reason = RealtimeErrorMessages[code];
282
296
  }
283
297
  }