@cartesia/cartesia-js 0.0.4-alpha.0 → 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 (87) hide show
  1. package/.turbo/turbo-build.log +64 -46
  2. package/CHANGELOG.md +6 -0
  3. package/README.md +123 -16
  4. package/dist/{chunk-XPIMIAAE.js → chunk-3FL2SNIR.js} +1 -1
  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-R4P7LWVZ.js → chunk-WIFMLPT5.js} +31 -6
  14. package/dist/chunk-X7SJMF2R.js +22 -0
  15. package/dist/index.cjs +391 -158
  16. package/dist/index.d.cts +7 -3
  17. package/dist/index.d.ts +7 -3
  18. package/dist/index.js +13 -6
  19. package/dist/lib/client.cjs +46 -0
  20. package/dist/lib/client.d.cts +2 -0
  21. package/dist/lib/client.d.ts +2 -0
  22. package/dist/lib/client.js +3 -3
  23. package/dist/lib/constants.cjs +11 -7
  24. package/dist/lib/constants.d.cts +2 -3
  25. package/dist/lib/constants.d.ts +2 -3
  26. package/dist/lib/constants.js +4 -6
  27. package/dist/lib/index.cjs +276 -163
  28. package/dist/lib/index.d.cts +6 -2
  29. package/dist/lib/index.d.ts +6 -2
  30. package/dist/lib/index.js +9 -6
  31. package/dist/react/index.cjs +524 -275
  32. package/dist/react/index.d.cts +20 -14
  33. package/dist/react/index.d.ts +20 -14
  34. package/dist/react/index.js +142 -98
  35. package/dist/react/utils.js +2 -2
  36. package/dist/tts/index.cjs +470 -0
  37. package/dist/tts/index.d.cts +17 -0
  38. package/dist/tts/index.d.ts +17 -0
  39. package/dist/tts/index.js +12 -0
  40. package/dist/tts/player.cjs +198 -0
  41. package/dist/tts/player.d.cts +43 -0
  42. package/dist/tts/player.d.ts +43 -0
  43. package/dist/tts/player.js +8 -0
  44. package/dist/tts/source.cjs +167 -0
  45. package/dist/tts/source.d.cts +53 -0
  46. package/dist/tts/source.d.ts +53 -0
  47. package/dist/tts/source.js +7 -0
  48. package/dist/{audio → tts}/utils.cjs +12 -53
  49. package/dist/tts/utils.d.cts +67 -0
  50. package/dist/tts/utils.d.ts +67 -0
  51. package/dist/{audio → tts}/utils.js +2 -7
  52. package/dist/{audio/index.cjs → tts/websocket.cjs} +213 -164
  53. package/dist/tts/websocket.d.cts +53 -0
  54. package/dist/tts/websocket.d.ts +53 -0
  55. package/dist/tts/websocket.js +11 -0
  56. package/dist/types/index.d.cts +50 -1
  57. package/dist/types/index.d.ts +50 -1
  58. package/dist/voices/index.cjs +155 -0
  59. package/dist/voices/index.d.cts +12 -0
  60. package/dist/voices/index.d.ts +12 -0
  61. package/dist/voices/index.js +9 -0
  62. package/package.json +2 -1
  63. package/src/index.ts +1 -0
  64. package/src/lib/client.ts +14 -1
  65. package/src/lib/constants.ts +13 -3
  66. package/src/lib/index.ts +6 -3
  67. package/src/react/index.ts +157 -103
  68. package/src/tts/index.ts +17 -0
  69. package/src/tts/player.ts +109 -0
  70. package/src/tts/source.ts +98 -0
  71. package/src/{audio → tts}/utils.ts +19 -97
  72. package/src/tts/websocket.ts +210 -0
  73. package/src/types/index.ts +63 -0
  74. package/src/voices/index.ts +47 -0
  75. package/dist/audio/index.d.cts +0 -5
  76. package/dist/audio/index.d.ts +0 -5
  77. package/dist/audio/index.js +0 -10
  78. package/dist/audio/utils.d.cts +0 -5
  79. package/dist/audio/utils.d.ts +0 -5
  80. package/dist/chunk-4MHF74A7.js +0 -272
  81. package/dist/chunk-5TSWLYOW.js +0 -113
  82. package/dist/chunk-MJIFZWHS.js +0 -18
  83. package/dist/chunk-OVI3W3GG.js +0 -12
  84. package/dist/chunk-S6A27RQL.js +0 -18
  85. package/dist/index-C2_3XFxn.d.cts +0 -163
  86. package/dist/index-DgwnZezj.d.ts +0 -163
  87. package/src/audio/index.ts +0 -297
package/dist/index.d.cts CHANGED
@@ -1,6 +1,10 @@
1
1
  export { Cartesia, Cartesia as default } from './lib/index.cjs';
2
- export { ClientOptions } from './types/index.cjs';
3
- import './index-C2_3XFxn.cjs';
2
+ export { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Sentinel, SourceEventData, StreamRequest, Voice, WebSocketOptions } from './types/index.cjs';
3
+ export { default as WebPlayer } from './tts/player.cjs';
4
+ import './tts/index.cjs';
5
+ import './lib/client.cjs';
6
+ import './tts/websocket.cjs';
4
7
  import 'emittery';
