@cartesia/cartesia-js 1.0.3 → 1.2.1-alpha.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/CHANGELOG.md +6 -0
- package/README.md +32 -3
- package/dist/{chunk-BHY7MNGT.js → chunk-5SBAQNWQ.js} +1 -1
- package/dist/{chunk-LZO6K34D.js → chunk-CSOXALSC.js} +7 -7
- package/dist/{chunk-PISCPZK4.js → chunk-FLWYXP5Z.js} +1 -1
- package/dist/chunk-GLZYI5DM.js +43 -0
- package/dist/{chunk-6YQ6KDIQ.js → chunk-I5YVYTNK.js} +47 -16
- package/dist/{chunk-NQVZNVOU.js → chunk-LKKWJLUG.js} +1 -1
- package/dist/{chunk-GHY2WEOK.js → chunk-NJDRWDQ3.js} +8 -35
- package/dist/{chunk-ZF6HASZT.js → chunk-QWNB544W.js} +7 -3
- package/dist/{chunk-YFN6TFR4.js → chunk-RJICGVPL.js} +12 -4
- package/dist/chunk-WLEVU3HN.js +42 -0
- package/dist/{chunk-EUW2435M.js → chunk-WSIVWXEI.js} +49 -25
- package/dist/index.cjs +162 -76
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -9
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +157 -71
- package/dist/lib/index.d.cts +2 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +9 -8
- package/dist/react/index.cjs +165 -76
- package/dist/react/index.js +14 -10
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +114 -69
- package/dist/tts/index.d.cts +8 -1
- package/dist/tts/index.d.ts +8 -1
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.cjs +13 -27
- package/dist/tts/player.js +4 -4
- package/dist/tts/source.cjs +54 -37
- package/dist/tts/source.d.cts +9 -0
- package/dist/tts/source.d.ts +9 -0
- package/dist/tts/source.js +2 -2
- package/dist/tts/utils.js +3 -3
- package/dist/tts/websocket.cjs +99 -69
- package/dist/tts/websocket.d.cts +15 -9
- package/dist/tts/websocket.d.ts +15 -9
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +42 -3
- package/dist/types/index.d.ts +42 -3
- package/dist/voice-changer/index.cjs +143 -0
- package/dist/voice-changer/index.d.cts +9 -0
- package/dist/voice-changer/index.d.ts +9 -0
- package/dist/voice-changer/index.js +9 -0
- package/dist/voices/index.cjs +10 -2
- 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 +8 -16
- package/src/lib/index.ts +3 -0
- package/src/react/index.ts +4 -0
- package/src/tts/index.ts +16 -1
- package/src/tts/source.ts +35 -0
- package/src/tts/websocket.ts +33 -2
- package/src/types/index.ts +60 -2
- package/src/voice-changer/index.ts +37 -0
- package/src/voices/index.ts +12 -3
- package/.turbo/turbo-build.log +0 -75
- package/dist/chunk-NWCW6C7H.js +0 -25
- package/tsconfig.json +0 -3
package/dist/index.cjs
CHANGED
|
@@ -9,6 +9,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
9
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
11
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __typeError = (msg) => {
|
|
13
|
+
throw TypeError(msg);
|
|
14
|
+
};
|
|
12
15
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
16
|
var __spreadValues = (a, b) => {
|
|
14
17
|
for (var prop in b || (b = {}))
|
|
@@ -22,18 +25,6 @@ var __spreadValues = (a, b) => {
|
|
|
22
25
|
return a;
|
|
23
26
|
};
|
|
24
27
|
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
|
-
};
|
|
37
28
|
var __export = (target, all) => {
|
|
38
29
|
for (var name in all)
|
|
39
30
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -55,28 +46,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
55
46
|
mod
|
|
56
47
|
));
|
|
57
48
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
var __accessCheck = (obj, member, msg) =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
__accessCheck(obj, member, "read from private field");
|
|
64
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
65
|
-
};
|
|
66
|
-
var __privateAdd = (obj, member, value) => {
|
|
67
|
-
if (member.has(obj))
|
|
68
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
69
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
70
|
-
};
|
|
71
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
72
|
-
__accessCheck(obj, member, "write to private field");
|
|
73
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
74
|
-
return value;
|
|
75
|
-
};
|
|
76
|
-
var __privateMethod = (obj, member, method) => {
|
|
77
|
-
__accessCheck(obj, member, "access private method");
|
|
78
|
-
return method;
|
|
79
|
-
};
|
|
49
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
50
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
51
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
52
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
53
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
80
54
|
var __async = (__this, __arguments, generator) => {
|
|
81
55
|
return new Promise((resolve, reject) => {
|
|
82
56
|
var fulfilled = (value) => {
|
|
@@ -161,7 +135,7 @@ var ENCODING_MAP = {
|
|
|
161
135
|
pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
|
|
162
136
|
pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
|
|
163
137
|
};
|
|
164
|
-
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container,
|
|
138
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _Source_instances, createBuffer_fn;
|
|
165
139
|
var Source = class {
|
|
166
140
|
/**
|
|
167
141
|
* Create a new Source.
|
|
@@ -174,21 +148,15 @@ var Source = class {
|
|
|
174
148
|
encoding,
|
|
175
149
|
container
|
|
176
150
|
}) {
|
|
177
|
-
|
|
178
|
-
* Create a new buffer for the source.
|
|
179
|
-
*
|
|
180
|
-
* @param size - The size of the buffer to create.
|
|
181
|
-
* @returns The new buffer as a TypedArray based on the encoding.
|
|
182
|
-
*/
|
|
183
|
-
__privateAdd(this, _createBuffer);
|
|
151
|
+
__privateAdd(this, _Source_instances);
|
|
184
152
|
__privateAdd(this, _emitter, new import_emittery.default());
|
|
185
|
-
__privateAdd(this, _buffer
|
|
153
|
+
__privateAdd(this, _buffer);
|
|
186
154
|
__privateAdd(this, _readIndex, 0);
|
|
187
155
|
__privateAdd(this, _writeIndex, 0);
|
|
188
156
|
__privateAdd(this, _closed, false);
|
|
189
|
-
__privateAdd(this, _sampleRate
|
|
190
|
-
__privateAdd(this, _encoding
|
|
191
|
-
__privateAdd(this, _container
|
|
157
|
+
__privateAdd(this, _sampleRate);
|
|
158
|
+
__privateAdd(this, _encoding);
|
|
159
|
+
__privateAdd(this, _container);
|
|
192
160
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
193
161
|
this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
|
|
194
162
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
@@ -196,7 +164,7 @@ var Source = class {
|
|
|
196
164
|
__privateSet(this, _sampleRate, sampleRate);
|
|
197
165
|
__privateSet(this, _encoding, encoding);
|
|
198
166
|
__privateSet(this, _container, container);
|
|
199
|
-
__privateSet(this, _buffer, __privateMethod(this,
|
|
167
|
+
__privateSet(this, _buffer, __privateMethod(this, _Source_instances, createBuffer_fn).call(this, 1024));
|
|
200
168
|
}
|
|
201
169
|
get sampleRate() {
|
|
202
170
|
return __privateGet(this, _sampleRate);
|
|
@@ -220,7 +188,7 @@ var Source = class {
|
|
|
220
188
|
while (newCapacity < requiredCapacity) {
|
|
221
189
|
newCapacity *= 2;
|
|
222
190
|
}
|
|
223
|
-
const newBuffer = __privateMethod(this,
|
|
191
|
+
const newBuffer = __privateMethod(this, _Source_instances, createBuffer_fn).call(this, newCapacity);
|
|
224
192
|
newBuffer.set(__privateGet(this, _buffer));
|
|
225
193
|
__privateSet(this, _buffer, newBuffer);
|
|
226
194
|
}
|
|
@@ -253,6 +221,37 @@ var Source = class {
|
|
|
253
221
|
return read;
|
|
254
222
|
});
|
|
255
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Seek in the buffer.
|
|
226
|
+
*
|
|
227
|
+
* @param offset The offset to seek to.
|
|
228
|
+
* @param whence The position to seek from.
|
|
229
|
+
* @returns The new position in the buffer.
|
|
230
|
+
* @throws {Error} If the seek is invalid.
|
|
231
|
+
*/
|
|
232
|
+
seek(offset, whence) {
|
|
233
|
+
return __async(this, null, function* () {
|
|
234
|
+
let position = __privateGet(this, _readIndex);
|
|
235
|
+
switch (whence) {
|
|
236
|
+
case "start":
|
|
237
|
+
position = offset;
|
|
238
|
+
break;
|
|
239
|
+
case "current":
|
|
240
|
+
position += offset;
|
|
241
|
+
break;
|
|
242
|
+
case "end":
|
|
243
|
+
position = __privateGet(this, _writeIndex) + offset;
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
throw new Error(`Invalid seek mode: ${whence}`);
|
|
247
|
+
}
|
|
248
|
+
if (position < 0 || position > __privateGet(this, _writeIndex)) {
|
|
249
|
+
throw new Error("Seek out of bounds");
|
|
250
|
+
}
|
|
251
|
+
__privateSet(this, _readIndex, position);
|
|
252
|
+
return position;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
256
255
|
/**
|
|
257
256
|
* Get the number of samples in a given duration.
|
|
258
257
|
*
|
|
@@ -294,7 +293,13 @@ _closed = new WeakMap();
|
|
|
294
293
|
_sampleRate = new WeakMap();
|
|
295
294
|
_encoding = new WeakMap();
|
|
296
295
|
_container = new WeakMap();
|
|
297
|
-
|
|
296
|
+
_Source_instances = new WeakSet();
|
|
297
|
+
/**
|
|
298
|
+
* Create a new buffer for the source.
|
|
299
|
+
*
|
|
300
|
+
* @param size - The size of the buffer to create.
|
|
301
|
+
* @returns The new buffer as a TypedArray based on the encoding.
|
|
302
|
+
*/
|
|
298
303
|
createBuffer_fn = function(size) {
|
|
299
304
|
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
300
305
|
return new ArrayType(size);
|
|
@@ -370,7 +375,7 @@ function getEmitteryCallbacks(emitter) {
|
|
|
370
375
|
}
|
|
371
376
|
|
|
372
377
|
// src/tts/websocket.ts
|
|
373
|
-
var _isConnected, _sampleRate2, _container2, _encoding2,
|
|
378
|
+
var _isConnected, _sampleRate2, _container2, _encoding2, _WebSocket_instances, generateId_fn;
|
|
374
379
|
var WebSocket = class extends Client {
|
|
375
380
|
/**
|
|
376
381
|
* Create a new WebSocket client.
|
|
@@ -379,19 +384,11 @@ var WebSocket = class extends Client {
|
|
|
379
384
|
*/
|
|
380
385
|
constructor({ sampleRate, container, encoding }, ...args) {
|
|
381
386
|
super(...args);
|
|
382
|
-
|
|
383
|
-
* Generate a unique ID suitable for a streaming context.
|
|
384
|
-
*
|
|
385
|
-
* Not suitable for security purposes or as a primary key, since
|
|
386
|
-
* it lacks the amount of entropy required for those use cases.
|
|
387
|
-
*
|
|
388
|
-
* @returns A unique ID.
|
|
389
|
-
*/
|
|
390
|
-
__privateAdd(this, _generateId);
|
|
387
|
+
__privateAdd(this, _WebSocket_instances);
|
|
391
388
|
__privateAdd(this, _isConnected, false);
|
|
392
|
-
__privateAdd(this, _sampleRate2
|
|
393
|
-
__privateAdd(this, _container2
|
|
394
|
-
__privateAdd(this, _encoding2
|
|
389
|
+
__privateAdd(this, _sampleRate2);
|
|
390
|
+
__privateAdd(this, _container2);
|
|
391
|
+
__privateAdd(this, _encoding2);
|
|
395
392
|
__privateSet(this, _sampleRate2, sampleRate);
|
|
396
393
|
__privateSet(this, _container2, container != null ? container : "raw");
|
|
397
394
|
__privateSet(this, _encoding2, encoding != null ? encoding : "pcm_f32le");
|
|
@@ -399,7 +396,7 @@ var WebSocket = class extends Client {
|
|
|
399
396
|
/**
|
|
400
397
|
* Send a message over the WebSocket to start a stream.
|
|
401
398
|
*
|
|
402
|
-
* @param inputs -
|
|
399
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type.
|
|
403
400
|
* @param options - Options for the stream.
|
|
404
401
|
* @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
|
|
405
402
|
* If set to `0`, the stream will not time out.
|
|
@@ -407,14 +404,13 @@ var WebSocket = class extends Client {
|
|
|
407
404
|
* @returns An Emittery instance that emits messages from the WebSocket.
|
|
408
405
|
* @returns An abort function that can be called to cancel the stream.
|
|
409
406
|
*/
|
|
410
|
-
send(
|
|
411
|
-
var
|
|
412
|
-
var _a2, _b, _c, _d;
|
|
407
|
+
send(inputs, { timeout = 0 } = {}) {
|
|
408
|
+
var _a, _b, _c, _d;
|
|
413
409
|
if (!__privateGet(this, _isConnected)) {
|
|
414
410
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
415
411
|
}
|
|
416
412
|
if (!inputs.context_id) {
|
|
417
|
-
inputs.context_id = __privateMethod(this,
|
|
413
|
+
inputs.context_id = __privateMethod(this, _WebSocket_instances, generateId_fn).call(this);
|
|
418
414
|
}
|
|
419
415
|
if (!inputs.output_format) {
|
|
420
416
|
inputs.output_format = {
|
|
@@ -423,7 +419,7 @@ var WebSocket = class extends Client {
|
|
|
423
419
|
sample_rate: __privateGet(this, _sampleRate2)
|
|
424
420
|
};
|
|
425
421
|
}
|
|
426
|
-
(
|
|
422
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
427
423
|
JSON.stringify(__spreadValues({}, inputs))
|
|
428
424
|
);
|
|
429
425
|
const emitter = new import_emittery2.default();
|
|
@@ -493,6 +489,32 @@ var WebSocket = class extends Client {
|
|
|
493
489
|
stop: streamCompleteController.abort.bind(streamCompleteController)
|
|
494
490
|
});
|
|
495
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Continue a stream.
|
|
494
|
+
*
|
|
495
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
|
|
496
|
+
*/
|
|
497
|
+
continue(inputs) {
|
|
498
|
+
var _a;
|
|
499
|
+
if (!__privateGet(this, _isConnected)) {
|
|
500
|
+
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
501
|
+
}
|
|
502
|
+
if (!inputs.context_id) {
|
|
503
|
+
throw new Error("context_id is required to continue a context.");
|
|
504
|
+
}
|
|
505
|
+
if (!inputs.output_format) {
|
|
506
|
+
inputs.output_format = {
|
|
507
|
+
container: __privateGet(this, _container2),
|
|
508
|
+
encoding: __privateGet(this, _encoding2),
|
|
509
|
+
sample_rate: __privateGet(this, _sampleRate2)
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
513
|
+
JSON.stringify(__spreadValues({
|
|
514
|
+
continue: true
|
|
515
|
+
}, inputs))
|
|
516
|
+
);
|
|
517
|
+
}
|
|
496
518
|
/**
|
|
497
519
|
* Authenticate and connect to a Cartesia streaming WebSocket.
|
|
498
520
|
*
|
|
@@ -568,7 +590,15 @@ _isConnected = new WeakMap();
|
|
|
568
590
|
_sampleRate2 = new WeakMap();
|
|
569
591
|
_container2 = new WeakMap();
|
|
570
592
|
_encoding2 = new WeakMap();
|
|
571
|
-
|
|
593
|
+
_WebSocket_instances = new WeakSet();
|
|
594
|
+
/**
|
|
595
|
+
* Generate a unique ID suitable for a streaming context.
|
|
596
|
+
*
|
|
597
|
+
* Not suitable for security purposes or as a primary key, since
|
|
598
|
+
* it lacks the amount of entropy required for those use cases.
|
|
599
|
+
*
|
|
600
|
+
* @returns A unique ID.
|
|
601
|
+
*/
|
|
572
602
|
generateId_fn = function() {
|
|
573
603
|
return (0, import_human_id.humanId)({
|
|
574
604
|
separator: "-",
|
|
@@ -589,6 +619,53 @@ var TTS = class extends Client {
|
|
|
589
619
|
baseUrl: this.baseUrl
|
|
590
620
|
});
|
|
591
621
|
}
|
|
622
|
+
/**
|
|
623
|
+
* Generate audio bytes from text.
|
|
624
|
+
*
|
|
625
|
+
* @param options - The options for the request.
|
|
626
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
627
|
+
*/
|
|
628
|
+
bytes(options) {
|
|
629
|
+
return __async(this, null, function* () {
|
|
630
|
+
const response = yield this._fetch("/tts/bytes", {
|
|
631
|
+
method: "POST",
|
|
632
|
+
body: JSON.stringify(options)
|
|
633
|
+
});
|
|
634
|
+
return response.arrayBuffer();
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
// src/voice-changer/index.ts
|
|
640
|
+
var VoiceChanger = class extends Client {
|
|
641
|
+
bytes(options) {
|
|
642
|
+
return __async(this, null, function* () {
|
|
643
|
+
const formData = new FormData();
|
|
644
|
+
formData.append("clip", options.clip);
|
|
645
|
+
formData.append("voice[id]", options.voice.id);
|
|
646
|
+
const fmt = options.output_format;
|
|
647
|
+
formData.append("output_format[container]", fmt.container);
|
|
648
|
+
if ("encoding" in fmt) {
|
|
649
|
+
formData.append("output_format[encoding]", fmt.encoding);
|
|
650
|
+
}
|
|
651
|
+
if ("bit_rate" in fmt) {
|
|
652
|
+
formData.append("output_format[bit_rate]", fmt.bit_rate.toString());
|
|
653
|
+
}
|
|
654
|
+
if ("sample_rate" in fmt) {
|
|
655
|
+
formData.append("output_format[sample_rate]", fmt.sample_rate.toString());
|
|
656
|
+
}
|
|
657
|
+
const response = yield this._fetch("/voice-changer/bytes", {
|
|
658
|
+
method: "POST",
|
|
659
|
+
body: formData
|
|
660
|
+
});
|
|
661
|
+
if (!response.ok) {
|
|
662
|
+
throw new Error(
|
|
663
|
+
`Voice changer error! status: ${response.status}, message: ${yield response.text()}`
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
return { buffer: yield response.arrayBuffer() };
|
|
667
|
+
});
|
|
668
|
+
}
|
|
592
669
|
};
|
|
593
670
|
|
|
594
671
|
// src/voices/index.ts
|
|
@@ -642,10 +719,18 @@ var Voices = class extends Client {
|
|
|
642
719
|
}
|
|
643
720
|
mix(options) {
|
|
644
721
|
return __async(this, null, function* () {
|
|
645
|
-
const request = options;
|
|
646
722
|
const response = yield this._fetch("/voices/mix", {
|
|
647
723
|
method: "POST",
|
|
648
|
-
body: JSON.stringify(
|
|
724
|
+
body: JSON.stringify(options)
|
|
725
|
+
});
|
|
726
|
+
return response.json();
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
localize(options) {
|
|
730
|
+
return __async(this, null, function* () {
|
|
731
|
+
const response = yield this._fetch("/voices/localize", {
|
|
732
|
+
method: "POST",
|
|
733
|
+
body: JSON.stringify(options)
|
|
649
734
|
});
|
|
650
735
|
return response.json();
|
|
651
736
|
});
|
|
@@ -658,11 +743,12 @@ var Cartesia = class extends Client {
|
|
|
658
743
|
super(options);
|
|
659
744
|
this.tts = new TTS(options);
|
|
660
745
|
this.voices = new Voices(options);
|
|
746
|
+
this.voiceChanger = new VoiceChanger(options);
|
|
661
747
|
}
|
|
662
748
|
};
|
|
663
749
|
|
|
664
750
|
// src/tts/player.ts
|
|
665
|
-
var _context, _startNextPlaybackAt, _bufferDuration,
|
|
751
|
+
var _context, _startNextPlaybackAt, _bufferDuration, _Player_instances, playBuffer_fn;
|
|
666
752
|
var Player = class {
|
|
667
753
|
/**
|
|
668
754
|
* Create a new Player.
|
|
@@ -671,10 +757,10 @@ var Player = class {
|
|
|
671
757
|
* @param options.bufferDuration - The duration of the audio buffer to play.
|
|
672
758
|
*/
|
|
673
759
|
constructor({ bufferDuration }) {
|
|
674
|
-
__privateAdd(this,
|
|
760
|
+
__privateAdd(this, _Player_instances);
|
|
675
761
|
__privateAdd(this, _context, null);
|
|
676
762
|
__privateAdd(this, _startNextPlaybackAt, 0);
|
|
677
|
-
__privateAdd(this, _bufferDuration
|
|
763
|
+
__privateAdd(this, _bufferDuration);
|
|
678
764
|
__privateSet(this, _bufferDuration, bufferDuration);
|
|
679
765
|
}
|
|
680
766
|
/**
|
|
@@ -694,7 +780,7 @@ var Player = class {
|
|
|
694
780
|
while (true) {
|
|
695
781
|
const read = yield source.read(buffer);
|
|
696
782
|
const playableAudio = buffer.subarray(0, read);
|
|
697
|
-
plays.push(__privateMethod(this,
|
|
783
|
+
plays.push(__privateMethod(this, _Player_instances, playBuffer_fn).call(this, playableAudio, source.sampleRate));
|
|
698
784
|
if (read < buffer.length) {
|
|
699
785
|
break;
|
|
700
786
|
}
|
|
@@ -763,7 +849,7 @@ var Player = class {
|
|
|
763
849
|
_context = new WeakMap();
|
|
764
850
|
_startNextPlaybackAt = new WeakMap();
|
|
765
851
|
_bufferDuration = new WeakMap();
|
|
766
|
-
|
|
852
|
+
_Player_instances = new WeakSet();
|
|
767
853
|
playBuffer_fn = function(buf, sampleRate) {
|
|
768
854
|
return __async(this, null, function* () {
|
|
769
855
|
if (!__privateGet(this, _context)) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { Cartesia, Cartesia as default } from './lib/index.cjs';
|
|
2
|
-
export { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps } from './types/index.cjs';
|
|
2
|
+
export { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceChangerBytesResponse, VoiceChangerOptions, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps } from './types/index.cjs';
|
|
3
3
|
export { default as WebPlayer } from './tts/player.cjs';
|
|
4
4
|
export { default as Source } from './tts/source.cjs';
|
|
5
5
|
export { default as WebSocket } from './tts/websocket.cjs';
|
|
6
6
|
import './tts/index.cjs';
|
|
7
7
|
import './lib/client.cjs';
|
|
8
|
+
import './voice-changer/index.cjs';
|
|
8
9
|
import './voices/index.cjs';
|
|
9
10
|
import 'emittery';
|
|
10
11
|
import 'partysocket';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { Cartesia, Cartesia as default } from './lib/index.js';
|
|
2
|
-
export { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps } from './types/index.js';
|
|
2
|
+
export { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceChangerBytesResponse, VoiceChangerOptions, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps } from './types/index.js';
|
|
3
3
|
export { default as WebPlayer } from './tts/player.js';
|
|
4
4
|
export { default as Source } from './tts/source.js';
|
|
5
5
|
export { default as WebSocket } from './tts/websocket.js';
|
|
6
6
|
import './tts/index.js';
|
|
7
7
|
import './lib/client.js';
|
|
8
|
+
import './voice-changer/index.js';
|
|
8
9
|
import './voices/index.js';
|
|
9
10
|
import 'emittery';
|
|
10
11
|
import 'partysocket';
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import "./chunk-FXPGR372.js";
|
|
2
2
|
import {
|
|
3
3
|
Cartesia
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-QWNB544W.js";
|
|
5
|
+
import "./chunk-WLEVU3HN.js";
|
|
6
|
+
import "./chunk-RJICGVPL.js";
|
|
7
|
+
import "./chunk-GLZYI5DM.js";
|
|
7
8
|
import {
|
|
8
9
|
WebSocket
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-WSIVWXEI.js";
|
|
11
|
+
import "./chunk-FLWYXP5Z.js";
|
|
11
12
|
import "./chunk-2BFEKY3F.js";
|
|
12
13
|
import {
|
|
13
14
|
Player
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-CSOXALSC.js";
|
|
16
|
+
import "./chunk-5SBAQNWQ.js";
|
|
16
17
|
import {
|
|
17
18
|
Source
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
19
|
+
} from "./chunk-I5YVYTNK.js";
|
|
20
|
+
import "./chunk-NJDRWDQ3.js";
|
|
20
21
|
export {
|
|
21
22
|
Cartesia,
|
|
22
23
|
Source,
|
package/dist/lib/client.js
CHANGED