@cartesia/cartesia-js 1.0.3 → 1.2.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +32 -3
- package/dist/{chunk-BHY7MNGT.js → chunk-5SBAQNWQ.js} +1 -1
- package/dist/{chunk-LZO6K34D.js → chunk-CSOXALSC.js} +7 -7
- package/dist/{chunk-PISCPZK4.js → chunk-FLWYXP5Z.js} +1 -1
- package/dist/chunk-GLZYI5DM.js +43 -0
- package/dist/{chunk-6YQ6KDIQ.js → chunk-I5YVYTNK.js} +47 -16
- package/dist/{chunk-NQVZNVOU.js → chunk-LKKWJLUG.js} +1 -1
- package/dist/{chunk-GHY2WEOK.js → chunk-NJDRWDQ3.js} +8 -35
- package/dist/{chunk-ZF6HASZT.js → chunk-QWNB544W.js} +7 -3
- package/dist/{chunk-YFN6TFR4.js → chunk-RJICGVPL.js} +12 -4
- package/dist/chunk-WLEVU3HN.js +42 -0
- package/dist/{chunk-EUW2435M.js → chunk-WSIVWXEI.js} +49 -25
- package/dist/index.cjs +162 -76
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -9
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +157 -71
- package/dist/lib/index.d.cts +2 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +9 -8
- package/dist/react/index.cjs +165 -76
- package/dist/react/index.js +14 -10
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +114 -69
- package/dist/tts/index.d.cts +8 -1
- package/dist/tts/index.d.ts +8 -1
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.cjs +13 -27
- package/dist/tts/player.js +4 -4
- package/dist/tts/source.cjs +54 -37
- package/dist/tts/source.d.cts +9 -0
- package/dist/tts/source.d.ts +9 -0
- package/dist/tts/source.js +2 -2
- package/dist/tts/utils.js +3 -3
- package/dist/tts/websocket.cjs +99 -69
- package/dist/tts/websocket.d.cts +15 -9
- package/dist/tts/websocket.d.ts +15 -9
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +42 -3
- package/dist/types/index.d.ts +42 -3
- package/dist/voice-changer/index.cjs +143 -0
- package/dist/voice-changer/index.d.cts +9 -0
- package/dist/voice-changer/index.d.ts +9 -0
- package/dist/voice-changer/index.js +9 -0
- package/dist/voices/index.cjs +10 -2
- package/dist/voices/index.d.cts +2 -1
- package/dist/voices/index.d.ts +2 -1
- package/dist/voices/index.js +3 -3
- package/package.json +8 -16
- package/src/lib/index.ts +3 -0
- package/src/react/index.ts +4 -0
- package/src/tts/index.ts +16 -1
- package/src/tts/source.ts +35 -0
- package/src/tts/websocket.ts +33 -2
- package/src/types/index.ts +60 -2
- package/src/voice-changer/index.ts +37 -0
- package/src/voices/index.ts +12 -3
- package/.turbo/turbo-build.log +0 -75
- package/dist/chunk-NWCW6C7H.js +0 -25
- package/tsconfig.json +0 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Cartesia JavaScript Client
|
|
2
2
|
|
|
3
3
|

