@cartesia/cartesia-js 0.0.3 → 1.0.0-alpha.1

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.
Files changed (103) hide show
  1. package/.turbo/turbo-build.log +68 -38
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +123 -16
  4. package/dist/chunk-3FL2SNIR.js +17 -0
  5. package/dist/chunk-3GBZUGUD.js +17 -0
  6. package/dist/chunk-4RMSIQLG.js +25 -0
  7. package/dist/chunk-BCQ63627.js +32 -0
  8. package/dist/chunk-JOHSCOLW.js +106 -0
  9. package/dist/chunk-LYPTISWL.js +75 -0
  10. package/dist/chunk-NDNN326Q.js +207 -0
  11. package/dist/chunk-WBK6LLXX.js +58 -0
  12. package/dist/chunk-WE63M7PJ.js +119 -0
  13. package/dist/{chunk-HNLIBHEN.mjs → chunk-WIFMLPT5.js} +31 -16
  14. package/dist/chunk-X7SJMF2R.js +22 -0
  15. package/dist/index.cjs +652 -0
  16. package/dist/index.d.cts +10 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.js +20 -0
  19. package/dist/lib/client.cjs +89 -0
  20. package/dist/lib/client.d.cts +11 -0
  21. package/dist/lib/client.d.ts +2 -0
  22. package/dist/lib/client.js +7 -42
  23. package/dist/lib/constants.cjs +42 -0
  24. package/dist/lib/constants.d.cts +4 -0
  25. package/dist/lib/constants.d.ts +2 -3
  26. package/dist/lib/constants.js +8 -37
  27. package/dist/lib/index.cjs +531 -0
  28. package/dist/lib/index.d.cts +16 -0
  29. package/dist/lib/index.d.ts +6 -2
  30. package/dist/lib/index.js +13 -409
  31. package/dist/react/index.cjs +846 -0
  32. package/dist/react/index.d.cts +33 -0
  33. package/dist/react/index.d.ts +20 -13
  34. package/dist/react/index.js +161 -501
  35. package/dist/react/utils.cjs +57 -0
  36. package/dist/react/utils.d.cts +7 -0
  37. package/dist/react/utils.d.ts +7 -0
  38. package/dist/react/utils.js +7 -0
  39. package/dist/tts/index.cjs +470 -0
  40. package/dist/tts/index.d.cts +17 -0
  41. package/dist/tts/index.d.ts +17 -0
  42. package/dist/tts/index.js +12 -0
  43. package/dist/tts/player.cjs +198 -0
  44. package/dist/tts/player.d.cts +43 -0
  45. package/dist/tts/player.d.ts +43 -0
  46. package/dist/tts/player.js +8 -0
  47. package/dist/tts/source.cjs +167 -0
  48. package/dist/tts/source.d.cts +53 -0
  49. package/dist/tts/source.d.ts +53 -0
  50. package/dist/tts/source.js +7 -0
  51. package/dist/{audio/utils.js → tts/utils.cjs} +13 -54
  52. package/dist/tts/utils.d.cts +67 -0
  53. package/dist/tts/utils.d.ts +67 -0
  54. package/dist/{audio/utils.mjs → tts/utils.js} +2 -6
  55. package/dist/tts/websocket.cjs +453 -0
  56. package/dist/tts/websocket.d.cts +53 -0
  57. package/dist/tts/websocket.d.ts +53 -0
  58. package/dist/tts/websocket.js +11 -0
  59. package/dist/types/index.cjs +18 -0
  60. package/dist/types/index.d.cts +55 -0
  61. package/dist/types/index.d.ts +50 -1
  62. package/dist/types/index.js +1 -18
  63. package/dist/voices/index.cjs +155 -0
  64. package/dist/voices/index.d.cts +12 -0
  65. package/dist/voices/index.d.ts +12 -0
  66. package/dist/voices/index.js +9 -0
  67. package/package.json +11 -7
  68. package/src/index.ts +4 -0
  69. package/src/lib/client.ts +14 -1
  70. package/src/lib/constants.ts +13 -3
  71. package/src/lib/index.ts +6 -3
  72. package/src/react/index.ts +167 -75
  73. package/src/react/utils.ts +11 -0
  74. package/src/tts/index.ts +17 -0
  75. package/src/tts/player.ts +109 -0
  76. package/src/tts/source.ts +98 -0
  77. package/src/{audio → tts}/utils.ts +19 -97
  78. package/src/tts/websocket.ts +210 -0
  79. package/src/types/index.ts +63 -0
  80. package/src/voices/index.ts +47 -0
  81. package/dist/audio/index.d.mts +0 -5
  82. package/dist/audio/index.d.ts +0 -5
  83. package/dist/audio/index.js +0 -396
  84. package/dist/audio/index.mjs +0 -9
  85. package/dist/audio/utils.d.mts +0 -5
  86. package/dist/audio/utils.d.ts +0 -5
  87. package/dist/chunk-3CYTAFLF.mjs +0 -262
  88. package/dist/chunk-FRIBQZPN.mjs +0 -113
  89. package/dist/chunk-XSFPHPPG.mjs +0 -18
  90. package/dist/index-DSBmfK9-.d.mts +0 -158
  91. package/dist/index-qwAyxV5I.d.ts +0 -158
  92. package/dist/lib/client.d.mts +0 -9
  93. package/dist/lib/client.mjs +0 -7
  94. package/dist/lib/constants.d.mts +0 -5
  95. package/dist/lib/constants.mjs +0 -10
  96. package/dist/lib/index.d.mts +0 -12
  97. package/dist/lib/index.mjs +0 -19
  98. package/dist/react/index.d.mts +0 -26
  99. package/dist/react/index.mjs +0 -130
  100. package/dist/types/index.d.mts +0 -6
  101. package/index.ts +0 -3
  102. package/src/audio/index.ts +0 -282
  103. /package/dist/{types/index.mjs → chunk-FXPGR372.js} +0 -0
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // src/lib/client.ts
48
+ var client_exports = {};
49
+ __export(client_exports, {
50
+ Client: () => Client
51
+ });
52
+ module.exports = __toCommonJS(client_exports);
53
+ var import_cross_fetch = __toESM(require("cross-fetch"), 1);
54
+
55
+ // src/lib/constants.ts
56
+ var BASE_URL = "https://api.cartesia.ai/v0";
57
+ var constructApiUrl = (baseUrl, path, protocol) => {
58
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
59
+ if (!protocol) {
60
+ return new URL(`${baseUrl}${normalizedPath}`);
61
+ }
62
+ if (!["http", "ws"].includes(protocol)) {
63
+ throw new Error(`Invalid protocol: ${protocol}`);
64
+ }
65
+ return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
66
+ };
67
+
68
+ // src/lib/client.ts
69
+ var Client = class {
70
+ constructor(options = {}) {
71
+ if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
72
+ throw new Error("Missing Cartesia API key.");
73
+ }
74
+ this.apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
75
+ this.baseUrl = options.baseUrl || BASE_URL;
76
+ }
77
+ fetch(path, options = {}) {
78
+ const url = constructApiUrl(this.baseUrl, path);
79
+ return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
80
+ headers: __spreadValues({
81
+ "X-API-KEY": this.apiKey
82
+ }, options.headers)
83
+ }));
84
+ }
85
+ };
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ Client
89
+ });
@@ -0,0 +1,11 @@
1
+ import { ClientOptions } from '../types/index.cjs';
2
+ import 'emittery';
3
+
4
+ declare class Client {
5
+ apiKey: string;
6
+ baseUrl: string;
7
+ constructor(options?: ClientOptions);
8
+ fetch(path: string, options?: RequestInit): Promise<Response>;
9
+ }
10
+
11
+ export { Client };
@@ -1,9 +1,11 @@
1
1
  import { ClientOptions } from '../types/index.js';
