assemblyai 4.4.0 → 4.4.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,8 @@
1
1
  import { WritableStream } from "#streams";
2
- import WebSocket from "#ws";
2
+ import {
3
+ PolyfillWebSocket,
4
+ factory as polyfillWebSocketFactory,
5
+ } from "#websocket";
3
6
  import { ErrorEvent, MessageEvent, CloseEvent } from "ws";
4
7
  import {
5
8
  RealtimeEvents,
@@ -50,10 +53,9 @@ export class RealtimeTranscriber {
50
53
  private apiKey?: string;
51
54
  private token?: string;
52
55
  private endUtteranceSilenceThreshold?: number;
53
- private enableExtraSessionInformation?: boolean;
54
56
  private disablePartialTranscripts?: boolean;
55
57
 
56
- private socket?: WebSocket;
58
+ private socket?: PolyfillWebSocket;
57
59
  private listeners: RealtimeListeners = {};
58
60
  private sessionTerminatedResolve?: () => void;
59
61
 
@@ -63,7 +65,6 @@ export class RealtimeTranscriber {
63
65
  this.wordBoost = params.wordBoost;
64
66
  this.encoding = params.encoding;
65
67
  this.endUtteranceSilenceThreshold = params.endUtteranceSilenceThreshold;
66
- this.enableExtraSessionInformation = params.enableExtraSessionInformation;
67
68
  this.disablePartialTranscripts = params.disablePartialTranscripts;
68
69
  if ("token" in params && params.token) this.token = params.token;
69
70
  if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
@@ -91,12 +92,9 @@ export class RealtimeTranscriber {
91
92
  if (this.encoding) {
92
93
  searchParams.set("encoding", this.encoding);
93
94
  }
94
- if (this.enableExtraSessionInformation) {
95
- searchParams.set(
96
- "enable_extra_session_information",
97
- this.enableExtraSessionInformation.toString(),
98
- );
99
- }
95
+
96
+ searchParams.set("enable_extra_session_information", "true");
97
+
100
98
  if (this.disablePartialTranscripts) {
101
99
  searchParams.set(
102
100
  "disable_partial_transcripts",
@@ -141,15 +139,15 @@ export class RealtimeTranscriber {
141
139
  const url = this.connectionUrl();
142
140
 
143
141
  if (this.token) {
144
- this.socket = new WebSocket(url.toString());
142
+ this.socket = polyfillWebSocketFactory(url.toString());
145
143
  } else {
146
- this.socket = new WebSocket(url.toString(), {
144
+ this.socket = polyfillWebSocketFactory(url.toString(), {
147
145
  headers: { Authorization: this.apiKey },
148
146
  });
149
147
  }
150
- this.socket.binaryType = "arraybuffer";
148
+ this.socket!.binaryType = "arraybuffer";
151
149
 
152
- this.socket.onopen = () => {
150
+ this.socket!.onopen = () => {
153
151
  if (
154
152
  this.endUtteranceSilenceThreshold === undefined ||
155
153
  this.endUtteranceSilenceThreshold === null
@@ -161,7 +159,7 @@ export class RealtimeTranscriber {
161
159
  );
162
160
  };
163
161
 
164
- this.socket.onclose = ({ code, reason }: CloseEvent) => {
162
+ this.socket!.onclose = ({ code, reason }: CloseEvent) => {
165
163
  if (!reason) {
166
164
  if (code in RealtimeErrorType) {
167
165
  reason = RealtimeErrorMessages[code as RealtimeErrorType];
@@ -170,12 +168,12 @@ export class RealtimeTranscriber {
170
168
  this.listeners.close?.(code, reason);
171
169
  };
172
170
 
173
- this.socket.onerror = (event: ErrorEvent) => {
171
+ this.socket!.onerror = (event: ErrorEvent) => {
174
172
  if (event.error) this.listeners.error?.(event.error as Error);
175
173
  else this.listeners.error?.(new Error(event.message));
176
174
  };
177
175
 
178
- this.socket.onmessage = ({ data }: MessageEvent) => {
176
+ this.socket!.onmessage = ({ data }: MessageEvent) => {
179
177
  const message = JSON.parse(data.toString()) as RealtimeMessage;
180
178
  if ("error" in message) {
181
179
  this.listeners.error?.(new RealtimeError(message.error));
@@ -247,7 +245,7 @@ export class RealtimeTranscriber {
247
245
  }
248
246
 
249
247
  private send(data: BufferLike) {
250
- if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
248
+ if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
251
249
  throw new Error("Socket is not open for communication");
252
250
  }
253
251
  this.socket.send(data);
@@ -255,7 +253,7 @@ export class RealtimeTranscriber {
255
253
 
256
254
  async close(waitForSessionTermination = true) {
257
255
  if (this.socket) {
258
- if (this.socket.readyState === WebSocket.OPEN) {
256
+ if (this.socket.readyState === this.socket.OPEN) {
259
257
  if (waitForSessionTermination) {
260
258
  const sessionTerminatedPromise = new Promise<void>((resolve) => {
261
259
  this.sessionTerminatedResolve = resolve;
@@ -266,7 +264,7 @@ export class RealtimeTranscriber {
266
264
  this.socket.send(terminateSessionMessage);
267
265
  }
268
266
  }
269
- if ("removeAllListeners" in this.socket) this.socket.removeAllListeners();
267
+ if (this.socket?.removeAllListeners) this.socket.removeAllListeners();
270
268
  this.socket.close();
271
269
  }
272
270
 
@@ -60,8 +60,12 @@ export class TranscriptService extends BaseService {
60
60
  // audio is local path, upload local file
61
61
  audioUrl = await this.files.upload(path);
62
62
  } else {
63
- // audio is not a local path, assume it's a URL
64
- audioUrl = audio;
63
+ if (audio.startsWith("data:")) {
64
+ audioUrl = await this.files.upload(audio);
65
+ } else {
66
+ // audio is not a local path, and not a data-URI, assume it's a normal URL
67
+ audioUrl = audio;
68
+ }
65
69
  }
66
70
  } else {
67
71
  // audio is of uploadable type
@@ -789,7 +789,7 @@ export type LemurQuestionAnswerResponse = LemurBaseResponse & {
789
789
  * ```js
790
790
  * {
791
791
  * "transcript_ids": [
792
- * "64nygnr62k-405c-4ae8-8a6b-d90b40ff3cce"
792
+ * "47b95ba5-8889-44d8-bc80-5de38306e582"
793
793
  * ],
794
794
  * "context": "This is an interview about wildfires.",
795
795
  * "final_model": "default",
@@ -901,7 +901,6 @@ export type ListTranscriptParams = {
901
901
  };
902
902
 
903
903
  /**
904
- * Details of the transcript page.
905
904
  * Details of the transcript page. Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts.
906
905
  * @example
907
906
  * ```js
@@ -924,12 +923,10 @@ export type PageDetails = {
924
923
  */
925
924
  limit: number;
926
925
  /**
927
- * The URL to the next page of transcripts
928
926
  * The URL to the next page of transcripts. The next URL always points to a page with newer transcripts.
929
927
  */
930
928
  next_url: string | null;
931
929
  /**
932
- * The URL to the previous page of transcripts
933
930
  * The URL to the next page of transcripts. The previous URL always points to a page with older transcripts.
934
931
  */
935
932
  prev_url: string | null;
@@ -1234,7 +1231,7 @@ export type SentencesResponse = {
1234
1231
  export type Sentiment = "POSITIVE" | "NEUTRAL" | "NEGATIVE";
1235
1232
 
1236
1233
  /**
1237
- * The result of the sentiment analysis model
1234
+ * The result of the Sentiment Analysis model
1238
1235
  * @example
1239
1236
  * ```js
1240
1237
  * {
@@ -2239,7 +2236,7 @@ export type Transcript = {
2239
2236
  auto_highlights: boolean;
2240
2237
  /**
2241
2238
  * An array of results for the Key Phrases model, if it is enabled.
2242
- * See {@link https://www.assemblyai.com/docs/models/key-phrases | Key phrases } for more information.
2239
+ * See {@link https://www.assemblyai.com/docs/models/key-phrases | Key Phrases } for more information.
2243
2240
  */
2244
2241
  auto_highlights_result?: AutoHighlightsResult | null;
2245
2242
  /**
@@ -2361,7 +2358,7 @@ export type Transcript = {
2361
2358
  sentiment_analysis?: boolean | null;
2362
2359
  /**
2363
2360
  * An array of results for the Sentiment Analysis model, if it is enabled.
2364
- * See {@link https://www.assemblyai.com/docs/models/sentiment-analysis | Sentiment analysis } for more information.
2361
+ * See {@link https://www.assemblyai.com/docs/models/sentiment-analysis | Sentiment Analysis } for more information.
2365
2362
  */
2366
2363
  sentiment_analysis_results?: SentimentAnalysisResult[] | null;
2367
2364
  /**
@@ -2438,7 +2435,7 @@ export type Transcript = {
2438
2435
  */
2439
2436
  webhook_status_code?: number | null;
2440
2437
  /**
2441
- * The URL to which we send webhooks upon trancription completion
2438
+ * The URL to which we send webhooks upon transcription completion
2442
2439
  */
2443
2440
  webhook_url?: string | null;
2444
2441
  /**
@@ -2497,19 +2494,100 @@ export type TranscriptLanguageCode =
2497
2494
  | "it"
2498
2495
  | "pt"
2499
2496
  | "nl"
2500
- | "hi"
2501
- | "ja"
2497
+ | "af"
2498
+ | "sq"
2499
+ | "am"
2500
+ | "ar"
2501
+ | "hy"
2502
+ | "as"
2503
+ | "az"
2504
+ | "ba"
2505
+ | "eu"
2506
+ | "be"
2507
+ | "bn"
2508
+ | "bs"
2509
+ | "br"
2510
+ | "bg"
2511
+ | "my"
2512
+ | "ca"
2502
2513
  | "zh"
2514
+ | "hr"
2515
+ | "cs"
2516
+ | "da"
2517
+ | "et"
2518
+ | "fo"
2503
2519
  | "fi"
2520
+ | "gl"
2521
+ | "ka"
2522
+ | "el"
2523
+ | "gu"
2524
+ | "ht"
2525
+ | "ha"
2526
+ | "haw"
2527
+ | "he"
2528
+ | "hi"
2529
+ | "hu"
2530
+ | "is"
2531
+ | "id"
2532
+ | "ja"
2533
+ | "jw"
2534
+ | "kn"
2535
+ | "kk"
2536
+ | "km"
2504
2537
  | "ko"
2538
+ | "lo"
2539
+ | "la"
2540
+ | "lv"
2541
+ | "ln"
2542
+ | "lt"
2543
+ | "lb"
2544
+ | "mk"
2545
+ | "mg"
2546
+ | "ms"
2547
+ | "ml"
2548
+ | "mt"
2549
+ | "mi"
2550
+ | "mr"
2551
+ | "mn"
2552
+ | "ne"
2553
+ | "no"
2554
+ | "nn"
2555
+ | "oc"
2556
+ | "pa"
2557
+ | "ps"
2558
+ | "fa"
2505
2559
  | "pl"
2560
+ | "ro"
2506
2561
  | "ru"
2562
+ | "sa"
2563
+ | "sr"
2564
+ | "sn"
2565
+ | "sd"
2566
+ | "si"
2567
+ | "sk"
2568
+ | "sl"
2569
+ | "so"
2570
+ | "su"
2571
+ | "sw"
2572
+ | "sv"
2573
+ | "tl"
2574
+ | "tg"
2575
+ | "ta"
2576
+ | "tt"
2577
+ | "te"
2578
+ | "th"
2579
+ | "bo"
2507
2580
  | "tr"
2581
+ | "tk"
2508
2582
  | "uk"
2509
- | "vi";
2583
+ | "ur"
2584
+ | "uz"
2585
+ | "vi"
2586
+ | "cy"
2587
+ | "yi"
2588
+ | "yo";
2510
2589
 
2511
2590
  /**
2512
- * A list of transcripts
2513
2591
  * A list of transcripts. Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts.
2514
2592
  * @example
2515
2593
  * ```js
@@ -2649,7 +2727,7 @@ export type TranscriptOptionalParams = {
2649
2727
  */
2650
2728
  auto_chapters?: boolean;
2651
2729
  /**
2652
- * Whether Key Phrases is enabled, either true or false
2730
+ * Enable Key Phrases, either true or false
2653
2731
  */
2654
2732
  auto_highlights?: boolean;
2655
2733
  /**
@@ -2661,7 +2739,7 @@ export type TranscriptOptionalParams = {
2661
2739
  */
2662
2740
  content_safety?: boolean;
2663
2741
  /**
2664
- * The confidence threshold for content moderation. Values must be between 25 and 100.
2742
+ * The confidence threshold for the Content Moderation model. Values must be between 25 and 100.
2665
2743
  */
2666
2744
  content_safety_confidence?: number;
2667
2745
  /**
@@ -2669,7 +2747,7 @@ export type TranscriptOptionalParams = {
2669
2747
  */
2670
2748
  custom_spelling?: TranscriptCustomSpelling[];
2671
2749
  /**
2672
- * Whether custom topics is enabled, either true or false
2750
+ * Enable custom topics, either true or false
2673
2751
  */
2674
2752
  custom_topics?: boolean;
2675
2753
  /**
@@ -2702,7 +2780,7 @@ export type TranscriptOptionalParams = {
2702
2780
  */
2703
2781
  language_code?: LiteralUnion<TranscriptLanguageCode, string> | null;
2704
2782
  /**
2705
- * Whether {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection } was enabled in the transcription request, either true or false.
2783
+ * Enable {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection }, either true or false.
2706
2784
  */
2707
2785
  language_detection?: boolean;
2708
2786
  /**
@@ -2770,7 +2848,7 @@ export type TranscriptOptionalParams = {
2770
2848
  */
2771
2849
  summary_type?: SummaryType;
2772
2850
  /**
2773
- * The list of custom topics provided, if custom topics is enabled
2851
+ * The list of custom topics
2774
2852
  */
2775
2853
  topics?: string[];
2776
2854
  /**
@@ -2784,7 +2862,7 @@ export type TranscriptOptionalParams = {
2784
2862
  */
2785
2863
  webhook_auth_header_value?: string | null;
2786
2864
  /**
2787
- * The URL to which AssemblyAI send webhooks upon trancription completion
2865
+ * The URL to which AssemblyAI send webhooks upon transcription completion
2788
2866
  */
2789
2867
  webhook_url?: string;
2790
2868
  /**
@@ -37,7 +37,8 @@ type CreateRealtimeTranscriberParams = {
37
37
  /**
38
38
  * Enable extra session information.
39
39
  * Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
40
- * @defaultValue false
40
+ * @defaultValue true
41
+ * @deprecated This parameter is now ignored and will be removed. Session information will always be sent.
41
42
  */
42
43
  enableExtraSessionInformation?: boolean;
43
44
  } & (
@@ -91,7 +92,8 @@ type RealtimeTranscriberParams = {
91
92
  /**
92
93
  * Enable extra session information.
93
94
  * Set to `true` to receive the `session_information` message before the session ends. Defaults to `false`.
94
- * @defaultValue false
95
+ * @defaultValue true
96
+ * @deprecated This parameter is now ignored and will be removed. Session information will always be sent.
95
97
  */
96
98
  enableExtraSessionInformation?: boolean;
97
99
  } & (
package/src/utils/path.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export function getPath(path: string) {
2
2
  if (path.startsWith("http")) return null;
3
3
  if (path.startsWith("https")) return null;
4
+ if (path.startsWith("data:")) return null;
4
5
  if (path.startsWith("file://")) return path.substring(7);
5
6
  if (path.startsWith("file:")) return path.substring(5);
6
7
  return path;
@@ -1,15 +0,0 @@
1
- var ws = null;
2
-
3
- if (typeof WebSocket !== "undefined") {
4
- ws = WebSocket;
5
- } else if (typeof MozWebSocket !== "undefined") {
6
- ws = MozWebSocket;
7
- } else if (typeof global !== "undefined") {
8
- ws = global.WebSocket || global.MozWebSocket;
9
- } else if (typeof window !== "undefined") {
10
- ws = window.WebSocket || window.MozWebSocket;
11
- } else if (typeof self !== "undefined") {
12
- ws = self.WebSocket || self.MozWebSocket;
13
- }
14
-
15
- export default ws;
@@ -1 +0,0 @@
1
- module.exports = require("ws");
@@ -1,2 +0,0 @@
1
- import ws from "ws";
2
- export default ws;
@@ -1,2 +0,0 @@
1
- import ws from "ws";
2
- export default ws;