@cartesia/cartesia-js 1.1.0 → 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/dist/{chunk-VCZESWYA.js → chunk-5SBAQNWQ.js} +1 -1
- package/dist/{chunk-MNOPO7G6.js → chunk-CSOXALSC.js} +7 -7
- package/dist/{chunk-6PWLZAMS.js → chunk-FLWYXP5Z.js} +1 -1
- package/dist/chunk-GLZYI5DM.js +43 -0
- 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-4GEDAGVY.js → chunk-QWNB544W.js} +7 -3
- package/dist/{chunk-CWIJUBG6.js → chunk-RJICGVPL.js} +2 -2
- package/dist/chunk-WLEVU3HN.js +42 -0
- package/dist/{chunk-L3OMQKWL.js → chunk-WSIVWXEI.js} +19 -19
- package/dist/index.cjs +91 -57
- 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 +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 +11 -10
- 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 +8 -16
- 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.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
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
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-QWNB544W.js";
|
|
4
|
+
import "../chunk-WLEVU3HN.js";
|
|
5
|
+
import "../chunk-RJICGVPL.js";
|
|
6
|
+
import "../chunk-GLZYI5DM.js";
|
|
7
|
+
import "../chunk-WSIVWXEI.js";
|
|
8
|
+
import "../chunk-FLWYXP5Z.js";
|
|
8
9
|
import "../chunk-2BFEKY3F.js";
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-5SBAQNWQ.js";
|
|
11
|
+
import "../chunk-I5YVYTNK.js";
|
|
12
|
+
import "../chunk-NJDRWDQ3.js";
|
|
12
13
|
export {
|
|
13
14
|
Cartesia
|
|
14
15
|
};
|
package/dist/react/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) => {
|
|
@@ -146,7 +132,7 @@ var ENCODING_MAP = {
|
|
|
146
132
|
pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
|
|
147
133
|
pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
|
|
148
134
|
};
|
|
149
|
-
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container,
|
|
135
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _Source_instances, createBuffer_fn;
|
|
150
136
|
var Source = class {
|
|
151
137
|
/**
|
|
152
138
|
* Create a new Source.
|
|
@@ -159,21 +145,15 @@ var Source = class {
|
|
|
159
145
|
encoding,
|
|
160
146
|
container
|
|
161
147
|
}) {
|
|
162
|
-
|
|
163
|
-
* Create a new buffer for the source.
|
|
164
|
-
*
|
|
165
|
-
* @param size - The size of the buffer to create.
|
|
166
|
-
* @returns The new buffer as a TypedArray based on the encoding.
|
|
167
|
-
*/
|
|
168
|
-
__privateAdd(this, _createBuffer);
|
|
148
|
+
__privateAdd(this, _Source_instances);
|
|
169
149
|
__privateAdd(this, _emitter, new import_emittery.default());
|
|
170
|
-
__privateAdd(this, _buffer
|
|
150
|
+
__privateAdd(this, _buffer);
|
|
171
151
|
__privateAdd(this, _readIndex, 0);
|
|
172
152
|
__privateAdd(this, _writeIndex, 0);
|
|
173
153
|
__privateAdd(this, _closed, false);
|
|
174
|
-
__privateAdd(this, _sampleRate
|
|
175
|
-
__privateAdd(this, _encoding
|
|
176
|
-
__privateAdd(this, _container
|
|
154
|
+
__privateAdd(this, _sampleRate);
|
|
155
|
+
__privateAdd(this, _encoding);
|
|
156
|
+
__privateAdd(this, _container);
|
|
177
157
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
178
158
|
this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
|
|
179
159
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
@@ -181,7 +161,7 @@ var Source = class {
|
|
|
181
161
|
__privateSet(this, _sampleRate, sampleRate);
|
|
182
162
|
__privateSet(this, _encoding, encoding);
|
|
183
163
|
__privateSet(this, _container, container);
|
|
184
|
-
__privateSet(this, _buffer, __privateMethod(this,
|
|
164
|
+
__privateSet(this, _buffer, __privateMethod(this, _Source_instances, createBuffer_fn).call(this, 1024));
|
|
185
165
|
}
|
|
186
166
|
get sampleRate() {
|
|
187
167
|
return __privateGet(this, _sampleRate);
|
|
@@ -205,7 +185,7 @@ var Source = class {
|
|
|
205
185
|
while (newCapacity < requiredCapacity) {
|
|
206
186
|
newCapacity *= 2;
|
|
207
187
|
}
|
|
208
|
-
const newBuffer = __privateMethod(this,
|
|
188
|
+
const newBuffer = __privateMethod(this, _Source_instances, createBuffer_fn).call(this, newCapacity);
|
|
209
189
|
newBuffer.set(__privateGet(this, _buffer));
|
|
210
190
|
__privateSet(this, _buffer, newBuffer);
|
|
211
191
|
}
|
|
@@ -310,7 +290,13 @@ _closed = new WeakMap();
|
|
|
310
290
|
_sampleRate = new WeakMap();
|
|
311
291
|
_encoding = new WeakMap();
|
|
312
292
|
_container = new WeakMap();
|
|
313
|
-
|
|
293
|
+
_Source_instances = new WeakSet();
|
|
294
|
+
/**
|
|
295
|
+
* Create a new buffer for the source.
|
|
296
|
+
*
|
|
297
|
+
* @param size - The size of the buffer to create.
|
|
298
|
+
* @returns The new buffer as a TypedArray based on the encoding.
|
|
299
|
+
*/
|
|
314
300
|
createBuffer_fn = function(size) {
|
|
315
301
|
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
316
302
|
return new ArrayType(size);
|
|
@@ -386,7 +372,7 @@ function getEmitteryCallbacks(emitter) {
|
|
|
386
372
|
}
|
|
387
373
|
|
|
388
374
|
// src/tts/websocket.ts
|
|
389
|
-
var _isConnected, _sampleRate2, _container2, _encoding2,
|
|
375
|
+
var _isConnected, _sampleRate2, _container2, _encoding2, _WebSocket_instances, generateId_fn;
|
|
390
376
|
var WebSocket = class extends Client {
|
|
391
377
|
/**
|
|
392
378
|
* Create a new WebSocket client.
|
|
@@ -395,19 +381,11 @@ var WebSocket = class extends Client {
|
|
|
395
381
|
*/
|
|
396
382
|
constructor({ sampleRate, container, encoding }, ...args) {
|
|
397
383
|
super(...args);
|
|
398
|
-
|
|
399
|
-
* Generate a unique ID suitable for a streaming context.
|
|
400
|
-
*
|
|
401
|
-
* Not suitable for security purposes or as a primary key, since
|
|
402
|
-
* it lacks the amount of entropy required for those use cases.
|
|
403
|
-
*
|
|
404
|
-
* @returns A unique ID.
|
|
405
|
-
*/
|
|
406
|
-
__privateAdd(this, _generateId);
|
|
384
|
+
__privateAdd(this, _WebSocket_instances);
|
|
407
385
|
__privateAdd(this, _isConnected, false);
|
|
408
|
-
__privateAdd(this, _sampleRate2
|
|
409
|
-
__privateAdd(this, _container2
|
|
410
|
-
__privateAdd(this, _encoding2
|
|
386
|
+
__privateAdd(this, _sampleRate2);
|
|
387
|
+
__privateAdd(this, _container2);
|
|
388
|
+
__privateAdd(this, _encoding2);
|
|
411
389
|
__privateSet(this, _sampleRate2, sampleRate);
|
|
412
390
|
__privateSet(this, _container2, container != null ? container : "raw");
|
|
413
391
|
__privateSet(this, _encoding2, encoding != null ? encoding : "pcm_f32le");
|
|
@@ -429,7 +407,7 @@ var WebSocket = class extends Client {
|
|
|
429
407
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
430
408
|
}
|
|
431
409
|
if (!inputs.context_id) {
|
|
432
|
-
inputs.context_id = __privateMethod(this,
|
|
410
|
+
inputs.context_id = __privateMethod(this, _WebSocket_instances, generateId_fn).call(this);
|
|
433
411
|
}
|
|
434
412
|
if (!inputs.output_format) {
|
|
435
413
|
inputs.output_format = {
|
|
@@ -609,7 +587,15 @@ _isConnected = new WeakMap();
|
|
|
609
587
|
_sampleRate2 = new WeakMap();
|
|
610
588
|
_container2 = new WeakMap();
|
|
611
589
|
_encoding2 = new WeakMap();
|
|
612
|
-
|
|
590
|
+
_WebSocket_instances = new WeakSet();
|
|
591
|
+
/**
|
|
592
|
+
* Generate a unique ID suitable for a streaming context.
|
|
593
|
+
*
|
|
594
|
+
* Not suitable for security purposes or as a primary key, since
|
|
595
|
+
* it lacks the amount of entropy required for those use cases.
|
|
596
|
+
*
|
|
597
|
+
* @returns A unique ID.
|
|
598
|
+
*/
|
|
613
599
|
generateId_fn = function() {
|
|
614
600
|
return (0, import_human_id.humanId)({
|
|
615
601
|
separator: "-",
|
|
@@ -630,6 +616,53 @@ var TTS = class extends Client {
|
|
|
630
616
|
baseUrl: this.baseUrl
|
|
631
617
|
});
|
|
632
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Generate audio bytes from text.
|
|
621
|
+
*
|
|
622
|
+
* @param options - The options for the request.
|
|
623
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
624
|
+
*/
|
|
625
|
+
bytes(options) {
|
|
626
|
+
return __async(this, null, function* () {
|
|
627
|
+
const response = yield this._fetch("/tts/bytes", {
|
|
628
|
+
method: "POST",
|
|
629
|
+
body: JSON.stringify(options)
|
|
630
|
+
});
|
|
631
|
+
return response.arrayBuffer();
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
// src/voice-changer/index.ts
|
|
637
|
+
var VoiceChanger = class extends Client {
|
|
638
|
+
bytes(options) {
|
|
639
|
+
return __async(this, null, function* () {
|
|
640
|
+
const formData = new FormData();
|
|
641
|
+
formData.append("clip", options.clip);
|
|
642
|
+
formData.append("voice[id]", options.voice.id);
|
|
643
|
+
const fmt = options.output_format;
|
|
644
|
+
formData.append("output_format[container]", fmt.container);
|
|
645
|
+
if ("encoding" in fmt) {
|
|
646
|
+
formData.append("output_format[encoding]", fmt.encoding);
|
|
647
|
+
}
|
|
648
|
+
if ("bit_rate" in fmt) {
|
|
649
|
+
formData.append("output_format[bit_rate]", fmt.bit_rate.toString());
|
|
650
|
+
}
|
|
651
|
+
if ("sample_rate" in fmt) {
|
|
652
|
+
formData.append("output_format[sample_rate]", fmt.sample_rate.toString());
|
|
653
|
+
}
|
|
654
|
+
const response = yield this._fetch("/voice-changer/bytes", {
|
|
655
|
+
method: "POST",
|
|
656
|
+
body: formData
|
|
657
|
+
});
|
|
658
|
+
if (!response.ok) {
|
|
659
|
+
throw new Error(
|
|
660
|
+
`Voice changer error! status: ${response.status}, message: ${yield response.text()}`
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
return { buffer: yield response.arrayBuffer() };
|
|
664
|
+
});
|
|
665
|
+
}
|
|
633
666
|
};
|
|
634
667
|
|
|
635
668
|
// src/voices/index.ts
|
|
@@ -707,11 +740,12 @@ var Cartesia = class extends Client {
|
|
|
707
740
|
super(options);
|
|
708
741
|
this.tts = new TTS(options);
|
|
709
742
|
this.voices = new Voices(options);
|
|
743
|
+
this.voiceChanger = new VoiceChanger(options);
|
|
710
744
|
}
|
|
711
745
|
};
|
|
712
746
|
|
|
713
747
|
// src/tts/player.ts
|
|
714
|
-
var _context, _startNextPlaybackAt, _bufferDuration,
|
|
748
|
+
var _context, _startNextPlaybackAt, _bufferDuration, _Player_instances, playBuffer_fn;
|
|
715
749
|
var Player = class {
|
|
716
750
|
/**
|
|
717
751
|
* Create a new Player.
|
|
@@ -720,10 +754,10 @@ var Player = class {
|
|
|
720
754
|
* @param options.bufferDuration - The duration of the audio buffer to play.
|
|
721
755
|
*/
|
|
722
756
|
constructor({ bufferDuration }) {
|
|
723
|
-
__privateAdd(this,
|
|
757
|
+
__privateAdd(this, _Player_instances);
|
|
724
758
|
__privateAdd(this, _context, null);
|
|
725
759
|
__privateAdd(this, _startNextPlaybackAt, 0);
|
|
726
|
-
__privateAdd(this, _bufferDuration
|
|
760
|
+
__privateAdd(this, _bufferDuration);
|
|
727
761
|
__privateSet(this, _bufferDuration, bufferDuration);
|
|
728
762
|
}
|
|
729
763
|
/**
|
|
@@ -743,7 +777,7 @@ var Player = class {
|
|
|
743
777
|
while (true) {
|
|
744
778
|
const read = yield source.read(buffer);
|
|
745
779
|
const playableAudio = buffer.subarray(0, read);
|
|
746
|
-
plays.push(__privateMethod(this,
|
|
780
|
+
plays.push(__privateMethod(this, _Player_instances, playBuffer_fn).call(this, playableAudio, source.sampleRate));
|
|
747
781
|
if (read < buffer.length) {
|
|
748
782
|
break;
|
|
749
783
|
}
|
|
@@ -812,7 +846,7 @@ var Player = class {
|
|
|
812
846
|
_context = new WeakMap();
|
|
813
847
|
_startNextPlaybackAt = new WeakMap();
|
|
814
848
|
_bufferDuration = new WeakMap();
|
|
815
|
-
|
|
849
|
+
_Player_instances = new WeakSet();
|
|
816
850
|
playBuffer_fn = function(buf, sampleRate) {
|
|
817
851
|
return __async(this, null, function* () {
|
|
818
852
|
if (!__privateGet(this, _context)) {
|
package/dist/react/index.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Cartesia
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-QWNB544W.js";
|
|
4
|
+
import "../chunk-WLEVU3HN.js";
|
|
5
|
+
import "../chunk-RJICGVPL.js";
|
|
5
6
|
import {
|
|
6
7
|
pingServer
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
8
|
+
} from "../chunk-LKKWJLUG.js";
|
|
9
|
+
import "../chunk-GLZYI5DM.js";
|
|
10
|
+
import "../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-
|
|
16
|
-
import "../chunk-
|
|
15
|
+
} from "../chunk-CSOXALSC.js";
|
|
16
|
+
import "../chunk-5SBAQNWQ.js";
|
|
17
|
+
import "../chunk-I5YVYTNK.js";
|
|
17
18
|
import {
|
|
18
19
|
__async
|
|
19
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-NJDRWDQ3.js";
|
|
20
21
|
|
|
21
22
|
// src/react/index.ts
|
|
22
23
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|