@livekit/agents-plugin-cartesia 1.4.4 → 1.4.6

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/README.md CHANGED
@@ -9,7 +9,7 @@ The Agents Framework is designed for building realtime, programmable
9
9
  participants that run on servers. Use it to create conversational, multi-modal
10
10
  voice agents that can see, hear, and understand.
11
11
 
12
- This package contains the Cartesia plugin, which allows for voice synthesis.
12
+ This package contains the Cartesia plugin, which allows for voice synthesis and speech recognition.
13
13
  Refer to the [documentation](https://docs.livekit.io/agents/overview/) for
14
14
  information on how to use it, or browse the [API
15
15
  reference](https://docs.livekit.io/agents-js/modules/plugins_agents_plugin_cartesia.html).
package/dist/index.cjs CHANGED
@@ -16,12 +16,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var index_exports = {};
17
17
  module.exports = __toCommonJS(index_exports);
18
18
  var import_agents = require("@livekit/agents");
19
+ __reExport(index_exports, require("./stt.cjs"), module.exports);
19
20
  __reExport(index_exports, require("./tts.cjs"), module.exports);
20
21
  class CartesiaPlugin extends import_agents.Plugin {
21
22
  constructor() {
22
23
  super({
23
24
  title: "cartesia",
24
- version: "1.4.4",
25
+ version: "1.4.6",
25
26
  package: "@livekit/agents-plugin-cartesia"
26
27
  });
27
28
  }
@@ -29,6 +30,7 @@ class CartesiaPlugin extends import_agents.Plugin {
29
30
  import_agents.Plugin.registerPlugin(new CartesiaPlugin());
30
31
  // Annotate the CommonJS export names for ESM import in node:
31
32
  0 && (module.exports = {
33
+ ...require("./stt.cjs"),
32
34
  ...require("./tts.cjs")
33
35
  });
34
36
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\n\nexport * from './tts.js';\n\nclass CartesiaPlugin extends Plugin {\n constructor() {\n super({\n title: 'cartesia',\n version: __PACKAGE_VERSION__,\n package: __PACKAGE_NAME__,\n });\n }\n}\n\nPlugin.registerPlugin(new CartesiaPlugin());\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAGA,oBAAuB;AAEvB,0BAAc,qBALd;AAOA,MAAM,uBAAuB,qBAAO;AAAA,EAClC,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEA,qBAAO,eAAe,IAAI,eAAe,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\n\nexport * from './stt.js';\nexport * from './tts.js';\n\nclass CartesiaPlugin extends Plugin {\n constructor() {\n super({\n title: 'cartesia',\n version: __PACKAGE_VERSION__,\n package: __PACKAGE_NAME__,\n });\n }\n}\n\nPlugin.registerPlugin(new CartesiaPlugin());\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAGA,oBAAuB;AAEvB,0BAAc,qBALd;AAMA,0BAAc,qBANd;AAQA,MAAM,uBAAuB,qBAAO;AAAA,EAClC,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEA,qBAAO,eAAe,IAAI,eAAe,CAAC;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from './stt.js';
1
2
  export * from './tts.js';
2
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from './stt.js';
1
2
  export * from './tts.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { Plugin } from "@livekit/agents";
2
+ export * from "./stt.js";
2
3
  export * from "./tts.js";
3
4
  class CartesiaPlugin extends Plugin {
4
5
  constructor() {
5
6
  super({
6
7
  title: "cartesia",
7
- version: "1.4.4",
8
+ version: "1.4.6",
8
9
  package: "@livekit/agents-plugin-cartesia"
9
10
  });
10
11
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\n\nexport * from './tts.js';\n\nclass CartesiaPlugin extends Plugin {\n constructor() {\n super({\n title: 'cartesia',\n version: __PACKAGE_VERSION__,\n package: __PACKAGE_NAME__,\n });\n }\n}\n\nPlugin.registerPlugin(new CartesiaPlugin());\n"],"mappings":"AAGA,SAAS,cAAc;AAEvB,cAAc;AAEd,MAAM,uBAAuB,OAAO;AAAA,EAClC,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEA,OAAO,eAAe,IAAI,eAAe,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\n\nexport * from './stt.js';\nexport * from './tts.js';\n\nclass CartesiaPlugin extends Plugin {\n constructor() {\n super({\n title: 'cartesia',\n version: __PACKAGE_VERSION__,\n package: __PACKAGE_NAME__,\n });\n }\n}\n\nPlugin.registerPlugin(new CartesiaPlugin());\n"],"mappings":"AAGA,SAAS,cAAc;AAEvB,cAAc;AACd,cAAc;AAEd,MAAM,uBAAuB,OAAO;AAAA,EAClC,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEA,OAAO,eAAe,IAAI,eAAe,CAAC;","names":[]}
package/dist/models.cjs CHANGED
@@ -18,14 +18,17 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var models_exports = {};
20
20
  __export(models_exports, {
21
+ AUDIO_ENCODING: () => AUDIO_ENCODING,
21
22
  TTSDefaultVoiceId: () => TTSDefaultVoiceId,
22
23
  isSonic3: () => isSonic3
23
24
  });
24
25
  module.exports = __toCommonJS(models_exports);
26
+ const AUDIO_ENCODING = "pcm_s16le";
25
27
  const TTSDefaultVoiceId = "f786b574-daa5-4673-aa0c-cbe3e8534c02";
26
28
  const isSonic3 = (model) => model.startsWith("sonic-3");
27
29
  // Annotate the CommonJS export names for ESM import in node:
28
30
  0 && (module.exports = {
31
+ AUDIO_ENCODING,
29
32
  TTSDefaultVoiceId,
30
33
  isSonic3
31
34
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/models.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\nexport type TTSModels =\n | 'sonic'\n | 'sonic-2'\n | 'sonic-3'\n | 'sonic-lite'\n | 'sonic-preview'\n | 'sonic-turbo';\n\nexport type TTSLanguages = 'en' | 'es' | 'fr' | 'de' | 'pt' | 'zh' | 'ja';\n\nexport const TTSDefaultVoiceId = 'f786b574-daa5-4673-aa0c-cbe3e8534c02';\n\nexport const isSonic3 = (model: string): boolean => model.startsWith('sonic-3');\n\nexport type TTSVoiceSpeed = 'fastest' | 'fast' | 'normal' | 'slow' | 'slowest';\n\nexport type TTSVoiceEmotion =\n | 'anger:lowest'\n | 'anger:low'\n | 'anger'\n | 'anger:high'\n | 'anger:highest'\n | 'positivity:lowest'\n | 'positivity:low'\n | 'positivity'\n | 'positivity:high'\n | 'positivity:highest'\n | 'surprise:lowest'\n | 'surprise:low'\n | 'surprise'\n | 'surprise:high'\n | 'surprise:highest'\n | 'sadness:lowest'\n | 'sadness:low'\n | 'sadness'\n | 'sadness:high'\n | 'sadness:highest'\n | 'curiosity:lowest'\n | 'curiosity:low'\n | 'curiosity'\n | 'curiosity:high'\n | 'curiosity:highest';\n\nexport type TTSEncoding =\n // XXX(nbsp): not yet supported\n // | 'pcm_f32le'\n // | 'pcm_mulaw'\n // | 'pcm_alaw'\n 'pcm_s16le';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcO,MAAM,oBAAoB;AAE1B,MAAM,WAAW,CAAC,UAA2B,MAAM,WAAW,SAAS;","names":[]}
1
+ {"version":3,"sources":["../src/models.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LiveKit uses this encoding for all audio\n */\nexport const AUDIO_ENCODING = 'pcm_s16le';\n\n// ============================================================================\n// TTS\n// ============================================================================\n\n/**\n * See [the docs](https://docs.cartesia.ai/build-with-cartesia/tts-models/latest) for all options.\n */\nexport type TTSModels =\n | 'sonic'\n | 'sonic-2'\n | 'sonic-3'\n | 'sonic-lite'\n | 'sonic-preview'\n | 'sonic-turbo';\n\n/**\n * See [the docs](https://docs.cartesia.ai/build-with-cartesia/tts-models/latest) for all options.\n */\nexport type TTSLanguages = 'en' | 'es' | 'fr' | 'de' | 'pt' | 'zh' | 'ja';\n\nexport const TTSDefaultVoiceId = 'f786b574-daa5-4673-aa0c-cbe3e8534c02';\n\nexport const isSonic3 = (model: string): boolean => model.startsWith('sonic-3');\n\nexport type TTSVoiceSpeed = 'fastest' | 'fast' | 'normal' | 'slow' | 'slowest';\n\nexport type TTSVoiceEmotion =\n | 'anger:lowest'\n | 'anger:low'\n | 'anger'\n | 'anger:high'\n | 'anger:highest'\n | 'positivity:lowest'\n | 'positivity:low'\n | 'positivity'\n | 'positivity:high'\n | 'positivity:highest'\n | 'surprise:lowest'\n | 'surprise:low'\n | 'surprise'\n | 'surprise:high'\n | 'surprise:highest'\n | 'sadness:lowest'\n | 'sadness:low'\n | 'sadness'\n | 'sadness:high'\n | 'sadness:highest'\n | 'curiosity:lowest'\n | 'curiosity:low'\n | 'curiosity'\n | 'curiosity:high'\n | 'curiosity:highest';\n\n/**\n * @deprecated Encoding should not be parameterized. Only `pcm_s16le`is allowed. Prefer using {@link AUDIO_ENCODING}.\n */\nexport type TTSEncoding = 'pcm_s16le';\n\n// ============================================================================\n// STT\n// ============================================================================\n\n/**\n * See [the docs](https://docs.cartesia.ai/build-with-cartesia/stt-models/latest) for all options.\n */\nexport type STTModel = 'ink-2';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,MAAM,iBAAiB;AAsBvB,MAAM,oBAAoB;AAE1B,MAAM,WAAW,CAAC,UAA2B,MAAM,WAAW,SAAS;","names":[]}
package/dist/models.d.cts CHANGED
@@ -1,8 +1,25 @@
1
+ /**
2
+ * LiveKit uses this encoding for all audio
3
+ */
4
+ export declare const AUDIO_ENCODING = "pcm_s16le";
5
+ /**
6
+ * See [the docs](https://docs.cartesia.ai/build-with-cartesia/tts-models/latest) for all options.
7
+ */
1
8
  export type TTSModels = 'sonic' | 'sonic-2' | 'sonic-3' | 'sonic-lite' | 'sonic-preview' | 'sonic-turbo';
9
+ /**
10
+ * See [the docs](https://docs.cartesia.ai/build-with-cartesia/tts-models/latest) for all options.
11
+ */
2
12
  export type TTSLanguages = 'en' | 'es' | 'fr' | 'de' | 'pt' | 'zh' | 'ja';
3
13
  export declare const TTSDefaultVoiceId = "f786b574-daa5-4673-aa0c-cbe3e8534c02";
4
14
  export declare const isSonic3: (model: string) => boolean;
5
15
  export type TTSVoiceSpeed = 'fastest' | 'fast' | 'normal' | 'slow' | 'slowest';
6
16
  export type TTSVoiceEmotion = 'anger:lowest' | 'anger:low' | 'anger' | 'anger:high' | 'anger:highest' | 'positivity:lowest' | 'positivity:low' | 'positivity' | 'positivity:high' | 'positivity:highest' | 'surprise:lowest' | 'surprise:low' | 'surprise' | 'surprise:high' | 'surprise:highest' | 'sadness:lowest' | 'sadness:low' | 'sadness' | 'sadness:high' | 'sadness:highest' | 'curiosity:lowest' | 'curiosity:low' | 'curiosity' | 'curiosity:high' | 'curiosity:highest';
17
+ /**
18
+ * @deprecated Encoding should not be parameterized. Only `pcm_s16le`is allowed. Prefer using {@link AUDIO_ENCODING}.
19
+ */
7
20
  export type TTSEncoding = 'pcm_s16le';
21
+ /**
22
+ * See [the docs](https://docs.cartesia.ai/build-with-cartesia/stt-models/latest) for all options.
23
+ */
24
+ export type STTModel = 'ink-2';
8
25
  //# sourceMappingURL=models.d.ts.map
package/dist/models.d.ts CHANGED
@@ -1,8 +1,25 @@
1
+ /**
2
+ * LiveKit uses this encoding for all audio
3
+ */
4
+ export declare const AUDIO_ENCODING = "pcm_s16le";
5
+ /**
6
+ * See [the docs](https://docs.cartesia.ai/build-with-cartesia/tts-models/latest) for all options.
7
+ */
1
8
  export type TTSModels = 'sonic' | 'sonic-2' | 'sonic-3' | 'sonic-lite' | 'sonic-preview' | 'sonic-turbo';
9
+ /**
10
+ * See [the docs](https://docs.cartesia.ai/build-with-cartesia/tts-models/latest) for all options.
11
+ */
2
12
  export type TTSLanguages = 'en' | 'es' | 'fr' | 'de' | 'pt' | 'zh' | 'ja';
3
13
  export declare const TTSDefaultVoiceId = "f786b574-daa5-4673-aa0c-cbe3e8534c02";
4
14
  export declare const isSonic3: (model: string) => boolean;
5
15
  export type TTSVoiceSpeed = 'fastest' | 'fast' | 'normal' | 'slow' | 'slowest';
6
16
  export type TTSVoiceEmotion = 'anger:lowest' | 'anger:low' | 'anger' | 'anger:high' | 'anger:highest' | 'positivity:lowest' | 'positivity:low' | 'positivity' | 'positivity:high' | 'positivity:highest' | 'surprise:lowest' | 'surprise:low' | 'surprise' | 'surprise:high' | 'surprise:highest' | 'sadness:lowest' | 'sadness:low' | 'sadness' | 'sadness:high' | 'sadness:highest' | 'curiosity:lowest' | 'curiosity:low' | 'curiosity' | 'curiosity:high' | 'curiosity:highest';
17
+ /**
18
+ * @deprecated Encoding should not be parameterized. Only `pcm_s16le`is allowed. Prefer using {@link AUDIO_ENCODING}.
19
+ */
7
20
  export type TTSEncoding = 'pcm_s16le';
21
+ /**
22
+ * See [the docs](https://docs.cartesia.ai/build-with-cartesia/stt-models/latest) for all options.
23
+ */
24
+ export type STTModel = 'ink-2';
8
25
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,SAAS,GACT,SAAS,GACT,YAAY,GACZ,eAAe,GACf,aAAa,CAAC;AAElB,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1E,eAAO,MAAM,iBAAiB,yCAAyC,CAAC;AAExE,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,OAAsC,CAAC;AAEhF,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAE/E,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,WAAW,GACX,OAAO,GACP,YAAY,GACZ,eAAe,GACf,mBAAmB,GACnB,gBAAgB,GAChB,YAAY,GACZ,iBAAiB,GACjB,oBAAoB,GACpB,iBAAiB,GACjB,cAAc,GACd,UAAU,GACV,eAAe,GACf,kBAAkB,GAClB,gBAAgB,GAChB,aAAa,GACb,SAAS,GACT,cAAc,GACd,iBAAiB,GACjB,kBAAkB,GAClB,eAAe,GACf,WAAW,GACX,gBAAgB,GAChB,mBAAmB,CAAC;AAExB,MAAM,MAAM,WAAW,GAKrB,WAAW,CAAC"}
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,cAAc,cAAc,CAAC;AAM1C;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,SAAS,GACT,SAAS,GACT,YAAY,GACZ,eAAe,GACf,aAAa,CAAC;AAElB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1E,eAAO,MAAM,iBAAiB,yCAAyC,CAAC;AAExE,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,OAAsC,CAAC;AAEhF,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAE/E,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,WAAW,GACX,OAAO,GACP,YAAY,GACZ,eAAe,GACf,mBAAmB,GACnB,gBAAgB,GAChB,YAAY,GACZ,iBAAiB,GACjB,oBAAoB,GACpB,iBAAiB,GACjB,cAAc,GACd,UAAU,GACV,eAAe,GACf,kBAAkB,GAClB,gBAAgB,GAChB,aAAa,GACb,SAAS,GACT,cAAc,GACd,iBAAiB,GACjB,kBAAkB,GAClB,eAAe,GACf,WAAW,GACX,gBAAgB,GAChB,mBAAmB,CAAC;AAExB;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC;AAMtC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC"}
package/dist/models.js CHANGED
@@ -1,6 +1,8 @@
1
+ const AUDIO_ENCODING = "pcm_s16le";
1
2
  const TTSDefaultVoiceId = "f786b574-daa5-4673-aa0c-cbe3e8534c02";
2
3
  const isSonic3 = (model) => model.startsWith("sonic-3");
3
4
  export {
5
+ AUDIO_ENCODING,
4
6
  TTSDefaultVoiceId,
5
7
  isSonic3
6
8
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/models.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\nexport type TTSModels =\n | 'sonic'\n | 'sonic-2'\n | 'sonic-3'\n | 'sonic-lite'\n | 'sonic-preview'\n | 'sonic-turbo';\n\nexport type TTSLanguages = 'en' | 'es' | 'fr' | 'de' | 'pt' | 'zh' | 'ja';\n\nexport const TTSDefaultVoiceId = 'f786b574-daa5-4673-aa0c-cbe3e8534c02';\n\nexport const isSonic3 = (model: string): boolean => model.startsWith('sonic-3');\n\nexport type TTSVoiceSpeed = 'fastest' | 'fast' | 'normal' | 'slow' | 'slowest';\n\nexport type TTSVoiceEmotion =\n | 'anger:lowest'\n | 'anger:low'\n | 'anger'\n | 'anger:high'\n | 'anger:highest'\n | 'positivity:lowest'\n | 'positivity:low'\n | 'positivity'\n | 'positivity:high'\n | 'positivity:highest'\n | 'surprise:lowest'\n | 'surprise:low'\n | 'surprise'\n | 'surprise:high'\n | 'surprise:highest'\n | 'sadness:lowest'\n | 'sadness:low'\n | 'sadness'\n | 'sadness:high'\n | 'sadness:highest'\n | 'curiosity:lowest'\n | 'curiosity:low'\n | 'curiosity'\n | 'curiosity:high'\n | 'curiosity:highest';\n\nexport type TTSEncoding =\n // XXX(nbsp): not yet supported\n // | 'pcm_f32le'\n // | 'pcm_mulaw'\n // | 'pcm_alaw'\n 'pcm_s16le';\n"],"mappings":"AAcO,MAAM,oBAAoB;AAE1B,MAAM,WAAW,CAAC,UAA2B,MAAM,WAAW,SAAS;","names":[]}
1
+ {"version":3,"sources":["../src/models.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LiveKit uses this encoding for all audio\n */\nexport const AUDIO_ENCODING = 'pcm_s16le';\n\n// ============================================================================\n// TTS\n// ============================================================================\n\n/**\n * See [the docs](https://docs.cartesia.ai/build-with-cartesia/tts-models/latest) for all options.\n */\nexport type TTSModels =\n | 'sonic'\n | 'sonic-2'\n | 'sonic-3'\n | 'sonic-lite'\n | 'sonic-preview'\n | 'sonic-turbo';\n\n/**\n * See [the docs](https://docs.cartesia.ai/build-with-cartesia/tts-models/latest) for all options.\n */\nexport type TTSLanguages = 'en' | 'es' | 'fr' | 'de' | 'pt' | 'zh' | 'ja';\n\nexport const TTSDefaultVoiceId = 'f786b574-daa5-4673-aa0c-cbe3e8534c02';\n\nexport const isSonic3 = (model: string): boolean => model.startsWith('sonic-3');\n\nexport type TTSVoiceSpeed = 'fastest' | 'fast' | 'normal' | 'slow' | 'slowest';\n\nexport type TTSVoiceEmotion =\n | 'anger:lowest'\n | 'anger:low'\n | 'anger'\n | 'anger:high'\n | 'anger:highest'\n | 'positivity:lowest'\n | 'positivity:low'\n | 'positivity'\n | 'positivity:high'\n | 'positivity:highest'\n | 'surprise:lowest'\n | 'surprise:low'\n | 'surprise'\n | 'surprise:high'\n | 'surprise:highest'\n | 'sadness:lowest'\n | 'sadness:low'\n | 'sadness'\n | 'sadness:high'\n | 'sadness:highest'\n | 'curiosity:lowest'\n | 'curiosity:low'\n | 'curiosity'\n | 'curiosity:high'\n | 'curiosity:highest';\n\n/**\n * @deprecated Encoding should not be parameterized. Only `pcm_s16le`is allowed. Prefer using {@link AUDIO_ENCODING}.\n */\nexport type TTSEncoding = 'pcm_s16le';\n\n// ============================================================================\n// STT\n// ============================================================================\n\n/**\n * See [the docs](https://docs.cartesia.ai/build-with-cartesia/stt-models/latest) for all options.\n */\nexport type STTModel = 'ink-2';\n"],"mappings":"AAOO,MAAM,iBAAiB;AAsBvB,MAAM,oBAAoB;AAE1B,MAAM,WAAW,CAAC,UAA2B,MAAM,WAAW,SAAS;","names":[]}
package/dist/stt.cjs ADDED
@@ -0,0 +1,409 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var stt_exports = {};
20
+ __export(stt_exports, {
21
+ STT: () => STT,
22
+ SpeechStream: () => SpeechStream
23
+ });
24
+ module.exports = __toCommonJS(stt_exports);
25
+ var import_agents = require("@livekit/agents");
26
+ var import_ws = require("ws");
27
+ var import_models = require("./models.cjs");
28
+ const AUTHORIZATION_HEADER = "X-API-Key";
29
+ const VERSION_HEADER = "Cartesia-Version";
30
+ const REQUEST_ID_HEADER = "cartesia-request-id";
31
+ const API_VERSION = "2026-03-01";
32
+ const DRAIN_TIMEOUT_MS = 5e3;
33
+ const KEEPALIVE_INTERVAL_MS = 3e4;
34
+ const defaultSTTOptions = {
35
+ model: "ink-2",
36
+ /** recommended default */
37
+ sampleRate: 16e3,
38
+ /** recommended default */
39
+ audioChunkDurationMS: 160,
40
+ baseUrl: "https://api.cartesia.ai"
41
+ };
42
+ function mergeSTTOptions(base, override) {
43
+ return {
44
+ apiKey: override.apiKey ?? base.apiKey,
45
+ baseUrl: override.baseUrl ?? base.baseUrl,
46
+ model: override.model ?? base.model,
47
+ sampleRate: override.sampleRate ?? base.sampleRate,
48
+ audioChunkDurationMS: override.audioChunkDurationMS ?? base.audioChunkDurationMS
49
+ };
50
+ }
51
+ class STT extends import_agents.stt.STT {
52
+ #opts;
53
+ constructor(opts = {}) {
54
+ super({
55
+ streaming: true,
56
+ interimResults: true,
57
+ alignedTranscript: false,
58
+ diarization: false
59
+ });
60
+ const apiKey = opts.apiKey ?? process.env.CARTESIA_API_KEY;
61
+ if (!apiKey) {
62
+ throw new Error(
63
+ "Cartesia API key is required, whether as an argument or as $CARTESIA_API_KEY"
64
+ );
65
+ }
66
+ this.#opts = mergeSTTOptions({ ...defaultSTTOptions, apiKey }, opts);
67
+ }
68
+ get label() {
69
+ return "cartesia.STT";
70
+ }
71
+ get model() {
72
+ return this.#opts.model;
73
+ }
74
+ get provider() {
75
+ return "Cartesia";
76
+ }
77
+ async _recognize() {
78
+ throw new Error("Cartesia STT does not support batch recognition, use stream() instead");
79
+ }
80
+ stream(options) {
81
+ return new SpeechStream(this, this.#opts, options == null ? void 0 : options.connOptions);
82
+ }
83
+ }
84
+ class SpeechStream extends import_agents.stt.SpeechStream {
85
+ #opts;
86
+ #logger = (0, import_agents.log)();
87
+ #ws = null;
88
+ #requestId;
89
+ #speaking = false;
90
+ #currentTranscript = "";
91
+ #speechDuration = 0;
92
+ #closingWs = false;
93
+ constructor(sttInstance, opts, connOptions) {
94
+ super(sttInstance, opts.sampleRate, connOptions);
95
+ this.#opts = { ...opts };
96
+ }
97
+ get label() {
98
+ return "cartesia.SpeechStream";
99
+ }
100
+ async run() {
101
+ var _a;
102
+ if (this.closed) {
103
+ this.close();
104
+ return;
105
+ }
106
+ this.#speaking = false;
107
+ this.#currentTranscript = "";
108
+ this.#speechDuration = 0;
109
+ this.#closingWs = false;
110
+ let keepaliveInterval;
111
+ const abortController = new AbortController();
112
+ try {
113
+ const url = this.#getCartesiaUrl();
114
+ this.#logger.debug(`Connecting to Cartesia STT: ${url}`);
115
+ const ws = new import_ws.WebSocket(url, {
116
+ headers: {
117
+ [AUTHORIZATION_HEADER]: this.#opts.apiKey,
118
+ [VERSION_HEADER]: API_VERSION
119
+ }
120
+ });
121
+ this.#ws = ws;
122
+ ws.once("upgrade", (response) => {
123
+ const headerValue = response.headers[REQUEST_ID_HEADER];
124
+ const requestId = Array.isArray(headerValue) ? headerValue[0] : headerValue;
125
+ if (requestId) {
126
+ this.#requestId = requestId;
127
+ this.#logger.debug({ cartesiaRequestId: requestId }, "Cartesia STT WebSocket connected");
128
+ }
129
+ });
130
+ await new Promise((resolve, reject) => {
131
+ const onOpen = () => {
132
+ ws.off("error", onError);
133
+ resolve();
134
+ };
135
+ const onError = (err) => {
136
+ ws.off("open", onOpen);
137
+ reject(new import_agents.APIConnectionError({ message: err.message, options: { retryable: true } }));
138
+ };
139
+ ws.once("open", onOpen);
140
+ ws.once("error", onError);
141
+ });
142
+ let firstError;
143
+ const stopPeer = (err) => {
144
+ if (firstError === void 0) firstError = err;
145
+ abortController.abort();
146
+ if (ws.readyState === import_ws.WebSocket.OPEN) ws.close();
147
+ };
148
+ const sendPromise = this.#sendTask(ws, abortController.signal).catch(stopPeer);
149
+ const recvPromise = this.#recvTask(ws).catch(stopPeer);
150
+ keepaliveInterval = setInterval(() => {
151
+ try {
152
+ if (ws.readyState === import_ws.WebSocket.OPEN) {
153
+ ws.ping();
154
+ }
155
+ } catch {
156
+ }
157
+ }, KEEPALIVE_INTERVAL_MS);
158
+ await Promise.all([sendPromise, recvPromise]);
159
+ if (firstError !== void 0) throw firstError;
160
+ } catch (error) {
161
+ this.#logger.error("Cartesia STT stream error", { error });
162
+ throw error;
163
+ } finally {
164
+ abortController.abort();
165
+ if (keepaliveInterval) clearInterval(keepaliveInterval);
166
+ if (((_a = this.#ws) == null ? void 0 : _a.readyState) === import_ws.WebSocket.OPEN) {
167
+ this.#ws.close();
168
+ }
169
+ }
170
+ this.close();
171
+ }
172
+ async #sendTask(ws, abortSignal) {
173
+ const samplesPerChunk = Math.floor(
174
+ this.#opts.sampleRate * this.#opts.audioChunkDurationMS / 1e3
175
+ );
176
+ const audioBstream = new import_agents.AudioByteStream(this.#opts.sampleRate, 1, samplesPerChunk);
177
+ let hasEnded = false;
178
+ const iterator = this.input[Symbol.asyncIterator]();
179
+ const abortPromise = (0, import_agents.waitForAbort)(abortSignal);
180
+ while (true) {
181
+ const result = await Promise.race([iterator.next(), abortPromise]);
182
+ if (result === void 0) return;
183
+ if (result.done) {
184
+ hasEnded = true;
185
+ } else {
186
+ const data = result.value;
187
+ const frames = [];
188
+ if (data === SpeechStream.FLUSH_SENTINEL) {
189
+ frames.push(...audioBstream.flush());
190
+ } else {
191
+ frames.push(...audioBstream.write(data.data));
192
+ }
193
+ for (const frame of frames) {
194
+ this.#speechDuration += (0, import_agents.calculateAudioDurationSeconds)(frame);
195
+ if (ws.readyState === import_ws.WebSocket.OPEN) {
196
+ ws.send(frame.data);
197
+ }
198
+ }
199
+ }
200
+ if (hasEnded) break;
201
+ }
202
+ if (ws.readyState === import_ws.WebSocket.OPEN) {
203
+ this.#closingWs = true;
204
+ this.#logger.debug("Sending close message to Cartesia STT");
205
+ ws.send(JSON.stringify({ type: "close" }));
206
+ const drainTimer = setTimeout(() => {
207
+ this.#logger.warn(
208
+ `Cartesia STT did not close within ${DRAIN_TIMEOUT_MS}ms after done; forcing close`
209
+ );
210
+ if (ws.readyState === import_ws.WebSocket.OPEN || ws.readyState === import_ws.WebSocket.CLOSING) {
211
+ ws.terminate();
212
+ }
213
+ }, DRAIN_TIMEOUT_MS);
214
+ ws.once("close", () => clearTimeout(drainTimer));
215
+ }
216
+ }
217
+ async #recvTask(ws) {
218
+ let pendingError = void 0;
219
+ return new Promise((resolve, reject) => {
220
+ const settle = (err) => {
221
+ if (err) reject(err);
222
+ else resolve();
223
+ };
224
+ ws.on("message", (data, isBinary) => {
225
+ if (isBinary) {
226
+ this.#logger.warn("Received unexpected binary message from Cartesia STT");
227
+ return;
228
+ }
229
+ let msg;
230
+ try {
231
+ msg = JSON.parse(data.toString());
232
+ } catch (error) {
233
+ this.#logger.error("Failed to parse Cartesia STT message", { error });
234
+ return;
235
+ }
236
+ try {
237
+ if (msg.type === "error") {
238
+ this.#logger.error("Cartesia sent an error", msg);
239
+ if (msg.status_code === void 0 || msg.status_code >= 500) {
240
+ pendingError = new import_agents.APIConnectionError({
241
+ message: msg.message || msg.title,
242
+ options: {
243
+ retryable: true
244
+ }
245
+ });
246
+ ws.close();
247
+ return;
248
+ }
249
+ } else {
250
+ this.#processStreamEvent(msg);
251
+ }
252
+ } catch (error) {
253
+ this.#logger.error("Failed to process Cartesia STT message", { error });
254
+ }
255
+ });
256
+ ws.on("close", (code, reason) => {
257
+ if (this.#speaking) {
258
+ if (this.#currentTranscript) {
259
+ this.#sendTranscriptEvent(
260
+ import_agents.stt.SpeechEventType.FINAL_TRANSCRIPT,
261
+ this.#currentTranscript
262
+ );
263
+ }
264
+ if (!this.queue.closed)
265
+ this.queue.put({
266
+ type: import_agents.stt.SpeechEventType.END_OF_SPEECH,
267
+ requestId: this.#requestId
268
+ });
269
+ this.#logger.debug("Cartesia STT END_OF_SPEECH");
270
+ if (this.#speechDuration > 0 && !this.queue.closed) {
271
+ this.queue.put({
272
+ type: import_agents.stt.SpeechEventType.RECOGNITION_USAGE,
273
+ requestId: this.#requestId,
274
+ recognitionUsage: { audioDuration: this.#speechDuration }
275
+ });
276
+ this.#speechDuration = 0;
277
+ }
278
+ this.#speaking = false;
279
+ this.#currentTranscript = "";
280
+ }
281
+ if (pendingError) {
282
+ settle(pendingError);
283
+ return;
284
+ }
285
+ if (this.#closingWs || this.closed) {
286
+ settle();
287
+ return;
288
+ }
289
+ this.#logger.warn(`Cartesia STT WebSocket closed: ${code} ${reason.toString()}`);
290
+ settle(
291
+ new import_agents.APIConnectionError({
292
+ message: `Cartesia STT connection closed unexpectedly (code=${code})`,
293
+ options: { retryable: true }
294
+ })
295
+ );
296
+ });
297
+ ws.on("error", (err) => {
298
+ if (this.closed) {
299
+ settle();
300
+ return;
301
+ }
302
+ settle(new import_agents.APIConnectionError({ message: err.message, options: { retryable: true } }));
303
+ });
304
+ });
305
+ }
306
+ #processStreamEvent(data) {
307
+ if (data.request_id) {
308
+ this.#requestId = data.request_id;
309
+ }
310
+ switch (data.type) {
311
+ case "connected":
312
+ return;
313
+ case "turn.start": {
314
+ if (this.#speaking) return;
315
+ this.#speaking = true;
316
+ this.#currentTranscript = "";
317
+ if (!this.queue.closed)
318
+ this.queue.put({
319
+ type: import_agents.stt.SpeechEventType.START_OF_SPEECH,
320
+ requestId: this.#requestId
321
+ });
322
+ this.#logger.debug("Cartesia STT START_OF_SPEECH");
323
+ return;
324
+ }
325
+ case "turn.update": {
326
+ if (!this.#speaking) return;
327
+ const transcript = data.transcript;
328
+ if (!transcript) return;
329
+ if (this.#currentTranscript === transcript) return;
330
+ this.#currentTranscript = transcript;
331
+ this.#sendTranscriptEvent(import_agents.stt.SpeechEventType.INTERIM_TRANSCRIPT, transcript);
332
+ return;
333
+ }
334
+ case "turn.eager_end": {
335
+ if (!this.#speaking) return;
336
+ const transcript = data.transcript;
337
+ if (!transcript) return;
338
+ this.#currentTranscript = transcript;
339
+ this.#sendTranscriptEvent(import_agents.stt.SpeechEventType.PREFLIGHT_TRANSCRIPT, transcript);
340
+ return;
341
+ }
342
+ case "turn.resume":
343
+ if (!this.#speaking || !this.#currentTranscript) return;
344
+ this.#sendTranscriptEvent(import_agents.stt.SpeechEventType.INTERIM_TRANSCRIPT, this.#currentTranscript);
345
+ return;
346
+ case "turn.end": {
347
+ if (!this.#speaking) return;
348
+ const transcript = data.transcript;
349
+ this.#sendTranscriptEvent(import_agents.stt.SpeechEventType.FINAL_TRANSCRIPT, transcript);
350
+ this.#speaking = false;
351
+ if (!this.queue.closed)
352
+ this.queue.put({
353
+ type: import_agents.stt.SpeechEventType.END_OF_SPEECH,
354
+ requestId: this.#requestId
355
+ });
356
+ this.#logger.debug("Cartesia STT END_OF_SPEECH");
357
+ this.#currentTranscript = "";
358
+ if (this.#speechDuration > 0 && !this.queue.closed) {
359
+ this.queue.put({
360
+ type: import_agents.stt.SpeechEventType.RECOGNITION_USAGE,
361
+ requestId: this.#requestId,
362
+ recognitionUsage: { audioDuration: this.#speechDuration }
363
+ });
364
+ this.#speechDuration = 0;
365
+ }
366
+ return;
367
+ }
368
+ default:
369
+ this.#logger.warn("received unexpected message from Cartesia STT", { data });
370
+ }
371
+ }
372
+ #sendTranscriptEvent(eventType, transcript) {
373
+ if (this.queue.closed) return;
374
+ this.queue.put({
375
+ type: eventType,
376
+ requestId: this.#requestId,
377
+ alternatives: [
378
+ {
379
+ // Cartesia STT only supports English at this time.
380
+ language: (0, import_agents.asLanguageCode)("en"),
381
+ text: transcript,
382
+ startTime: 0,
383
+ endTime: 0,
384
+ confidence: 0
385
+ }
386
+ ]
387
+ });
388
+ }
389
+ #getCartesiaUrl() {
390
+ const params = new URLSearchParams({
391
+ model: this.#opts.model,
392
+ sample_rate: this.#opts.sampleRate.toString(),
393
+ encoding: import_models.AUDIO_ENCODING
394
+ });
395
+ const wsBase = this.#opts.baseUrl.replace(/^http/, "ws");
396
+ return `${wsBase}/stt/turns/websocket?${params.toString()}`;
397
+ }
398
+ close() {
399
+ var _a;
400
+ super.close();
401
+ (_a = this.#ws) == null ? void 0 : _a.close();
402
+ }
403
+ }
404
+ // Annotate the CommonJS export names for ESM import in node:
405
+ 0 && (module.exports = {
406
+ STT,
407
+ SpeechStream
408
+ });
409
+ //# sourceMappingURL=stt.cjs.map