@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,531 @@
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
+ var __accessCheck = (obj, member, msg) => {
47
+ if (!member.has(obj))
48
+ throw TypeError("Cannot " + msg);
49
+ };
50
+ var __privateGet = (obj, member, getter) => {
51
+ __accessCheck(obj, member, "read from private field");
52
+ return getter ? getter.call(obj) : member.get(obj);
53
+ };
54
+ var __privateAdd = (obj, member, value) => {
55
+ if (member.has(obj))
56
+ throw TypeError("Cannot add the same private member more than once");
57
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
58
+ };
59
+ var __privateSet = (obj, member, value, setter) => {
60
+ __accessCheck(obj, member, "write to private field");
61
+ setter ? setter.call(obj, value) : member.set(obj, value);
62
+ return value;
63
+ };
64
+ var __privateMethod = (obj, member, method) => {
65
+ __accessCheck(obj, member, "access private method");
66
+ return method;
67
+ };
68
+ var __async = (__this, __arguments, generator) => {
69
+ return new Promise((resolve, reject) => {
70
+ var fulfilled = (value) => {
71
+ try {
72
+ step(generator.next(value));
73
+ } catch (e) {
74
+ reject(e);
75
+ }
76
+ };
77
+ var rejected = (value) => {
78
+ try {
79
+ step(generator.throw(value));
80
+ } catch (e) {
81
+ reject(e);
82
+ }
83
+ };
84
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
85
+ step((generator = generator.apply(__this, __arguments)).next());
86
+ });
87
+ };
88
+
89
+ // src/lib/index.ts
90
+ var lib_exports = {};
91
+ __export(lib_exports, {
92
+ Cartesia: () => Cartesia
93
+ });
94
+ module.exports = __toCommonJS(lib_exports);
95
+
96
+ // src/lib/client.ts
97
+ var import_cross_fetch = __toESM(require("cross-fetch"), 1);
98
+
99
+ // src/lib/constants.ts
100
+ var BASE_URL = "https://api.cartesia.ai/v0";
101
+ var constructApiUrl = (baseUrl, path, protocol) => {
102
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
103
+ if (!protocol) {
104
+ return new URL(`${baseUrl}${normalizedPath}`);
105
+ }
106
+ if (!["http", "ws"].includes(protocol)) {
107
+ throw new Error(`Invalid protocol: ${protocol}`);
108
+ }
109
+ return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
110
+ };
111
+
112
+ // src/lib/client.ts
113
+ var Client = class {
114
+ constructor(options = {}) {
115
+ if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
116
+ throw new Error("Missing Cartesia API key.");
117
+ }
118
+ this.apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
119
+ this.baseUrl = options.baseUrl || BASE_URL;
120
+ }
121
+ fetch(path, options = {}) {
122
+ const url = constructApiUrl(this.baseUrl, path);
123
+ return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
124
+ headers: __spreadValues({
125
+ "X-API-KEY": this.apiKey
126
+ }, options.headers)
127
+ }));
128
+ }
129
+ };
130
+
131
+ // src/tts/websocket.ts
132
+ var import_emittery2 = __toESM(require("emittery"), 1);
133
+ var import_human_id = require("human-id");
134
+ var import_partysocket = require("partysocket");
135
+
136
+ // src/tts/source.ts
137
+ var import_emittery = __toESM(require("emittery"), 1);
138
+ var _emitter, _buffer, _readIndex, _closed, _sampleRate;
139
+ var Source = class {
140
+ /**
141
+ * Create a new Source.
142
+ *
143
+ * @param options - Options for the Source.
144
+ * @param options.sampleRate - The sample rate of the audio.
145
+ */
146
+ constructor({ sampleRate }) {
147
+ __privateAdd(this, _emitter, new import_emittery.default());
148
+ __privateAdd(this, _buffer, new Float32Array());
149
+ __privateAdd(this, _readIndex, 0);
150
+ __privateAdd(this, _closed, false);
151
+ __privateAdd(this, _sampleRate, void 0);
152
+ this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
153
+ this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
154
+ this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
155
+ this.off = __privateGet(this, _emitter).off.bind(__privateGet(this, _emitter));
156
+ __privateSet(this, _sampleRate, sampleRate);
157
+ }
158
+ get sampleRate() {
159
+ return __privateGet(this, _sampleRate);
160
+ }
161
+ /**
162
+ * Append audio to the buffer.
163
+ *
164
+ * @param src The audio to append.
165
+ */
166
+ enqueue(src) {
167
+ return __async(this, null, function* () {
168
+ __privateSet(this, _buffer, new Float32Array([...__privateGet(this, _buffer), ...src]));
169
+ yield __privateGet(this, _emitter).emit("enqueue");
170
+ });
171
+ }
172
+ /**
173
+ * Read audio from the buffer.
174
+ *
175
+ * @param dst The buffer to read the audio into.
176
+ * @returns The number of samples read. If the source is closed, this will be
177
+ * less than the length of the provided buffer.
178
+ */
179
+ read(dst) {
180
+ return __async(this, null, function* () {
181
+ const targetReadIndex = __privateGet(this, _readIndex) + dst.length;
182
+ while (!__privateGet(this, _closed) && targetReadIndex > __privateGet(this, _buffer).length) {
183
+ yield __privateGet(this, _emitter).emit("wait");
184
+ yield Promise.race([
185
+ __privateGet(this, _emitter).once("enqueue"),
186
+ __privateGet(this, _emitter).once("close")
187
+ ]);
188
+ yield __privateGet(this, _emitter).emit("read");
189
+ }
190
+ const read = Math.min(dst.length, __privateGet(this, _buffer).length - __privateGet(this, _readIndex));
191
+ dst.set(__privateGet(this, _buffer).slice(__privateGet(this, _readIndex), __privateGet(this, _readIndex) + read));
192
+ __privateSet(this, _readIndex, __privateGet(this, _readIndex) + read);
193
+ return read;
194
+ });
195
+ }
196
+ /**
197
+ * Get the number of samples in a given duration.
198
+ *
199
+ * @param durationSecs The duration in seconds.
200
+ * @returns The number of samples.
201
+ */
202
+ durationToSampleCount(durationSecs) {
203
+ return Math.trunc(durationSecs * __privateGet(this, _sampleRate));
204
+ }
205
+ get buffer() {
206
+ return __privateGet(this, _buffer);
207
+ }
208
+ get readIndex() {
209
+ return __privateGet(this, _readIndex);
210
+ }
211
+ /**
212
+ * Close the source. This signals that no more audio will be enqueued.
213
+ *
214
+ * This will emit a "close" event.
215
+ *
216
+ * @returns A promise that resolves when the source is closed.
217
+ */
218
+ close() {
219
+ return __async(this, null, function* () {
220
+ __privateSet(this, _closed, true);
221
+ yield __privateGet(this, _emitter).emit("close");
222
+ __privateGet(this, _emitter).clearListeners();
223
+ });
224
+ }
225
+ };
226
+ _emitter = new WeakMap();
227
+ _buffer = new WeakMap();
228
+ _readIndex = new WeakMap();
229
+ _closed = new WeakMap();
230
+ _sampleRate = new WeakMap();
231
+
232
+ // src/tts/utils.ts
233
+ var import_base64_js = __toESM(require("base64-js"), 1);
234
+ function base64ToArray(b64) {
235
+ return filterSentinel(b64).reduce((acc, b) => {
236
+ const floats = new Float32Array(import_base64_js.default.toByteArray(b).buffer);
237
+ const newAcc = new Float32Array(acc.length + floats.length);
238
+ newAcc.set(acc, 0);
239
+ newAcc.set(floats, acc.length);
240
+ return newAcc;
241
+ }, new Float32Array(0));
242
+ }
243
+ function createMessageHandlerForContextId(contextId, handler) {
244
+ return (event) => {
245
+ if (typeof event.data !== "string") {
246
+ return;
247
+ }
248
+ const message = JSON.parse(event.data);
249
+ if (message.context_id !== contextId) {
250
+ return;
251
+ }
252
+ let chunk;
253
+ if (message.done) {
254
+ chunk = getSentinel();
255
+ } else {
256
+ chunk = message.data;
257
+ }
258
+ handler({ chunk, message: event.data });
259
+ };
260
+ }
261
+ function getSentinel() {
262
+ return null;
263
+ }
264
+ function isSentinel(x) {
265
+ return x === getSentinel();
266
+ }
267
+ function filterSentinel(collection) {
268
+ return collection.filter(
269
+ (x) => !isSentinel(x)
270
+ );
271
+ }
272
+ function getEmitteryCallbacks(emitter) {
273
+ return {
274
+ on: emitter.on.bind(emitter),
275
+ off: emitter.off.bind(emitter),
276
+ once: emitter.once.bind(emitter),
277
+ events: emitter.events.bind(emitter)
278
+ };
279
+ }
280
+
281
+ // src/tts/websocket.ts
282
+ var _isConnected, _sampleRate2, _generateId, generateId_fn;
283
+ var WebSocket = class extends Client {
284
+ /**
285
+ * Create a new WebSocket client.
286
+ *
287
+ * @param args - Arguments to pass to the Client constructor.
288
+ */
289
+ constructor({ sampleRate }, ...args) {
290
+ super(...args);
291
+ /**
292
+ * Generate a unique ID suitable for a streaming context.
293
+ *
294
+ * Not suitable for security purposes or as a primary key, since
295
+ * it lacks the amount of entropy required for those use cases.
296
+ *
297
+ * @returns A unique ID.
298
+ */
299
+ __privateAdd(this, _generateId);
300
+ __privateAdd(this, _isConnected, false);
301
+ __privateAdd(this, _sampleRate2, void 0);
302
+ __privateSet(this, _sampleRate2, sampleRate);
303
+ }
304
+ /**
305
+ * Send a message over the WebSocket in order to start a stream.
306
+ *
307
+ * @param inputs - Stream options.
308
+ * @param options - Options for the stream.
309
+ * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
310
+ * If `0`, the stream will not time out.
311
+ * @returns A Source object that can be passed to a Player to play the audio.
312
+ */
313
+ send(inputs, { timeout = 0 } = {}) {
314
+ var _a, _b, _c, _d;
315
+ if (!__privateGet(this, _isConnected)) {
316
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
317
+ }
318
+ const contextId = __privateMethod(this, _generateId, generateId_fn).call(this);
319
+ (_a = this.socket) == null ? void 0 : _a.send(
320
+ JSON.stringify(__spreadProps(__spreadValues({
321
+ context_id: contextId
322
+ }, inputs), {
323
+ output_format: {
324
+ container: "raw",
325
+ encoding: "pcm_f32le",
326
+ sample_rate: __privateGet(this, _sampleRate2)
327
+ }
328
+ }))
329
+ );
330
+ const emitter = new import_emittery2.default();
331
+ const source = new Source({
332
+ sampleRate: __privateGet(this, _sampleRate2)
333
+ });
334
+ const streamCompleteController = new AbortController();
335
+ let timeoutId = null;
336
+ if (timeout > 0) {
337
+ timeoutId = setTimeout(streamCompleteController.abort, timeout);
338
+ }
339
+ const handleMessage = createMessageHandlerForContextId(
340
+ contextId,
341
+ (_0) => __async(this, [_0], function* ({ chunk, message }) {
342
+ emitter.emit("message", message);
343
+ if (isSentinel(chunk)) {
344
+ yield source.close();
345
+ streamCompleteController.abort();
346
+ return;
347
+ }
348
+ yield source.enqueue(base64ToArray([chunk]));
349
+ if (timeoutId) {
350
+ clearTimeout(timeoutId);
351
+ timeoutId = setTimeout(streamCompleteController.abort, timeout);
352
+ }
353
+ })
354
+ );
355
+ (_b = this.socket) == null ? void 0 : _b.addEventListener("message", handleMessage, {
356
+ signal: streamCompleteController.signal
357
+ });
358
+ (_c = this.socket) == null ? void 0 : _c.addEventListener(
359
+ "close",
360
+ () => {
361
+ streamCompleteController.abort();
362
+ },
363
+ {
364
+ once: true
365
+ }
366
+ );
367
+ (_d = this.socket) == null ? void 0 : _d.addEventListener(
368
+ "error",
369
+ () => {
370
+ streamCompleteController.abort();
371
+ },
372
+ {
373
+ once: true
374
+ }
375
+ );
376
+ streamCompleteController.signal.addEventListener("abort", () => {
377
+ source.close();
378
+ if (timeoutId) {
379
+ clearTimeout(timeoutId);
380
+ }
381
+ });
382
+ return __spreadValues({ source }, getEmitteryCallbacks(emitter));
383
+ }
384
+ /**
385
+ * Authenticate and connect to a Cartesia streaming WebSocket.
386
+ *
387
+ * @returns A promise that resolves when the WebSocket is connected.
388
+ * @throws {Error} If the WebSocket fails to connect.
389
+ */
390
+ connect() {
391
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", "ws");
392
+ url.searchParams.set("api_key", this.apiKey);
393
+ const emitter = new import_emittery2.default();
394
+ this.socket = new import_partysocket.WebSocket(url.toString());
395
+ this.socket.onopen = () => {
396
+ __privateSet(this, _isConnected, true);
397
+ emitter.emit("open");
398
+ };
399
+ this.socket.onclose = () => {
400
+ __privateSet(this, _isConnected, false);
401
+ emitter.emit("close");
402
+ };
403
+ return new Promise(
404
+ (resolve, reject) => {
405
+ var _a, _b, _c;
406
+ (_a = this.socket) == null ? void 0 : _a.addEventListener(
407
+ "open",
408
+ () => {
409
+ resolve(getEmitteryCallbacks(emitter));
410
+ },
411
+ {
412
+ once: true
413
+ }
414
+ );
415
+ const aborter = new AbortController();
416
+ (_b = this.socket) == null ? void 0 : _b.addEventListener(
417
+ "error",
418
+ () => {
419
+ aborter.abort();
420
+ reject(new Error("WebSocket failed to connect."));
421
+ },
422
+ {
423
+ signal: aborter.signal
424
+ }
425
+ );
426
+ (_c = this.socket) == null ? void 0 : _c.addEventListener(
427
+ "close",
428
+ () => {
429
+ aborter.abort();
430
+ reject(new Error("WebSocket closed before it could connect."));
431
+ },
432
+ {
433
+ signal: aborter.signal
434
+ }
435
+ );
436
+ }
437
+ );
438
+ }
439
+ /**
440
+ * Disconnect from the Cartesia streaming WebSocket.
441
+ */
442
+ disconnect() {
443
+ var _a;
444
+ (_a = this.socket) == null ? void 0 : _a.close();
445
+ }
446
+ };
447
+ _isConnected = new WeakMap();
448
+ _sampleRate2 = new WeakMap();
449
+ _generateId = new WeakSet();
450
+ generateId_fn = function() {
451
+ return (0, import_human_id.humanId)({
452
+ separator: "-",
453
+ capitalize: false
454
+ });
455
+ };
456
+
457
+ // src/tts/index.ts
458
+ var TTS = class extends Client {
459
+ /**
460
+ * Get a WebSocket client for streaming audio from the TTS API.
461
+ *
462
+ * @returns {WebSocket} A Cartesia WebSocket client.
463
+ */
464
+ websocket(options) {
465
+ return new WebSocket(options, {
466
+ apiKey: this.apiKey,
467
+ baseUrl: this.baseUrl
468
+ });
469
+ }
470
+ };
471
+
472
+ // src/voices/index.ts
473
+ var Voices = class extends Client {
474
+ list() {
475
+ return __async(this, null, function* () {
476
+ const response = yield this.fetch("/voices");
477
+ return response.json();
478
+ });
479
+ }
480
+ get(voiceId) {
481
+ return __async(this, null, function* () {
482
+ const response = yield this.fetch(`/voices/${voiceId}`);
483
+ return response.json();
484
+ });
485
+ }
486
+ create(voice) {
487
+ return __async(this, null, function* () {
488
+ const response = yield this.fetch("/voices", {
489
+ method: "POST",
490
+ body: JSON.stringify(voice)
491
+ });
492
+ return response.json();
493
+ });
494
+ }
495
+ clone(options) {
496
+ return __async(this, null, function* () {
497
+ if (options.mode === "url") {
498
+ const response = yield this.fetch(
499
+ `/voices/clone/url?link=${options.link}`,
500
+ {
501
+ method: "POST"
502
+ }
503
+ );
504
+ return response.json();
505
+ }
506
+ if (options.mode === "clip") {
507
+ const formData = new FormData();
508
+ formData.append("clip", options.clip);
509
+ const response = yield this.fetch("/voices/clone/clip", {
510
+ method: "POST",
511
+ body: formData
512
+ });
513
+ return response.json();
514
+ }
515
+ throw new Error("Invalid mode for clone()");
516
+ });
517
+ }
518
+ };
519
+
520
+ // src/lib/index.ts
521
+ var Cartesia = class extends Client {
522
+ constructor(options = {}) {
523
+ super(options);
524
+ this.tts = new TTS(options);
525
+ this.voices = new Voices(options);
526
+ }
527
+ };
528
+ // Annotate the CommonJS export names for ESM import in node:
529
+ 0 && (module.exports = {
530
+ Cartesia
531
+ });
@@ -0,0 +1,16 @@
1
+ import TTS from '../tts/index.cjs';
2
+ import { ClientOptions } from '../types/index.cjs';
3
+ import Voices from '../voices/index.cjs';
4
+ import { Client } from './client.cjs';
5
+ import '../tts/websocket.cjs';
6
+ import 'emittery';
7
+ import 'partysocket';
8
+ import '../tts/source.cjs';
9
+
10
+ declare class Cartesia extends Client {
11
+ tts: TTS;
12
+ voices: Voices;
13
+ constructor(options?: ClientOptions);
14
+ }
15
+
16
+ export { Cartesia };
@@ -1,11 +1,15 @@
1
- import { e as export_default } from '../index-qwAyxV5I.js';
1
+ import TTS from '../tts/index.js';
2
2
  import { ClientOptions } from '../types/index.js';
3
+ import Voices from '../voices/index.js';
3
4
  import { Client } from './client.js';
5
+ import '../tts/websocket.js';
4
6
  import 'emittery';
5
7
  import 'partysocket';
8
+ import '../tts/source.js';
6
9
 
7
10
  declare class Cartesia extends Client {
8
- audio: export_default;
11
+ tts: TTS;
12
+ voices: Voices;
9
13
  constructor(options?: ClientOptions);
10
14
  }
11
15