assemblyai 4.7.0-alpha → 4.7.1
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 +18 -0
- package/README.md +4 -4
- package/dist/assemblyai.streaming.umd.js +5 -1
- package/dist/assemblyai.streaming.umd.min.js +1 -1
- package/dist/assemblyai.umd.js +12 -6
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +11 -5
- package/dist/bun.mjs +1 -6
- package/dist/deno.mjs +1 -6
- package/dist/index.cjs +8 -6
- package/dist/index.mjs +8 -6
- package/dist/node.cjs +1 -6
- package/dist/node.mjs +1 -6
- package/dist/polyfills/websocket/index.d.ts +1 -0
- package/dist/streaming.browser.mjs +4 -0
- package/dist/streaming.cjs +1 -1
- package/dist/streaming.mjs +1 -1
- package/dist/types/openapi.generated.d.ts +6 -6
- package/dist/utils/conditions/browser.d.ts +2 -0
- package/dist/utils/conditions/bun.d.ts +2 -0
- package/dist/utils/conditions/conditions.d.ts +10 -0
- package/dist/utils/conditions/default.d.ts +2 -0
- package/dist/utils/conditions/deno.d.ts +2 -0
- package/dist/utils/conditions/node.d.ts +2 -0
- package/dist/utils/conditions/react-native.d.ts +2 -0
- package/dist/utils/conditions/workerd.d.ts +2 -0
- package/dist/workerd.mjs +1 -6
- package/package.json +34 -23
- package/src/services/base.ts +7 -4
- package/src/services/realtime/service.ts +8 -0
- package/src/types/openapi.generated.ts +6 -6
- package/src/utils/conditions/browser.ts +12 -0
- package/src/utils/conditions/bun.ts +12 -0
- package/src/utils/conditions/conditions.ts +10 -0
- package/src/utils/conditions/default.ts +12 -0
- package/src/utils/conditions/deno.ts +12 -0
- package/src/utils/conditions/node.ts +12 -0
- package/src/utils/conditions/react-native.ts +12 -0
- package/src/utils/conditions/workerd.ts +12 -0
- package/README.internal.md +0 -100
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.7.1]
|
|
4
|
+
|
|
5
|
+
* Log a warning when a user tries to use API key authentication in the browser to connect to the real-time Streaming STT API.
|
|
6
|
+
* Update dependencies
|
|
7
|
+
* Use assembly.ai short URL for sample files
|
|
8
|
+
|
|
9
|
+
## [4.7.0]
|
|
10
|
+
|
|
11
|
+
- Add `language_confidence_threshold` to `Transcript`, `TranscriptParams`, and `TranscriptOptionalParams`.
|
|
12
|
+
> The confidence threshold for the automatically detected language.
|
|
13
|
+
> An error will be returned if the langauge confidence is below this threshold.
|
|
14
|
+
- Add `language_confidence` to `Transcript`
|
|
15
|
+
> The confidence score for the detected language, between 0.0 (low confidence) and 1.0 (high confidence)
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
[Learn more about the new automatic language detection model and feature improvements on our blog.](https://www.assemblyai.com/blog/ald-improvements)
|
|
20
|
+
|
|
3
21
|
## [4.6.2]
|
|
4
22
|
|
|
5
23
|
- Change `RealtimeErrorType` from enum to const object.
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://twitter.com/AssemblyAI)
|
|
9
9
|
[](https://www.youtube.com/@AssemblyAI)
|
|
10
10
|
[
|
|
11
|
-
](https://
|
|
11
|
+
](https://assembly.ai/discord)
|
|
12
12
|
|
|
13
13
|
# AssemblyAI JavaScript SDK
|
|
14
14
|
|
|
@@ -97,7 +97,7 @@ When you create a transcript, you can either pass in a URL to an audio file or u
|
|
|
97
97
|
```js
|
|
98
98
|
// Transcribe file at remote URL
|
|
99
99
|
let transcript = await client.transcripts.transcribe({
|
|
100
|
-
audio: "https://
|
|
100
|
+
audio: "https://assembly.ai/espn.m4a",
|
|
101
101
|
});
|
|
102
102
|
```
|
|
103
103
|
|
|
@@ -110,7 +110,7 @@ If you don't want to wait until the transcript is ready, you can use `submit`:
|
|
|
110
110
|
|
|
111
111
|
```js
|
|
112
112
|
let transcript = await client.transcripts.submit({
|
|
113
|
-
audio: "https://
|
|
113
|
+
audio: "https://assembly.ai/espn.m4a",
|
|
114
114
|
});
|
|
115
115
|
```
|
|
116
116
|
|
|
@@ -151,7 +151,7 @@ For example, here's how to enable [Speaker diarization](https://www.assemblyai.c
|
|
|
151
151
|
|
|
152
152
|
```js
|
|
153
153
|
let transcript = await client.transcripts.transcribe({
|
|
154
|
-
audio: "https://
|
|
154
|
+
audio: "https://assembly.ai/espn.m4a",
|
|
155
155
|
speaker_labels: true,
|
|
156
156
|
});
|
|
157
157
|
for (let utterance of transcript.utterances) {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
19
|
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
21
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
@@ -180,6 +180,10 @@
|
|
|
180
180
|
this.socket = factory(url.toString());
|
|
181
181
|
}
|
|
182
182
|
else {
|
|
183
|
+
{
|
|
184
|
+
console.warn(`API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.
|
|
185
|
+
Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility.`);
|
|
186
|
+
}
|
|
183
187
|
this.socket = factory(url.toString(), {
|
|
184
188
|
headers: { Authorization: this.apiKey },
|
|
185
189
|
});
|
|
@@ -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),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,
|
|
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()):(console.warn("API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.\nLearn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility."),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,m,f,w,v;const b=JSON.parse(t.toString());if("error"in b)null===(i=(s=this.listeners).error)||void 0===i||i.call(s,new l(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=(o=this.listeners).open)||void 0===n||n.call(o,t);break}case"PartialTranscript":b.created=new Date(b.created),null===(a=(r=this.listeners).transcript)||void 0===a||a.call(r,b),null===(d=(c=this.listeners)["transcript.partial"])||void 0===d||d.call(c,b);break;case"FinalTranscript":b.created=new Date(b.created),null===(u=(h=this.listeners).transcript)||void 0===u||u.call(h,b),null===(m=(p=this.listeners)["transcript.final"])||void 0===m||m.call(p,b);break;case"SessionInformation":null===(w=(f=this.listeners).session_information)||void 0===w||w.call(f,b);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(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}));
|
package/dist/assemblyai.umd.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
19
|
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
21
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
function __rest(s, e) {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
defaultUserAgentString += navigator.userAgent;
|
|
66
66
|
}
|
|
67
67
|
const defaultUserAgent = {
|
|
68
|
-
sdk: { name: "JavaScript", version: "4.
|
|
68
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
69
69
|
};
|
|
70
70
|
if (typeof process !== "undefined") {
|
|
71
71
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -117,10 +117,12 @@
|
|
|
117
117
|
headers = Object.assign(Object.assign({}, headers), init.headers);
|
|
118
118
|
if (this.userAgent) {
|
|
119
119
|
headers["User-Agent"] = this.userAgent;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
{
|
|
121
|
+
// chromium browsers have a bug where the user agent can't be modified
|
|
122
|
+
if (typeof window !== "undefined" && "chrome" in window) {
|
|
123
|
+
headers["AssemblyAI-Agent"] =
|
|
124
|
+
this.userAgent;
|
|
125
|
+
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
init.headers = headers;
|
|
@@ -337,6 +339,10 @@
|
|
|
337
339
|
this.socket = factory(url.toString());
|
|
338
340
|
}
|
|
339
341
|
else {
|
|
342
|
+
{
|
|
343
|
+
console.warn(`API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.
|
|
344
|
+
Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility.`);
|
|
345
|
+
}
|
|
340
346
|
this.socket = factory(url.toString(), {
|
|
341
347
|
headers: { Authorization: this.apiKey },
|
|
342
348
|
});
|
|
@@ -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(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.6.2"}};"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}));
|
|
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.1"}};"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 p extends Error{}const f='{"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()):(console.warn("API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.\nLearn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility."),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,f,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 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===(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===(f=(u=this.listeners)["transcript.final"])||void 0===f||f.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(f),yield e}else this.socket.send(f);(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.
|
|
18
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
19
19
|
};
|
|
20
20
|
if (typeof process !== "undefined") {
|
|
21
21
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -66,10 +66,12 @@ class BaseService {
|
|
|
66
66
|
headers = { ...headers, ...init.headers };
|
|
67
67
|
if (this.userAgent) {
|
|
68
68
|
headers["User-Agent"] = this.userAgent;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
{
|
|
70
|
+
// chromium browsers have a bug where the user agent can't be modified
|
|
71
|
+
if (typeof window !== "undefined" && "chrome" in window) {
|
|
72
|
+
headers["AssemblyAI-Agent"] =
|
|
73
|
+
this.userAgent;
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
init.headers = headers;
|
|
@@ -281,6 +283,10 @@ class RealtimeTranscriber {
|
|
|
281
283
|
this.socket = factory(url.toString());
|
|
282
284
|
}
|
|
283
285
|
else {
|
|
286
|
+
{
|
|
287
|
+
console.warn(`API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.
|
|
288
|
+
Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility.`);
|
|
289
|
+
}
|
|
284
290
|
this.socket = factory(url.toString(), {
|
|
285
291
|
headers: { Authorization: this.apiKey },
|
|
286
292
|
});
|
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.
|
|
20
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
21
21
|
};
|
|
22
22
|
if (typeof process !== "undefined") {
|
|
23
23
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -68,11 +68,6 @@ class BaseService {
|
|
|
68
68
|
headers = { ...headers, ...init.headers };
|
|
69
69
|
if (this.userAgent) {
|
|
70
70
|
headers["User-Agent"] = this.userAgent;
|
|
71
|
-
// chromium browsers have a bug where the user agent can't be modified
|
|
72
|
-
if (typeof window !== "undefined" && "chrome" in window) {
|
|
73
|
-
headers["AssemblyAI-Agent"] =
|
|
74
|
-
this.userAgent;
|
|
75
|
-
}
|
|
76
71
|
}
|
|
77
72
|
init.headers = headers;
|
|
78
73
|
if (!input.startsWith("http"))
|
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.
|
|
20
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
21
21
|
};
|
|
22
22
|
if (typeof process !== "undefined") {
|
|
23
23
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -68,11 +68,6 @@ class BaseService {
|
|
|
68
68
|
headers = { ...headers, ...init.headers };
|
|
69
69
|
if (this.userAgent) {
|
|
70
70
|
headers["User-Agent"] = this.userAgent;
|
|
71
|
-
// chromium browsers have a bug where the user agent can't be modified
|
|
72
|
-
if (typeof window !== "undefined" && "chrome" in window) {
|
|
73
|
-
headers["AssemblyAI-Agent"] =
|
|
74
|
-
this.userAgent;
|
|
75
|
-
}
|
|
76
71
|
}
|
|
77
72
|
init.headers = headers;
|
|
78
73
|
if (!input.startsWith("http"))
|
package/dist/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
16
16
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
17
|
PERFORMANCE OF THIS SOFTWARE.
|
|
18
18
|
***************************************************************************** */
|
|
19
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
19
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
function __rest(s, e) {
|
|
@@ -63,7 +63,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
63
63
|
defaultUserAgentString += navigator.userAgent;
|
|
64
64
|
}
|
|
65
65
|
const defaultUserAgent = {
|
|
66
|
-
sdk: { name: "JavaScript", version: "4.
|
|
66
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
67
67
|
};
|
|
68
68
|
if (typeof process !== "undefined") {
|
|
69
69
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -115,10 +115,12 @@ class BaseService {
|
|
|
115
115
|
headers = Object.assign(Object.assign({}, headers), init.headers);
|
|
116
116
|
if (this.userAgent) {
|
|
117
117
|
headers["User-Agent"] = this.userAgent;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
{
|
|
119
|
+
// chromium browsers have a bug where the user agent can't be modified
|
|
120
|
+
if (typeof window !== "undefined" && "chrome" in window) {
|
|
121
|
+
headers["AssemblyAI-Agent"] =
|
|
122
|
+
this.userAgent;
|
|
123
|
+
}
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
init.headers = headers;
|
package/dist/index.mjs
CHANGED
|
@@ -14,7 +14,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
14
14
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
***************************************************************************** */
|
|
17
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
function __rest(s, e) {
|
|
@@ -61,7 +61,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
61
61
|
defaultUserAgentString += navigator.userAgent;
|
|
62
62
|
}
|
|
63
63
|
const defaultUserAgent = {
|
|
64
|
-
sdk: { name: "JavaScript", version: "4.
|
|
64
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
65
65
|
};
|
|
66
66
|
if (typeof process !== "undefined") {
|
|
67
67
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -113,10 +113,12 @@ class BaseService {
|
|
|
113
113
|
headers = Object.assign(Object.assign({}, headers), init.headers);
|
|
114
114
|
if (this.userAgent) {
|
|
115
115
|
headers["User-Agent"] = this.userAgent;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
{
|
|
117
|
+
// chromium browsers have a bug where the user agent can't be modified
|
|
118
|
+
if (typeof window !== "undefined" && "chrome" in window) {
|
|
119
|
+
headers["AssemblyAI-Agent"] =
|
|
120
|
+
this.userAgent;
|
|
121
|
+
}
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
init.headers = headers;
|
package/dist/node.cjs
CHANGED
|
@@ -22,7 +22,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
22
22
|
defaultUserAgentString += navigator.userAgent;
|
|
23
23
|
}
|
|
24
24
|
const defaultUserAgent = {
|
|
25
|
-
sdk: { name: "JavaScript", version: "4.
|
|
25
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
26
26
|
};
|
|
27
27
|
if (typeof process !== "undefined") {
|
|
28
28
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -73,11 +73,6 @@ class BaseService {
|
|
|
73
73
|
headers = { ...headers, ...init.headers };
|
|
74
74
|
if (this.userAgent) {
|
|
75
75
|
headers["User-Agent"] = this.userAgent;
|
|
76
|
-
// chromium browsers have a bug where the user agent can't be modified
|
|
77
|
-
if (typeof window !== "undefined" && "chrome" in window) {
|
|
78
|
-
headers["AssemblyAI-Agent"] =
|
|
79
|
-
this.userAgent;
|
|
80
|
-
}
|
|
81
76
|
}
|
|
82
77
|
init.headers = headers;
|
|
83
78
|
if (!input.startsWith("http"))
|
package/dist/node.mjs
CHANGED
|
@@ -20,7 +20,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
|
|
|
20
20
|
defaultUserAgentString += navigator.userAgent;
|
|
21
21
|
}
|
|
22
22
|
const defaultUserAgent = {
|
|
23
|
-
sdk: { name: "JavaScript", version: "4.
|
|
23
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
24
24
|
};
|
|
25
25
|
if (typeof process !== "undefined") {
|
|
26
26
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -71,11 +71,6 @@ class BaseService {
|
|
|
71
71
|
headers = { ...headers, ...init.headers };
|
|
72
72
|
if (this.userAgent) {
|
|
73
73
|
headers["User-Agent"] = this.userAgent;
|
|
74
|
-
// chromium browsers have a bug where the user agent can't be modified
|
|
75
|
-
if (typeof window !== "undefined" && "chrome" in window) {
|
|
76
|
-
headers["AssemblyAI-Agent"] =
|
|
77
|
-
this.userAgent;
|
|
78
|
-
}
|
|
79
74
|
}
|
|
80
75
|
init.headers = headers;
|
|
81
76
|
if (!input.startsWith("http"))
|
|
@@ -140,6 +140,10 @@ class RealtimeTranscriber {
|
|
|
140
140
|
this.socket = factory(url.toString());
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
143
|
+
{
|
|
144
|
+
console.warn(`API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.
|
|
145
|
+
Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility.`);
|
|
146
|
+
}
|
|
143
147
|
this.socket = factory(url.toString(), {
|
|
144
148
|
headers: { Authorization: this.apiKey },
|
|
145
149
|
});
|
package/dist/streaming.cjs
CHANGED
|
@@ -16,7 +16,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
16
16
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
17
|
PERFORMANCE OF THIS SOFTWARE.
|
|
18
18
|
***************************************************************************** */
|
|
19
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
19
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
function __awaiter(thisArg, _arguments, P, generator) {
|
package/dist/streaming.mjs
CHANGED
|
@@ -14,7 +14,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
14
14
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
***************************************************************************** */
|
|
17
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
@@ -1448,7 +1448,7 @@ export type TopicDetectionResult = {
|
|
|
1448
1448
|
* "acoustic_model": "assemblyai_default",
|
|
1449
1449
|
* "language_code": "en_us",
|
|
1450
1450
|
* "status": "completed",
|
|
1451
|
-
* "audio_url": "https://
|
|
1451
|
+
* "audio_url": "https://assembly.ai/wildfires.mp3",
|
|
1452
1452
|
* "text": "Smoke from hundreds of wildfires in Canada is triggering air quality alerts throughout the US. Skylines from Maine to Maryland to Minnesota are gray and smoggy. And in some places, the air quality warnings include the warning to stay inside. We wanted to better understand what's happening here and why, so we called Peter de Carlo, an associate professor in the Department of Environmental Health and Engineering at Johns Hopkins University Varsity. Good morning, professor. Good morning. What is it about the conditions right now that have caused this round of wildfires to affect so many people so far away? Well, there's a couple of things. The season has been pretty dry already. And then the fact that we're getting hit in the US. Is because there's a couple of weather systems that are essentially channeling the smoke from those Canadian wildfires through Pennsylvania into the Mid Atlantic and the Northeast and kind of just dropping the smoke there. So what is it in this haze that makes it harmful? And I'm assuming it is harmful. It is. The levels outside right now in Baltimore are considered unhealthy. And most of that is due to what's called particulate matter, which are tiny particles, microscopic smaller than the width of your hair that can get into your lungs and impact your respiratory system, your cardiovascular system, and even your neurological your brain. What makes this particularly harmful? Is it the volume of particulant? Is it something in particular? What is it exactly? Can you just drill down on that a little bit more? Yeah. So the concentration of particulate matter I was looking at some of the monitors that we have was reaching levels of what are, in science, big 150 micrograms per meter cubed, which is more than ten times what the annual average should be and about four times higher than what you're supposed to have on a 24 hours average. And so the concentrations of these particles in the air are just much, much higher than we typically see. And exposure to those high levels can lead to a host of health problems. And who is most vulnerable? I noticed that in New York City, for example, they're canceling outdoor activities. And so here it is in the early days of summer, and they have to keep all the kids inside. So who tends to be vulnerable in a situation like this? It's the youngest. So children, obviously, whose bodies are still developing. The elderly, who are their bodies are more in decline and they're more susceptible to the health impacts of breathing, the poor air quality. And then people who have preexisting health conditions, people with respiratory conditions or heart conditions can be triggered by high levels of air pollution. Could this get worse? That's a good question. In some areas, it's much worse than others. And it just depends on kind of where the smoke is concentrated. I think New York has some of the higher concentrations right now, but that's going to change as that air moves away from the New York area. But over the course of the next few days, we will see different areas being hit at different times with the highest concentrations. I was going to ask you about more fires start burning. I don't expect the concentrations to go up too much higher. I was going to ask you how and you started to answer this, but how much longer could this last? Or forgive me if I'm asking you to speculate, but what do you think? Well, I think the fires are going to burn for a little bit longer, but the key for us in the US. Is the weather system changing. And so right now, it's kind of the weather systems that are pulling that air into our mid Atlantic and Northeast region. As those weather systems change and shift, we'll see that smoke going elsewhere and not impact us in this region as much. And so I think that's going to be the defining factor. And I think the next couple of days we're going to see a shift in that weather pattern and start to push the smoke away from where we are. And finally, with the impacts of climate change, we are seeing more wildfires. Will we be seeing more of these kinds of wide ranging air quality consequences or circumstances? I mean, that is one of the predictions for climate change. Looking into the future, the fire season is starting earlier and lasting longer, and we're seeing more frequent fires. So, yeah, this is probably something that we'll be seeing more frequently. This tends to be much more of an issue in the Western US. So the eastern US. Getting hit right now is a little bit new. But yeah, I think with climate change moving forward, this is something that is going to happen more frequently. That's Peter De Carlo, associate professor in the Department of Environmental Health and Engineering at Johns Hopkins University. Sergeant Carlo, thanks so much for joining us and sharing this expertise with us. Thank you for having me.",
|
|
1453
1453
|
* "words": [
|
|
1454
1454
|
* {
|
|
@@ -2444,8 +2444,8 @@ export type TranscriptLanguageCode = "en" | "en_au" | "en_uk" | "en_us" | "es" |
|
|
|
2444
2444
|
* "status": "error",
|
|
2445
2445
|
* "created": "2024-03-11T21:23:59.979420",
|
|
2446
2446
|
* "completed": null,
|
|
2447
|
-
* "audio_url": "https://storage.googleapis.com/client-docs-samples/nbc.
|
|
2448
|
-
* "error": "Download error, unable to download https://storage.googleapis.com/client-docs-samples/nbc.
|
|
2447
|
+
* "audio_url": "https://storage.googleapis.com/client-docs-samples/nbc.oopsie",
|
|
2448
|
+
* "error": "Download error, unable to download https://storage.googleapis.com/client-docs-samples/nbc.oopsie. Please make sure the file exists and is accessible from the internet."
|
|
2449
2449
|
* },
|
|
2450
2450
|
* {
|
|
2451
2451
|
* "id": "28a73d01-98db-41dd-9e98-2533ba0af117",
|
|
@@ -2453,7 +2453,7 @@ export type TranscriptLanguageCode = "en" | "en_au" | "en_uk" | "en_us" | "es" |
|
|
|
2453
2453
|
* "status": "completed",
|
|
2454
2454
|
* "created": "2024-03-11T21:12:57.372215",
|
|
2455
2455
|
* "completed": "2024-03-11T21:13:03.267020",
|
|
2456
|
-
* "audio_url": "https://
|
|
2456
|
+
* "audio_url": "https://assembly.ai/nbc.mp3",
|
|
2457
2457
|
* "error": null
|
|
2458
2458
|
* }
|
|
2459
2459
|
* ]
|
|
@@ -2473,7 +2473,7 @@ export type TranscriptList = {
|
|
|
2473
2473
|
* "status": "completed",
|
|
2474
2474
|
* "created": "2023-11-02T21:49:25.586965",
|
|
2475
2475
|
* "completed": "2023-11-02T21:49:25.586965",
|
|
2476
|
-
* "audio_url": "https://
|
|
2476
|
+
* "audio_url": "https://assembly.ai/wildfires.mp3",
|
|
2477
2477
|
* "error": null
|
|
2478
2478
|
* }
|
|
2479
2479
|
* ```
|
|
@@ -2762,7 +2762,7 @@ export type TranscriptParagraph = {
|
|
|
2762
2762
|
* {
|
|
2763
2763
|
* "speech_model": null,
|
|
2764
2764
|
* "language_code": "en_us",
|
|
2765
|
-
* "audio_url": "https://
|
|
2765
|
+
* "audio_url": "https://assembly.ai/wildfires.mp3",
|
|
2766
2766
|
* "punctuate": true,
|
|
2767
2767
|
* "format_text": true,
|
|
2768
2768
|
* "dual_channel": true,
|
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.
|
|
18
|
+
sdk: { name: "JavaScript", version: "4.7.1" },
|
|
19
19
|
};
|
|
20
20
|
if (typeof process !== "undefined") {
|
|
21
21
|
if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
|
|
@@ -66,11 +66,6 @@ class BaseService {
|
|
|
66
66
|
headers = { ...headers, ...init.headers };
|
|
67
67
|
if (this.userAgent) {
|
|
68
68
|
headers["User-Agent"] = this.userAgent;
|
|
69
|
-
// chromium browsers have a bug where the user agent can't be modified
|
|
70
|
-
if (typeof window !== "undefined" && "chrome" in window) {
|
|
71
|
-
headers["AssemblyAI-Agent"] =
|
|
72
|
-
this.userAgent;
|
|
73
|
-
}
|
|
74
69
|
}
|
|
75
70
|
init.headers = headers;
|
|
76
71
|
if (!input.startsWith("http"))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblyai",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.1",
|
|
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"
|
|
@@ -56,6 +56,15 @@
|
|
|
56
56
|
"browser": "./src/polyfills/websocket/browser.ts",
|
|
57
57
|
"node": "./src/polyfills/websocket/default.ts",
|
|
58
58
|
"default": "./src/polyfills/websocket/default.ts"
|
|
59
|
+
},
|
|
60
|
+
"#conditions": {
|
|
61
|
+
"bun": "./src/utils/conditions/bun.ts",
|
|
62
|
+
"deno": "./src/utils/conditions/deno.ts",
|
|
63
|
+
"workerd": "./src/utils/conditions/workerd.ts",
|
|
64
|
+
"react-native": "./src/utils/conditions/react-native.ts",
|
|
65
|
+
"browser": "./src/utils/conditions/browser.ts",
|
|
66
|
+
"node": "./src/utils/conditions/node.ts",
|
|
67
|
+
"default": "./src/utils/conditions/default.ts"
|
|
59
68
|
}
|
|
60
69
|
},
|
|
61
70
|
"type": "commonjs",
|
|
@@ -71,7 +80,7 @@
|
|
|
71
80
|
"url": "git+https://github.com/AssemblyAI/assemblyai-node-sdk.git"
|
|
72
81
|
},
|
|
73
82
|
"publishConfig": {
|
|
74
|
-
"tag": "
|
|
83
|
+
"tag": "latest",
|
|
75
84
|
"access": "public",
|
|
76
85
|
"registry": "https://registry.npmjs.org/"
|
|
77
86
|
},
|
|
@@ -115,19 +124,19 @@
|
|
|
115
124
|
"docs"
|
|
116
125
|
],
|
|
117
126
|
"devDependencies": {
|
|
118
|
-
"@babel/preset-env": "^7.
|
|
127
|
+
"@babel/preset-env": "^7.25.4",
|
|
119
128
|
"@babel/preset-typescript": "^7.24.7",
|
|
120
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
121
|
-
"@rollup/plugin-replace": "^
|
|
129
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
130
|
+
"@rollup/plugin-replace": "^6.0.1",
|
|
122
131
|
"@rollup/plugin-terser": "^0.4.4",
|
|
123
|
-
"@rollup/plugin-typescript": "^
|
|
124
|
-
"@types/jest": "^29.5.
|
|
125
|
-
"@types/node": "^18.19.
|
|
132
|
+
"@rollup/plugin-typescript": "^12.1.0",
|
|
133
|
+
"@types/jest": "^29.5.13",
|
|
134
|
+
"@types/node": "^18.19.53",
|
|
126
135
|
"@types/websocket": "^1.0.10",
|
|
127
|
-
"@types/ws": "^8.5.
|
|
128
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
136
|
+
"@types/ws": "^8.5.12",
|
|
137
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
129
138
|
"dotenv": "^16.4.5",
|
|
130
|
-
"eslint": "^8.57.
|
|
139
|
+
"eslint": "^8.57.1",
|
|
131
140
|
"eslint-plugin-tsdoc": "^0.3.0",
|
|
132
141
|
"jest": "^29.7.0",
|
|
133
142
|
"jest-cli": "^29.7.0",
|
|
@@ -135,31 +144,33 @@
|
|
|
135
144
|
"jest-junit": "^16.0.0",
|
|
136
145
|
"jest-websocket-mock": "^2.5.0",
|
|
137
146
|
"mock-socket": "^9.3.1",
|
|
138
|
-
"openapi-typescript": "^6.7.
|
|
139
|
-
"prettier": "^3.3.
|
|
140
|
-
"publint": "^0.2.
|
|
141
|
-
"rimraf": "^
|
|
142
|
-
"rollup": "^4.
|
|
143
|
-
"ts-jest": "^29.
|
|
144
|
-
"tslib": "^2.
|
|
145
|
-
"typedoc": "^0.
|
|
146
|
-
"typedoc-plugin-extras": "^3.
|
|
147
|
+
"openapi-typescript": "^6.7.6",
|
|
148
|
+
"prettier": "^3.3.3",
|
|
149
|
+
"publint": "^0.2.11",
|
|
150
|
+
"rimraf": "^6.0.1",
|
|
151
|
+
"rollup": "^4.22.4",
|
|
152
|
+
"ts-jest": "^29.2.5",
|
|
153
|
+
"tslib": "^2.7.0",
|
|
154
|
+
"typedoc": "^0.26.7",
|
|
155
|
+
"typedoc-plugin-extras": "^3.1.0",
|
|
147
156
|
"typescript": "^5.4.5"
|
|
148
157
|
},
|
|
149
158
|
"dependencies": {
|
|
150
|
-
"ws": "^8.
|
|
159
|
+
"ws": "^8.18.0"
|
|
151
160
|
},
|
|
152
161
|
"pnpm": {
|
|
153
162
|
"packageExtensions": {
|
|
154
163
|
"ws": {
|
|
155
164
|
"peerDependencies": {
|
|
156
|
-
"@types/ws": "^8.5.
|
|
165
|
+
"@types/ws": "^8.5.12"
|
|
157
166
|
}
|
|
158
167
|
}
|
|
159
168
|
},
|
|
160
169
|
"overrides": {
|
|
161
170
|
"undici@<5.28.4": ">=5.28.4",
|
|
162
|
-
"braces@<3.0.3": ">=3.0.3"
|
|
171
|
+
"braces@<3.0.3": ">=3.0.3",
|
|
172
|
+
"micromatch@<4.0.8": ">=4.0.8",
|
|
173
|
+
"rollup@<2.79.2": ">=2.79.2"
|
|
163
174
|
}
|
|
164
175
|
}
|
|
165
176
|
}
|
package/src/services/base.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { conditions } from "#conditions";
|
|
1
2
|
import { DEFAULT_FETCH_INIT } from "#fetch";
|
|
2
3
|
import { BaseServiceParams, Error as JsonError } from "..";
|
|
3
4
|
import { buildUserAgent } from "../utils/userAgent";
|
|
@@ -33,10 +34,12 @@ export abstract class BaseService {
|
|
|
33
34
|
|
|
34
35
|
if (this.userAgent) {
|
|
35
36
|
(headers as Record<string, string>)["User-Agent"] = this.userAgent;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
(
|
|
39
|
-
|
|
37
|
+
if (conditions.browser || conditions.default) {
|
|
38
|
+
// chromium browsers have a bug where the user agent can't be modified
|
|
39
|
+
if (typeof window !== "undefined" && "chrome" in window) {
|
|
40
|
+
(headers as Record<string, string>)["AssemblyAI-Agent"] =
|
|
41
|
+
this.userAgent;
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
init.headers = headers;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WritableStream } from "#streams";
|
|
2
|
+
import { conditions } from "#conditions";
|
|
2
3
|
import {
|
|
3
4
|
PolyfillWebSocket,
|
|
4
5
|
factory as polyfillWebSocketFactory,
|
|
@@ -190,6 +191,13 @@ export class RealtimeTranscriber {
|
|
|
190
191
|
if (this.token) {
|
|
191
192
|
this.socket = polyfillWebSocketFactory(url.toString());
|
|
192
193
|
} else {
|
|
194
|
+
if (conditions.browser) {
|
|
195
|
+
console.warn(
|
|
196
|
+
`API key authentication is not supported for the RealtimeTranscriber in browser environment. Use temporary token authentication instead.
|
|
197
|
+
Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility.`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
193
201
|
this.socket = polyfillWebSocketFactory(url.toString(), {
|
|
194
202
|
headers: { Authorization: this.apiKey },
|
|
195
203
|
});
|
|
@@ -1615,7 +1615,7 @@ export type TopicDetectionResult = {
|
|
|
1615
1615
|
* "acoustic_model": "assemblyai_default",
|
|
1616
1616
|
* "language_code": "en_us",
|
|
1617
1617
|
* "status": "completed",
|
|
1618
|
-
* "audio_url": "https://
|
|
1618
|
+
* "audio_url": "https://assembly.ai/wildfires.mp3",
|
|
1619
1619
|
* "text": "Smoke from hundreds of wildfires in Canada is triggering air quality alerts throughout the US. Skylines from Maine to Maryland to Minnesota are gray and smoggy. And in some places, the air quality warnings include the warning to stay inside. We wanted to better understand what's happening here and why, so we called Peter de Carlo, an associate professor in the Department of Environmental Health and Engineering at Johns Hopkins University Varsity. Good morning, professor. Good morning. What is it about the conditions right now that have caused this round of wildfires to affect so many people so far away? Well, there's a couple of things. The season has been pretty dry already. And then the fact that we're getting hit in the US. Is because there's a couple of weather systems that are essentially channeling the smoke from those Canadian wildfires through Pennsylvania into the Mid Atlantic and the Northeast and kind of just dropping the smoke there. So what is it in this haze that makes it harmful? And I'm assuming it is harmful. It is. The levels outside right now in Baltimore are considered unhealthy. And most of that is due to what's called particulate matter, which are tiny particles, microscopic smaller than the width of your hair that can get into your lungs and impact your respiratory system, your cardiovascular system, and even your neurological your brain. What makes this particularly harmful? Is it the volume of particulant? Is it something in particular? What is it exactly? Can you just drill down on that a little bit more? Yeah. So the concentration of particulate matter I was looking at some of the monitors that we have was reaching levels of what are, in science, big 150 micrograms per meter cubed, which is more than ten times what the annual average should be and about four times higher than what you're supposed to have on a 24 hours average. And so the concentrations of these particles in the air are just much, much higher than we typically see. And exposure to those high levels can lead to a host of health problems. And who is most vulnerable? I noticed that in New York City, for example, they're canceling outdoor activities. And so here it is in the early days of summer, and they have to keep all the kids inside. So who tends to be vulnerable in a situation like this? It's the youngest. So children, obviously, whose bodies are still developing. The elderly, who are their bodies are more in decline and they're more susceptible to the health impacts of breathing, the poor air quality. And then people who have preexisting health conditions, people with respiratory conditions or heart conditions can be triggered by high levels of air pollution. Could this get worse? That's a good question. In some areas, it's much worse than others. And it just depends on kind of where the smoke is concentrated. I think New York has some of the higher concentrations right now, but that's going to change as that air moves away from the New York area. But over the course of the next few days, we will see different areas being hit at different times with the highest concentrations. I was going to ask you about more fires start burning. I don't expect the concentrations to go up too much higher. I was going to ask you how and you started to answer this, but how much longer could this last? Or forgive me if I'm asking you to speculate, but what do you think? Well, I think the fires are going to burn for a little bit longer, but the key for us in the US. Is the weather system changing. And so right now, it's kind of the weather systems that are pulling that air into our mid Atlantic and Northeast region. As those weather systems change and shift, we'll see that smoke going elsewhere and not impact us in this region as much. And so I think that's going to be the defining factor. And I think the next couple of days we're going to see a shift in that weather pattern and start to push the smoke away from where we are. And finally, with the impacts of climate change, we are seeing more wildfires. Will we be seeing more of these kinds of wide ranging air quality consequences or circumstances? I mean, that is one of the predictions for climate change. Looking into the future, the fire season is starting earlier and lasting longer, and we're seeing more frequent fires. So, yeah, this is probably something that we'll be seeing more frequently. This tends to be much more of an issue in the Western US. So the eastern US. Getting hit right now is a little bit new. But yeah, I think with climate change moving forward, this is something that is going to happen more frequently. That's Peter De Carlo, associate professor in the Department of Environmental Health and Engineering at Johns Hopkins University. Sergeant Carlo, thanks so much for joining us and sharing this expertise with us. Thank you for having me.",
|
|
1620
1620
|
* "words": [
|
|
1621
1621
|
* {
|
|
@@ -2717,8 +2717,8 @@ export type TranscriptLanguageCode =
|
|
|
2717
2717
|
* "status": "error",
|
|
2718
2718
|
* "created": "2024-03-11T21:23:59.979420",
|
|
2719
2719
|
* "completed": null,
|
|
2720
|
-
* "audio_url": "https://storage.googleapis.com/client-docs-samples/nbc.
|
|
2721
|
-
* "error": "Download error, unable to download https://storage.googleapis.com/client-docs-samples/nbc.
|
|
2720
|
+
* "audio_url": "https://storage.googleapis.com/client-docs-samples/nbc.oopsie",
|
|
2721
|
+
* "error": "Download error, unable to download https://storage.googleapis.com/client-docs-samples/nbc.oopsie. Please make sure the file exists and is accessible from the internet."
|
|
2722
2722
|
* },
|
|
2723
2723
|
* {
|
|
2724
2724
|
* "id": "28a73d01-98db-41dd-9e98-2533ba0af117",
|
|
@@ -2726,7 +2726,7 @@ export type TranscriptLanguageCode =
|
|
|
2726
2726
|
* "status": "completed",
|
|
2727
2727
|
* "created": "2024-03-11T21:12:57.372215",
|
|
2728
2728
|
* "completed": "2024-03-11T21:13:03.267020",
|
|
2729
|
-
* "audio_url": "https://
|
|
2729
|
+
* "audio_url": "https://assembly.ai/nbc.mp3",
|
|
2730
2730
|
* "error": null
|
|
2731
2731
|
* }
|
|
2732
2732
|
* ]
|
|
@@ -2747,7 +2747,7 @@ export type TranscriptList = {
|
|
|
2747
2747
|
* "status": "completed",
|
|
2748
2748
|
* "created": "2023-11-02T21:49:25.586965",
|
|
2749
2749
|
* "completed": "2023-11-02T21:49:25.586965",
|
|
2750
|
-
* "audio_url": "https://
|
|
2750
|
+
* "audio_url": "https://assembly.ai/wildfires.mp3",
|
|
2751
2751
|
* "error": null
|
|
2752
2752
|
* }
|
|
2753
2753
|
* ```
|
|
@@ -3039,7 +3039,7 @@ export type TranscriptParagraph = {
|
|
|
3039
3039
|
* {
|
|
3040
3040
|
* "speech_model": null,
|
|
3041
3041
|
* "language_code": "en_us",
|
|
3042
|
-
* "audio_url": "https://
|
|
3042
|
+
* "audio_url": "https://assembly.ai/wildfires.mp3",
|
|
3043
3043
|
* "punctuate": true,
|
|
3044
3044
|
* "format_text": true,
|
|
3045
3045
|
* "dual_channel": true,
|
package/README.internal.md
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# AssemblyAI JavaScript SDK
|
|
2
|
-
|
|
3
|
-
The AssemblyAI JavaScript SDK is developed using:
|
|
4
|
-
|
|
5
|
-
- Language: TypeScript
|
|
6
|
-
- Testing: Jest
|
|
7
|
-
- Bundler: Rollup
|
|
8
|
-
- Package manager: pnpm
|
|
9
|
-
|
|
10
|
-
## Private vs public spec repository
|
|
11
|
-
|
|
12
|
-
This README.internal.md file and adjacent files are stored in
|
|
13
|
-
the [DeepLearning monorepo](#private-deeplearning-monorepo), which is private for AssemblyAI employees only.
|
|
14
|
-
|
|
15
|
-
Most files are also synced to the [public spec repo](#public-spec-repo) using [Copybara](#copybara).
|
|
16
|
-
|
|
17
|
-
### Private DeepLearning monorepo
|
|
18
|
-
|
|
19
|
-
While most of the files in this folder are shared publicly using the public spec repo,
|
|
20
|
-
some files should only be kept in the [private repo](https://github.com/AssemblyAI/DeepLearning), like this README.internal.md.
|
|
21
|
-
|
|
22
|
-
The files that are synced are defined in the [Copybara configuration](./copy.bara.sky).
|
|
23
|
-
|
|
24
|
-
### Public spec repo
|
|
25
|
-
|
|
26
|
-
[The public spec repo](https://github.com/AssemblyAI/assemblyai-node-sdk) has multiple purposes:
|
|
27
|
-
|
|
28
|
-
1. Open-source the SDK code
|
|
29
|
-
2. Accept feedback & contributions through issues and PRs
|
|
30
|
-
3. Release the SDK to npmjs
|
|
31
|
-
4. Publish the API reference using GitHub Actions
|
|
32
|
-
|
|
33
|
-
## Copybara
|
|
34
|
-
|
|
35
|
-
We use [Copybara](https://github.com/google/copybara) to synchronize the private and public repo.
|
|
36
|
-
Copybara relies on [Bazel](https://bazel.build/) as part of the monorepo tooling.
|
|
37
|
-
To use the Copybara scripts, you must [set up Bazel](../../../docs/general/installation/05-bazel.md).
|
|
38
|
-
|
|
39
|
-
To create a PR with synced changes from the private to the public repo, run the following:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
./copybara.sh sync_out --init-history
|
|
43
|
-
## or the pnpm script
|
|
44
|
-
# pnpm copybara:pr
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
To verify the synced changes before create the PR, you can also perform a _dry run_:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
./copybara.sh dry_run --init-history
|
|
51
|
-
## or the pnpm script
|
|
52
|
-
# pnpm copybara:dry-run
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
The Copybara configuration is defined in [copy.bara.sky](./copy.bara.sky).
|
|
56
|
-
|
|
57
|
-
## Contribute to the JavaScript SDK
|
|
58
|
-
|
|
59
|
-
If you want to contribute to the spec, you should do so via the [private monorepo](#private-deeplearning-monorepo).
|
|
60
|
-
The private repo enforces our internal rules and peer-reviews.
|
|
61
|
-
|
|
62
|
-
### Set up
|
|
63
|
-
|
|
64
|
-
Follow these steps to set up the private repo:
|
|
65
|
-
|
|
66
|
-
1. Clone the [monorepo](https://github.com/AssemblyAI/DeepLearning).
|
|
67
|
-
2. [Set up Bazel](../../../docs/general/installation/05-bazel.md).
|
|
68
|
-
3. [Set up pnpm (version 8)](https://pnpm.io/installation).
|
|
69
|
-
|
|
70
|
-
### Make changes
|
|
71
|
-
|
|
72
|
-
Refer to the [CONTRIBUTING.md](./CONTRIBUTING.md) file for guidance on how to contribute.
|
|
73
|
-
The CONTRIBUTING.md file is written for contributors that don't work at AssemblyAI.
|
|
74
|
-
|
|
75
|
-
For AssemblyAI, the development workflow differs in the following ways:
|
|
76
|
-
|
|
77
|
-
- Instead of forking the public repo and cloning it, clone the monorepo.
|
|
78
|
-
- Get the latest changes from the `master` branch, not the `main` branch.
|
|
79
|
-
- Commit your changes, push your branch, and create a pull request (follow [the PR guidelines](../../../docs/general/pr_process.md)).
|
|
80
|
-
- Your PR will be checked using GitHub Actions. These checks run [Bazel](#Bazel) targets.
|
|
81
|
-
|
|
82
|
-
### Push changes to public repo
|
|
83
|
-
|
|
84
|
-
Follow these steps to push your changes to the public spec repo:
|
|
85
|
-
|
|
86
|
-
1. Make sure your changes have been merged into `master` via a PR.
|
|
87
|
-
2. Git checkout `master` and get the latest changes.
|
|
88
|
-
3. Run `pnpm copybara:dry-run` and verify the output is desired.
|
|
89
|
-
If not desired, update the [copy.bara.sky](./copy.bara.sky) file.
|
|
90
|
-
4. Run `pnpm copybara:pr`.
|
|
91
|
-
5. Go to the new PR, update the title and description.
|
|
92
|
-
6. Ensure the checks pass for the PR before merging the PR to `main`.
|
|
93
|
-
|
|
94
|
-
## Notes about the JavaScript SDK
|
|
95
|
-
|
|
96
|
-
### Bazel
|
|
97
|
-
|
|
98
|
-
Bazel is used to automate and ensure code quality inside the DeepLearning monorepo.
|
|
99
|
-
GitHub Actions will run a variety of checks which run Bazel targets defined for the
|
|
100
|
-
whole repo, and additional targets defined in [BUILD.bazel](./BUILD.bazel).
|