assemblyai 4.0.0-beta.1 → 4.0.0-beta.3

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/dist/deno.mjs ADDED
@@ -0,0 +1,545 @@
1
+ import WebSocket from '#ws';
2
+
3
+ /**
4
+ * Base class for services that communicate with the API.
5
+ */
6
+ class BaseService {
7
+ /**
8
+ * Create a new service.
9
+ * @param params The parameters to use for the service.
10
+ */
11
+ constructor(params) {
12
+ this.params = params;
13
+ }
14
+ async fetch(input, init) {
15
+ init = init ?? {};
16
+ init.headers = init.headers ?? {};
17
+ init.headers = {
18
+ Authorization: this.params.apiKey,
19
+ "Content-Type": "application/json",
20
+ ...init.headers,
21
+ };
22
+ if (!input.startsWith("http"))
23
+ input = this.params.baseUrl + input;
24
+ const response = await fetch(input, init);
25
+ if (response.status >= 400) {
26
+ let json;
27
+ const text = await response.text();
28
+ if (text) {
29
+ try {
30
+ json = JSON.parse(text);
31
+ }
32
+ catch {
33
+ /* empty */
34
+ }
35
+ if (json?.error)
36
+ throw new Error(json.error);
37
+ throw new Error(text);
38
+ }
39
+ throw new Error(`HTTP Error: ${response.status} ${response.statusText}`);
40
+ }
41
+ return response;
42
+ }
43
+ async fetchJson(input, init) {
44
+ const response = await this.fetch(input, init);
45
+ return response.json();
46
+ }
47
+ }
48
+
49
+ class LemurService extends BaseService {
50
+ summary(params) {
51
+ return this.fetchJson("/lemur/v3/generate/summary", {
52
+ method: "POST",
53
+ body: JSON.stringify(params),
54
+ });
55
+ }
56
+ questionAnswer(params) {
57
+ return this.fetchJson("/lemur/v3/generate/question-answer", {
58
+ method: "POST",
59
+ body: JSON.stringify(params),
60
+ });
61
+ }
62
+ actionItems(params) {
63
+ return this.fetchJson("/lemur/v3/generate/action-items", {
64
+ method: "POST",
65
+ body: JSON.stringify(params),
66
+ });
67
+ }
68
+ task(params) {
69
+ return this.fetchJson("/lemur/v3/generate/task", {
70
+ method: "POST",
71
+ body: JSON.stringify(params),
72
+ });
73
+ }
74
+ /**
75
+ * Delete the data for a previously submitted LeMUR request.
76
+ * @param id ID of the LeMUR request
77
+ */
78
+ purgeRequestData(id) {
79
+ return this.fetchJson(`/lemur/v3/${id}`, {
80
+ method: "DELETE",
81
+ });
82
+ }
83
+ }
84
+
85
+ const { WritableStream } = typeof window !== "undefined"
86
+ ? window
87
+ : typeof global !== "undefined"
88
+ ? global
89
+ : globalThis;
90
+
91
+ var RealtimeErrorType;
92
+ (function (RealtimeErrorType) {
93
+ RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
94
+ RealtimeErrorType[RealtimeErrorType["AuthFailed"] = 4001] = "AuthFailed";
95
+ // Both InsufficientFunds and FreeAccount error use 4002
96
+ RealtimeErrorType[RealtimeErrorType["InsufficientFundsOrFreeAccount"] = 4002] = "InsufficientFundsOrFreeAccount";
97
+ RealtimeErrorType[RealtimeErrorType["NonexistentSessionId"] = 4004] = "NonexistentSessionId";
98
+ RealtimeErrorType[RealtimeErrorType["SessionExpired"] = 4008] = "SessionExpired";
99
+ RealtimeErrorType[RealtimeErrorType["ClosedSession"] = 4010] = "ClosedSession";
100
+ RealtimeErrorType[RealtimeErrorType["RateLimited"] = 4029] = "RateLimited";
101
+ RealtimeErrorType[RealtimeErrorType["UniqueSessionViolation"] = 4030] = "UniqueSessionViolation";
102
+ RealtimeErrorType[RealtimeErrorType["SessionTimeout"] = 4031] = "SessionTimeout";
103
+ RealtimeErrorType[RealtimeErrorType["AudioTooShort"] = 4032] = "AudioTooShort";
104
+ RealtimeErrorType[RealtimeErrorType["AudioTooLong"] = 4033] = "AudioTooLong";
105
+ RealtimeErrorType[RealtimeErrorType["BadJson"] = 4100] = "BadJson";
106
+ RealtimeErrorType[RealtimeErrorType["BadSchema"] = 4101] = "BadSchema";
107
+ RealtimeErrorType[RealtimeErrorType["TooManyStreams"] = 4102] = "TooManyStreams";
108
+ RealtimeErrorType[RealtimeErrorType["Reconnected"] = 4103] = "Reconnected";
109
+ RealtimeErrorType[RealtimeErrorType["ReconnectAttemptsExhausted"] = 1013] = "ReconnectAttemptsExhausted";
110
+ })(RealtimeErrorType || (RealtimeErrorType = {}));
111
+ const RealtimeErrorMessages = {
112
+ [RealtimeErrorType.BadSampleRate]: "Sample rate must be a positive integer",
113
+ [RealtimeErrorType.AuthFailed]: "Not Authorized",
114
+ [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.",
115
+ [RealtimeErrorType.NonexistentSessionId]: "Session ID does not exist",
116
+ [RealtimeErrorType.SessionExpired]: "Session has expired",
117
+ [RealtimeErrorType.ClosedSession]: "Session is closed",
118
+ [RealtimeErrorType.RateLimited]: "Rate limited",
119
+ [RealtimeErrorType.UniqueSessionViolation]: "Unique session violation",
120
+ [RealtimeErrorType.SessionTimeout]: "Session Timeout",
121
+ [RealtimeErrorType.AudioTooShort]: "Audio too short",
122
+ [RealtimeErrorType.AudioTooLong]: "Audio too long",
123
+ [RealtimeErrorType.BadJson]: "Bad JSON",
124
+ [RealtimeErrorType.BadSchema]: "Bad schema",
125
+ [RealtimeErrorType.TooManyStreams]: "Too many streams",
126
+ [RealtimeErrorType.Reconnected]: "Reconnected",
127
+ [RealtimeErrorType.ReconnectAttemptsExhausted]: "Reconnect attempts exhausted",
128
+ };
129
+ class RealtimeError extends Error {
130
+ }
131
+
132
+ const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
133
+ class RealtimeService {
134
+ constructor(params) {
135
+ this.listeners = {};
136
+ this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
137
+ this.sampleRate = params.sampleRate ?? 16000;
138
+ this.wordBoost = params.wordBoost;
139
+ if ("apiKey" in params && params.apiKey)
140
+ this.apiKey = params.apiKey;
141
+ if ("token" in params && params.token)
142
+ this.token = params.token;
143
+ if (!(this.apiKey || this.token)) {
144
+ throw new Error("API key or temporary token is required.");
145
+ }
146
+ }
147
+ connectionUrl() {
148
+ const url = new URL(this.realtimeUrl);
149
+ if (url.protocol !== "wss:") {
150
+ throw new Error("Invalid protocol, must be wss");
151
+ }
152
+ const searchParams = new URLSearchParams();
153
+ if (this.token) {
154
+ searchParams.set("token", this.token);
155
+ }
156
+ searchParams.set("sample_rate", this.sampleRate.toString());
157
+ if (this.wordBoost && this.wordBoost.length > 0) {
158
+ searchParams.set("word_boost", JSON.stringify(this.wordBoost));
159
+ }
160
+ url.search = searchParams.toString();
161
+ return url;
162
+ }
163
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
164
+ on(event, listener) {
165
+ this.listeners[event] = listener;
166
+ }
167
+ connect() {
168
+ return new Promise((resolve) => {
169
+ if (this.socket) {
170
+ throw new Error("Already connected");
171
+ }
172
+ const url = this.connectionUrl();
173
+ if (this.token) {
174
+ this.socket = new WebSocket(url.toString());
175
+ }
176
+ else {
177
+ this.socket = new WebSocket(url.toString(), {
178
+ headers: { Authorization: this.apiKey },
179
+ });
180
+ }
181
+ this.socket.onclose = ({ code, reason }) => {
182
+ if (!reason) {
183
+ if (code in RealtimeErrorType) {
184
+ reason = RealtimeErrorMessages[code];
185
+ }
186
+ }
187
+ this.listeners.close?.(code, reason);
188
+ };
189
+ this.socket.onerror = (event) => {
190
+ if (event.error)
191
+ this.listeners.error?.(event.error);
192
+ else
193
+ this.listeners.error?.(new Error(event.message));
194
+ };
195
+ this.socket.onmessage = ({ data }) => {
196
+ const message = JSON.parse(data.toString());
197
+ if ("error" in message) {
198
+ this.listeners.error?.(new RealtimeError(message.error));
199
+ return;
200
+ }
201
+ switch (message.message_type) {
202
+ case "SessionBegins": {
203
+ const openObject = {
204
+ sessionId: message.session_id,
205
+ expiresAt: new Date(message.expires_at),
206
+ };
207
+ resolve(openObject);
208
+ this.listeners.open?.(openObject);
209
+ break;
210
+ }
211
+ case "PartialTranscript": {
212
+ // message.created is actually a string when coming from the socket
213
+ message.created = new Date(message.created);
214
+ this.listeners.transcript?.(message);
215
+ this.listeners["transcript.partial"]?.(message);
216
+ break;
217
+ }
218
+ case "FinalTranscript": {
219
+ // message.created is actually a string when coming from the socket
220
+ message.created = new Date(message.created);
221
+ this.listeners.transcript?.(message);
222
+ this.listeners["transcript.final"]?.(message);
223
+ break;
224
+ }
225
+ case "SessionTerminated": {
226
+ this.sessionTerminatedResolve?.();
227
+ break;
228
+ }
229
+ }
230
+ };
231
+ });
232
+ }
233
+ sendAudio(audio) {
234
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
235
+ throw new Error("Socket is not open for communication");
236
+ }
237
+ let audioData;
238
+ if (typeof Buffer !== "undefined") {
239
+ audioData = Buffer.from(audio).toString("base64");
240
+ }
241
+ else {
242
+ // Buffer is not available in the browser by default
243
+ // https://stackoverflow.com/a/42334410/2919731
244
+ audioData = btoa(new Uint8Array(audio).reduce((data, byte) => data + String.fromCharCode(byte), ""));
245
+ }
246
+ const payload = {
247
+ audio_data: audioData,
248
+ };
249
+ this.socket.send(JSON.stringify(payload));
250
+ }
251
+ stream() {
252
+ return new WritableStream({
253
+ write: (chunk) => {
254
+ this.sendAudio(chunk);
255
+ },
256
+ });
257
+ }
258
+ async close(waitForSessionTermination = true) {
259
+ if (this.socket) {
260
+ if (this.socket.readyState === WebSocket.OPEN) {
261
+ const terminateSessionMessage = `{"terminate_session": true}`;
262
+ if (waitForSessionTermination) {
263
+ const sessionTerminatedPromise = new Promise((resolve) => {
264
+ this.sessionTerminatedResolve = resolve;
265
+ });
266
+ this.socket.send(terminateSessionMessage);
267
+ await sessionTerminatedPromise;
268
+ }
269
+ else {
270
+ this.socket.send(terminateSessionMessage);
271
+ }
272
+ }
273
+ if ("removeAllListeners" in this.socket)
274
+ this.socket.removeAllListeners();
275
+ this.socket.close();
276
+ }
277
+ this.listeners = {};
278
+ this.socket = undefined;
279
+ }
280
+ }
281
+
282
+ class RealtimeServiceFactory extends BaseService {
283
+ constructor(params) {
284
+ super(params);
285
+ this.rtFactoryParams = params;
286
+ }
287
+ createService(params) {
288
+ if (!params)
289
+ params = { apiKey: this.rtFactoryParams.apiKey };
290
+ else if (!("token" in params) && !params.apiKey) {
291
+ params.apiKey = this.rtFactoryParams.apiKey;
292
+ }
293
+ return new RealtimeService(params);
294
+ }
295
+ async createTemporaryToken(params) {
296
+ const data = await this.fetchJson("/v2/realtime/token", {
297
+ method: "POST",
298
+ body: JSON.stringify(params),
299
+ });
300
+ return data.token;
301
+ }
302
+ }
303
+
304
+ class TranscriptService extends BaseService {
305
+ constructor(params, files) {
306
+ super(params);
307
+ this.files = files;
308
+ }
309
+ /**
310
+ * Transcribe an audio file. This will create a transcript and wait until the transcript status is "completed" or "error".
311
+ * @param params The parameters to transcribe an audio file.
312
+ * @param options The options to transcribe an audio file.
313
+ * @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
314
+ */
315
+ async transcribe(params, options) {
316
+ const transcript = await this.submit(params);
317
+ return await this.waitUntilReady(transcript.id, options);
318
+ }
319
+ /**
320
+ * Submits a transcription job for an audio file. This will not wait until the transcript status is "completed" or "error".
321
+ * @param params The parameters to start the transcription of an audio file.
322
+ * @returns A promise that resolves to the queued transcript.
323
+ */
324
+ async submit(params) {
325
+ const { audio, ...createParams } = params;
326
+ let audioUrl;
327
+ if (typeof audio === "string") {
328
+ const path = getPath(audio);
329
+ if (path !== null) {
330
+ // audio is local path, upload local file
331
+ audioUrl = await this.files.upload(path);
332
+ }
333
+ else {
334
+ // audio is not a local path, assume it's a URL
335
+ audioUrl = audio;
336
+ }
337
+ }
338
+ else {
339
+ // audio is of uploadable type
340
+ audioUrl = await this.files.upload(audio);
341
+ }
342
+ const data = await this.fetchJson("/v2/transcript", {
343
+ method: "POST",
344
+ body: JSON.stringify({ ...createParams, audio_url: audioUrl }),
345
+ });
346
+ return data;
347
+ }
348
+ /**
349
+ * Create a transcript.
350
+ * @param params The parameters to create a transcript.
351
+ * @param options The options used for creating the new transcript.
352
+ * @returns A promise that resolves to the transcript.
353
+ * @deprecated Use `transcribe` instead to transcribe a audio file that includes polling, or `submit` to transcribe a audio file without polling.
354
+ */
355
+ async create(params, options) {
356
+ const path = getPath(params.audio_url);
357
+ if (path !== null) {
358
+ const uploadUrl = await this.files.upload(path);
359
+ params.audio_url = uploadUrl;
360
+ }
361
+ const data = await this.fetchJson("/v2/transcript", {
362
+ method: "POST",
363
+ body: JSON.stringify(params),
364
+ });
365
+ if (options?.poll ?? true) {
366
+ return await this.waitUntilReady(data.id, options);
367
+ }
368
+ return data;
369
+ }
370
+ /**
371
+ * Wait until the transcript ready, either the status is "completed" or "error".
372
+ * @param transcriptId The ID of the transcript.
373
+ * @param options The options to wait until the transcript is ready.
374
+ * @returns A promise that resolves to the transcript. The transcript status is "completed" or "error".
375
+ */
376
+ async waitUntilReady(transcriptId, options) {
377
+ const pollingInterval = options?.pollingInterval ?? 3000;
378
+ const pollingTimeout = options?.pollingTimeout ?? -1;
379
+ const startTime = Date.now();
380
+ // eslint-disable-next-line no-constant-condition
381
+ while (true) {
382
+ const transcript = await this.get(transcriptId);
383
+ if (transcript.status === "completed" || transcript.status === "error") {
384
+ return transcript;
385
+ }
386
+ else if (pollingTimeout > 0 &&
387
+ Date.now() - startTime > pollingTimeout) {
388
+ throw new Error("Polling timeout");
389
+ }
390
+ else {
391
+ await new Promise((resolve) => setTimeout(resolve, pollingInterval));
392
+ }
393
+ }
394
+ }
395
+ /**
396
+ * Retrieve a transcript.
397
+ * @param id The identifier of the transcript.
398
+ * @returns A promise that resolves to the transcript.
399
+ */
400
+ get(id) {
401
+ return this.fetchJson(`/v2/transcript/${id}`);
402
+ }
403
+ /**
404
+ * Retrieves a page of transcript listings.
405
+ * @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
406
+ */
407
+ async list(parameters) {
408
+ let url = "/v2/transcript";
409
+ if (typeof parameters === "string") {
410
+ url = parameters;
411
+ }
412
+ else if (parameters) {
413
+ url = `${url}?${new URLSearchParams(Object.keys(parameters).map((key) => [
414
+ key,
415
+ parameters[key]?.toString() || "",
416
+ ]))}`;
417
+ }
418
+ const data = await this.fetchJson(url);
419
+ for (const transcriptListItem of data.transcripts) {
420
+ transcriptListItem.created = new Date(transcriptListItem.created);
421
+ if (transcriptListItem.completed) {
422
+ transcriptListItem.completed = new Date(transcriptListItem.completed);
423
+ }
424
+ }
425
+ return data;
426
+ }
427
+ /**
428
+ * Delete a transcript
429
+ * @param id The identifier of the transcript.
430
+ * @returns A promise that resolves to the transcript.
431
+ */
432
+ delete(id) {
433
+ return this.fetchJson(`/v2/transcript/${id}`, { method: "DELETE" });
434
+ }
435
+ /**
436
+ * Search through the transcript for a specific set of keywords.
437
+ * You can search for individual words, numbers, or phrases containing up to five words or numbers.
438
+ * @param id The identifier of the transcript.
439
+ * @param words Keywords to search for.
440
+ * @return A promise that resolves to the sentences.
441
+ */
442
+ wordSearch(id, words) {
443
+ const params = new URLSearchParams({ words: words.join(",") });
444
+ return this.fetchJson(`/v2/transcript/${id}/word-search?${params.toString()}`);
445
+ }
446
+ /**
447
+ * Retrieve all sentences of a transcript.
448
+ * @param id The identifier of the transcript.
449
+ * @return A promise that resolves to the sentences.
450
+ */
451
+ sentences(id) {
452
+ return this.fetchJson(`/v2/transcript/${id}/sentences`);
453
+ }
454
+ /**
455
+ * Retrieve all paragraphs of a transcript.
456
+ * @param id The identifier of the transcript.
457
+ * @return A promise that resolves to the paragraphs.
458
+ */
459
+ paragraphs(id) {
460
+ return this.fetchJson(`/v2/transcript/${id}/paragraphs`);
461
+ }
462
+ /**
463
+ * Retrieve subtitles of a transcript.
464
+ * @param id The identifier of the transcript.
465
+ * @param format The format of the subtitles.
466
+ * @param chars_per_caption The maximum number of characters per caption.
467
+ * @return A promise that resolves to the subtitles text.
468
+ */
469
+ async subtitles(id, format = "srt", chars_per_caption) {
470
+ let url = `/v2/transcript/${id}/${format}`;
471
+ if (chars_per_caption) {
472
+ const params = new URLSearchParams();
473
+ params.set("chars_per_caption", chars_per_caption.toString());
474
+ url += `?${params.toString()}`;
475
+ }
476
+ const response = await this.fetch(url);
477
+ return await response.text();
478
+ }
479
+ /**
480
+ * Retrieve redactions of a transcript.
481
+ * @param id The identifier of the transcript.
482
+ * @return A promise that resolves to the subtitles text.
483
+ */
484
+ redactions(id) {
485
+ return this.fetchJson(`/v2/transcript/${id}/redacted-audio`);
486
+ }
487
+ }
488
+ function getPath(path) {
489
+ let url;
490
+ try {
491
+ url = new URL(path);
492
+ if (url.protocol === "file:")
493
+ return url.pathname;
494
+ else
495
+ return null;
496
+ }
497
+ catch {
498
+ return path;
499
+ }
500
+ }
501
+
502
+ const readFile = async (path) => (await Deno.open(path)).readable;
503
+
504
+ class FileService extends BaseService {
505
+ /**
506
+ * Upload a local file to AssemblyAI.
507
+ * @param input The local file path to upload, or a stream or buffer of the file to upload.
508
+ * @return A promise that resolves to the uploaded file URL.
509
+ */
510
+ async upload(input) {
511
+ let fileData;
512
+ if (typeof input === "string")
513
+ fileData = await readFile(input);
514
+ else
515
+ fileData = input;
516
+ const data = await this.fetchJson("/v2/upload", {
517
+ method: "POST",
518
+ body: fileData,
519
+ headers: {
520
+ "Content-Type": "application/octet-stream",
521
+ },
522
+ duplex: "half",
523
+ });
524
+ return data.upload_url;
525
+ }
526
+ }
527
+
528
+ const defaultBaseUrl = "https://api.assemblyai.com";
529
+ class AssemblyAI {
530
+ /**
531
+ * Create a new AssemblyAI client.
532
+ * @param params The parameters for the service, including the API key and base URL, if any.
533
+ */
534
+ constructor(params) {
535
+ params.baseUrl = params.baseUrl || defaultBaseUrl;
536
+ if (params.baseUrl && params.baseUrl.endsWith("/"))
537
+ params.baseUrl = params.baseUrl.slice(0, -1);
538
+ this.files = new FileService(params);
539
+ this.transcripts = new TranscriptService(params, this.files);
540
+ this.lemur = new LemurService(params);
541
+ this.realtime = new RealtimeServiceFactory(params);
542
+ }
543
+ }
544
+
545
+ export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
package/dist/index.cjs CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var isomorphicStreams = require('@swimburger/isomorphic-streams');
4
- var WebSocket = require('isomorphic-ws');
3
+ var WebSocket = require('#ws');
5
4
 
