@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
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
playAudioBuffer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5SBAQNWQ.js";
|
|
4
4
|
import {
|
|
5
5
|
__async,
|
|
6
6
|
__privateAdd,
|
|
7
7
|
__privateGet,
|
|
8
8
|
__privateMethod,
|
|
9
9
|
__privateSet
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NJDRWDQ3.js";
|
|
11
11
|
|
|
12
12
|
// src/tts/player.ts
|
|
13
|
-
var _context, _startNextPlaybackAt, _bufferDuration,
|
|
13
|
+
var _context, _startNextPlaybackAt, _bufferDuration, _Player_instances, playBuffer_fn;
|
|
14
14
|
var Player = class {
|
|
15
15
|
/**
|
|
16
16
|
* Create a new Player.
|
|
@@ -19,10 +19,10 @@ var Player = class {
|
|
|
19
19
|
* @param options.bufferDuration - The duration of the audio buffer to play.
|
|
20
20
|
*/
|
|
21
21
|
constructor({ bufferDuration }) {
|
|
22
|
-
__privateAdd(this,
|
|
22
|
+
__privateAdd(this, _Player_instances);
|
|
23
23
|
__privateAdd(this, _context, null);
|
|
24
24
|
__privateAdd(this, _startNextPlaybackAt, 0);
|
|
25
|
-
__privateAdd(this, _bufferDuration
|
|
25
|
+
__privateAdd(this, _bufferDuration);
|
|
26
26
|
__privateSet(this, _bufferDuration, bufferDuration);
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -42,7 +42,7 @@ var Player = class {
|
|
|
42
42
|
while (true) {
|
|
43
43
|
const read = yield source.read(buffer);
|
|
44
44
|
const playableAudio = buffer.subarray(0, read);
|
|
45
|
-
plays.push(__privateMethod(this,
|
|
45
|
+
plays.push(__privateMethod(this, _Player_instances, playBuffer_fn).call(this, playableAudio, source.sampleRate));
|
|
46
46
|
if (read < buffer.length) {
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
@@ -111,7 +111,7 @@ var Player = class {
|
|
|
111
111
|
_context = new WeakMap();
|
|
112
112
|
_startNextPlaybackAt = new WeakMap();
|
|
113
113
|
_bufferDuration = new WeakMap();
|
|
114
|
-
|
|
114
|
+
_Player_instances = new WeakSet();
|
|
115
115
|
playBuffer_fn = function(buf, sampleRate) {
|
|
116
116
|
return __async(this, null, function* () {
|
|
117
117
|
if (!__privateGet(this, _context)) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WebSocket
|
|
3
|
+
} from "./chunk-WSIVWXEI.js";
|
|
4
|
+
import {
|
|
5
|
+
Client
|
|
6
|
+
} from "./chunk-FLWYXP5Z.js";
|
|
7
|
+
import {
|
|
8
|
+
__async
|
|
9
|
+
} from "./chunk-NJDRWDQ3.js";
|
|
10
|
+
|
|
11
|
+
// src/tts/index.ts
|
|
12
|
+
var TTS = class extends Client {
|
|
13
|
+
/**
|
|
14
|
+
* Get a WebSocket client for streaming audio from the TTS API.
|
|
15
|
+
*
|
|
16
|
+
* @returns {WebSocket} A Cartesia WebSocket client.
|
|
17
|
+
*/
|
|
18
|
+
websocket(options) {
|
|
19
|
+
return new WebSocket(options, {
|
|
20
|
+
apiKey: this.apiKey,
|
|
21
|
+
baseUrl: this.baseUrl
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate audio bytes from text.
|
|
26
|
+
*
|
|
27
|
+
* @param options - The options for the request.
|
|
28
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
29
|
+
*/
|
|
30
|
+
bytes(options) {
|
|
31
|
+
return __async(this, null, function* () {
|
|
32
|
+
const response = yield this._fetch("/tts/bytes", {
|
|
33
|
+
method: "POST",
|
|
34
|
+
body: JSON.stringify(options)
|
|
35
|
+
});
|
|
36
|
+
return response.arrayBuffer();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
TTS
|
|
43
|
+
};
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
__privateGet,
|
|
5
5
|
__privateMethod,
|
|
6
6
|
__privateSet
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NJDRWDQ3.js";
|
|
8
8
|
|
|
9
9
|
// src/tts/source.ts
|
|
10
10
|
import Emittery from "emittery";
|
|
@@ -14,7 +14,7 @@ var ENCODING_MAP = {
|
|
|
14
14
|
pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
|
|
15
15
|
pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
|
|
16
16
|
};
|
|
17
|
-
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container,
|
|
17
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _Source_instances, createBuffer_fn;
|
|
18
18
|
var Source = class {
|
|
19
19
|
/**
|
|
20
20
|
* Create a new Source.
|
|
@@ -27,21 +27,15 @@ var Source = class {
|
|
|
27
27
|
encoding,
|
|
28
28
|
container
|
|
29
29
|
}) {
|
|
30
|
-
|
|
31
|
-
* Create a new buffer for the source.
|
|
32
|
-
*
|
|
33
|
-
* @param size - The size of the buffer to create.
|
|
34
|
-
* @returns The new buffer as a TypedArray based on the encoding.
|
|
35
|
-
*/
|
|
36
|
-
__privateAdd(this, _createBuffer);
|
|
30
|
+
__privateAdd(this, _Source_instances);
|
|
37
31
|
__privateAdd(this, _emitter, new Emittery());
|
|
38
|
-
__privateAdd(this, _buffer
|
|
32
|
+
__privateAdd(this, _buffer);
|
|
39
33
|
__privateAdd(this, _readIndex, 0);
|
|
40
34
|
__privateAdd(this, _writeIndex, 0);
|
|
41
35
|
__privateAdd(this, _closed, false);
|
|
42
|
-
__privateAdd(this, _sampleRate
|
|
43
|
-
__privateAdd(this, _encoding
|
|
44
|
-
__privateAdd(this, _container
|
|
36
|
+
__privateAdd(this, _sampleRate);
|
|
37
|
+
__privateAdd(this, _encoding);
|
|
38
|
+
__privateAdd(this, _container);
|
|
45
39
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
46
40
|
this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
|
|
47
41
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
@@ -49,7 +43,7 @@ var Source = class {
|
|
|
49
43
|
__privateSet(this, _sampleRate, sampleRate);
|
|
50
44
|
__privateSet(this, _encoding, encoding);
|
|
51
45
|
__privateSet(this, _container, container);
|
|
52
|
-
__privateSet(this, _buffer, __privateMethod(this,
|
|
46
|
+
__privateSet(this, _buffer, __privateMethod(this, _Source_instances, createBuffer_fn).call(this, 1024));
|
|
53
47
|
}
|
|
54
48
|
get sampleRate() {
|
|
55
49
|
return __privateGet(this, _sampleRate);
|
|
@@ -73,7 +67,7 @@ var Source = class {
|
|
|
73
67
|
while (newCapacity < requiredCapacity) {
|
|
74
68
|
newCapacity *= 2;
|
|
75
69
|
}
|
|
76
|
-
const newBuffer = __privateMethod(this,
|
|
70
|
+
const newBuffer = __privateMethod(this, _Source_instances, createBuffer_fn).call(this, newCapacity);
|
|
77
71
|
newBuffer.set(__privateGet(this, _buffer));
|
|
78
72
|
__privateSet(this, _buffer, newBuffer);
|
|
79
73
|
}
|
|
@@ -178,7 +172,13 @@ _closed = new WeakMap();
|
|
|
178
172
|
_sampleRate = new WeakMap();
|
|
179
173
|
_encoding = new WeakMap();
|
|
180
174
|
_container = new WeakMap();
|
|
181
|
-
|
|
175
|
+
_Source_instances = new WeakSet();
|
|
176
|
+
/**
|
|
177
|
+
* Create a new buffer for the source.
|
|
178
|
+
*
|
|
179
|
+
* @param size - The size of the buffer to create.
|
|
180
|
+
* @returns The new buffer as a TypedArray based on the encoding.
|
|
181
|
+
*/
|
|
182
182
|
createBuffer_fn = function(size) {
|
|
183
183
|
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
184
184
|
return new ArrayType(size);
|
|
@@ -4,6 +4,9 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
7
10
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
11
|
var __spreadValues = (a, b) => {
|
|
9
12
|
for (var prop in b || (b = {}))
|
|
@@ -17,28 +20,11 @@ var __spreadValues = (a, b) => {
|
|
|
17
20
|
return a;
|
|
18
21
|
};
|
|
19
22
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __accessCheck = (obj, member, msg) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
__accessCheck(obj, member, "read from private field");
|
|
26
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
27
|
-
};
|
|
28
|
-
var __privateAdd = (obj, member, value) => {
|
|
29
|
-
if (member.has(obj))
|
|
30
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
31
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
32
|
-
};
|
|
33
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
34
|
-
__accessCheck(obj, member, "write to private field");
|
|
35
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
36
|
-
return value;
|
|
37
|
-
};
|
|
38
|
-
var __privateMethod = (obj, member, method) => {
|
|
39
|
-
__accessCheck(obj, member, "access private method");
|
|
40
|
-
return method;
|
|
41
|
-
};
|
|
23
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
24
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
25
|
+
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);
|
|
26
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
27
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
42
28
|
var __async = (__this, __arguments, generator) => {
|
|
43
29
|
return new Promise((resolve, reject) => {
|
|
44
30
|
var fulfilled = (value) => {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VoiceChanger
|
|
3
|
+
} from "./chunk-WLEVU3HN.js";
|
|
1
4
|
import {
|
|
2
5
|
Voices
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-RJICGVPL.js";
|
|
4
7
|
import {
|
|
5
8
|
TTS
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-GLZYI5DM.js";
|
|
7
10
|
import {
|
|
8
11
|
Client
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-FLWYXP5Z.js";
|
|
10
13
|
|
|
11
14
|
// src/lib/index.ts
|
|
12
15
|
var Cartesia = class extends Client {
|
|
@@ -14,6 +17,7 @@ var Cartesia = class extends Client {
|
|
|
14
17
|
super(options);
|
|
15
18
|
this.tts = new TTS(options);
|
|
16
19
|
this.voices = new Voices(options);
|
|
20
|
+
this.voiceChanger = new VoiceChanger(options);
|
|
17
21
|
}
|
|
18
22
|
};
|
|
19
23
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Client
|
|
3
|
+
} from "./chunk-FLWYXP5Z.js";
|
|
4
|
+
import {
|
|
5
|
+
__async
|
|
6
|
+
} from "./chunk-NJDRWDQ3.js";
|
|
7
|
+
|
|
8
|
+
// src/voice-changer/index.ts
|
|
9
|
+
var VoiceChanger = class extends Client {
|
|
10
|
+
bytes(options) {
|
|
11
|
+
return __async(this, null, function* () {
|
|
12
|
+
const formData = new FormData();
|
|
13
|
+
formData.append("clip", options.clip);
|
|
14
|
+
formData.append("voice[id]", options.voice.id);
|
|
15
|
+
const fmt = options.output_format;
|
|
16
|
+
formData.append("output_format[container]", fmt.container);
|
|
17
|
+
if ("encoding" in fmt) {
|
|
18
|
+
formData.append("output_format[encoding]", fmt.encoding);
|
|
19
|
+
}
|
|
20
|
+
if ("bit_rate" in fmt) {
|
|
21
|
+
formData.append("output_format[bit_rate]", fmt.bit_rate.toString());
|
|
22
|
+
}
|
|
23
|
+
if ("sample_rate" in fmt) {
|
|
24
|
+
formData.append("output_format[sample_rate]", fmt.sample_rate.toString());
|
|
25
|
+
}
|
|
26
|
+
const response = yield this._fetch("/voice-changer/bytes", {
|
|
27
|
+
method: "POST",
|
|
28
|
+
body: formData
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Voice changer error! status: ${response.status}, message: ${yield response.text()}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return { buffer: yield response.arrayBuffer() };
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
VoiceChanger
|
|
42
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Client
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FLWYXP5Z.js";
|
|
4
4
|
import {
|
|
5
5
|
CARTESIA_VERSION,
|
|
6
6
|
constructApiUrl
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
createMessageHandlerForContextId,
|
|
11
11
|
getEmitteryCallbacks,
|
|
12
12
|
isSentinel
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-5SBAQNWQ.js";
|
|
14
14
|
import {
|
|
15
15
|
Source
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-I5YVYTNK.js";
|
|
17
17
|
import {
|
|
18
18
|
__async,
|
|
19
19
|
__privateAdd,
|
|
@@ -22,13 +22,13 @@ import {
|
|
|
22
22
|
__privateSet,
|
|
23
23
|
__spreadProps,
|
|
24
24
|
__spreadValues
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-NJDRWDQ3.js";
|
|
26
26
|
|
|
27
27
|
// src/tts/websocket.ts
|
|
28
28
|
import Emittery from "emittery";
|
|
29
29
|
import { humanId } from "human-id";
|
|
30
30
|
import { WebSocket as PartySocketWebSocket } from "partysocket";
|
|
31
|
-
var _isConnected, _sampleRate, _container, _encoding,
|
|
31
|
+
var _isConnected, _sampleRate, _container, _encoding, _WebSocket_instances, generateId_fn;
|
|
32
32
|
var WebSocket = class extends Client {
|
|
33
33
|
/**
|
|
34
34
|
* Create a new WebSocket client.
|
|
@@ -37,19 +37,11 @@ var WebSocket = class extends Client {
|
|
|
37
37
|
*/
|
|
38
38
|
constructor({ sampleRate, container, encoding }, ...args) {
|
|
39
39
|
super(...args);
|
|
40
|
-
|
|
41
|
-
* Generate a unique ID suitable for a streaming context.
|
|
42
|
-
*
|
|
43
|
-
* Not suitable for security purposes or as a primary key, since
|
|
44
|
-
* it lacks the amount of entropy required for those use cases.
|
|
45
|
-
*
|
|
46
|
-
* @returns A unique ID.
|
|
47
|
-
*/
|
|
48
|
-
__privateAdd(this, _generateId);
|
|
40
|
+
__privateAdd(this, _WebSocket_instances);
|
|
49
41
|
__privateAdd(this, _isConnected, false);
|
|
50
|
-
__privateAdd(this, _sampleRate
|
|
51
|
-
__privateAdd(this, _container
|
|
52
|
-
__privateAdd(this, _encoding
|
|
42
|
+
__privateAdd(this, _sampleRate);
|
|
43
|
+
__privateAdd(this, _container);
|
|
44
|
+
__privateAdd(this, _encoding);
|
|
53
45
|
__privateSet(this, _sampleRate, sampleRate);
|
|
54
46
|
__privateSet(this, _container, container != null ? container : "raw");
|
|
55
47
|
__privateSet(this, _encoding, encoding != null ? encoding : "pcm_f32le");
|
|
@@ -71,7 +63,7 @@ var WebSocket = class extends Client {
|
|
|
71
63
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
72
64
|
}
|
|
73
65
|
if (!inputs.context_id) {
|
|
74
|
-
inputs.context_id = __privateMethod(this,
|
|
66
|
+
inputs.context_id = __privateMethod(this, _WebSocket_instances, generateId_fn).call(this);
|
|
75
67
|
}
|
|
76
68
|
if (!inputs.output_format) {
|
|
77
69
|
inputs.output_format = {
|
|
@@ -251,7 +243,15 @@ _isConnected = new WeakMap();
|
|
|
251
243
|
_sampleRate = new WeakMap();
|
|
252
244
|
_container = new WeakMap();
|
|
253
245
|
_encoding = new WeakMap();
|
|
254
|
-
|
|
246
|
+
_WebSocket_instances = new WeakSet();
|
|
247
|
+
/**
|
|
248
|
+
* Generate a unique ID suitable for a streaming context.
|
|
249
|
+
*
|
|
250
|
+
* Not suitable for security purposes or as a primary key, since
|
|
251
|
+
* it lacks the amount of entropy required for those use cases.
|
|
252
|
+
*
|
|
253
|
+
* @returns A unique ID.
|
|
254
|
+
*/
|
|
255
255
|
generateId_fn = function() {
|
|
256
256
|
return humanId({
|
|
257
257
|
separator: "-",
|
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)) {
|