2
+ import 'emittery';
2
3
 
3
4
  declare class Client {
4
5
  apiKey: string;
5
6
  baseUrl: string;
6
7
  constructor(options?: ClientOptions);
8
+ fetch(path: string, options?: RequestInit): Promise<Response>;
7
9
  }
8
10
 
9
11
  export { Client };
@@ -1,43 +1,8 @@
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
-
20
- // src/lib/client.ts
21
- var client_exports = {};
22
- __export(client_exports, {
23
- Client: () => Client
24
- });
25
- module.exports = __toCommonJS(client_exports);
26
-
27
- // src/lib/constants.ts
28
- var BASE_URL = "https://api.cartesia.ai/v0";
29
-
30
- // src/lib/client.ts
31
- var Client = class {
32
- constructor(options = {}) {
33
- if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
34
- throw new Error("Missing Cartesia API key.");
35
- }
36
- this.apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
37
- this.baseUrl = options.baseUrl || BASE_URL;
38
- }
39
- };
40
- // Annotate the CommonJS export names for ESM import in node:
41
- 0 && (module.exports = {
1
+ import {
42
2
  Client
43
- });
3
+ } from "../chunk-BCQ63627.js";
4
+ import "../chunk-3GBZUGUD.js";
5
+ import "../chunk-WIFMLPT5.js";
6
+ export {
7
+ Client
8
+ };
@@ -0,0 +1,42 @@
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
+
20
+ // src/lib/constants.ts
21
+ var constants_exports = {};
22
+ __export(constants_exports, {
23
+ BASE_URL: () => BASE_URL,
24
+ constructApiUrl: () => constructApiUrl
25
+ });
26
+ module.exports = __toCommonJS(constants_exports);
27
+ var BASE_URL = "https://api.cartesia.ai/v0";
28
+ var constructApiUrl = (baseUrl, path, protocol) => {
29
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
30
+ if (!protocol) {
31
+ return new URL(`${baseUrl}${normalizedPath}`);
32
+ }
33
+ if (!["http", "ws"].includes(protocol)) {
34
+ throw new Error(`Invalid protocol: ${protocol}`);
35
+ }
36
+ return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ BASE_URL,
41
+ constructApiUrl
42
+ });
@@ -0,0 +1,4 @@
1
+ declare const BASE_URL = "https://api.cartesia.ai/v0";
2
+ declare const constructApiUrl: (baseUrl: string, path: string, protocol?: string) => URL;
3
+
4
+ export { BASE_URL, constructApiUrl };
@@ -1,5 +1,4 @@
1
1
  declare const BASE_URL = "https://api.cartesia.ai/v0";