5
8
  import 'partysocket';
6
- import './lib/client.cjs';
9
+ import './tts/source.cjs';
10
+ import './voices/index.cjs';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  export { Cartesia, Cartesia as default } from './lib/index.js';
2
- export { ClientOptions } from './types/index.js';
3
- import './index-DgwnZezj.js';
2
+ export { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Sentinel, SourceEventData, StreamRequest, Voice, WebSocketOptions } from './types/index.js';
3
+ export { default as WebPlayer } from './tts/player.js';
4
+ import './tts/index.js';
5
+ import './lib/client.js';
6
+ import './tts/websocket.js';
4
7
  import 'emittery';
5
8
  import 'partysocket';
6
- import './lib/client.js';
9
+ import './tts/source.js';
10
+ import './voices/index.js';
package/dist/index.js CHANGED
@@ -1,13 +1,20 @@
1
1
  import "./chunk-FXPGR372.js";
2
2
  import {
3
3
  Cartesia
4
- } from "./chunk-S6A27RQL.js";
5
- import "./chunk-4MHF74A7.js";
6
- import "./chunk-5TSWLYOW.js";
7
- import "./chunk-MJIFZWHS.js";
8
- import "./chunk-OVI3W3GG.js";
9
- import "./chunk-R4P7LWVZ.js";
4
+ } from "./chunk-X7SJMF2R.js";
5
+ import "./chunk-WBK6LLXX.js";
6
+ import "./chunk-4RMSIQLG.js";
7
+ import "./chunk-NDNN326Q.js";
8
+ import "./chunk-JOHSCOLW.js";
9
+ import "./chunk-BCQ63627.js";
10
+ import "./chunk-3GBZUGUD.js";
11
+ import {
12
+ Player
13
+ } from "./chunk-WE63M7PJ.js";
14
+ import "./chunk-LYPTISWL.js";
15
+ import "./chunk-WIFMLPT5.js";
10
16
  export {
11
17
  Cartesia,
18
+ Player as WebPlayer,
12
19
  Cartesia as default
13
20
  };
@@ -1,8 +1,27 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
3
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
5
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));
6
25
  var __export = (target, all) => {
7
26
  for (var name in all)
8
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,6 +34,14 @@ var __copyProps = (to, from, except, desc) => {
15
34
  }
16
35
  return to;
17
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
+ ));
18
45
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
46
 
20
47
  // src/lib/client.ts
@@ -23,9 +50,20 @@ __export(client_exports, {
23
50
  Client: () => Client
24
51
  });
25
52
  module.exports = __toCommonJS(client_exports);
53
+ var import_cross_fetch = __toESM(require("cross-fetch"), 1);
26
54
 
27
55
  // src/lib/constants.ts
28
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
+ };
29
67
 
30
68
  // src/lib/client.ts
31
69
  var Client = class {
@@ -36,6 +74,14 @@ var Client = class {
36
74
  this.apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
37
75
  this.baseUrl = options.baseUrl || BASE_URL;
38
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
+ }
39
85
  };
40
86
  // Annotate the CommonJS export names for ESM import in node:
41
87
  0 && (module.exports = {
@@ -1,9 +1,11 @@
1
1
  import { ClientOptions } from '../types/index.cjs';
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,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,8 +1,8 @@
1
1
  import {
2
2
  Client
3
- } from "../chunk-MJIFZWHS.js";
4
- import "../chunk-OVI3W3GG.js";
5
- import "../chunk-R4P7LWVZ.js";
3
+ } from "../chunk-BCQ63627.js";
4
+ import "../chunk-3GBZUGUD.js";
5
+ import "../chunk-WIFMLPT5.js";
6
6
  export {
7
7
  Client
8
8
  };
@@ -21,18 +21,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var constants_exports = {};
22
22
  __export(constants_exports, {
23
23
  BASE_URL: () => BASE_URL,
24
- SAMPLE_RATE: () => SAMPLE_RATE,
25
- constructWebsocketUrl: () => constructWebsocketUrl
24
+ constructApiUrl: () => constructApiUrl
26
25
  });
27
26
  module.exports = __toCommonJS(constants_exports);
28
27
  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`);
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}`);
32
37
  };
33
38
  // Annotate the CommonJS export names for ESM import in node:
34
39
  0 && (module.exports = {
35
40
  BASE_URL,
36
- SAMPLE_RATE,
37
- constructWebsocketUrl
41
+ constructApiUrl
38
42
  });
@@ -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,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,11 +1,9 @@
1
1
  import {
2
2
  BASE_URL,
3
- SAMPLE_RATE,
4
- constructWebsocketUrl
5
- } from "../chunk-OVI3W3GG.js";
6
- import "../chunk-R4P7LWVZ.js";
3
+ constructApiUrl
4
+ } from "../chunk-3GBZUGUD.js";
5
+ import "../chunk-WIFMLPT5.js";
7
6
  export {
8
7
  BASE_URL,
9
- SAMPLE_RATE,
10
- constructWebsocketUrl
8
+ constructApiUrl
11
9
  };