assemblyai 4.35.0 → 4.35.4

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/browser.mjs CHANGED
@@ -28,7 +28,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
28
28
  defaultUserAgentString += navigator.userAgent;
29
29
  }
30
30
  const defaultUserAgent = {
31
- sdk: { name: "JavaScript", version: "4.35.0" },
31
+ sdk: { name: "JavaScript", version: "4.35.4" },
32
32
  };
33
33
  if (typeof process !== "undefined") {
34
34
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1053,6 +1053,10 @@ class StreamingTranscriber {
1053
1053
  if (!(this.token || this.apiKey)) {
1054
1054
  throw new Error("API key or temporary token is required.");
1055
1055
  }
1056
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1057
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1058
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
1059
+ }
1056
1060
  if (params.channels) {
1057
1061
  if (params.channels.length !== 2) {
1058
1062
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -1078,10 +1082,12 @@ class StreamingTranscriber {
1078
1082
  "speaker-history") {
1079
1083
  this.speakerHistory = new Map();
1080
1084
  }
1081
- // 20 ms VAD frames at the transcriber's target sample rate.
1082
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
1083
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
1084
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
1085
+ // 20 ms VAD frames at the transcriber's target sample rate. The
1086
+ // constructor check above guarantees sampleRate in dual-channel mode.
1087
+ const sampleRate = params.sampleRate;
1088
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
1089
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
1090
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
1085
1091
  this.channelBuffers = new Map(names.map((n) => [n, []]));
1086
1092
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
1087
1093
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -1099,7 +1105,9 @@ class StreamingTranscriber {
1099
1105
  if (this.token) {
1100
1106
  searchParams.set("token", this.token);
1101
1107
  }
1102
- searchParams.set("sample_rate", this.params.sampleRate.toString());
1108
+ if (this.params.sampleRate !== undefined) {
1109
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
1110
+ }
1103
1111
  if (this.params.endOfTurnConfidenceThreshold) {
1104
1112
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
1105
1113
  }
@@ -1151,8 +1159,12 @@ class StreamingTranscriber {
1151
1159
  searchParams.set("speech_model", this.params.speechModel.toString());
1152
1160
  }
1153
1161
  if (this.params.languageCode !== undefined) {
1162
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
1154
1163
  searchParams.set("language_code", this.params.languageCode);
1155
1164
  }
1165
+ if (this.params.languageCodes !== undefined) {
1166
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
1167
+ }
1156
1168
  if (this.params.languageDetection !== undefined) {
1157
1169
  searchParams.set("language_detection", this.params.languageDetection.toString());
1158
1170
  }
package/dist/bun.mjs CHANGED
@@ -30,7 +30,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
30
30
  defaultUserAgentString += navigator.userAgent;
31
31
  }
32
32
  const defaultUserAgent = {
33
- sdk: { name: "JavaScript", version: "4.35.0" },
33
+ sdk: { name: "JavaScript", version: "4.35.4" },
34
34
  };
35
35
  if (typeof process !== "undefined") {
36
36
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1034,6 +1034,10 @@ class StreamingTranscriber {
1034
1034
  if (!(this.token || this.apiKey)) {
1035
1035
  throw new Error("API key or temporary token is required.");
1036
1036
  }
1037
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1038
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1039
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
1040
+ }
1037
1041
  if (params.channels) {
1038
1042
  if (params.channels.length !== 2) {
1039
1043
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -1059,10 +1063,12 @@ class StreamingTranscriber {
1059
1063
  "speaker-history") {
1060
1064
  this.speakerHistory = new Map();
1061
1065
  }
1062
- // 20 ms VAD frames at the transcriber's target sample rate.
1063
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
1064
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
1065
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
1066
+ // 20 ms VAD frames at the transcriber's target sample rate. The
1067
+ // constructor check above guarantees sampleRate in dual-channel mode.
1068
+ const sampleRate = params.sampleRate;
1069
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
1070
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
1071
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
1066
1072
  this.channelBuffers = new Map(names.map((n) => [n, []]));
1067
1073
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
1068
1074
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -1080,7 +1086,9 @@ class StreamingTranscriber {
1080
1086
  if (this.token) {
1081
1087
  searchParams.set("token", this.token);
1082
1088
  }
1083
- searchParams.set("sample_rate", this.params.sampleRate.toString());
1089
+ if (this.params.sampleRate !== undefined) {
1090
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
1091
+ }
1084
1092
  if (this.params.endOfTurnConfidenceThreshold) {
1085
1093
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
1086
1094
  }
@@ -1132,8 +1140,12 @@ class StreamingTranscriber {
1132
1140
  searchParams.set("speech_model", this.params.speechModel.toString());
1133
1141
  }
1134
1142
  if (this.params.languageCode !== undefined) {
1143
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
1135
1144
  searchParams.set("language_code", this.params.languageCode);
1136
1145
  }
1146
+ if (this.params.languageCodes !== undefined) {
1147
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
1148
+ }
1137
1149
  if (this.params.languageDetection !== undefined) {
1138
1150
  searchParams.set("language_detection", this.params.languageDetection.toString());
1139
1151
  }
package/dist/deno.mjs CHANGED
@@ -30,7 +30,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
30
30
  defaultUserAgentString += navigator.userAgent;
31
31
  }
32
32
  const defaultUserAgent = {
33
- sdk: { name: "JavaScript", version: "4.35.0" },
33
+ sdk: { name: "JavaScript", version: "4.35.4" },
34
34
  };
35
35
  if (typeof process !== "undefined") {
36
36
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1034,6 +1034,10 @@ class StreamingTranscriber {
1034
1034
  if (!(this.token || this.apiKey)) {
1035
1035
  throw new Error("API key or temporary token is required.");
1036
1036
  }
1037
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1038
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1039
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
1040
+ }
1037
1041
  if (params.channels) {
1038
1042
  if (params.channels.length !== 2) {
1039
1043
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -1059,10 +1063,12 @@ class StreamingTranscriber {
1059
1063
  "speaker-history") {
1060
1064
  this.speakerHistory = new Map();
1061
1065
  }
1062
- // 20 ms VAD frames at the transcriber's target sample rate.
1063
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
1064
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
1065
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
1066
+ // 20 ms VAD frames at the transcriber's target sample rate. The
1067
+ // constructor check above guarantees sampleRate in dual-channel mode.
1068
+ const sampleRate = params.sampleRate;
1069
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
1070
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
1071
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
1066
1072
  this.channelBuffers = new Map(names.map((n) => [n, []]));
1067
1073
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
1068
1074
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -1080,7 +1086,9 @@ class StreamingTranscriber {
1080
1086
  if (this.token) {
1081
1087
  searchParams.set("token", this.token);
1082
1088
  }
1083
- searchParams.set("sample_rate", this.params.sampleRate.toString());
1089
+ if (this.params.sampleRate !== undefined) {
1090
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
1091
+ }
1084
1092
  if (this.params.endOfTurnConfidenceThreshold) {
1085
1093
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
1086
1094
  }
@@ -1132,8 +1140,12 @@ class StreamingTranscriber {
1132
1140
  searchParams.set("speech_model", this.params.speechModel.toString());
1133
1141
  }
1134
1142
  if (this.params.languageCode !== undefined) {
1143
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
1135
1144
  searchParams.set("language_code", this.params.languageCode);
1136
1145
  }
1146
+ if (this.params.languageCodes !== undefined) {
1147
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
1148
+ }
1137
1149
  if (this.params.languageDetection !== undefined) {
1138
1150
  searchParams.set("language_detection", this.params.languageDetection.toString());
1139
1151
  }
@@ -1,7 +1,7 @@
1
1
  export * from "../types/asyncapi.generated";
2
2
  export * from "../types/realtime";
3
3
  export * from "../types/helpers";
4
- export * from "../types/streaming/dual-channel";
4
+ export * from "../types/streaming";
5
5
  export * from "../services/realtime/service";
6
6
  export * from "../services/streaming/service";
7
7
  export * from "../services/streaming/factory";
package/dist/index.cjs CHANGED
@@ -76,7 +76,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
76
76
  defaultUserAgentString += navigator.userAgent;
77
77
  }
78
78
  const defaultUserAgent = {
79
- sdk: { name: "JavaScript", version: "4.35.0" },
79
+ sdk: { name: "JavaScript", version: "4.35.4" },
80
80
  };
81
81
  if (typeof process !== "undefined") {
82
82
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1128,6 +1128,10 @@ class StreamingTranscriber {
1128
1128
  if (!(this.token || this.apiKey)) {
1129
1129
  throw new Error("API key or temporary token is required.");
1130
1130
  }
1131
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1132
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1133
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
1134
+ }
1131
1135
  if (params.channels) {
1132
1136
  if (params.channels.length !== 2) {
1133
1137
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -1153,10 +1157,12 @@ class StreamingTranscriber {
1153
1157
  "speaker-history") {
1154
1158
  this.speakerHistory = new Map();
1155
1159
  }
1156
- // 20 ms VAD frames at the transcriber's target sample rate.
1157
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
1158
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
1159
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
1160
+ // 20 ms VAD frames at the transcriber's target sample rate. The
1161
+ // constructor check above guarantees sampleRate in dual-channel mode.
1162
+ const sampleRate = params.sampleRate;
1163
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
1164
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
1165
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
1160
1166
  this.channelBuffers = new Map(names.map((n) => [n, []]));
1161
1167
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
1162
1168
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -1175,7 +1181,9 @@ class StreamingTranscriber {
1175
1181
  if (this.token) {
1176
1182
  searchParams.set("token", this.token);
1177
1183
  }
1178
- searchParams.set("sample_rate", this.params.sampleRate.toString());
1184
+ if (this.params.sampleRate !== undefined) {
1185
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
1186
+ }
1179
1187
  if (this.params.endOfTurnConfidenceThreshold) {
1180
1188
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
1181
1189
  }
@@ -1226,8 +1234,12 @@ class StreamingTranscriber {
1226
1234
  searchParams.set("speech_model", this.params.speechModel.toString());
1227
1235
  }
1228
1236
  if (this.params.languageCode !== undefined) {
1237
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
1229
1238
  searchParams.set("language_code", this.params.languageCode);
1230
1239
  }
1240
+ if (this.params.languageCodes !== undefined) {
1241
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
1242
+ }
1231
1243
  if (this.params.languageDetection !== undefined) {
1232
1244
  searchParams.set("language_detection", this.params.languageDetection.toString());
1233
1245
  }
package/dist/index.mjs CHANGED
@@ -74,7 +74,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
74
74
  defaultUserAgentString += navigator.userAgent;
75
75
  }
76
76
  const defaultUserAgent = {
77
- sdk: { name: "JavaScript", version: "4.35.0" },
77
+ sdk: { name: "JavaScript", version: "4.35.4" },
78
78
  };
79
79
  if (typeof process !== "undefined") {
80
80
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1126,6 +1126,10 @@ class StreamingTranscriber {
1126
1126
  if (!(this.token || this.apiKey)) {
1127
1127
  throw new Error("API key or temporary token is required.");
1128
1128
  }
1129
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1130
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1131
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
1132
+ }
1129
1133
  if (params.channels) {
1130
1134
  if (params.channels.length !== 2) {
1131
1135
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -1151,10 +1155,12 @@ class StreamingTranscriber {
1151
1155
  "speaker-history") {
1152
1156
  this.speakerHistory = new Map();
1153
1157
  }
1154
- // 20 ms VAD frames at the transcriber's target sample rate.
1155
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
1156
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
1157
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
1158
+ // 20 ms VAD frames at the transcriber's target sample rate. The
1159
+ // constructor check above guarantees sampleRate in dual-channel mode.
1160
+ const sampleRate = params.sampleRate;
1161
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
1162
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
1163
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
1158
1164
  this.channelBuffers = new Map(names.map((n) => [n, []]));
1159
1165
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
1160
1166
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -1173,7 +1179,9 @@ class StreamingTranscriber {
1173
1179
  if (this.token) {
1174
1180
  searchParams.set("token", this.token);
1175
1181
  }
1176
- searchParams.set("sample_rate", this.params.sampleRate.toString());
1182
+ if (this.params.sampleRate !== undefined) {
1183
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
1184
+ }
1177
1185
  if (this.params.endOfTurnConfidenceThreshold) {
1178
1186
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
1179
1187
  }
@@ -1224,8 +1232,12 @@ class StreamingTranscriber {
1224
1232
  searchParams.set("speech_model", this.params.speechModel.toString());
1225
1233
  }
1226
1234
  if (this.params.languageCode !== undefined) {
1235
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
1227
1236
  searchParams.set("language_code", this.params.languageCode);
1228
1237
  }
1238
+ if (this.params.languageCodes !== undefined) {
1239
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
1240
+ }
1229
1241
  if (this.params.languageDetection !== undefined) {
1230
1242
  searchParams.set("language_detection", this.params.languageDetection.toString());
1231
1243
  }
package/dist/node.cjs CHANGED
@@ -35,7 +35,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
35
35
  defaultUserAgentString += navigator.userAgent;
36
36
  }
37
37
  const defaultUserAgent = {
38
- sdk: { name: "JavaScript", version: "4.35.0" },
38
+ sdk: { name: "JavaScript", version: "4.35.4" },
39
39
  };
40
40
  if (typeof process !== "undefined") {
41
41
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1033,6 +1033,10 @@ class StreamingTranscriber {
1033
1033
  if (!(this.token || this.apiKey)) {
1034
1034
  throw new Error("API key or temporary token is required.");
1035
1035
  }
1036
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1037
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1038
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
1039
+ }
1036
1040
  if (params.channels) {
1037
1041
  if (params.channels.length !== 2) {
1038
1042
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -1058,10 +1062,12 @@ class StreamingTranscriber {
1058
1062
  "speaker-history") {
1059
1063
  this.speakerHistory = new Map();
1060
1064
  }
1061
- // 20 ms VAD frames at the transcriber's target sample rate.
1062
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
1063
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
1064
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
1065
+ // 20 ms VAD frames at the transcriber's target sample rate. The
1066
+ // constructor check above guarantees sampleRate in dual-channel mode.
1067
+ const sampleRate = params.sampleRate;
1068
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
1069
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
1070
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
1065
1071
  this.channelBuffers = new Map(names.map((n) => [n, []]));
1066
1072
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
1067
1073
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -1079,7 +1085,9 @@ class StreamingTranscriber {
1079
1085
  if (this.token) {
1080
1086
  searchParams.set("token", this.token);
1081
1087
  }
1082
- searchParams.set("sample_rate", this.params.sampleRate.toString());
1088
+ if (this.params.sampleRate !== undefined) {
1089
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
1090
+ }
1083
1091
  if (this.params.endOfTurnConfidenceThreshold) {
1084
1092
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
1085
1093
  }
@@ -1131,8 +1139,12 @@ class StreamingTranscriber {
1131
1139
  searchParams.set("speech_model", this.params.speechModel.toString());
1132
1140
  }
1133
1141
  if (this.params.languageCode !== undefined) {
1142
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
1134
1143
  searchParams.set("language_code", this.params.languageCode);
1135
1144
  }
1145
+ if (this.params.languageCodes !== undefined) {
1146
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
1147
+ }
1136
1148
  if (this.params.languageDetection !== undefined) {
1137
1149
  searchParams.set("language_detection", this.params.languageDetection.toString());
1138
1150
  }
package/dist/node.mjs CHANGED
@@ -33,7 +33,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
33
33
  defaultUserAgentString += navigator.userAgent;
34
34
  }
35
35
  const defaultUserAgent = {
36
- sdk: { name: "JavaScript", version: "4.35.0" },
36
+ sdk: { name: "JavaScript", version: "4.35.4" },
37
37
  };
38
38
  if (typeof process !== "undefined") {
39
39
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1031,6 +1031,10 @@ class StreamingTranscriber {
1031
1031
  if (!(this.token || this.apiKey)) {
1032
1032
  throw new Error("API key or temporary token is required.");
1033
1033
  }
1034
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1035
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1036
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
1037
+ }
1034
1038
  if (params.channels) {
1035
1039
  if (params.channels.length !== 2) {
1036
1040
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -1056,10 +1060,12 @@ class StreamingTranscriber {
1056
1060
  "speaker-history") {
1057
1061
  this.speakerHistory = new Map();
1058
1062
  }
1059
- // 20 ms VAD frames at the transcriber's target sample rate.
1060
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
1061
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
1062
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
1063
+ // 20 ms VAD frames at the transcriber's target sample rate. The
1064
+ // constructor check above guarantees sampleRate in dual-channel mode.
1065
+ const sampleRate = params.sampleRate;
1066
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
1067
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
1068
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
1063
1069
  this.channelBuffers = new Map(names.map((n) => [n, []]));
1064
1070
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
1065
1071
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -1077,7 +1083,9 @@ class StreamingTranscriber {
1077
1083
  if (this.token) {
1078
1084
  searchParams.set("token", this.token);
1079
1085
  }
1080
- searchParams.set("sample_rate", this.params.sampleRate.toString());
1086
+ if (this.params.sampleRate !== undefined) {
1087
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
1088
+ }
1081
1089
  if (this.params.endOfTurnConfidenceThreshold) {
1082
1090
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
1083
1091
  }
@@ -1129,8 +1137,12 @@ class StreamingTranscriber {
1129
1137
  searchParams.set("speech_model", this.params.speechModel.toString());
1130
1138
  }
1131
1139
  if (this.params.languageCode !== undefined) {
1140
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
1132
1141
  searchParams.set("language_code", this.params.languageCode);
1133
1142
  }
1143
+ if (this.params.languageCodes !== undefined) {
1144
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
1145
+ }
1134
1146
  if (this.params.languageDetection !== undefined) {
1135
1147
  searchParams.set("language_detection", this.params.languageDetection.toString());
1136
1148
  }
@@ -584,6 +584,10 @@ class StreamingTranscriber {
584
584
  if (!(this.token || this.apiKey)) {
585
585
  throw new Error("API key or temporary token is required.");
586
586
  }
587
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
588
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
589
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
590
+ }
587
591
  if (params.channels) {
588
592
  if (params.channels.length !== 2) {
589
593
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -609,10 +613,12 @@ class StreamingTranscriber {
609
613
  "speaker-history") {
610
614
  this.speakerHistory = new Map();
611
615
  }
612
- // 20 ms VAD frames at the transcriber's target sample rate.
613
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
614
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
615
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
616
+ // 20 ms VAD frames at the transcriber's target sample rate. The
617
+ // constructor check above guarantees sampleRate in dual-channel mode.
618
+ const sampleRate = params.sampleRate;
619
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
620
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
621
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
616
622
  this.channelBuffers = new Map(names.map((n) => [n, []]));
617
623
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
618
624
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -630,7 +636,9 @@ class StreamingTranscriber {
630
636
  if (this.token) {
631
637
  searchParams.set("token", this.token);
632
638
  }
633
- searchParams.set("sample_rate", this.params.sampleRate.toString());
639
+ if (this.params.sampleRate !== undefined) {
640
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
641
+ }
634
642
  if (this.params.endOfTurnConfidenceThreshold) {
635
643
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
636
644
  }
@@ -682,8 +690,12 @@ class StreamingTranscriber {
682
690
  searchParams.set("speech_model", this.params.speechModel.toString());
683
691
  }
684
692
  if (this.params.languageCode !== undefined) {
693
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
685
694
  searchParams.set("language_code", this.params.languageCode);
686
695
  }
696
+ if (this.params.languageCodes !== undefined) {
697
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
698
+ }
687
699
  if (this.params.languageDetection !== undefined) {
688
700
  searchParams.set("language_detection", this.params.languageDetection.toString());
689
701
  }
@@ -1300,7 +1312,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
1300
1312
  defaultUserAgentString += navigator.userAgent;
1301
1313
  }
1302
1314
  const defaultUserAgent = {
1303
- sdk: { name: "JavaScript", version: "4.35.0" },
1315
+ sdk: { name: "JavaScript", version: "4.35.4" },
1304
1316
  };
1305
1317
  if (typeof process !== "undefined") {
1306
1318
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -630,6 +630,10 @@ class StreamingTranscriber {
630
630
  if (!(this.token || this.apiKey)) {
631
631
  throw new Error("API key or temporary token is required.");
632
632
  }
633
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
634
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
635
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
636
+ }
633
637
  if (params.channels) {
634
638
  if (params.channels.length !== 2) {
635
639
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -655,10 +659,12 @@ class StreamingTranscriber {
655
659
  "speaker-history") {
656
660
  this.speakerHistory = new Map();
657
661
  }
658
- // 20 ms VAD frames at the transcriber's target sample rate.
659
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
660
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
661
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
662
+ // 20 ms VAD frames at the transcriber's target sample rate. The
663
+ // constructor check above guarantees sampleRate in dual-channel mode.
664
+ const sampleRate = params.sampleRate;
665
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
666
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
667
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
662
668
  this.channelBuffers = new Map(names.map((n) => [n, []]));
663
669
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
664
670
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -677,7 +683,9 @@ class StreamingTranscriber {
677
683
  if (this.token) {
678
684
  searchParams.set("token", this.token);
679
685
  }
680
- searchParams.set("sample_rate", this.params.sampleRate.toString());
686
+ if (this.params.sampleRate !== undefined) {
687
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
688
+ }
681
689
  if (this.params.endOfTurnConfidenceThreshold) {
682
690
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
683
691
  }
@@ -728,8 +736,12 @@ class StreamingTranscriber {
728
736
  searchParams.set("speech_model", this.params.speechModel.toString());
729
737
  }
730
738
  if (this.params.languageCode !== undefined) {
739
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
731
740
  searchParams.set("language_code", this.params.languageCode);
732
741
  }
742
+ if (this.params.languageCodes !== undefined) {
743
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
744
+ }
733
745
  if (this.params.languageDetection !== undefined) {
734
746
  searchParams.set("language_detection", this.params.languageDetection.toString());
735
747
  }
@@ -628,6 +628,10 @@ class StreamingTranscriber {
628
628
  if (!(this.token || this.apiKey)) {
629
629
  throw new Error("API key or temporary token is required.");
630
630
  }
631
+ const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
632
+ if (params.sampleRate === undefined && (!isOpus || params.channels)) {
633
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus" or "ogg_opus" (the Opus stream is self-describing) and dual-channel mode is not used.');
634
+ }
631
635
  if (params.channels) {
632
636
  if (params.channels.length !== 2) {
633
637
  throw new Error("StreamingTranscriber.channels must have exactly 2 entries.");
@@ -653,10 +657,12 @@ class StreamingTranscriber {
653
657
  "speaker-history") {
654
658
  this.speakerHistory = new Map();
655
659
  }
656
- // 20 ms VAD frames at the transcriber's target sample rate.
657
- this.vadFrameSamples = Math.max(1, Math.round(params.sampleRate * 0.02));
658
- this.minChunkSamples = Math.max(1, Math.round(params.sampleRate * (MIN_CHUNK_MS / 1000)));
659
- this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(params.sampleRate * (MAX_CHUNK_MS / 1000)));
660
+ // 20 ms VAD frames at the transcriber's target sample rate. The
661
+ // constructor check above guarantees sampleRate in dual-channel mode.
662
+ const sampleRate = params.sampleRate;
663
+ this.vadFrameSamples = Math.max(1, Math.round(sampleRate * 0.02));
664
+ this.minChunkSamples = Math.max(1, Math.round(sampleRate * (MIN_CHUNK_MS / 1000)));
665
+ this.maxChunkSamples = Math.max(this.minChunkSamples, Math.round(sampleRate * (MAX_CHUNK_MS / 1000)));
660
666
  this.channelBuffers = new Map(names.map((n) => [n, []]));
661
667
  this.channelSamplesReceived = new Map(names.map((n) => [n, 0]));
662
668
  this.channelVadFloatBuffers = new Map(names.map((n) => [n, new Float32Array(this.vadFrameSamples)]));
@@ -675,7 +681,9 @@ class StreamingTranscriber {
675
681
  if (this.token) {
676
682
  searchParams.set("token", this.token);
677
683
  }
678
- searchParams.set("sample_rate", this.params.sampleRate.toString());
684
+ if (this.params.sampleRate !== undefined) {
685
+ searchParams.set("sample_rate", this.params.sampleRate.toString());
686
+ }
679
687
  if (this.params.endOfTurnConfidenceThreshold) {
680
688
  searchParams.set("end_of_turn_confidence_threshold", this.params.endOfTurnConfidenceThreshold.toString());
681
689
  }
@@ -726,8 +734,12 @@ class StreamingTranscriber {
726
734
  searchParams.set("speech_model", this.params.speechModel.toString());
727
735
  }
728
736
  if (this.params.languageCode !== undefined) {
737
+ console.warn("[Deprecation Warning] `languageCode` is deprecated and will be removed in a future release. Please use `languageCodes` instead.");
729
738
  searchParams.set("language_code", this.params.languageCode);
730
739
  }
740
+ if (this.params.languageCodes !== undefined) {
741
+ searchParams.set("language_codes", JSON.stringify(this.params.languageCodes));
742
+ }
731
743
  if (this.params.languageDetection !== undefined) {
732
744
  searchParams.set("language_detection", this.params.languageDetection.toString());
733
745
  }
@@ -6,7 +6,7 @@ export type AudioData = ArrayBufferLike;
6
6
  * The encoding of the audio data
7
7
  * @defaultValue "pcm_s16"le
8
8
  */
9
- export type AudioEncoding = "pcm_s16le" | "pcm_mulaw";
9
+ export type AudioEncoding = "pcm_s16le" | "pcm_mulaw" | "opus" | "ogg_opus";
10
10
  /**
11
11
  * Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
12
12
  */