|
|
4
|
-
[](https://discord.gg/
|
|
4
|
+
[](https://discord.gg/cartesia)
|
|
5
5
|
|
|
6
6
|
This client provides convenient access to [Cartesia's TTS models](https://cartesia.ai/). Sonic is the fastest text-to-speech model around—it can generate a second of audio in just 650ms, and it can stream out the first audio chunk in just 135ms. Alongside Sonic, we also offer an extensive prebuilt voice library for a variety of use cases.
|
|
7
7
|
|
|
@@ -63,6 +63,13 @@ const mixedVoiceEmbedding = await cartesia.voices.mix({
|
|
|
63
63
|
voices: [{ id: "<voice-id-1>", weight: 0.6 }, { id: "<voice-id-2>", weight: 0.4 }],
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
// Localize a voice.
|
|
67
|
+
const localizedVoiceEmbedding = await cartesia.voices.localize({
|
|
68
|
+
embedding: Array(192).fill(1.0),
|
|
69
|
+
original_speaker_gender: "female",
|
|
70
|
+
language: "es",
|
|
71
|
+
});
|
|
72
|
+
|
|
66
73
|
// Create a voice.
|
|
67
74
|
const newVoice = await cartesia.voices.create({
|
|
68
75
|
name: "Tim",
|
|
@@ -120,9 +127,31 @@ for await (const message of response.events('message')) {
|
|
|
120
127
|
|
|
121
128
|
#### Input Streaming with Contexts
|
|
122
129
|
|
|
123
|
-
|
|
130
|
+
```js
|
|
131
|
+
const contextOptions = {
|
|
132
|
+
context_id: "my-context",
|
|
133
|
+
model_id: "sonic-english",
|
|
134
|
+
voice: {
|
|
135
|
+
mode: "id",
|
|
136
|
+
id: "a0e99841-438c-4a64-b679-ae501e7d6091",
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Initial request on the context uses websocket.send().
|
|
141
|
+
// This response object will aggregate the results of all the inputs sent on the context.
|
|
142
|
+
const response = await websocket.send({
|
|
143
|
+
...contextOptions,
|
|
144
|
+
transcript: "Hello, world!",
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Subsequent requests on the same context use websocket.continue().
|
|
148
|
+
await websocket.continue({
|
|
149
|
+
...contextOptions,
|
|
150
|
+
transcript: " How are you today?",
|
|
151
|
+
});
|
|
152
|
+
```
|
|
124
153
|
|
|
125
|
-
|
|
154
|
+
See the [input streaming docs](https://docs.cartesia.ai/reference/web-socket/stream-speech/working-with-web-sockets#input-streaming-with-contexts) for more information.
|
|
126
155
|
|
|
127
156
|
#### Timestamps
|
|
128
157
|
|
|
@@ -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
|
}
|
|
@@ -106,6 +100,37 @@ var Source = class {
|
|
|
106
100
|
return read;
|
|
107
101
|
});
|
|
108
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Seek in the buffer.
|
|
105
|
+
*
|
|
106
|
+
* @param offset The offset to seek to.
|
|
107
|
+
* @param whence The position to seek from.
|
|
108
|
+
* @returns The new position in the buffer.
|
|
109
|
+
* @throws {Error} If the seek is invalid.
|
|
110
|
+
*/
|
|
111
|
+
seek(offset, whence) {
|
|
112
|
+
return __async(this, null, function* () {
|
|
113
|
+
let position = __privateGet(this, _readIndex);
|
|
114
|
+
switch (whence) {
|
|
115
|
+
case "start":
|
|
116
|
+
position = offset;
|
|
117
|
+
break;
|
|
118
|
+
case "current":
|
|
119
|
+
position += offset;
|
|
120
|
+
break;
|
|
121
|
+
case "end":
|
|
122
|
+
position = __privateGet(this, _writeIndex) + offset;
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
throw new Error(`Invalid seek mode: ${whence}`);
|
|
126
|
+
}
|
|
127
|
+
if (position < 0 || position > __privateGet(this, _writeIndex)) {
|
|
128
|
+
throw new Error("Seek out of bounds");
|
|
129
|
+
}
|
|
130
|
+
__privateSet(this, _readIndex, position);
|
|
131
|
+
return position;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
109
134
|
/**
|
|
110
135
|
* Get the number of samples in a given duration.
|
|
111
136
|
*
|
|
@@ -147,7 +172,13 @@ _closed = new WeakMap();
|
|
|
147
172
|
_sampleRate = new WeakMap();
|
|
148
173
|
_encoding = new WeakMap();
|
|
149
174
|
_container = new WeakMap();
|
|
150
|
-
|
|
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
|
+
*/
|
|
151
182
|
createBuffer_fn = function(size) {
|
|
152
183
|
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
153
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,40 +20,11 @@ var __spreadValues = (a, b) => {
|
|
|
17
20
|
return a;
|
|
18
21
|
};
|
|
19
22
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
var __accessCheck = (obj, member, msg) => {
|
|
33
|
-
if (!member.has(obj))
|
|
34
|
-
throw TypeError("Cannot " + msg);
|
|
35
|
-
};
|
|
36
|
-
var __privateGet = (obj, member, getter) => {
|
|
37
|
-
__accessCheck(obj, member, "read from private field");
|
|
38
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
39
|
-
};
|
|
40
|
-
var __privateAdd = (obj, member, value) => {
|
|
41
|
-
if (member.has(obj))
|
|
42
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
43
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
44
|
-
};
|
|
45
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
46
|
-
__accessCheck(obj, member, "write to private field");
|
|
47
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
48
|
-
return value;
|
|
49
|
-
};
|
|
50
|
-
var __privateMethod = (obj, member, method) => {
|
|
51
|
-
__accessCheck(obj, member, "access private method");
|
|
52
|
-
return method;
|
|
53
|
-
};
|
|
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);
|
|
54
28
|
var __async = (__this, __arguments, generator) => {
|
|
55
29
|
return new Promise((resolve, reject) => {
|
|
56
30
|
var fulfilled = (value) => {
|
|
@@ -75,7 +49,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
75
49
|
export {
|
|
76
50
|
__spreadValues,
|
|
77
51
|
__spreadProps,
|
|
78
|
-
__objRest,
|
|
79
52
|
__privateGet,
|
|
80
53
|
__privateAdd,
|
|
81
54
|
__privateSet,
|
|
@@ -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
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Client
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FLWYXP5Z.js";
|
|
4
4
|
import {
|
|
5
5
|
__async
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-NJDRWDQ3.js";
|
|
7
7
|
|
|
8
8
|
// src/voices/index.ts
|
|
9
9
|
var Voices = class extends Client {
|
|
@@ -56,10 +56,18 @@ var Voices = class extends Client {
|
|
|
56
56
|
}
|
|
57
57
|
mix(options) {
|
|
58
58
|
return __async(this, null, function* () {
|
|
59
|
-
const request = options;
|
|
60
59
|
const response = yield this._fetch("/voices/mix", {
|
|
61
60
|
method: "POST",
|
|
62
|
-
body: JSON.stringify(
|
|
61
|
+
body: JSON.stringify(options)
|
|
62
|
+
});
|
|
63
|
+
return response.json();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
localize(options) {
|
|
67
|
+
return __async(this, null, function* () {
|
|
68
|
+
const response = yield this._fetch("/voices/localize", {
|
|
69
|
+
method: "POST",
|
|
70
|
+
body: JSON.stringify(options)
|
|
63
71
|
});
|
|
64
72
|
return response.json();
|
|
65
73
|
});
|
|
@@ -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,26 +10,25 @@ 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
|
-
__objRest,
|
|
20
19
|
__privateAdd,
|
|
21
20
|
__privateGet,
|
|
22
21
|
__privateMethod,
|
|
23
22
|
__privateSet,
|
|
24
23
|
__spreadProps,
|
|
25
24
|
__spreadValues
|
|
26
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-NJDRWDQ3.js";
|
|
27
26
|
|
|
28
27
|
// src/tts/websocket.ts
|
|
29
28
|
import Emittery from "emittery";
|
|
30
29
|
import { humanId } from "human-id";
|
|
31
30
|
import { WebSocket as PartySocketWebSocket } from "partysocket";
|
|
32
|
-
var _isConnected, _sampleRate, _container, _encoding,
|
|
31
|
+
var _isConnected, _sampleRate, _container, _encoding, _WebSocket_instances, generateId_fn;
|
|
33
32
|
var WebSocket = class extends Client {
|
|
34
33
|
/**
|
|
35
34
|
* Create a new WebSocket client.
|
|
@@ -38,19 +37,11 @@ var WebSocket = class extends Client {
|
|
|
38
37
|
*/
|
|
39
38
|
constructor({ sampleRate, container, encoding }, ...args) {
|
|
40
39
|
super(...args);
|
|
41
|
-
|
|
42
|
-
* Generate a unique ID suitable for a streaming context.
|
|
43
|
-
*
|
|
44
|
-
* Not suitable for security purposes or as a primary key, since
|
|
45
|
-
* it lacks the amount of entropy required for those use cases.
|
|
46
|
-
*
|
|
47
|
-
* @returns A unique ID.
|
|
48
|
-
*/
|
|
49
|
-
__privateAdd(this, _generateId);
|
|
40
|
+
__privateAdd(this, _WebSocket_instances);
|
|
50
41
|
__privateAdd(this, _isConnected, false);
|
|
51
|
-
__privateAdd(this, _sampleRate
|
|
52
|
-
__privateAdd(this, _container
|
|
53
|
-
__privateAdd(this, _encoding
|
|
42
|
+
__privateAdd(this, _sampleRate);
|
|
43
|
+
__privateAdd(this, _container);
|
|
44
|
+
__privateAdd(this, _encoding);
|
|
54
45
|
__privateSet(this, _sampleRate, sampleRate);
|
|
55
46
|
__privateSet(this, _container, container != null ? container : "raw");
|
|
56
47
|
__privateSet(this, _encoding, encoding != null ? encoding : "pcm_f32le");
|
|
@@ -58,7 +49,7 @@ var WebSocket = class extends Client {
|
|
|
58
49
|
/**
|
|
59
50
|
* Send a message over the WebSocket to start a stream.
|
|
60
51
|
*
|
|
61
|
-
* @param inputs -
|
|
52
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type.
|
|
62
53
|
* @param options - Options for the stream.
|
|
63
54
|
* @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
|
|
64
55
|
* If set to `0`, the stream will not time out.
|
|
@@ -66,14 +57,13 @@ var WebSocket = class extends Client {
|
|
|
66
57
|
* @returns An Emittery instance that emits messages from the WebSocket.
|
|
67
58
|
* @returns An abort function that can be called to cancel the stream.
|
|
68
59
|
*/
|
|
69
|
-
send(
|
|
70
|
-
var
|
|
71
|
-
var _a2, _b, _c, _d;
|
|
60
|
+
send(inputs, { timeout = 0 } = {}) {
|
|
61
|
+
var _a, _b, _c, _d;
|
|
72
62
|
if (!__privateGet(this, _isConnected)) {
|
|
73
63
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
74
64
|
}
|
|
75
65
|
if (!inputs.context_id) {
|
|
76
|
-
inputs.context_id = __privateMethod(this,
|
|
66
|
+
inputs.context_id = __privateMethod(this, _WebSocket_instances, generateId_fn).call(this);
|
|
77
67
|
}
|
|
78
68
|
if (!inputs.output_format) {
|
|
79
69
|
inputs.output_format = {
|
|
@@ -82,7 +72,7 @@ var WebSocket = class extends Client {
|
|
|
82
72
|
sample_rate: __privateGet(this, _sampleRate)
|
|
83
73
|
};
|
|
84
74
|
}
|
|
85
|
-
(
|
|
75
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
86
76
|
JSON.stringify(__spreadValues({}, inputs))
|
|
87
77
|
);
|
|
88
78
|
const emitter = new Emittery();
|
|
@@ -152,6 +142,32 @@ var WebSocket = class extends Client {
|
|
|
152
142
|
stop: streamCompleteController.abort.bind(streamCompleteController)
|
|
153
143
|
});
|
|
154
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Continue a stream.
|
|
147
|
+
*
|
|
148
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
|
|
149
|
+
*/
|
|
150
|
+
continue(inputs) {
|
|
151
|
+
var _a;
|
|
152
|
+
if (!__privateGet(this, _isConnected)) {
|
|
153
|
+
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
154
|
+
}
|
|
155
|
+
if (!inputs.context_id) {
|
|
156
|
+
throw new Error("context_id is required to continue a context.");
|
|
157
|
+
}
|
|
158
|
+
if (!inputs.output_format) {
|
|
159
|
+
inputs.output_format = {
|
|
160
|
+
container: __privateGet(this, _container),
|
|
161
|
+
encoding: __privateGet(this, _encoding),
|
|
162
|
+
sample_rate: __privateGet(this, _sampleRate)
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
166
|
+
JSON.stringify(__spreadValues({
|
|
167
|
+
continue: true
|
|
168
|
+
}, inputs))
|
|
169
|
+
);
|
|
170
|
+
}
|
|
155
171
|
/**
|
|
156
172
|
* Authenticate and connect to a Cartesia streaming WebSocket.
|
|
157
173
|
*
|
|
@@ -227,7 +243,15 @@ _isConnected = new WeakMap();
|
|
|
227
243
|
_sampleRate = new WeakMap();
|
|
228
244
|
_container = new WeakMap();
|
|
229
245
|
_encoding = new WeakMap();
|
|
230
|
-
|
|
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
|
+
*/
|
|
231
255
|
generateId_fn = function() {
|
|
232
256
|
return humanId({
|
|
233
257
|
separator: "-",
|