6
5
  /******************************************************************************
7
6
  Copyright (c) Microsoft Corporation.
@@ -130,6 +129,12 @@ class LemurService extends BaseService {
130
129
  }
131
130
  }
132
131
 
132
+ const { WritableStream } = typeof window !== "undefined"
133
+ ? window
134
+ : typeof global !== "undefined"
135
+ ? global
136
+ : globalThis;
137
+
133
138
  var RealtimeErrorType;
134
139
  (function (RealtimeErrorType) {
135
140
  RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
@@ -295,7 +300,7 @@ class RealtimeService {
295
300
  this.socket.send(JSON.stringify(payload));
296
301
  }
297
302
  stream() {
298
- return new isomorphicStreams.WritableStream({
303
+ return new WritableStream({
299
304
  write: (chunk) => {
300
305
  this.sendAudio(chunk);
301
306
  },
@@ -566,13 +571,12 @@ function getPath(path) {
566
571
  }
567
572
  }
568
573
 
569
- function throwError() {
570
- throw new Error("'fs' is not supported in this environment.");
571
- }
572
-
573
- const createReadStream = throwError;
574
- var fs = {
575
- createReadStream,
574
+ const readFile = function (
575
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
576
+ path) {
577
+ return __awaiter(this, void 0, void 0, function* () {
578
+ throw new Error("Interacting with the file system is not supported in this environment.");
579
+ });
576
580
  };
577
581
 
578
582
  class FileService extends BaseService {
@@ -585,7 +589,7 @@ class FileService extends BaseService {
585
589
  return __awaiter(this, void 0, void 0, function* () {
586
590
  let fileData;
587
591
  if (typeof input === "string")
588
- fileData = fs.createReadStream(input);
592
+ fileData = yield readFile();
589
593
  else
590
594
  fileData = input;
591
595
  const data = yield this.fetchJson("/v2/upload", {
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { WritableStream } from '@swimburger/isomorphic-streams';
2
- import WebSocket from 'isomorphic-ws';
1
+ import WebSocket from '#ws';
3
2
 
4
3
  /******************************************************************************
5
4
  Copyright (c) Microsoft Corporation.
@@ -128,6 +127,12 @@ class LemurService extends BaseService {
128
127
  }
129
128
  }
130
129
 
130
+ const { WritableStream } = typeof window !== "undefined"
131
+ ? window
132
+ : typeof global !== "undefined"
133
+ ? global
134
+ : globalThis;
135
+
131
136
  var RealtimeErrorType;
132
137
  (function (RealtimeErrorType) {
133
138
  RealtimeErrorType[RealtimeErrorType["BadSampleRate"] = 4000] = "BadSampleRate";
@@ -564,13 +569,12 @@ function getPath(path) {
564
569
  }
565
570
  }
566
571
 
567
- function throwError() {
568
- throw new Error("'fs' is not supported in this environment.");
569
- }
570
-
571
- const createReadStream = throwError;
572
- var fs = {
573
- createReadStream,
572
+ const readFile = function (
573
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
574
+ path) {
575
+ return __awaiter(this, void 0, void 0, function* () {
576
+ throw new Error("Interacting with the file system is not supported in this environment.");
577
+ });
574
578
  };
575
579
 
576
580
  class FileService extends BaseService {
@@ -583,7 +587,7 @@ class FileService extends BaseService {
583
587
  return __awaiter(this, void 0, void 0, function* () {
584
588
  let fileData;
585
589
  if (typeof input === "string")
586
- fileData = fs.createReadStream(input);
590
+ fileData = yield readFile();
587
591
  else
588
592
  fileData = input;
589
593
  const data = yield this.fetchJson("/v2/upload", {