assemblyai 4.0.0 → 4.1.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,8 +1,9 @@
1
- import { FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType } from "../asyncapi.generated";
1
+ import { AudioEncoding, FinalTranscript, PartialTranscript, RealtimeTranscript, RealtimeTranscriptType } from "../asyncapi.generated";
2
2
  type CreateRealtimeServiceParams = {
3
3
  realtimeUrl?: string;
4
4
  sampleRate?: number;
5
5
  wordBoost?: string[];
6
+ encoding?: AudioEncoding;
6
7
  } & ({
7
8
  apiKey?: string;
8
9
  } | {
@@ -12,6 +13,7 @@ type RealtimeServiceParams = {
12
13
  realtimeUrl?: string;
13
14
  sampleRate?: number;
14
15
  wordBoost?: string[];
16
+ encoding?: AudioEncoding;
15
17
  } & ({
16
18
  apiKey: string;
17
19
  } | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
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"
@@ -16,12 +16,12 @@ export class RealtimeServiceFactory extends BaseService {
16
16
  }
17
17
 
18
18
  createService(params?: CreateRealtimeServiceParams): RealtimeService {
19
- if (!params) params = { apiKey: this.rtFactoryParams.apiKey };
20
- else if (!("token" in params) && !params.apiKey) {
21
- params.apiKey = this.rtFactoryParams.apiKey;
19
+ const serviceParams = { ...params } as Record<string, unknown>;
20
+ if (!serviceParams.token && !serviceParams.apiKey) {
21
+ serviceParams.apiKey = this.rtFactoryParams.apiKey;
22
22
  }
23
23
 
24
- return new RealtimeService(params as RealtimeServiceParams);
24
+ return new RealtimeService(serviceParams as RealtimeServiceParams);
25
25
  }
26
26
 
27
27
  async createTemporaryToken(params: RealtimeTokenParams) {
@@ -10,6 +10,7 @@ import {
10
10
  PartialTranscript,
11
11
  FinalTranscript,
12
12
  SessionBeginsEventData,
13
+ AudioEncoding,
13
14
  } from "../..";
14
15
  import {
15
16
  RealtimeError,
@@ -23,6 +24,7 @@ export class RealtimeService {
23
24
  private realtimeUrl: string;
24
25
  private sampleRate: number;
25
26
  private wordBoost?: string[];
27
+ private encoding?: AudioEncoding;
26
28
  private apiKey?: string;
27
29
  private token?: string;
28
30
  private socket?: WebSocket;
@@ -33,10 +35,11 @@ export class RealtimeService {
33
35
  this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
34
36
  this.sampleRate = params.sampleRate ?? 16_000;
35
37
  this.wordBoost = params.wordBoost;
36
- if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
38
+ this.encoding = params.encoding;
37
39
  if ("token" in params && params.token) this.token = params.token;
40
+ if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
38
41
 
39
- if (!(this.apiKey || this.token)) {
42
+ if (!(this.token || this.apiKey)) {
40
43
  throw new Error("API key or temporary token is required.");
41
44
  }
42
45
  }
@@ -56,6 +59,9 @@ export class RealtimeService {
56
59
  if (this.wordBoost && this.wordBoost.length > 0) {
57
60
  searchParams.set("word_boost", JSON.stringify(this.wordBoost));
58
61
  }
62
+ if (this.encoding) {
63
+ searchParams.set("encoding", this.encoding);
64
+ }
59
65
  url.search = searchParams.toString();
60
66
 
61
67
  return url;
@@ -2,6 +2,8 @@
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
4
 
5
+ import { LiteralUnion } from "./helpers";
6
+
5
7
  /** OneOf type helpers */
6
8
  type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
7
9
  type XOR<T, U> = T | U extends object
@@ -18,6 +20,13 @@ export type AudioData = {
18
20
  audio_data: string;
19
21
  };
20
22
 
23
+ /**
24
+ * @description The encoding of the audio data
25
+ * @default pcm_s16le
26
+ * @enum {string}
27
+ */
28
+ export type AudioEncoding = "pcm_s16le" | "pcm_mulaw";
29
+
21
30
  export type FinalTranscript = RealtimeBaseTranscript & {
22
31
  /**
23
32
  * @description Describes the type of message
@@ -95,7 +104,10 @@ export type SessionBegins = RealtimeBaseMessage & {
95
104
  * @constant
96
105
  */
97
106
  message_type: "SessionBegins";
98
- /** @description Unique identifier for the established session */
107
+ /**
108
+ * Format: uuid
109
+ * @description Unique identifier for the established session
110
+ */
99
111
  session_id: string;
100
112
  };
101
113
 
@@ -0,0 +1,4 @@
1
+ // source: https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts
2
+ export type LiteralUnion<LiteralType, BaseType> =
3
+ | LiteralType
4
+ | (BaseType & Record<never, never>);