@cartesia/cartesia-js 1.0.0 → 1.0.2
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/.turbo/turbo-build.log +50 -50
- package/CHANGELOG.md +12 -0
- package/LICENSE.md +21 -0
- package/README.md +92 -19
- package/dist/{chunk-PQ6CIPFW.js → chunk-6YQ6KDIQ.js} +44 -5
- package/dist/{chunk-RO7TY474.js → chunk-BHY7MNGT.js} +11 -6
- package/dist/{chunk-F4QWVJY3.js → chunk-EDAAHENY.js} +2 -2
- package/dist/{chunk-WIFMLPT5.js → chunk-GHY2WEOK.js} +13 -0
- package/dist/{chunk-FN7BK4PS.js → chunk-IZBPLCGW.js} +97 -75
- package/dist/{chunk-JYLAM6VU.js → chunk-LZO6K34D.js} +2 -2
- package/dist/{chunk-3FL2SNIR.js → chunk-NQVZNVOU.js} +1 -1
- package/dist/{chunk-IEN4NCER.js → chunk-NVOCUUOF.js} +3 -3
- package/dist/chunk-PISCPZK4.js +40 -0
- package/dist/{chunk-SGXUEFII.js → chunk-UCYL2SOX.js} +18 -15
- package/dist/index.cjs +186 -103
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +15 -9
- package/dist/lib/client.cjs +35 -10
- package/dist/lib/client.d.cts +2 -2
- package/dist/lib/client.d.ts +2 -2
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +181 -102
- package/dist/lib/index.js +8 -8
- package/dist/react/index.cjs +286 -158
- package/dist/react/index.d.cts +5 -4
- package/dist/react/index.d.ts +5 -4
- package/dist/react/index.js +115 -66
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +165 -89
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.cjs +5 -0
- package/dist/tts/player.js +4 -3
- package/dist/tts/source.cjs +50 -4
- package/dist/tts/source.d.cts +16 -6
- package/dist/tts/source.d.ts +16 -6
- package/dist/tts/source.js +4 -2
- package/dist/tts/utils.cjs +18 -6
- package/dist/tts/utils.d.cts +7 -5
- package/dist/tts/utils.d.ts +7 -5
- package/dist/tts/utils.js +3 -2
- package/dist/tts/websocket.cjs +165 -89
- package/dist/tts/websocket.d.cts +12 -8
- package/dist/tts/websocket.d.ts +12 -8
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +65 -5
- package/dist/types/index.d.ts +65 -5
- package/dist/voices/index.cjs +31 -23
- package/dist/voices/index.d.cts +2 -1
- package/dist/voices/index.d.ts +2 -1
- package/dist/voices/index.js +3 -3
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/lib/client.ts +10 -10
- package/src/react/index.ts +115 -64
- package/src/tts/source.ts +53 -7
- package/src/tts/utils.ts +26 -12
- package/src/tts/websocket.ts +42 -23
- package/src/types/index.ts +89 -4
- package/src/voices/index.ts +22 -15
- package/dist/chunk-PQ5EVEEH.js +0 -34
package/dist/lib/index.cjs
CHANGED
|
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
25
37
|
var __export = (target, all) => {
|
|
26
38
|
for (var name in all)
|
|
27
39
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -110,20 +122,25 @@ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
|
|
|
110
122
|
// src/lib/client.ts
|
|
111
123
|
var Client = class {
|
|
112
124
|
constructor(options = {}) {
|
|
113
|
-
|
|
125
|
+
const apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
|
|
126
|
+
if (!apiKey) {
|
|
114
127
|
throw new Error("Missing Cartesia API key.");
|
|
115
128
|
}
|
|
116
|
-
this.apiKey =
|
|
129
|
+
this.apiKey = typeof apiKey === "function" ? apiKey : () => __async(this, null, function* () {
|
|
130
|
+
return apiKey;
|
|
131
|
+
});
|
|
117
132
|
this.baseUrl = options.baseUrl || BASE_URL;
|
|
118
133
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
headers
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}, options
|
|
126
|
-
|
|
134
|
+
_fetch(_0) {
|
|
135
|
+
return __async(this, arguments, function* (path, options = {}) {
|
|
136
|
+
const url = constructApiUrl(this.baseUrl, path);
|
|
137
|
+
const headers = new Headers(options.headers);
|
|
138
|
+
headers.set("X-API-Key", yield this.apiKey());
|
|
139
|
+
headers.set("Cartesia-Version", CARTESIA_VERSION);
|
|
140
|
+
return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
|
|
141
|
+
headers
|
|
142
|
+
}));
|
|
143
|
+
});
|
|
127
144
|
}
|
|
128
145
|
};
|
|
129
146
|
|
|
@@ -134,7 +151,13 @@ var import_partysocket = require("partysocket");
|
|
|
134
151
|
|
|
135
152
|
// src/tts/source.ts
|
|
136
153
|
var import_emittery = __toESM(require("emittery"), 1);
|
|
137
|
-
var
|
|
154
|
+
var ENCODING_MAP = {
|
|
155
|
+
pcm_f32le: { arrayType: Float32Array, bytesPerElement: 4 },
|
|
156
|
+
pcm_s16le: { arrayType: Int16Array, bytesPerElement: 2 },
|
|
157
|
+
pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
|
|
158
|
+
pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
|
|
159
|
+
};
|
|
160
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _createBuffer, createBuffer_fn;
|
|
138
161
|
var Source = class {
|
|
139
162
|
/**
|
|
140
163
|
* Create a new Source.
|
|
@@ -142,23 +165,44 @@ var Source = class {
|
|
|
142
165
|
* @param options - Options for the Source.
|
|
143
166
|
* @param options.sampleRate - The sample rate of the audio.
|
|
144
167
|
*/
|
|
145
|
-
constructor({
|
|
168
|
+
constructor({
|
|
169
|
+
sampleRate,
|
|
170
|
+
encoding,
|
|
171
|
+
container
|
|
172
|
+
}) {
|
|
173
|
+
/**
|
|
174
|
+
* Create a new buffer for the source.
|
|
175
|
+
*
|
|
176
|
+
* @param size - The size of the buffer to create.
|
|
177
|
+
* @returns The new buffer as a TypedArray based on the encoding.
|
|
178
|
+
*/
|
|
179
|
+
__privateAdd(this, _createBuffer);
|
|
146
180
|
__privateAdd(this, _emitter, new import_emittery.default());
|
|
147
181
|
__privateAdd(this, _buffer, void 0);
|
|
148
182
|
__privateAdd(this, _readIndex, 0);
|
|
149
183
|
__privateAdd(this, _writeIndex, 0);
|
|
150
184
|
__privateAdd(this, _closed, false);
|
|
151
185
|
__privateAdd(this, _sampleRate, void 0);
|
|
186
|
+
__privateAdd(this, _encoding, void 0);
|
|
187
|
+
__privateAdd(this, _container, void 0);
|
|
152
188
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
153
189
|
this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
|
|
154
190
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
155
191
|
this.off = __privateGet(this, _emitter).off.bind(__privateGet(this, _emitter));
|
|
156
192
|
__privateSet(this, _sampleRate, sampleRate);
|
|
157
|
-
__privateSet(this,
|
|
193
|
+
__privateSet(this, _encoding, encoding);
|
|
194
|
+
__privateSet(this, _container, container);
|
|
195
|
+
__privateSet(this, _buffer, __privateMethod(this, _createBuffer, createBuffer_fn).call(this, 1024));
|
|
158
196
|
}
|
|
159
197
|
get sampleRate() {
|
|
160
198
|
return __privateGet(this, _sampleRate);
|
|
161
199
|
}
|
|
200
|
+
get encoding() {
|
|
201
|
+
return __privateGet(this, _encoding);
|
|
202
|
+
}
|
|
203
|
+
get container() {
|
|
204
|
+
return __privateGet(this, _container);
|
|
205
|
+
}
|
|
162
206
|
/**
|
|
163
207
|
* Append audio to the buffer.
|
|
164
208
|
*
|
|
@@ -172,7 +216,7 @@ var Source = class {
|
|
|
172
216
|
while (newCapacity < requiredCapacity) {
|
|
173
217
|
newCapacity *= 2;
|
|
174
218
|
}
|
|
175
|
-
const newBuffer =
|
|
219
|
+
const newBuffer = __privateMethod(this, _createBuffer, createBuffer_fn).call(this, newCapacity);
|
|
176
220
|
newBuffer.set(__privateGet(this, _buffer));
|
|
177
221
|
__privateSet(this, _buffer, newBuffer);
|
|
178
222
|
}
|
|
@@ -220,6 +264,9 @@ var Source = class {
|
|
|
220
264
|
get readIndex() {
|
|
221
265
|
return __privateGet(this, _readIndex);
|
|
222
266
|
}
|
|
267
|
+
get writeIndex() {
|
|
268
|
+
return __privateGet(this, _writeIndex);
|
|
269
|
+
}
|
|
223
270
|
/**
|
|
224
271
|
* Close the source. This signals that no more audio will be enqueued.
|
|
225
272
|
*
|
|
@@ -241,19 +288,27 @@ _readIndex = new WeakMap();
|
|
|
241
288
|
_writeIndex = new WeakMap();
|
|
242
289
|
_closed = new WeakMap();
|
|
243
290
|
_sampleRate = new WeakMap();
|
|
291
|
+
_encoding = new WeakMap();
|
|
292
|
+
_container = new WeakMap();
|
|
293
|
+
_createBuffer = new WeakSet();
|
|
294
|
+
createBuffer_fn = function(size) {
|
|
295
|
+
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
296
|
+
return new ArrayType(size);
|
|
297
|
+
};
|
|
244
298
|
|
|
245
299
|
// src/tts/utils.ts
|
|
246
300
|
var import_base64_js = __toESM(require("base64-js"), 1);
|
|
247
|
-
function base64ToArray(b64) {
|
|
301
|
+
function base64ToArray(b64, encoding) {
|
|
248
302
|
const byteArrays = filterSentinel(b64).map((b) => import_base64_js.default.toByteArray(b));
|
|
303
|
+
const { arrayType: ArrayType, bytesPerElement } = ENCODING_MAP[encoding];
|
|
249
304
|
const totalLength = byteArrays.reduce(
|
|
250
|
-
(acc, arr) => acc + arr.length /
|
|
305
|
+
(acc, arr) => acc + arr.length / bytesPerElement,
|
|
251
306
|
0
|
|
252
307
|
);
|
|
253
|
-
const result = new
|
|
308
|
+
const result = new ArrayType(totalLength);
|
|
254
309
|
let offset = 0;
|
|
255
310
|
for (const arr of byteArrays) {
|
|
256
|
-
const floats = new
|
|
311
|
+
const floats = new ArrayType(arr.buffer);
|
|
257
312
|
result.set(floats, offset);
|
|
258
313
|
offset += floats.length;
|
|
259
314
|
}
|
|
@@ -271,10 +326,10 @@ function createMessageHandlerForContextId(contextId, handler) {
|
|
|
271
326
|
let chunk;
|
|
272
327
|
if (message.done) {
|
|
273
328
|
chunk = getSentinel();
|
|
274
|
-
} else {
|
|
329
|
+
} else if (message.type === "chunk") {
|
|
275
330
|
chunk = message.data;
|
|
276
331
|
}
|
|
277
|
-
handler({ chunk, message: event.data });
|
|
332
|
+
handler({ chunk, message: event.data, data: message });
|
|
278
333
|
};
|
|
279
334
|
}
|
|
280
335
|
function getSentinel() {
|
|
@@ -298,14 +353,14 @@ function getEmitteryCallbacks(emitter) {
|
|
|
298
353
|
}
|
|
299
354
|
|
|
300
355
|
// src/tts/websocket.ts
|
|
301
|
-
var _isConnected, _sampleRate2, _generateId, generateId_fn;
|
|
356
|
+
var _isConnected, _sampleRate2, _container2, _encoding2, _generateId, generateId_fn;
|
|
302
357
|
var WebSocket = class extends Client {
|
|
303
358
|
/**
|
|
304
359
|
* Create a new WebSocket client.
|
|
305
360
|
*
|
|
306
361
|
* @param args - Arguments to pass to the Client constructor.
|
|
307
362
|
*/
|
|
308
|
-
constructor({ sampleRate }, ...args) {
|
|
363
|
+
constructor({ sampleRate, container, encoding }, ...args) {
|
|
309
364
|
super(...args);
|
|
310
365
|
/**
|
|
311
366
|
* Generate a unique ID suitable for a streaming context.
|
|
@@ -318,12 +373,16 @@ var WebSocket = class extends Client {
|
|
|
318
373
|
__privateAdd(this, _generateId);
|
|
319
374
|
__privateAdd(this, _isConnected, false);
|
|
320
375
|
__privateAdd(this, _sampleRate2, void 0);
|
|
376
|
+
__privateAdd(this, _container2, void 0);
|
|
377
|
+
__privateAdd(this, _encoding2, void 0);
|
|
321
378
|
__privateSet(this, _sampleRate2, sampleRate);
|
|
379
|
+
__privateSet(this, _container2, container != null ? container : "raw");
|
|
380
|
+
__privateSet(this, _encoding2, encoding != null ? encoding : "pcm_f32le");
|
|
322
381
|
}
|
|
323
382
|
/**
|
|
324
383
|
* Send a message over the WebSocket to start a stream.
|
|
325
384
|
*
|
|
326
|
-
* @param inputs - Stream options.
|
|
385
|
+
* @param inputs - Stream options. Defined in the StreamRequest type.
|
|
327
386
|
* @param options - Options for the stream.
|
|
328
387
|
* @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
|
|
329
388
|
* If set to `0`, the stream will not time out.
|
|
@@ -331,26 +390,30 @@ var WebSocket = class extends Client {
|
|
|
331
390
|
* @returns An Emittery instance that emits messages from the WebSocket.
|
|
332
391
|
* @returns An abort function that can be called to cancel the stream.
|
|
333
392
|
*/
|
|
334
|
-
send(
|
|
335
|
-
var
|
|
393
|
+
send(_a, { timeout = 0 } = {}) {
|
|
394
|
+
var inputs = __objRest(_a, []);
|
|
395
|
+
var _a2, _b, _c, _d;
|
|
336
396
|
if (!__privateGet(this, _isConnected)) {
|
|
337
397
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
338
398
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
399
|
+
if (!inputs.context_id) {
|
|
400
|
+
inputs.context_id = __privateMethod(this, _generateId, generateId_fn).call(this);
|
|
401
|
+
}
|
|
402
|
+
if (!inputs.output_format) {
|
|
403
|
+
inputs.output_format = {
|
|
404
|
+
container: __privateGet(this, _container2),
|
|
405
|
+
encoding: __privateGet(this, _encoding2),
|
|
406
|
+
sample_rate: __privateGet(this, _sampleRate2)
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
(_a2 = this.socket) == null ? void 0 : _a2.send(
|
|
410
|
+
JSON.stringify(__spreadValues({}, inputs))
|
|
350
411
|
);
|
|
351
412
|
const emitter = new import_emittery2.default();
|
|
352
413
|
const source = new Source({
|
|
353
|
-
sampleRate: __privateGet(this, _sampleRate2)
|
|
414
|
+
sampleRate: __privateGet(this, _sampleRate2),
|
|
415
|
+
encoding: __privateGet(this, _encoding2),
|
|
416
|
+
container: __privateGet(this, _container2)
|
|
354
417
|
});
|
|
355
418
|
const streamCompleteController = new AbortController();
|
|
356
419
|
let timeoutId = null;
|
|
@@ -358,19 +421,26 @@ var WebSocket = class extends Client {
|
|
|
358
421
|
timeoutId = setTimeout(streamCompleteController.abort, timeout);
|
|
359
422
|
}
|
|
360
423
|
const handleMessage = createMessageHandlerForContextId(
|
|
361
|
-
|
|
362
|
-
(_0) => __async(this, [_0], function* ({ chunk, message }) {
|
|
424
|
+
inputs.context_id,
|
|
425
|
+
(_0) => __async(this, [_0], function* ({ chunk, message, data }) {
|
|
363
426
|
emitter.emit("message", message);
|
|
427
|
+
if (data.type === "timestamps") {
|
|
428
|
+
emitter.emit("timestamps", data.word_timestamps);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
364
431
|
if (isSentinel(chunk)) {
|
|
365
432
|
yield source.close();
|
|
366
433
|
streamCompleteController.abort();
|
|
367
434
|
return;
|
|
368
435
|
}
|
|
369
|
-
yield source.enqueue(base64ToArray([chunk]));
|
|
370
436
|
if (timeoutId) {
|
|
371
437
|
clearTimeout(timeoutId);
|
|
372
438
|
timeoutId = setTimeout(streamCompleteController.abort, timeout);
|
|
373
439
|
}
|
|
440
|
+
if (!chunk) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
yield source.enqueue(base64ToArray([chunk], __privateGet(this, _encoding2)));
|
|
374
444
|
})
|
|
375
445
|
);
|
|
376
446
|
(_b = this.socket) == null ? void 0 : _b.addEventListener("message", handleMessage, {
|
|
@@ -413,56 +483,60 @@ var WebSocket = class extends Client {
|
|
|
413
483
|
* @throws {Error} If the WebSocket fails to connect.
|
|
414
484
|
*/
|
|
415
485
|
connect() {
|
|
416
|
-
|
|
417
|
-
|
|
486
|
+
return __async(this, null, function* () {
|
|
487
|
+
const emitter = new import_emittery2.default();
|
|
488
|
+
this.socket = new import_partysocket.WebSocket(() => __async(this, null, function* () {
|
|
489
|
+
const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
|
|
490
|
+
websocket: true
|
|
491
|
+
});
|
|
492
|
+
url.searchParams.set("api_key", yield this.apiKey());
|
|
493
|
+
url.searchParams.set("cartesia_version", CARTESIA_VERSION);
|
|
494
|
+
return url.toString();
|
|
495
|
+
}));
|
|
496
|
+
this.socket.onopen = () => {
|
|
497
|
+
__privateSet(this, _isConnected, true);
|
|
498
|
+
emitter.emit("open");
|
|
499
|
+
};
|
|
500
|
+
this.socket.onclose = () => {
|
|
501
|
+
__privateSet(this, _isConnected, false);
|
|
502
|
+
emitter.emit("close");
|
|
503
|
+
};
|
|
504
|
+
return new Promise(
|
|
505
|
+
(resolve, reject) => {
|
|
506
|
+
var _a, _b, _c;
|
|
507
|
+
(_a = this.socket) == null ? void 0 : _a.addEventListener(
|
|
508
|
+
"open",
|
|
509
|
+
() => {
|
|
510
|
+
resolve(getEmitteryCallbacks(emitter));
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
once: true
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
const aborter = new AbortController();
|
|
517
|
+
(_b = this.socket) == null ? void 0 : _b.addEventListener(
|
|
518
|
+
"error",
|
|
519
|
+
() => {
|
|
520
|
+
aborter.abort();
|
|
521
|
+
reject(new Error("WebSocket failed to connect."));
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
signal: aborter.signal
|
|
525
|
+
}
|
|
526
|
+
);
|
|
527
|
+
(_c = this.socket) == null ? void 0 : _c.addEventListener(
|
|
528
|
+
"close",
|
|
529
|
+
() => {
|
|
530
|
+
aborter.abort();
|
|
531
|
+
reject(new Error("WebSocket closed before it could connect."));
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
signal: aborter.signal
|
|
535
|
+
}
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
);
|
|
418
539
|
});
|
|
419
|
-
url.searchParams.set("api_key", this.apiKey);
|
|
420
|
-
url.searchParams.set("cartesia_version", CARTESIA_VERSION);
|
|
421
|
-
const emitter = new import_emittery2.default();
|
|
422
|
-
this.socket = new import_partysocket.WebSocket(url.toString());
|
|
423
|
-
this.socket.onopen = () => {
|
|
424
|
-
__privateSet(this, _isConnected, true);
|
|
425
|
-
emitter.emit("open");
|
|
426
|
-
};
|
|
427
|
-
this.socket.onclose = () => {
|
|
428
|
-
__privateSet(this, _isConnected, false);
|
|
429
|
-
emitter.emit("close");
|
|
430
|
-
};
|
|
431
|
-
return new Promise(
|
|
432
|
-
(resolve, reject) => {
|
|
433
|
-
var _a, _b, _c;
|
|
434
|
-
(_a = this.socket) == null ? void 0 : _a.addEventListener(
|
|
435
|
-
"open",
|
|
436
|
-
() => {
|
|
437
|
-
resolve(getEmitteryCallbacks(emitter));
|
|
438
|
-
},
|
|
439
|
-
{
|
|
440
|
-
once: true
|
|
441
|
-
}
|
|
442
|
-
);
|
|
443
|
-
const aborter = new AbortController();
|
|
444
|
-
(_b = this.socket) == null ? void 0 : _b.addEventListener(
|
|
445
|
-
"error",
|
|
446
|
-
() => {
|
|
447
|
-
aborter.abort();
|
|
448
|
-
reject(new Error("WebSocket failed to connect."));
|
|
449
|
-
},
|
|
450
|
-
{
|
|
451
|
-
signal: aborter.signal
|
|
452
|
-
}
|
|
453
|
-
);
|
|
454
|
-
(_c = this.socket) == null ? void 0 : _c.addEventListener(
|
|
455
|
-
"close",
|
|
456
|
-
() => {
|
|
457
|
-
aborter.abort();
|
|
458
|
-
reject(new Error("WebSocket closed before it could connect."));
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
signal: aborter.signal
|
|
462
|
-
}
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
);
|
|
466
540
|
}
|
|
467
541
|
/**
|
|
468
542
|
* Disconnect from the Cartesia streaming WebSocket.
|
|
@@ -474,6 +548,8 @@ var WebSocket = class extends Client {
|
|
|
474
548
|
};
|
|
475
549
|
_isConnected = new WeakMap();
|
|
476
550
|
_sampleRate2 = new WeakMap();
|
|
551
|
+
_container2 = new WeakMap();
|
|
552
|
+
_encoding2 = new WeakMap();
|
|
477
553
|
_generateId = new WeakSet();
|
|
478
554
|
generateId_fn = function() {
|
|
479
555
|
return (0, import_human_id.humanId)({
|
|
@@ -501,40 +577,43 @@ var TTS = class extends Client {
|
|
|
501
577
|
var Voices = class extends Client {
|
|
502
578
|
list() {
|
|
503
579
|
return __async(this, null, function* () {
|
|
504
|
-
const response = yield this.
|
|
580
|
+
const response = yield this._fetch("/voices");
|
|
505
581
|
return response.json();
|
|
506
582
|
});
|
|
507
583
|
}
|
|
508
584
|
get(voiceId) {
|
|
509
585
|
return __async(this, null, function* () {
|
|
510
|
-
const response = yield this.
|
|
586
|
+
const response = yield this._fetch(`/voices/${voiceId}`);
|
|
511
587
|
return response.json();
|
|
512
588
|
});
|
|
513
589
|
}
|
|
514
590
|
create(voice) {
|
|
515
591
|
return __async(this, null, function* () {
|
|
516
|
-
const response = yield this.
|
|
592
|
+
const response = yield this._fetch("/voices", {
|
|
517
593
|
method: "POST",
|
|
518
594
|
body: JSON.stringify(voice)
|
|
519
595
|
});
|
|
520
596
|
return response.json();
|
|
521
597
|
});
|
|
522
598
|
}
|
|
599
|
+
update(id, voice) {
|
|
600
|
+
return __async(this, null, function* () {
|
|
601
|
+
const response = yield this._fetch(`/voices/${id}`, {
|
|
602
|
+
method: "PATCH",
|
|
603
|
+
body: JSON.stringify(voice)
|
|
604
|
+
});
|
|
605
|
+
return response.json();
|
|
606
|
+
});
|
|
607
|
+
}
|
|
523
608
|
clone(options) {
|
|
524
609
|
return __async(this, null, function* () {
|
|
525
|
-
if (options.mode === "url") {
|
|
526
|
-
const response = yield this.fetch(
|
|
527
|
-
`/voices/clone/url?link=${options.link}`,
|
|
528
|
-
{
|
|
529
|
-
method: "POST"
|
|
530
|
-
}
|
|
531
|
-
);
|
|
532
|
-
return response.json();
|
|
533
|
-
}
|
|
534
610
|
if (options.mode === "clip") {
|
|
535
611
|
const formData = new FormData();
|
|
536
612
|
formData.append("clip", options.clip);
|
|
537
|
-
|
|
613
|
+
if (options.enhance !== void 0) {
|
|
614
|
+
formData.append("enhance", options.enhance.toString());
|
|
615
|
+
}
|
|
616
|
+
const response = yield this._fetch("/voices/clone/clip", {
|
|
538
617
|
method: "POST",
|
|
539
618
|
body: formData
|
|
540
619
|
});
|
package/dist/lib/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Cartesia
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-PQ5EVEEH.js";
|
|
3
|
+
} from "../chunk-NVOCUUOF.js";
|
|
4
|
+
import "../chunk-UCYL2SOX.js";
|
|
5
|
+
import "../chunk-EDAAHENY.js";
|
|
6
|
+
import "../chunk-IZBPLCGW.js";
|
|
7
|
+
import "../chunk-PISCPZK4.js";
|
|
9
8
|
import "../chunk-2BFEKY3F.js";
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-BHY7MNGT.js";
|
|
10
|
+
import "../chunk-6YQ6KDIQ.js";
|
|
11
|
+
import "../chunk-GHY2WEOK.js";
|
|
12
12
|
export {
|
|
13
13
|
Cartesia
|
|
14
14
|
};
|