2
- declare const SAMPLE_RATE = 44100;
3
- declare const constructWebsocketUrl: (baseUrl: string) => URL;
2
+ declare const constructApiUrl: (baseUrl: string, path: string, protocol?: string) => URL;
4
3
 
5
- export { BASE_URL, SAMPLE_RATE, constructWebsocketUrl };
4
+ export { BASE_URL, constructApiUrl };
@@ -1,38 +1,9 @@
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
-
20
- // src/lib/constants.ts
21
- var constants_exports = {};
22
- __export(constants_exports, {
23
- BASE_URL: () => BASE_URL,
24
- SAMPLE_RATE: () => SAMPLE_RATE,
25
- constructWebsocketUrl: () => constructWebsocketUrl
26
- });
27
- module.exports = __toCommonJS(constants_exports);
28
- var BASE_URL = "https://api.cartesia.ai/v0";
29
- var SAMPLE_RATE = 44100;
30
- var constructWebsocketUrl = (baseUrl) => {
31
- return new URL(`${baseUrl.replace(/^http/, "ws")}/audio/websocket`);
32
- };
33
- // Annotate the CommonJS export names for ESM import in node:
34
- 0 && (module.exports = {
1
+ import {
35
2
  BASE_URL,
36
- SAMPLE_RATE,
37
- constructWebsocketUrl
38
- });
3
+ constructApiUrl
4
+ } from "../chunk-3GBZUGUD.js";
5
+ import "../chunk-WIFMLPT5.js";
6
+ export {
7
+ BASE_URL,
8
+ constructApiUrl
9
+ };