assemblyai 4.36.3 → 4.36.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/deno.mjs CHANGED
@@ -37,7 +37,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
37
37
  defaultUserAgentString += navigator.userAgent;
38
38
  }
39
39
  const defaultUserAgent = {
40
- sdk: { name: "JavaScript", version: "4.36.3" },
40
+ sdk: { name: "JavaScript", version: "4.36.4" },
41
41
  };
42
42
  if (typeof process !== "undefined") {
43
43
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1368,9 +1368,12 @@ class StreamingTranscriber {
1368
1368
  if (!(this.token || this.apiKey)) {
1369
1369
  throw new Error("API key or temporary token is required.");
1370
1370
  }
1371
- const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1372
- if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1373
- 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.');
1371
+ const isSelfDescribing = params.encoding === "opus" ||
1372
+ params.encoding === "ogg_opus" ||
1373
+ params.encoding === "aac";
1374
+ if (params.sampleRate === undefined &&
1375
+ (!isSelfDescribing || params.channels)) {
1376
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
1374
1377
  }
1375
1378
  if (params.channels) {
1376
1379
  if (params.channels.length !== 2) {
@@ -1448,6 +1451,9 @@ class StreamingTranscriber {
1448
1451
  if (this.params.formatTurns) {
1449
1452
  searchParams.set("format_turns", this.params.formatTurns.toString());
1450
1453
  }
1454
+ if (this.params.sessionHeartbeat !== undefined) {
1455
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
1456
+ }
1451
1457
  if (this.params.encoding) {
1452
1458
  searchParams.set("encoding", this.params.encoding.toString());
1453
1459
  }
@@ -1732,6 +1738,10 @@ class StreamingTranscriber {
1732
1738
  this.listeners.warning?.(warning);
1733
1739
  break;
1734
1740
  }
1741
+ case "Heartbeat": {
1742
+ this.listeners.heartbeat?.(message);
1743
+ break;
1744
+ }
1735
1745
  case "Termination": {
1736
1746
  this.sessionTerminatedResolve?.();
1737
1747
  break;
package/dist/index.cjs CHANGED
@@ -109,7 +109,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
109
109
  defaultUserAgentString += navigator.userAgent;
110
110
  }
111
111
  const defaultUserAgent = {
112
- sdk: { name: "JavaScript", version: "4.36.3" },
112
+ sdk: { name: "JavaScript", version: "4.36.4" },
113
113
  };
114
114
  if (typeof process !== "undefined") {
115
115
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1514,9 +1514,12 @@ class StreamingTranscriber {
1514
1514
  if (!(this.token || this.apiKey)) {
1515
1515
  throw new Error("API key or temporary token is required.");
1516
1516
  }
1517
- const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1518
- if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1519
- 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.');
1517
+ const isSelfDescribing = params.encoding === "opus" ||
1518
+ params.encoding === "ogg_opus" ||
1519
+ params.encoding === "aac";
1520
+ if (params.sampleRate === undefined &&
1521
+ (!isSelfDescribing || params.channels)) {
1522
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
1520
1523
  }
1521
1524
  if (params.channels) {
1522
1525
  if (params.channels.length !== 2) {
@@ -1594,6 +1597,9 @@ class StreamingTranscriber {
1594
1597
  if (this.params.formatTurns) {
1595
1598
  searchParams.set("format_turns", this.params.formatTurns.toString());
1596
1599
  }
1600
+ if (this.params.sessionHeartbeat !== undefined) {
1601
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
1602
+ }
1597
1603
  if (this.params.encoding) {
1598
1604
  searchParams.set("encoding", this.params.encoding.toString());
1599
1605
  }
@@ -1825,7 +1831,7 @@ class StreamingTranscriber {
1825
1831
  (_c = (_b = this.listeners).error) === null || _c === void 0 ? void 0 : _c.call(_b, error);
1826
1832
  };
1827
1833
  this.socket.onmessage = ({ data }) => {
1828
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
1834
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
1829
1835
  const message = JSON.parse(data.toString());
1830
1836
  if ("error" in message) {
1831
1837
  const err = new StreamingError(message.error);
@@ -1885,8 +1891,12 @@ class StreamingTranscriber {
1885
1891
  (_p = (_o = this.listeners).warning) === null || _p === void 0 ? void 0 : _p.call(_o, warning);
1886
1892
  break;
1887
1893
  }
1894
+ case "Heartbeat": {
1895
+ (_r = (_q = this.listeners).heartbeat) === null || _r === void 0 ? void 0 : _r.call(_q, message);
1896
+ break;
1897
+ }
1888
1898
  case "Termination": {
1889
- (_q = this.sessionTerminatedResolve) === null || _q === void 0 ? void 0 : _q.call(this);
1899
+ (_s = this.sessionTerminatedResolve) === null || _s === void 0 ? void 0 : _s.call(this);
1890
1900
  break;
1891
1901
  }
1892
1902
  }
package/dist/index.mjs CHANGED
@@ -107,7 +107,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
107
107
  defaultUserAgentString += navigator.userAgent;
108
108
  }
109
109
  const defaultUserAgent = {
110
- sdk: { name: "JavaScript", version: "4.36.3" },
110
+ sdk: { name: "JavaScript", version: "4.36.4" },
111
111
  };
112
112
  if (typeof process !== "undefined") {
113
113
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1512,9 +1512,12 @@ class StreamingTranscriber {
1512
1512
  if (!(this.token || this.apiKey)) {
1513
1513
  throw new Error("API key or temporary token is required.");
1514
1514
  }
1515
- const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1516
- if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1517
- 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.');
1515
+ const isSelfDescribing = params.encoding === "opus" ||
1516
+ params.encoding === "ogg_opus" ||
1517
+ params.encoding === "aac";
1518
+ if (params.sampleRate === undefined &&
1519
+ (!isSelfDescribing || params.channels)) {
1520
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
1518
1521
  }
1519
1522
  if (params.channels) {
1520
1523
  if (params.channels.length !== 2) {
@@ -1592,6 +1595,9 @@ class StreamingTranscriber {
1592
1595
  if (this.params.formatTurns) {
1593
1596
  searchParams.set("format_turns", this.params.formatTurns.toString());
1594
1597
  }
1598
+ if (this.params.sessionHeartbeat !== undefined) {
1599
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
1600
+ }
1595
1601
  if (this.params.encoding) {
1596
1602
  searchParams.set("encoding", this.params.encoding.toString());
1597
1603
  }
@@ -1823,7 +1829,7 @@ class StreamingTranscriber {
1823
1829
  (_c = (_b = this.listeners).error) === null || _c === void 0 ? void 0 : _c.call(_b, error);
1824
1830
  };
1825
1831
  this.socket.onmessage = ({ data }) => {
1826
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
1832
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
1827
1833
  const message = JSON.parse(data.toString());
1828
1834
  if ("error" in message) {
1829
1835
  const err = new StreamingError(message.error);
@@ -1883,8 +1889,12 @@ class StreamingTranscriber {
1883
1889
  (_p = (_o = this.listeners).warning) === null || _p === void 0 ? void 0 : _p.call(_o, warning);
1884
1890
  break;
1885
1891
  }
1892
+ case "Heartbeat": {
1893
+ (_r = (_q = this.listeners).heartbeat) === null || _r === void 0 ? void 0 : _r.call(_q, message);
1894
+ break;
1895
+ }
1886
1896
  case "Termination": {
1887
- (_q = this.sessionTerminatedResolve) === null || _q === void 0 ? void 0 : _q.call(this);
1897
+ (_s = this.sessionTerminatedResolve) === null || _s === void 0 ? void 0 : _s.call(this);
1888
1898
  break;
1889
1899
  }
1890
1900
  }
package/dist/node.cjs CHANGED
@@ -42,7 +42,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
42
42
  defaultUserAgentString += navigator.userAgent;
43
43
  }
44
44
  const defaultUserAgent = {
45
- sdk: { name: "JavaScript", version: "4.36.3" },
45
+ sdk: { name: "JavaScript", version: "4.36.4" },
46
46
  };
47
47
  if (typeof process !== "undefined") {
48
48
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1367,9 +1367,12 @@ class StreamingTranscriber {
1367
1367
  if (!(this.token || this.apiKey)) {
1368
1368
  throw new Error("API key or temporary token is required.");
1369
1369
  }
1370
- const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1371
- if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1372
- 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.');
1370
+ const isSelfDescribing = params.encoding === "opus" ||
1371
+ params.encoding === "ogg_opus" ||
1372
+ params.encoding === "aac";
1373
+ if (params.sampleRate === undefined &&
1374
+ (!isSelfDescribing || params.channels)) {
1375
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
1373
1376
  }
1374
1377
  if (params.channels) {
1375
1378
  if (params.channels.length !== 2) {
@@ -1447,6 +1450,9 @@ class StreamingTranscriber {
1447
1450
  if (this.params.formatTurns) {
1448
1451
  searchParams.set("format_turns", this.params.formatTurns.toString());
1449
1452
  }
1453
+ if (this.params.sessionHeartbeat !== undefined) {
1454
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
1455
+ }
1450
1456
  if (this.params.encoding) {
1451
1457
  searchParams.set("encoding", this.params.encoding.toString());
1452
1458
  }
@@ -1731,6 +1737,10 @@ class StreamingTranscriber {
1731
1737
  this.listeners.warning?.(warning);
1732
1738
  break;
1733
1739
  }
1740
+ case "Heartbeat": {
1741
+ this.listeners.heartbeat?.(message);
1742
+ break;
1743
+ }
1734
1744
  case "Termination": {
1735
1745
  this.sessionTerminatedResolve?.();
1736
1746
  break;
package/dist/node.mjs CHANGED
@@ -40,7 +40,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
40
40
  defaultUserAgentString += navigator.userAgent;
41
41
  }
42
42
  const defaultUserAgent = {
43
- sdk: { name: "JavaScript", version: "4.36.3" },
43
+ sdk: { name: "JavaScript", version: "4.36.4" },
44
44
  };
45
45
  if (typeof process !== "undefined") {
46
46
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1365,9 +1365,12 @@ class StreamingTranscriber {
1365
1365
  if (!(this.token || this.apiKey)) {
1366
1366
  throw new Error("API key or temporary token is required.");
1367
1367
  }
1368
- const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1369
- if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1370
- 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.');
1368
+ const isSelfDescribing = params.encoding === "opus" ||
1369
+ params.encoding === "ogg_opus" ||
1370
+ params.encoding === "aac";
1371
+ if (params.sampleRate === undefined &&
1372
+ (!isSelfDescribing || params.channels)) {
1373
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
1371
1374
  }
1372
1375
  if (params.channels) {
1373
1376
  if (params.channels.length !== 2) {
@@ -1445,6 +1448,9 @@ class StreamingTranscriber {
1445
1448
  if (this.params.formatTurns) {
1446
1449
  searchParams.set("format_turns", this.params.formatTurns.toString());
1447
1450
  }
1451
+ if (this.params.sessionHeartbeat !== undefined) {
1452
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
1453
+ }
1448
1454
  if (this.params.encoding) {
1449
1455
  searchParams.set("encoding", this.params.encoding.toString());
1450
1456
  }
@@ -1729,6 +1735,10 @@ class StreamingTranscriber {
1729
1735
  this.listeners.warning?.(warning);
1730
1736
  break;
1731
1737
  }
1738
+ case "Heartbeat": {
1739
+ this.listeners.heartbeat?.(message);
1740
+ break;
1741
+ }
1732
1742
  case "Termination": {
1733
1743
  this.sessionTerminatedResolve?.();
1734
1744
  break;
@@ -1,4 +1,4 @@
1
- import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent, LLMGatewayResponseEvent, SpeakerRevisionEvent, StreamingUpdateConfiguration, WarningEvent } from "../..";
1
+ import { StreamingTranscriberParams, AudioData, BeginEvent, TurnEvent, LLMGatewayResponseEvent, SpeakerRevisionEvent, StreamingUpdateConfiguration, WarningEvent, HeartbeatEvent } from "../..";
2
2
  import type { VadFrame } from "../../types/streaming/dual-channel";
3
3
  /**
4
4
  * Options for `sendAudio`. In dual-channel mode (when `channels` is configured
@@ -36,6 +36,7 @@ export declare class StreamingTranscriber {
36
36
  on(event: "llmGatewayResponse", listener: (event: LLMGatewayResponseEvent) => void): void;
37
37
  on(event: "speakerRevision", listener: (event: SpeakerRevisionEvent) => void): void;
38
38
  on(event: "warning", listener: (event: WarningEvent) => void): void;
39
+ on(event: "heartbeat", listener: (event: HeartbeatEvent) => void): void;
39
40
  on(event: "vad", listener: (event: VadFrame) => void): void;
40
41
  on(event: "error", listener: (error: Error) => void): void;
41
42
  on(event: "close", listener: (code: number, reason: string) => void): void;
@@ -584,9 +584,12 @@ 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.');
587
+ const isSelfDescribing = params.encoding === "opus" ||
588
+ params.encoding === "ogg_opus" ||
589
+ params.encoding === "aac";
590
+ if (params.sampleRate === undefined &&
591
+ (!isSelfDescribing || params.channels)) {
592
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
590
593
  }
591
594
  if (params.channels) {
592
595
  if (params.channels.length !== 2) {
@@ -664,6 +667,9 @@ class StreamingTranscriber {
664
667
  if (this.params.formatTurns) {
665
668
  searchParams.set("format_turns", this.params.formatTurns.toString());
666
669
  }
670
+ if (this.params.sessionHeartbeat !== undefined) {
671
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
672
+ }
667
673
  if (this.params.encoding) {
668
674
  searchParams.set("encoding", this.params.encoding.toString());
669
675
  }
@@ -952,6 +958,10 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
952
958
  this.listeners.warning?.(warning);
953
959
  break;
954
960
  }
961
+ case "Heartbeat": {
962
+ this.listeners.heartbeat?.(message);
963
+ break;
964
+ }
955
965
  case "Termination": {
956
966
  this.sessionTerminatedResolve?.();
957
967
  break;
@@ -1312,7 +1322,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
1312
1322
  defaultUserAgentString += navigator.userAgent;
1313
1323
  }
1314
1324
  const defaultUserAgent = {
1315
- sdk: { name: "JavaScript", version: "4.36.3" },
1325
+ sdk: { name: "JavaScript", version: "4.36.4" },
1316
1326
  };
1317
1327
  if (typeof process !== "undefined") {
1318
1328
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -630,9 +630,12 @@ 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.');
633
+ const isSelfDescribing = params.encoding === "opus" ||
634
+ params.encoding === "ogg_opus" ||
635
+ params.encoding === "aac";
636
+ if (params.sampleRate === undefined &&
637
+ (!isSelfDescribing || params.channels)) {
638
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
636
639
  }
637
640
  if (params.channels) {
638
641
  if (params.channels.length !== 2) {
@@ -710,6 +713,9 @@ class StreamingTranscriber {
710
713
  if (this.params.formatTurns) {
711
714
  searchParams.set("format_turns", this.params.formatTurns.toString());
712
715
  }
716
+ if (this.params.sessionHeartbeat !== undefined) {
717
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
718
+ }
713
719
  if (this.params.encoding) {
714
720
  searchParams.set("encoding", this.params.encoding.toString());
715
721
  }
@@ -941,7 +947,7 @@ class StreamingTranscriber {
941
947
  (_c = (_b = this.listeners).error) === null || _c === void 0 ? void 0 : _c.call(_b, error);
942
948
  };
943
949
  this.socket.onmessage = ({ data }) => {
944
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
950
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
945
951
  const message = JSON.parse(data.toString());
946
952
  if ("error" in message) {
947
953
  const err = new StreamingError(message.error);
@@ -1001,8 +1007,12 @@ class StreamingTranscriber {
1001
1007
  (_p = (_o = this.listeners).warning) === null || _p === void 0 ? void 0 : _p.call(_o, warning);
1002
1008
  break;
1003
1009
  }
1010
+ case "Heartbeat": {
1011
+ (_r = (_q = this.listeners).heartbeat) === null || _r === void 0 ? void 0 : _r.call(_q, message);
1012
+ break;
1013
+ }
1004
1014
  case "Termination": {
1005
- (_q = this.sessionTerminatedResolve) === null || _q === void 0 ? void 0 : _q.call(this);
1015
+ (_s = this.sessionTerminatedResolve) === null || _s === void 0 ? void 0 : _s.call(this);
1006
1016
  break;
1007
1017
  }
1008
1018
  }
@@ -628,9 +628,12 @@ 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.');
631
+ const isSelfDescribing = params.encoding === "opus" ||
632
+ params.encoding === "ogg_opus" ||
633
+ params.encoding === "aac";
634
+ if (params.sampleRate === undefined &&
635
+ (!isSelfDescribing || params.channels)) {
636
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
634
637
  }
635
638
  if (params.channels) {
636
639
  if (params.channels.length !== 2) {
@@ -708,6 +711,9 @@ class StreamingTranscriber {
708
711
  if (this.params.formatTurns) {
709
712
  searchParams.set("format_turns", this.params.formatTurns.toString());
710
713
  }
714
+ if (this.params.sessionHeartbeat !== undefined) {
715
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
716
+ }
711
717
  if (this.params.encoding) {
712
718
  searchParams.set("encoding", this.params.encoding.toString());
713
719
  }
@@ -939,7 +945,7 @@ class StreamingTranscriber {
939
945
  (_c = (_b = this.listeners).error) === null || _c === void 0 ? void 0 : _c.call(_b, error);
940
946
  };
941
947
  this.socket.onmessage = ({ data }) => {
942
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
948
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
943
949
  const message = JSON.parse(data.toString());
944
950
  if ("error" in message) {
945
951
  const err = new StreamingError(message.error);
@@ -999,8 +1005,12 @@ class StreamingTranscriber {
999
1005
  (_p = (_o = this.listeners).warning) === null || _p === void 0 ? void 0 : _p.call(_o, warning);
1000
1006
  break;
1001
1007
  }
1008
+ case "Heartbeat": {
1009
+ (_r = (_q = this.listeners).heartbeat) === null || _r === void 0 ? void 0 : _r.call(_q, message);
1010
+ break;
1011
+ }
1002
1012
  case "Termination": {
1003
- (_q = this.sessionTerminatedResolve) === null || _q === void 0 ? void 0 : _q.call(this);
1013
+ (_s = this.sessionTerminatedResolve) === null || _s === void 0 ? void 0 : _s.call(this);
1004
1014
  break;
1005
1015
  }
1006
1016
  }
@@ -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" | "opus" | "ogg_opus";
9
+ export type AudioEncoding = "pcm_s16le" | "pcm_mulaw" | "opus" | "ogg_opus" | "aac";
10
10
  /**
11
11
  * Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
12
12
  */
@@ -89,8 +89,8 @@ export type StreamingTranscriberParams = {
89
89
  connectionRetryDelay?: number;
90
90
  /**
91
91
  * Required for PCM encodings (and for dual-channel mode). May be omitted
92
- * for Opus encodings (`opus`, `ogg_opus`) — the stream is self-describing
93
- * and the server ignores the value.
92
+ * for self-describing encodings (`opus`, `ogg_opus`, `aac`) — the stream
93
+ * carries its own rate and the server ignores the value.
94
94
  */
95
95
  sampleRate?: number;
96
96
  encoding?: AudioEncoding;
@@ -103,6 +103,7 @@ export type StreamingTranscriberParams = {
103
103
  maxTurnSilence?: number;
104
104
  vadThreshold?: number;
105
105
  formatTurns?: boolean;
106
+ sessionHeartbeat?: boolean;
106
107
  filterProfanity?: boolean;
107
108
  keyterms?: string[];
108
109
  keytermsPrompt?: string[];
@@ -172,7 +173,7 @@ export type StreamingTranscriberParams = {
172
173
  /** Tuning for dual-channel attribution. Ignored when `channels` is unset. */
173
174
  channelAttribution?: ChannelAttributionParams;
174
175
  };
175
- export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "speakerRevision" | "warning" | "vad" | "error";
176
+ export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "speakerRevision" | "warning" | "heartbeat" | "vad" | "error";
176
177
  export type StreamingListeners = {
177
178
  open?: (event: BeginEvent) => void;
178
179
  close?: (code: number, reason: string) => void;
@@ -181,6 +182,7 @@ export type StreamingListeners = {
181
182
  llmGatewayResponse?: (event: LLMGatewayResponseEvent) => void;
182
183
  speakerRevision?: (event: SpeakerRevisionEvent) => void;
183
184
  warning?: (event: WarningEvent) => void;
185
+ heartbeat?: (event: HeartbeatEvent) => void;
184
186
  vad?: (event: VadFrame) => void;
185
187
  error?: (error: Error) => void;
186
188
  };
@@ -266,6 +268,7 @@ export type StreamingUpdateConfiguration = {
266
268
  max_turn_silence?: number;
267
269
  vad_threshold?: number;
268
270
  format_turns?: boolean;
271
+ session_heartbeat?: boolean;
269
272
  keyterms_prompt?: string[];
270
273
  prompt?: string;
271
274
  agent_context?: string;
@@ -295,6 +298,13 @@ export type WarningEvent = {
295
298
  warning_code: number;
296
299
  warning: string;
297
300
  };
301
+ export type HeartbeatEvent = {
302
+ type: "Heartbeat";
303
+ total_audio_received_ms: number;
304
+ total_duration_ms: number;
305
+ realtime_factor: number;
306
+ max_speech_probability: number;
307
+ };
298
308
  export type LLMGatewayResponseEvent = {
299
309
  type: "LLMGatewayResponse";
300
310
  turn_order: number;
@@ -323,5 +333,5 @@ export type SpeakerRevisionEvent = {
323
333
  type: "SpeakerRevision";
324
334
  revisions: SpeakerRevisionItem[];
325
335
  };
326
- export type StreamingEventMessage = BeginEvent | TurnEvent | SpeechStartedEvent | TerminationEvent | LLMGatewayResponseEvent | SpeakerRevisionEvent | ErrorEvent | WarningEvent;
336
+ export type StreamingEventMessage = BeginEvent | TurnEvent | SpeechStartedEvent | TerminationEvent | LLMGatewayResponseEvent | SpeakerRevisionEvent | ErrorEvent | WarningEvent | HeartbeatEvent;
327
337
  export type StreamingOperationMessage = StreamingUpdateConfiguration | StreamingForceEndpoint | StreamingKeepAlive | StreamingTerminateSession;
package/dist/workerd.mjs CHANGED
@@ -39,7 +39,7 @@ if (typeof navigator !== "undefined" && navigator.userAgent) {
39
39
  defaultUserAgentString += navigator.userAgent;
40
40
  }
41
41
  const defaultUserAgent = {
42
- sdk: { name: "JavaScript", version: "4.36.3" },
42
+ sdk: { name: "JavaScript", version: "4.36.4" },
43
43
  };
44
44
  if (typeof process !== "undefined") {
45
45
  if (process.versions.node && defaultUserAgentString.indexOf("Node") === -1) {
@@ -1370,9 +1370,12 @@ class StreamingTranscriber {
1370
1370
  if (!(this.token || this.apiKey)) {
1371
1371
  throw new Error("API key or temporary token is required.");
1372
1372
  }
1373
- const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
1374
- if (params.sampleRate === undefined && (!isOpus || params.channels)) {
1375
- 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.');
1373
+ const isSelfDescribing = params.encoding === "opus" ||
1374
+ params.encoding === "ogg_opus" ||
1375
+ params.encoding === "aac";
1376
+ if (params.sampleRate === undefined &&
1377
+ (!isSelfDescribing || params.channels)) {
1378
+ throw new Error('`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.');
1376
1379
  }
1377
1380
  if (params.channels) {
1378
1381
  if (params.channels.length !== 2) {
@@ -1450,6 +1453,9 @@ class StreamingTranscriber {
1450
1453
  if (this.params.formatTurns) {
1451
1454
  searchParams.set("format_turns", this.params.formatTurns.toString());
1452
1455
  }
1456
+ if (this.params.sessionHeartbeat !== undefined) {
1457
+ searchParams.set("session_heartbeat", this.params.sessionHeartbeat.toString());
1458
+ }
1453
1459
  if (this.params.encoding) {
1454
1460
  searchParams.set("encoding", this.params.encoding.toString());
1455
1461
  }
@@ -1734,6 +1740,10 @@ class StreamingTranscriber {
1734
1740
  this.listeners.warning?.(warning);
1735
1741
  break;
1736
1742
  }
1743
+ case "Heartbeat": {
1744
+ this.listeners.heartbeat?.(message);
1745
+ break;
1746
+ }
1737
1747
  case "Termination": {
1738
1748
  this.sessionTerminatedResolve?.();
1739
1749
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "4.36.3",
3
+ "version": "4.36.4",
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"
@@ -20,6 +20,7 @@ import {
20
20
  StreamingForceEndpoint,
21
21
  StreamingKeepAlive,
22
22
  WarningEvent,
23
+ HeartbeatEvent,
23
24
  } from "../..";
24
25
  import type { VadDetector, VadFrame } from "../../types/streaming/dual-channel";
25
26
  import { EnergyVad } from "./energy-vad";
@@ -164,10 +165,16 @@ export class StreamingTranscriber {
164
165
  throw new Error("API key or temporary token is required.");
165
166
  }
166
167
 
167
- const isOpus = params.encoding === "opus" || params.encoding === "ogg_opus";
168
- if (params.sampleRate === undefined && (!isOpus || params.channels)) {
168
+ const isSelfDescribing =
169
+ params.encoding === "opus" ||
170
+ params.encoding === "ogg_opus" ||
171
+ params.encoding === "aac";
172
+ if (
173
+ params.sampleRate === undefined &&
174
+ (!isSelfDescribing || params.channels)
175
+ ) {
169
176
  throw new Error(
170
- '`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.',
177
+ '`sampleRate` is required; it may only be omitted when `encoding` is "opus", "ogg_opus", or "aac" (these streams are self-describing) and dual-channel mode is not used.',
171
178
  );
172
179
  }
173
180
 
@@ -283,6 +290,13 @@ export class StreamingTranscriber {
283
290
  searchParams.set("format_turns", this.params.formatTurns.toString());
284
291
  }
285
292
 
293
+ if (this.params.sessionHeartbeat !== undefined) {
294
+ searchParams.set(
295
+ "session_heartbeat",
296
+ this.params.sessionHeartbeat.toString(),
297
+ );
298
+ }
299
+
286
300
  if (this.params.encoding) {
287
301
  searchParams.set("encoding", this.params.encoding.toString());
288
302
  }
@@ -474,6 +488,7 @@ export class StreamingTranscriber {
474
488
  listener: (event: SpeakerRevisionEvent) => void,
475
489
  ): void;
476
490
  on(event: "warning", listener: (event: WarningEvent) => void): void;
491
+ on(event: "heartbeat", listener: (event: HeartbeatEvent) => void): void;
477
492
  on(event: "vad", listener: (event: VadFrame) => void): void;
478
493
  on(event: "error", listener: (error: Error) => void): void;
479
494
  on(event: "close", listener: (code: number, reason: string) => void): void;
@@ -693,6 +708,10 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
693
708
  this.listeners.warning?.(warning);
694
709
  break;
695
710
  }
711
+ case "Heartbeat": {
712
+ this.listeners.heartbeat?.(message);
713
+ break;
714
+ }
696
715
  case "Termination": {
697
716
  this.sessionTerminatedResolve?.();
698
717
  break;
@@ -25,7 +25,12 @@ export type AudioData = ArrayBufferLike;
25
25
  * The encoding of the audio data
26
26
  * @defaultValue "pcm_s16"le
27
27
  */
28
- export type AudioEncoding = "pcm_s16le" | "pcm_mulaw" | "opus" | "ogg_opus";
28
+ export type AudioEncoding =
29
+ | "pcm_s16le"
30
+ | "pcm_mulaw"
31
+ | "opus"
32
+ | "ogg_opus"
33
+ | "aac";
29
34
 
30
35
  /**
31
36
  * Configure the threshold for how long to wait before ending an utterance. Default is 700ms.