@cartesia/cartesia-js 1.1.0 → 1.2.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.
- package/dist/{chunk-VCZESWYA.js → chunk-5SBAQNWQ.js} +1 -1
- package/dist/{chunk-MNOPO7G6.js → chunk-CSOXALSC.js} +7 -7
- package/dist/chunk-EYRYHK3X.js +43 -0
- package/dist/{chunk-6PWLZAMS.js → chunk-FLWYXP5Z.js} +1 -1
- package/dist/{chunk-L3OMQKWL.js → chunk-HQOC2S6C.js} +25 -25
- package/dist/{chunk-VVDJR3OA.js → chunk-I5YVYTNK.js} +16 -16
- package/dist/{chunk-3FL2SNIR.js → chunk-LKKWJLUG.js} +1 -1
- package/dist/{chunk-WIFMLPT5.js → chunk-NJDRWDQ3.js} +8 -22
- package/dist/{chunk-CWIJUBG6.js → chunk-RJICGVPL.js} +2 -2
- package/dist/chunk-WLEVU3HN.js +42 -0
- package/dist/{chunk-4GEDAGVY.js → chunk-YUGIYUMT.js} +8 -4
- package/dist/index.cjs +91 -57
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +14 -13
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +86 -52
- 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 +91 -57
- package/dist/react/index.js +13 -12
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +53 -52
- 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 +23 -37
- package/dist/tts/source.js +2 -2
- package/dist/tts/utils.js +3 -3
- package/dist/tts/websocket.cjs +38 -52
- package/dist/tts/websocket.d.cts +6 -6
- package/dist/tts/websocket.d.ts +6 -6
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +25 -1
- package/dist/types/index.d.ts +25 -1
- 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.js +3 -3
- package/package.json +10 -17
- package/src/lib/index.ts +3 -0
- package/src/tts/index.ts +16 -1
- package/src/types/index.ts +31 -0
- package/src/voice-changer/index.ts +37 -0
- package/.turbo/turbo-build.log +0 -75
- package/dist/chunk-MUPVAEL7.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 = {}))
|
|
@@ -43,28 +46,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
43
46
|
mod
|
|
44
47
|
));
|
|
45
48
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
-
var __accessCheck = (obj, member, msg) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var
|
|
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
|
-
};
|
|
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);
|
|
68
54
|
var __async = (__this, __arguments, generator) => {
|
|
69
55
|
return new Promise((resolve, reject) => {
|
|
70
56
|
var fulfilled = (value) => {
|
|
@@ -149,7 +135,7 @@ var ENCODING_MAP = {
|
|
|
149
135
|
pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
|
|
150
136
|
pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
|
|
151
137
|
};
|
|
152
|
-
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container,
|
|
138
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _Source_instances, createBuffer_fn;
|
|
153
139
|
var Source = class {
|
|
154
140
|
/**
|
|
155
141
|
* Create a new Source.
|
|
@@ -162,21 +148,15 @@ var Source = class {
|
|
|
162
148
|
encoding,
|
|
163
149
|
container
|
|
164
150
|
}) {
|
|
165
|
-
|
|
166
|
-
* Create a new buffer for the source.
|
|
167
|
-
*
|
|
168
|
-
* @param size - The size of the buffer to create.
|
|
169
|
-
* @returns The new buffer as a TypedArray based on the encoding.
|
|
170
|
-
*/
|
|
171
|
-
__privateAdd(this, _createBuffer);
|
|
151
|
+
__privateAdd(this, _Source_instances);
|
|
172
152
|
__privateAdd(this, _emitter, new import_emittery.default());
|
|
173
|
-
__privateAdd(this, _buffer
|
|
153
|
+
__privateAdd(this, _buffer);
|
|
174
154
|
__privateAdd(this, _readIndex, 0);
|
|
175
155
|
__privateAdd(this, _writeIndex, 0);
|
|
176
156
|
__privateAdd(this, _closed, false);
|
|
177
|
-
__privateAdd(this, _sampleRate
|
|
178
|
-
__privateAdd(this, _encoding
|
|
179
|
-
__privateAdd(this, _container
|
|
157
|
+
__privateAdd(this, _sampleRate);
|
|
158
|
+
__privateAdd(this, _encoding);
|
|
159
|
+
__privateAdd(this, _container);
|
|
180
160
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
181
161
|
this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
|
|
182
162
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
@@ -184,7 +164,7 @@ var Source = class {
|
|
|
184
164
|
__privateSet(this, _sampleRate, sampleRate);
|
|
185
165
|
__privateSet(this, _encoding, encoding);
|
|
186
166
|
__privateSet(this, _container, container);
|
|
187
|
-
__privateSet(this, _buffer, __privateMethod(this,
|
|
167
|
+
__privateSet(this, _buffer, __privateMethod(this, _Source_instances, createBuffer_fn).call(this, 1024));
|
|
188
168
|
}
|
|
189
169
|
get sampleRate() {
|
|
190
170
|
return __privateGet(this, _sampleRate);
|
|
@@ -208,7 +188,7 @@ var Source = class {
|
|
|
208
188
|
while (newCapacity < requiredCapacity) {
|
|
209
189
|
newCapacity *= 2;
|
|
210
190
|
}
|
|
211
|
-
const newBuffer = __privateMethod(this,
|
|
191
|
+
const newBuffer = __privateMethod(this, _Source_instances, createBuffer_fn).call(this, newCapacity);
|
|
212
192
|
newBuffer.set(__privateGet(this, _buffer));
|
|
213
193
|
__privateSet(this, _buffer, newBuffer);
|
|
214
194
|
}
|
|
@@ -313,7 +293,13 @@ _closed = new WeakMap();
|
|
|
313
293
|
_sampleRate = new WeakMap();
|
|
314
294
|
_encoding = new WeakMap();
|
|
315
295
|
_container = new WeakMap();
|
|
316
|
-
|
|
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
|
+
*/
|
|
317
303
|
createBuffer_fn = function(size) {
|
|
318
304
|
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
319
305
|
return new ArrayType(size);
|
|
@@ -389,7 +375,7 @@ function getEmitteryCallbacks(emitter) {
|
|
|
389
375
|
}
|
|
390
376
|
|
|
391
377
|
// src/tts/websocket.ts
|
|
392
|
-
var _isConnected, _sampleRate2, _container2, _encoding2,
|
|
378
|
+
var _isConnected, _sampleRate2, _container2, _encoding2, _WebSocket_instances, generateId_fn;
|
|
393
379
|
var WebSocket = class extends Client {
|
|
394
380
|
/**
|
|
395
381
|
* Create a new WebSocket client.
|
|
@@ -398,19 +384,11 @@ var WebSocket = class extends Client {
|
|
|
398
384
|
*/
|
|
399
385
|
constructor({ sampleRate, container, encoding }, ...args) {
|
|
400
386
|
super(...args);
|
|
401
|
-
|
|
402
|
-
* Generate a unique ID suitable for a streaming context.
|
|
403
|
-
*
|
|
404
|
-
* Not suitable for security purposes or as a primary key, since
|
|
405
|
-
* it lacks the amount of entropy required for those use cases.
|
|
406
|
-
*
|
|
407
|
-
* @returns A unique ID.
|
|
408
|
-
*/
|
|
409
|
-
__privateAdd(this, _generateId);
|
|
387
|
+
__privateAdd(this, _WebSocket_instances);
|
|
410
388
|
__privateAdd(this, _isConnected, false);
|
|
411
|
-
__privateAdd(this, _sampleRate2
|
|
412
|
-
__privateAdd(this, _container2
|
|
413
|
-
__privateAdd(this, _encoding2
|
|
389
|
+
__privateAdd(this, _sampleRate2);
|
|
390
|
+
__privateAdd(this, _container2);
|
|
391
|
+
__privateAdd(this, _encoding2);
|
|
414
392
|
__privateSet(this, _sampleRate2, sampleRate);
|
|
415
393
|
__privateSet(this, _container2, container != null ? container : "raw");
|
|
416
394
|
__privateSet(this, _encoding2, encoding != null ? encoding : "pcm_f32le");
|
|
@@ -432,7 +410,7 @@ var WebSocket = class extends Client {
|
|
|
432
410
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
433
411
|
}
|
|
434
412
|
if (!inputs.context_id) {
|
|
435
|
-
inputs.context_id = __privateMethod(this,
|
|
413
|
+
inputs.context_id = __privateMethod(this, _WebSocket_instances, generateId_fn).call(this);
|
|
436
414
|
}
|
|
437
415
|
if (!inputs.output_format) {
|
|
438
416
|
inputs.output_format = {
|
|
@@ -612,7 +590,15 @@ _isConnected = new WeakMap();
|
|
|
612
590
|
_sampleRate2 = new WeakMap();
|
|
613
591
|
_container2 = new WeakMap();
|
|
614
592
|
_encoding2 = new WeakMap();
|
|
615
|
-
|
|
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
|
+
*/
|
|
616
602
|
generateId_fn = function() {
|
|
617
603
|
return (0, import_human_id.humanId)({
|
|
618
604
|
separator: "-",
|
|
@@ -633,6 +619,53 @@ var TTS = class extends Client {
|
|
|
633
619
|
baseUrl: this.baseUrl
|
|
634
620
|
});
|
|
635
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
|
+
}
|
|
636
669
|
};
|
|
637
670
|
|
|
638
671
|
// src/voices/index.ts
|
|
@@ -710,11 +743,12 @@ var Cartesia = class extends Client {
|
|
|
710
743
|
super(options);
|
|
711
744
|
this.tts = new TTS(options);
|
|
712
745
|
this.voices = new Voices(options);
|
|
746
|
+
this.voiceChanger = new VoiceChanger(options);
|
|
713
747
|
}
|
|
714
748
|
};
|
|
715
749
|
|
|
716
750
|
// src/tts/player.ts
|
|
717
|
-
var _context, _startNextPlaybackAt, _bufferDuration,
|
|
751
|
+
var _context, _startNextPlaybackAt, _bufferDuration, _Player_instances, playBuffer_fn;
|
|
718
752
|
var Player = class {
|
|
719
753
|
/**
|
|
720
754
|
* Create a new Player.
|
|
@@ -723,10 +757,10 @@ var Player = class {
|
|
|
723
757
|
* @param options.bufferDuration - The duration of the audio buffer to play.
|
|
724
758
|
*/
|
|
725
759
|
constructor({ bufferDuration }) {
|
|
726
|
-
__privateAdd(this,
|
|
760
|
+
__privateAdd(this, _Player_instances);
|
|
727
761
|
__privateAdd(this, _context, null);
|
|
728
762
|
__privateAdd(this, _startNextPlaybackAt, 0);
|
|
729
|
-
__privateAdd(this, _bufferDuration
|
|
763
|
+
__privateAdd(this, _bufferDuration);
|
|
730
764
|
__privateSet(this, _bufferDuration, bufferDuration);
|
|
731
765
|
}
|
|
732
766
|
/**
|
|
@@ -746,7 +780,7 @@ var Player = class {
|
|
|
746
780
|
while (true) {
|
|
747
781
|
const read = yield source.read(buffer);
|
|
748
782
|
const playableAudio = buffer.subarray(0, read);
|
|
749
|
-
plays.push(__privateMethod(this,
|
|
783
|
+
plays.push(__privateMethod(this, _Player_instances, playBuffer_fn).call(this, playableAudio, source.sampleRate));
|
|
750
784
|
if (read < buffer.length) {
|
|
751
785
|
break;
|
|
752
786
|
}
|
|
@@ -815,7 +849,7 @@ var Player = class {
|
|
|
815
849
|
_context = new WeakMap();
|
|
816
850
|
_startNextPlaybackAt = new WeakMap();
|
|
817
851
|
_bufferDuration = new WeakMap();
|
|
818
|
-
|
|
852
|
+
_Player_instances = new WeakSet();
|
|
819
853
|
playBuffer_fn = function(buf, sampleRate) {
|
|
820
854
|
return __async(this, null, function* () {
|
|
821
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, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, 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, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, 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
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
Player
|
|
3
|
+
} from "./chunk-CSOXALSC.js";
|
|
2
4
|
import {
|
|
3
5
|
Cartesia
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-MUPVAEL7.js";
|
|
6
|
+
} from "./chunk-YUGIYUMT.js";
|
|
7
|
+
import "./chunk-EYRYHK3X.js";
|
|
7
8
|
import {
|
|
8
9
|
WebSocket
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-2BFEKY3F.js";
|
|
12
|
-
import {
|
|
13
|
-
Player
|
|
14
|
-
} from "./chunk-MNOPO7G6.js";
|
|
15
|
-
import "./chunk-VCZESWYA.js";
|
|
10
|
+
} from "./chunk-HQOC2S6C.js";
|
|
11
|
+
import "./chunk-5SBAQNWQ.js";
|
|
16
12
|
import {
|
|
17
13
|
Source
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-I5YVYTNK.js";
|
|
15
|
+
import "./chunk-RJICGVPL.js";
|
|
16
|
+
import "./chunk-FXPGR372.js";
|
|
17
|
+
import "./chunk-WLEVU3HN.js";
|
|
18
|
+
import "./chunk-FLWYXP5Z.js";
|
|
19
|
+
import "./chunk-2BFEKY3F.js";
|
|
20
|
+
import "./chunk-NJDRWDQ3.js";
|
|
20
21
|
export {
|
|
21
22
|
Cartesia,
|
|
22
23
|
Source,
|
package/dist/lib/client.js
CHANGED
package/dist/lib/constants.js
CHANGED
package/dist/lib/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 = {}))
|
|
@@ -43,28 +46,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
43
46
|
mod
|
|
44
47
|
));
|
|
45
48
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
-
var __accessCheck = (obj, member, msg) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var
|
|
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
|
-
};
|
|
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);
|
|
68
54
|
var __async = (__this, __arguments, generator) => {
|
|
69
55
|
return new Promise((resolve, reject) => {
|
|
70
56
|
var fulfilled = (value) => {
|
|
@@ -145,7 +131,7 @@ var ENCODING_MAP = {
|
|
|
145
131
|
pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
|
|
146
132
|
pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
|
|
147
133
|
};
|
|
148
|
-
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container,
|
|
134
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _Source_instances, createBuffer_fn;
|
|
149
135
|
var Source = class {
|
|
150
136
|
/**
|
|
151
137
|
* Create a new Source.
|
|
@@ -158,21 +144,15 @@ var Source = class {
|
|
|
158
144
|
encoding,
|
|
159
145
|
container
|
|
160
146
|
}) {
|
|
161
|
-
|
|
162
|
-
* Create a new buffer for the source.
|
|
163
|
-
*
|
|
164
|
-
* @param size - The size of the buffer to create.
|
|
165
|
-
* @returns The new buffer as a TypedArray based on the encoding.
|
|
166
|
-
*/
|
|
167
|
-
__privateAdd(this, _createBuffer);
|
|
147
|
+
__privateAdd(this, _Source_instances);
|
|
168
148
|
__privateAdd(this, _emitter, new import_emittery.default());
|
|
169
|
-
__privateAdd(this, _buffer
|
|
149
|
+
__privateAdd(this, _buffer);
|
|
170
150
|
__privateAdd(this, _readIndex, 0);
|
|
171
151
|
__privateAdd(this, _writeIndex, 0);
|
|
172
152
|
__privateAdd(this, _closed, false);
|
|
173
|
-
__privateAdd(this, _sampleRate
|
|
174
|
-
__privateAdd(this, _encoding
|
|
175
|
-
__privateAdd(this, _container
|
|
153
|
+
__privateAdd(this, _sampleRate);
|
|
154
|
+
__privateAdd(this, _encoding);
|
|
155
|
+
__privateAdd(this, _container);
|
|
176
156
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
177
157
|
this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
|
|
178
158
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
@@ -180,7 +160,7 @@ var Source = class {
|
|
|
180
160
|
__privateSet(this, _sampleRate, sampleRate);
|
|
181
161
|
__privateSet(this, _encoding, encoding);
|
|
182
162
|
__privateSet(this, _container, container);
|
|
183
|
-
__privateSet(this, _buffer, __privateMethod(this,
|
|
163
|
+
__privateSet(this, _buffer, __privateMethod(this, _Source_instances, createBuffer_fn).call(this, 1024));
|
|
184
164
|
}
|
|
185
165
|
get sampleRate() {
|
|
186
166
|
return __privateGet(this, _sampleRate);
|
|
@@ -204,7 +184,7 @@ var Source = class {
|
|
|
204
184
|
while (newCapacity < requiredCapacity) {
|
|
205
185
|
newCapacity *= 2;
|
|
206
186
|
}
|
|
207
|
-
const newBuffer = __privateMethod(this,
|
|
187
|
+
const newBuffer = __privateMethod(this, _Source_instances, createBuffer_fn).call(this, newCapacity);
|
|
208
188
|
newBuffer.set(__privateGet(this, _buffer));
|
|
209
189
|
__privateSet(this, _buffer, newBuffer);
|
|
210
190
|
}
|
|
@@ -309,7 +289,13 @@ _closed = new WeakMap();
|
|
|
309
289
|
_sampleRate = new WeakMap();
|
|
310
290
|
_encoding = new WeakMap();
|
|
311
291
|
_container = new WeakMap();
|
|
312
|
-
|
|
292
|
+
_Source_instances = new WeakSet();
|
|
293
|
+
/**
|
|
294
|
+
* Create a new buffer for the source.
|
|
295
|
+
*
|
|
296
|
+
* @param size - The size of the buffer to create.
|
|
297
|
+
* @returns The new buffer as a TypedArray based on the encoding.
|
|
298
|
+
*/
|
|
313
299
|
createBuffer_fn = function(size) {
|
|
314
300
|
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
315
301
|
return new ArrayType(size);
|
|
@@ -372,7 +358,7 @@ function getEmitteryCallbacks(emitter) {
|
|
|
372
358
|
}
|
|
373
359
|
|
|
374
360
|
// src/tts/websocket.ts
|
|
375
|
-
var _isConnected, _sampleRate2, _container2, _encoding2,
|
|
361
|
+
var _isConnected, _sampleRate2, _container2, _encoding2, _WebSocket_instances, generateId_fn;
|
|
376
362
|
var WebSocket = class extends Client {
|
|
377
363
|
/**
|
|
378
364
|
* Create a new WebSocket client.
|
|
@@ -381,19 +367,11 @@ var WebSocket = class extends Client {
|
|
|
381
367
|
*/
|
|
382
368
|
constructor({ sampleRate, container, encoding }, ...args) {
|
|
383
369
|
super(...args);
|
|
384
|
-
|
|
385
|
-
* Generate a unique ID suitable for a streaming context.
|
|
386
|
-
*
|
|
387
|
-
* Not suitable for security purposes or as a primary key, since
|
|
388
|
-
* it lacks the amount of entropy required for those use cases.
|
|
389
|
-
*
|
|
390
|
-
* @returns A unique ID.
|
|
391
|
-
*/
|
|
392
|
-
__privateAdd(this, _generateId);
|
|
370
|
+
__privateAdd(this, _WebSocket_instances);
|
|
393
371
|
__privateAdd(this, _isConnected, false);
|
|
394
|
-
__privateAdd(this, _sampleRate2
|
|
395
|
-
__privateAdd(this, _container2
|
|
396
|
-
__privateAdd(this, _encoding2
|
|
372
|
+
__privateAdd(this, _sampleRate2);
|
|
373
|
+
__privateAdd(this, _container2);
|
|
374
|
+
__privateAdd(this, _encoding2);
|
|
397
375
|
__privateSet(this, _sampleRate2, sampleRate);
|
|
398
376
|
__privateSet(this, _container2, container != null ? container : "raw");
|
|
399
377
|
__privateSet(this, _encoding2, encoding != null ? encoding : "pcm_f32le");
|
|
@@ -415,7 +393,7 @@ var WebSocket = class extends Client {
|
|
|
415
393
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
416
394
|
}
|
|
417
395
|
if (!inputs.context_id) {
|
|
418
|
-
inputs.context_id = __privateMethod(this,
|
|
396
|
+
inputs.context_id = __privateMethod(this, _WebSocket_instances, generateId_fn).call(this);
|
|
419
397
|
}
|
|
420
398
|
if (!inputs.output_format) {
|
|
421
399
|
inputs.output_format = {
|
|
@@ -595,7 +573,15 @@ _isConnected = new WeakMap();
|
|
|
595
573
|
_sampleRate2 = new WeakMap();
|
|
596
574
|
_container2 = new WeakMap();
|
|
597
575
|
_encoding2 = new WeakMap();
|
|
598
|
-
|
|
576
|
+
_WebSocket_instances = new WeakSet();
|
|
577
|
+
/**
|
|
578
|
+
* Generate a unique ID suitable for a streaming context.
|
|
579
|
+
*
|
|
580
|
+
* Not suitable for security purposes or as a primary key, since
|
|
581
|
+
* it lacks the amount of entropy required for those use cases.
|
|
582
|
+
*
|
|
583
|
+
* @returns A unique ID.
|
|
584
|
+
*/
|
|
599
585
|
generateId_fn = function() {
|
|
600
586
|
return (0, import_human_id.humanId)({
|
|
601
587
|
separator: "-",
|
|
@@ -616,6 +602,53 @@ var TTS = class extends Client {
|
|
|
616
602
|
baseUrl: this.baseUrl
|
|
617
603
|
});
|
|
618
604
|
}
|
|
605
|
+
/**
|
|
606
|
+
* Generate audio bytes from text.
|
|
607
|
+
*
|
|
608
|
+
* @param options - The options for the request.
|
|
609
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
610
|
+
*/
|
|
611
|
+
bytes(options) {
|
|
612
|
+
return __async(this, null, function* () {
|
|
613
|
+
const response = yield this._fetch("/tts/bytes", {
|
|
614
|
+
method: "POST",
|
|
615
|
+
body: JSON.stringify(options)
|
|
616
|
+
});
|
|
617
|
+
return response.arrayBuffer();
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
// src/voice-changer/index.ts
|
|
623
|
+
var VoiceChanger = class extends Client {
|
|
624
|
+
bytes(options) {
|
|
625
|
+
return __async(this, null, function* () {
|
|
626
|
+
const formData = new FormData();
|
|
627
|
+
formData.append("clip", options.clip);
|
|
628
|
+
formData.append("voice[id]", options.voice.id);
|
|
629
|
+
const fmt = options.output_format;
|
|
630
|
+
formData.append("output_format[container]", fmt.container);
|
|
631
|
+
if ("encoding" in fmt) {
|
|
632
|
+
formData.append("output_format[encoding]", fmt.encoding);
|
|
633
|
+
}
|
|
634
|
+
if ("bit_rate" in fmt) {
|
|
635
|
+
formData.append("output_format[bit_rate]", fmt.bit_rate.toString());
|
|
636
|
+
}
|
|
637
|
+
if ("sample_rate" in fmt) {
|
|
638
|
+
formData.append("output_format[sample_rate]", fmt.sample_rate.toString());
|
|
639
|
+
}
|
|
640
|
+
const response = yield this._fetch("/voice-changer/bytes", {
|
|
641
|
+
method: "POST",
|
|
642
|
+
body: formData
|
|
643
|
+
});
|
|
644
|
+
if (!response.ok) {
|
|
645
|
+
throw new Error(
|
|
646
|
+
`Voice changer error! status: ${response.status}, message: ${yield response.text()}`
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
return { buffer: yield response.arrayBuffer() };
|
|
650
|
+
});
|
|
651
|
+
}
|
|
619
652
|
};
|
|
620
653
|
|
|
621
654
|
// src/voices/index.ts
|
|
@@ -693,6 +726,7 @@ var Cartesia = class extends Client {
|
|
|
693
726
|
super(options);
|
|
694
727
|
this.tts = new TTS(options);
|
|
695
728
|
this.voices = new Voices(options);
|
|
729
|
+
this.voiceChanger = new VoiceChanger(options);
|
|
696
730
|
}
|
|
697
731
|
};
|
|
698
732
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/lib/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import TTS from '../tts/index.cjs';
|
|
2
2
|
import { ClientOptions } from '../types/index.cjs';
|
|
3
|
+
import VoiceChanger from '../voice-changer/index.cjs';
|
|
3
4
|
import Voices from '../voices/index.cjs';
|
|
4
5
|
import { Client } from './client.cjs';
|
|
5
6
|
import '../tts/websocket.cjs';
|
|
@@ -10,6 +11,7 @@ import '../tts/source.cjs';
|
|
|
10
11
|
declare class Cartesia extends Client {
|
|
11
12
|
tts: TTS;
|
|
12
13
|
voices: Voices;
|
|
14
|
+
voiceChanger: VoiceChanger;
|
|
13
15
|
constructor(options?: ClientOptions);
|
|
14
16
|
}
|
|
15
17
|
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import TTS from '../tts/index.js';
|
|
2
2
|
import { ClientOptions } from '../types/index.js';
|
|
3
|
+
import VoiceChanger from '../voice-changer/index.js';
|
|
3
4
|
import Voices from '../voices/index.js';
|
|
4
5
|
import { Client } from './client.js';
|
|
5
6
|
import '../tts/websocket.js';
|
|
@@ -10,6 +11,7 @@ import '../tts/source.js';
|
|
|
10
11
|
declare class Cartesia extends Client {
|
|
11
12
|
tts: TTS;
|
|
12
13
|
voices: Voices;
|
|
14
|
+
voiceChanger: VoiceChanger;
|
|
13
15
|
constructor(options?: ClientOptions);
|
|
14
16
|
}
|
|
15
17
|
|
package/dist/lib/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Cartesia
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-YUGIYUMT.js";
|
|
4
|
+
import "../chunk-EYRYHK3X.js";
|
|
5
|
+
import "../chunk-HQOC2S6C.js";
|
|
6
|
+
import "../chunk-5SBAQNWQ.js";
|
|
7
|
+
import "../chunk-I5YVYTNK.js";
|
|
8
|
+
import "../chunk-RJICGVPL.js";
|
|
9
|
+
import "../chunk-WLEVU3HN.js";
|
|
10
|
+
import "../chunk-FLWYXP5Z.js";
|
|
8
11
|
import "../chunk-2BFEKY3F.js";
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-VVDJR3OA.js";
|
|
11
|
-
import "../chunk-WIFMLPT5.js";
|
|
12
|
+
import "../chunk-NJDRWDQ3.js";
|
|
12
13
|
export {
|
|
13
14
|
Cartesia
|
|
14
15
|
};
|