@cartesia/cartesia-js 1.0.3 → 1.1.0
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/.turbo/turbo-build.log +34 -34
- package/CHANGELOG.md +6 -0
- package/README.md +32 -3
- package/dist/{chunk-NQVZNVOU.js → chunk-3FL2SNIR.js} +1 -1
- package/dist/{chunk-ZF6HASZT.js → chunk-4GEDAGVY.js} +3 -3
- package/dist/{chunk-PISCPZK4.js → chunk-6PWLZAMS.js} +1 -1
- package/dist/{chunk-YFN6TFR4.js → chunk-CWIJUBG6.js} +12 -4
- package/dist/{chunk-EUW2435M.js → chunk-L3OMQKWL.js} +34 -10
- package/dist/{chunk-LZO6K34D.js → chunk-MNOPO7G6.js} +2 -2
- package/dist/{chunk-NWCW6C7H.js → chunk-MUPVAEL7.js} +2 -2
- package/dist/{chunk-BHY7MNGT.js → chunk-VCZESWYA.js} +1 -1
- package/dist/{chunk-6YQ6KDIQ.js → chunk-VVDJR3OA.js} +32 -1
- package/dist/{chunk-GHY2WEOK.js → chunk-WIFMLPT5.js} +0 -13
- package/dist/index.cjs +71 -19
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +71 -19
- package/dist/lib/index.js +8 -8
- package/dist/react/index.cjs +74 -19
- package/dist/react/index.js +13 -10
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +61 -17
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.js +4 -4
- package/dist/tts/source.cjs +31 -0
- 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 +61 -17
- package/dist/tts/websocket.d.cts +9 -3
- package/dist/tts/websocket.d.ts +9 -3
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +18 -3
- package/dist/types/index.d.ts +18 -3
- 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 +1 -1
- package/src/react/index.ts +4 -0
- package/src/tts/source.ts +35 -0
- package/src/tts/websocket.ts +33 -2
- package/src/types/index.ts +29 -2
- package/src/voices/index.ts +12 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -5,49 +5,49 @@ $ tsup src/ --format cjs,esm --dts
|
|
|
5
5
|
[34mCLI[39m Target: es6
|
|
6
6
|
[34mCJS[39m Build start
|
|
7
7
|
[34mESM[39m Build start
|
|
8
|
-
[32mESM[39m [1mdist/chunk-FXPGR372.js [22m[32m0 B[39m
|
|
9
8
|
[32mESM[39m [1mdist/index.js [22m[32m499.00 B[39m
|
|
9
|
+
[32mESM[39m [1mdist/chunk-FXPGR372.js [22m[32m0 B[39m
|
|
10
10
|
[32mESM[39m [1mdist/lib/client.js [22m[32m132.00 B[39m
|
|
11
|
-
[32mESM[39m [1mdist/react/index.js [22m[32m7.
|
|
11
|
+
[32mESM[39m [1mdist/react/index.js [22m[32m7.73 KB[39m
|
|
12
12
|
[32mESM[39m [1mdist/tts/index.js [22m[32m261.00 B[39m
|
|
13
13
|
[32mESM[39m [1mdist/lib/constants.js [22m[32m183.00 B[39m
|
|
14
14
|
[32mESM[39m [1mdist/lib/index.js [22m[32m322.00 B[39m
|
|
15
|
-
[32mESM[39m [1mdist/chunk-
|
|
16
|
-
[32mESM[39m [1mdist/chunk-YFN6TFR4.js [22m[32m1.74 KB[39m
|
|
15
|
+
[32mESM[39m [1mdist/chunk-4GEDAGVY.js [22m[32m353.00 B[39m
|
|
17
16
|
[32mESM[39m [1mdist/react/utils.js [22m[32m109.00 B[39m
|
|
18
|
-
[32mESM[39m [1mdist/chunk-
|
|
19
|
-
[32mESM[39m [1mdist/chunk-
|
|
20
|
-
[32mESM[39m [1mdist/chunk-
|
|
21
|
-
[32mESM[39m [1mdist/chunk-
|
|
17
|
+
[32mESM[39m [1mdist/chunk-CWIJUBG6.js [22m[32m1.95 KB[39m
|
|
18
|
+
[32mESM[39m [1mdist/chunk-3FL2SNIR.js [22m[32m337.00 B[39m
|
|
19
|
+
[32mESM[39m [1mdist/chunk-MUPVAEL7.js [22m[32m439.00 B[39m
|
|
20
|
+
[32mESM[39m [1mdist/chunk-L3OMQKWL.js [22m[32m7.95 KB[39m
|
|
21
|
+
[32mESM[39m [1mdist/chunk-6PWLZAMS.js [22m[32m1.02 KB[39m
|
|
22
22
|
[32mESM[39m [1mdist/chunk-2BFEKY3F.js [22m[32m366.00 B[39m
|
|
23
23
|
[32mESM[39m [1mdist/tts/player.js [22m[32m174.00 B[39m
|
|
24
|
-
[32mESM[39m [1mdist/chunk-
|
|
25
|
-
[32mESM[39m [1mdist/chunk-
|
|
26
|
-
[32mESM[39m [1mdist/chunk-
|
|
27
|
-
[32mESM[39m [1mdist/chunk-
|
|
28
|
-
[32mESM[39m [1mdist/voices/index.js [22m[32m174.00 B[39m
|
|
24
|
+
[32mESM[39m [1mdist/chunk-MNOPO7G6.js [22m[32m3.76 KB[39m
|
|
25
|
+
[32mESM[39m [1mdist/chunk-VVDJR3OA.js [22m[32m6.20 KB[39m
|
|
26
|
+
[32mESM[39m [1mdist/chunk-VCZESWYA.js [22m[32m2.11 KB[39m
|
|
27
|
+
[32mESM[39m [1mdist/chunk-WIFMLPT5.js [22m[32m2.27 KB[39m
|
|
29
28
|
[32mESM[39m [1mdist/types/index.js [22m[32m31.00 B[39m
|
|
29
|
+
[32mESM[39m [1mdist/voices/index.js [22m[32m174.00 B[39m
|
|
30
30
|
[32mESM[39m [1mdist/tts/source.js [22m[32m144.00 B[39m
|
|
31
31
|
[32mESM[39m [1mdist/tts/utils.js [22m[32m426.00 B[39m
|
|
32
32
|
[32mESM[39m [1mdist/tts/websocket.js [22m[32m242.00 B[39m
|
|
33
|
-
[32mESM[39m ⚡️ Build success in
|
|
34
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
33
|
+
[32mESM[39m ⚡️ Build success in 134ms
|
|
34
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m26.45 KB[39m
|
|
35
35
|
[32mCJS[39m [1mdist/lib/client.cjs [22m[32m4.07 KB[39m
|
|
36
36
|
[32mCJS[39m [1mdist/lib/constants.cjs [22m[32m1.43 KB[39m
|
|
37
|
-
[32mCJS[39m [1mdist/lib/index.cjs [22m[
|
|
38
|
-
[32mCJS[39m [1mdist/react/index.cjs [22m[
|
|
39
|
-
[32mCJS[39m [1mdist/
|
|
40
|
-
[32mCJS[39m [1mdist/tts/index.cjs [22m[32m18.96 KB[39m
|
|
37
|
+
[32mCJS[39m [1mdist/lib/index.cjs [22m[32m22.35 KB[39m
|
|
38
|
+
[32mCJS[39m [1mdist/react/index.cjs [22m[32m34.12 KB[39m
|
|
39
|
+
[32mCJS[39m [1mdist/tts/index.cjs [22m[32m20.23 KB[39m
|
|
41
40
|
[32mCJS[39m [1mdist/tts/player.cjs [22m[32m6.96 KB[39m
|
|
41
|
+
[32mCJS[39m [1mdist/react/utils.cjs [22m[32m1.80 KB[39m
|
|
42
42
|
[32mCJS[39m [1mdist/tts/utils.cjs [22m[32m4.33 KB[39m
|
|
43
|
-
[32mCJS[39m [1mdist/tts/source.cjs [22m[
|
|
43
|
+
[32mCJS[39m [1mdist/tts/source.cjs [22m[32m9.03 KB[39m
|
|
44
44
|
[32mCJS[39m [1mdist/types/index.cjs [22m[32m764.00 B[39m
|
|
45
|
-
[32mCJS[39m [1mdist/tts/websocket.cjs [22m[
|
|
46
|
-
[32mCJS[39m [1mdist/voices/index.cjs [22m[32m5.
|
|
47
|
-
[32mCJS[39m ⚡️ Build success in
|
|
45
|
+
[32mCJS[39m [1mdist/tts/websocket.cjs [22m[32m19.92 KB[39m
|
|
46
|
+
[32mCJS[39m [1mdist/voices/index.cjs [22m[32m5.83 KB[39m
|
|
47
|
+
[32mCJS[39m ⚡️ Build success in 142ms
|
|
48
48
|
[34mDTS[39m Build start
|
|
49
|
-
[32mDTS[39m ⚡️ Build success in
|
|
50
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[
|
|
49
|
+
[32mDTS[39m ⚡️ Build success in 7238ms
|
|
50
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m928.00 B[39m
|
|
51
51
|
[32mDTS[39m [1mdist/lib/constants.d.cts [22m[32m564.00 B[39m
|
|
52
52
|
[32mDTS[39m [1mdist/lib/index.d.cts [22m[32m410.00 B[39m
|
|
53
53
|
[32mDTS[39m [1mdist/react/index.d.cts [22m[32m1.09 KB[39m
|
|
@@ -55,12 +55,12 @@ $ tsup src/ --format cjs,esm --dts
|
|
|
55
55
|
[32mDTS[39m [1mdist/tts/index.d.cts [22m[32m471.00 B[39m
|
|
56
56
|
[32mDTS[39m [1mdist/tts/player.d.cts [22m[32m1.20 KB[39m
|
|
57
57
|
[32mDTS[39m [1mdist/tts/utils.d.cts [22m[32m2.68 KB[39m
|
|
58
|
-
[32mDTS[39m [1mdist/tts/websocket.d.cts [22m[
|
|
59
|
-
[32mDTS[39m [1mdist/tts/source.d.cts [22m[32m2.
|
|
60
|
-
[32mDTS[39m [1mdist/voices/index.d.cts [22m[
|
|
58
|
+
[32mDTS[39m [1mdist/tts/websocket.d.cts [22m[32m3.21 KB[39m
|
|
59
|
+
[32mDTS[39m [1mdist/tts/source.d.cts [22m[32m2.86 KB[39m
|
|
60
|
+
[32mDTS[39m [1mdist/voices/index.d.cts [22m[32m675.00 B[39m
|
|
61
61
|
[32mDTS[39m [1mdist/lib/client.d.cts [22m[32m293.00 B[39m
|
|
62
|
-
[32mDTS[39m [1mdist/types/index.d.cts [22m[32m3.
|
|
63
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
62
|
+
[32mDTS[39m [1mdist/types/index.d.cts [22m[32m3.96 KB[39m
|
|
63
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m920.00 B[39m
|
|
64
64
|
[32mDTS[39m [1mdist/lib/constants.d.ts [22m[32m564.00 B[39m
|
|
65
65
|
[32mDTS[39m [1mdist/lib/index.d.ts [22m[32m404.00 B[39m
|
|
66
66
|
[32mDTS[39m [1mdist/react/index.d.ts [22m[32m1.09 KB[39m
|
|
@@ -68,8 +68,8 @@ $ tsup src/ --format cjs,esm --dts
|
|
|
68
68
|
[32mDTS[39m [1mdist/tts/index.d.ts [22m[32m467.00 B[39m
|
|
69
69
|
[32mDTS[39m [1mdist/tts/player.d.ts [22m[32m1.20 KB[39m
|
|
70
70
|
[32mDTS[39m [1mdist/tts/utils.d.ts [22m[32m2.68 KB[39m
|
|
71
|
-
[32mDTS[39m [1mdist/tts/websocket.d.ts [22m[
|
|
72
|
-
[32mDTS[39m [1mdist/tts/source.d.ts [22m[32m2.
|
|
73
|
-
[32mDTS[39m [1mdist/voices/index.d.ts [22m[
|
|
71
|
+
[32mDTS[39m [1mdist/tts/websocket.d.ts [22m[32m3.20 KB[39m
|
|
72
|
+
[32mDTS[39m [1mdist/tts/source.d.ts [22m[32m2.86 KB[39m
|
|
73
|
+
[32mDTS[39m [1mdist/voices/index.d.ts [22m[32m673.00 B[39m
|
|
74
74
|
[32mDTS[39m [1mdist/lib/client.d.ts [22m[32m292.00 B[39m
|
|
75
|
-
[32mDTS[39m [1mdist/types/index.d.ts [22m[32m3.
|
|
75
|
+
[32mDTS[39m [1mdist/types/index.d.ts [22m[32m3.96 KB[39m
|
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,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Voices
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CWIJUBG6.js";
|
|
4
4
|
import {
|
|
5
5
|
TTS
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MUPVAEL7.js";
|
|
7
7
|
import {
|
|
8
8
|
Client
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-6PWLZAMS.js";
|
|
10
10
|
|
|
11
11
|
// src/lib/index.ts
|
|
12
12
|
var Cartesia = class extends Client {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Client
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6PWLZAMS.js";
|
|
4
4
|
import {
|
|
5
5
|
__async
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WIFMLPT5.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
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Client
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6PWLZAMS.js";
|
|
4
4
|
import {
|
|
5
5
|
CARTESIA_VERSION,
|
|
6
6
|
constructApiUrl
|
|
@@ -10,20 +10,19 @@ import {
|
|
|
10
10
|
createMessageHandlerForContextId,
|
|
11
11
|
getEmitteryCallbacks,
|
|
12
12
|
isSentinel
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-VCZESWYA.js";
|
|
14
14
|
import {
|
|
15
15
|
Source
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-VVDJR3OA.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-WIFMLPT5.js";
|
|
27
26
|
|
|
28
27
|
// src/tts/websocket.ts
|
|
29
28
|
import Emittery from "emittery";
|
|
@@ -58,7 +57,7 @@ var WebSocket = class extends Client {
|
|
|
58
57
|
/**
|
|
59
58
|
* Send a message over the WebSocket to start a stream.
|
|
60
59
|
*
|
|
61
|
-
* @param inputs -
|
|
60
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type.
|
|
62
61
|
* @param options - Options for the stream.
|
|
63
62
|
* @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
|
|
64
63
|
* If set to `0`, the stream will not time out.
|
|
@@ -66,9 +65,8 @@ var WebSocket = class extends Client {
|
|
|
66
65
|
* @returns An Emittery instance that emits messages from the WebSocket.
|
|
67
66
|
* @returns An abort function that can be called to cancel the stream.
|
|
68
67
|
*/
|
|
69
|
-
send(
|
|
70
|
-
var
|
|
71
|
-
var _a2, _b, _c, _d;
|
|
68
|
+
send(inputs, { timeout = 0 } = {}) {
|
|
69
|
+
var _a, _b, _c, _d;
|
|
72
70
|
if (!__privateGet(this, _isConnected)) {
|
|
73
71
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
74
72
|
}
|
|
@@ -82,7 +80,7 @@ var WebSocket = class extends Client {
|
|
|
82
80
|
sample_rate: __privateGet(this, _sampleRate)
|
|
83
81
|
};
|
|
84
82
|
}
|
|
85
|
-
(
|
|
83
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
86
84
|
JSON.stringify(__spreadValues({}, inputs))
|
|
87
85
|
);
|
|
88
86
|
const emitter = new Emittery();
|
|
@@ -152,6 +150,32 @@ var WebSocket = class extends Client {
|
|
|
152
150
|
stop: streamCompleteController.abort.bind(streamCompleteController)
|
|
153
151
|
});
|
|
154
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Continue a stream.
|
|
155
|
+
*
|
|
156
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
|
|
157
|
+
*/
|
|
158
|
+
continue(inputs) {
|
|
159
|
+
var _a;
|
|
160
|
+
if (!__privateGet(this, _isConnected)) {
|
|
161
|
+
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
162
|
+
}
|
|
163
|
+
if (!inputs.context_id) {
|
|
164
|
+
throw new Error("context_id is required to continue a context.");
|
|
165
|
+
}
|
|
166
|
+
if (!inputs.output_format) {
|
|
167
|
+
inputs.output_format = {
|
|
168
|
+
container: __privateGet(this, _container),
|
|
169
|
+
encoding: __privateGet(this, _encoding),
|
|
170
|
+
sample_rate: __privateGet(this, _sampleRate)
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
174
|
+
JSON.stringify(__spreadValues({
|
|
175
|
+
continue: true
|
|
176
|
+
}, inputs))
|
|
177
|
+
);
|
|
178
|
+
}
|
|
155
179
|
/**
|
|
156
180
|
* Authenticate and connect to a Cartesia streaming WebSocket.
|
|
157
181
|
*
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
playAudioBuffer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VCZESWYA.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-WIFMLPT5.js";
|
|
11
11
|
|
|
12
12
|
// src/tts/player.ts
|
|
13
13
|
var _context, _startNextPlaybackAt, _bufferDuration, _playBuffer, playBuffer_fn;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
__privateGet,
|
|
5
5
|
__privateMethod,
|
|
6
6
|
__privateSet
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-WIFMLPT5.js";
|
|
8
8
|
|
|
9
9
|
// src/tts/source.ts
|
|
10
10
|
import Emittery from "emittery";
|
|
@@ -106,6 +106,37 @@ var Source = class {
|
|
|
106
106
|
return read;
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Seek in the buffer.
|
|
111
|
+
*
|
|
112
|
+
* @param offset The offset to seek to.
|
|
113
|
+
* @param whence The position to seek from.
|
|
114
|
+
* @returns The new position in the buffer.
|
|
115
|
+
* @throws {Error} If the seek is invalid.
|
|
116
|
+
*/
|
|
117
|
+
seek(offset, whence) {
|
|
118
|
+
return __async(this, null, function* () {
|
|
119
|
+
let position = __privateGet(this, _readIndex);
|
|
120
|
+
switch (whence) {
|
|
121
|
+
case "start":
|
|
122
|
+
position = offset;
|
|
123
|
+
break;
|
|
124
|
+
case "current":
|
|
125
|
+
position += offset;
|
|
126
|
+
break;
|
|
127
|
+
case "end":
|
|
128
|
+
position = __privateGet(this, _writeIndex) + offset;
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
throw new Error(`Invalid seek mode: ${whence}`);
|
|
132
|
+
}
|
|
133
|
+
if (position < 0 || position > __privateGet(this, _writeIndex)) {
|
|
134
|
+
throw new Error("Seek out of bounds");
|
|
135
|
+
}
|
|
136
|
+
__privateSet(this, _readIndex, position);
|
|
137
|
+
return position;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
109
140
|
/**
|
|
110
141
|
* Get the number of samples in a given duration.
|
|
111
142
|
*
|
|
@@ -17,18 +17,6 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
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
20
|
var __accessCheck = (obj, member, msg) => {
|
|
33
21
|
if (!member.has(obj))
|
|
34
22
|
throw TypeError("Cannot " + msg);
|
|
@@ -75,7 +63,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
75
63
|
export {
|
|
76
64
|
__spreadValues,
|
|
77
65
|
__spreadProps,
|
|
78
|
-
__objRest,
|
|
79
66
|
__privateGet,
|
|
80
67
|
__privateAdd,
|
|
81
68
|
__privateSet,
|
package/dist/index.cjs
CHANGED
|
@@ -22,18 +22,6 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
25
|
var __export = (target, all) => {
|
|
38
26
|
for (var name in all)
|
|
39
27
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -253,6 +241,37 @@ var Source = class {
|
|
|
253
241
|
return read;
|
|
254
242
|
});
|
|
255
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Seek in the buffer.
|
|
246
|
+
*
|
|
247
|
+
* @param offset The offset to seek to.
|
|
248
|
+
* @param whence The position to seek from.
|
|
249
|
+
* @returns The new position in the buffer.
|
|
250
|
+
* @throws {Error} If the seek is invalid.
|
|
251
|
+
*/
|
|
252
|
+
seek(offset, whence) {
|
|
253
|
+
return __async(this, null, function* () {
|
|
254
|
+
let position = __privateGet(this, _readIndex);
|
|
255
|
+
switch (whence) {
|
|
256
|
+
case "start":
|
|
257
|
+
position = offset;
|
|
258
|
+
break;
|
|
259
|
+
case "current":
|
|
260
|
+
position += offset;
|
|
261
|
+
break;
|
|
262
|
+
case "end":
|
|
263
|
+
position = __privateGet(this, _writeIndex) + offset;
|
|
264
|
+
break;
|
|
265
|
+
default:
|
|
266
|
+
throw new Error(`Invalid seek mode: ${whence}`);
|
|
267
|
+
}
|
|
268
|
+
if (position < 0 || position > __privateGet(this, _writeIndex)) {
|
|
269
|
+
throw new Error("Seek out of bounds");
|
|
270
|
+
}
|
|
271
|
+
__privateSet(this, _readIndex, position);
|
|
272
|
+
return position;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
256
275
|
/**
|
|
257
276
|
* Get the number of samples in a given duration.
|
|
258
277
|
*
|
|
@@ -399,7 +418,7 @@ var WebSocket = class extends Client {
|
|
|
399
418
|
/**
|
|
400
419
|
* Send a message over the WebSocket to start a stream.
|
|
401
420
|
*
|
|
402
|
-
* @param inputs -
|
|
421
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type.
|
|
403
422
|
* @param options - Options for the stream.
|
|
404
423
|
* @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
|
|
405
424
|
* If set to `0`, the stream will not time out.
|
|
@@ -407,9 +426,8 @@ var WebSocket = class extends Client {
|
|
|
407
426
|
* @returns An Emittery instance that emits messages from the WebSocket.
|
|
408
427
|
* @returns An abort function that can be called to cancel the stream.
|
|
409
428
|
*/
|
|
410
|
-
send(
|
|
411
|
-
var
|
|
412
|
-
var _a2, _b, _c, _d;
|
|
429
|
+
send(inputs, { timeout = 0 } = {}) {
|
|
430
|
+
var _a, _b, _c, _d;
|
|
413
431
|
if (!__privateGet(this, _isConnected)) {
|
|
414
432
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
415
433
|
}
|
|
@@ -423,7 +441,7 @@ var WebSocket = class extends Client {
|
|
|
423
441
|
sample_rate: __privateGet(this, _sampleRate2)
|
|
424
442
|
};
|
|
425
443
|
}
|
|
426
|
-
(
|
|
444
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
427
445
|
JSON.stringify(__spreadValues({}, inputs))
|
|
428
446
|
);
|
|
429
447
|
const emitter = new import_emittery2.default();
|
|
@@ -493,6 +511,32 @@ var WebSocket = class extends Client {
|
|
|
493
511
|
stop: streamCompleteController.abort.bind(streamCompleteController)
|
|
494
512
|
});
|
|
495
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Continue a stream.
|
|
516
|
+
*
|
|
517
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
|
|
518
|
+
*/
|
|
519
|
+
continue(inputs) {
|
|
520
|
+
var _a;
|
|
521
|
+
if (!__privateGet(this, _isConnected)) {
|
|
522
|
+
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
523
|
+
}
|
|
524
|
+
if (!inputs.context_id) {
|
|
525
|
+
throw new Error("context_id is required to continue a context.");
|
|
526
|
+
}
|
|
527
|
+
if (!inputs.output_format) {
|
|
528
|
+
inputs.output_format = {
|
|
529
|
+
container: __privateGet(this, _container2),
|
|
530
|
+
encoding: __privateGet(this, _encoding2),
|
|
531
|
+
sample_rate: __privateGet(this, _sampleRate2)
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
535
|
+
JSON.stringify(__spreadValues({
|
|
536
|
+
continue: true
|
|
537
|
+
}, inputs))
|
|
538
|
+
);
|
|
539
|
+
}
|
|
496
540
|
/**
|
|
497
541
|
* Authenticate and connect to a Cartesia streaming WebSocket.
|
|
498
542
|
*
|
|
@@ -642,10 +686,18 @@ var Voices = class extends Client {
|
|
|
642
686
|
}
|
|
643
687
|
mix(options) {
|
|
644
688
|
return __async(this, null, function* () {
|
|
645
|
-
const request = options;
|
|
646
689
|
const response = yield this._fetch("/voices/mix", {
|
|
647
690
|
method: "POST",
|
|
648
|
-
body: JSON.stringify(
|
|
691
|
+
body: JSON.stringify(options)
|
|
692
|
+
});
|
|
693
|
+
return response.json();
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
localize(options) {
|
|
697
|
+
return __async(this, null, function* () {
|
|
698
|
+
const response = yield this._fetch("/voices/localize", {
|
|
699
|
+
method: "POST",
|
|
700
|
+
body: JSON.stringify(options)
|
|
649
701
|
});
|
|
650
702
|
return response.json();
|
|
651
703
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Cartesia, Cartesia as default } from './lib/index.cjs';
|
|
2
|
-
export { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps } from './types/index.cjs';
|
|
2
|
+
export { 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';
|
|
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';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Cartesia, Cartesia as default } from './lib/index.js';
|
|
2
|
-
export { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps } from './types/index.js';
|
|
2
|
+
export { 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';
|
|
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';
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import "./chunk-FXPGR372.js";
|
|
2
2
|
import {
|
|
3
3
|
Cartesia
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-4GEDAGVY.js";
|
|
5
|
+
import "./chunk-CWIJUBG6.js";
|
|
6
|
+
import "./chunk-MUPVAEL7.js";
|
|
7
7
|
import {
|
|
8
8
|
WebSocket
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-L3OMQKWL.js";
|
|
10
|
+
import "./chunk-6PWLZAMS.js";
|
|
11
11
|
import "./chunk-2BFEKY3F.js";
|
|
12
12
|
import {
|
|
13
13
|
Player
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-MNOPO7G6.js";
|
|
15
|
+
import "./chunk-VCZESWYA.js";
|
|
16
16
|
import {
|
|
17
17
|
Source
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-VVDJR3OA.js";
|
|
19
|
+
import "./chunk-WIFMLPT5.js";
|
|
20
20
|
export {
|
|
21
21
|
Cartesia,
|
|
22
22
|
Source,
|
package/dist/lib/client.js
CHANGED