@cartesia/cartesia-js 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-VCZESWYA.js → chunk-5SBAQNWQ.js} +1 -1
- package/dist/{chunk-MNOPO7G6.js → chunk-CSOXALSC.js} +7 -7
- package/dist/chunk-EYRYHK3X.js +43 -0
- package/dist/{chunk-6PWLZAMS.js → chunk-FLWYXP5Z.js} +1 -1
- package/dist/{chunk-L3OMQKWL.js → chunk-HQOC2S6C.js} +25 -25
- package/dist/{chunk-VVDJR3OA.js → chunk-I5YVYTNK.js} +16 -16
- package/dist/{chunk-3FL2SNIR.js → chunk-LKKWJLUG.js} +1 -1
- package/dist/{chunk-WIFMLPT5.js → chunk-NJDRWDQ3.js} +8 -22
- package/dist/{chunk-CWIJUBG6.js → chunk-RJICGVPL.js} +2 -2
- package/dist/chunk-WLEVU3HN.js +42 -0
- package/dist/{chunk-4GEDAGVY.js → chunk-YUGIYUMT.js} +8 -4
- package/dist/index.cjs +91 -57
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +14 -13
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +86 -52
- package/dist/lib/index.d.cts +2 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +9 -8
- package/dist/react/index.cjs +91 -57
- package/dist/react/index.js +13 -12
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +53 -52
- package/dist/tts/index.d.cts +8 -1
- package/dist/tts/index.d.ts +8 -1
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.cjs +13 -27
- package/dist/tts/player.js +4 -4
- package/dist/tts/source.cjs +23 -37
- package/dist/tts/source.js +2 -2
- package/dist/tts/utils.js +3 -3
- package/dist/tts/websocket.cjs +38 -52
- package/dist/tts/websocket.d.cts +6 -6
- package/dist/tts/websocket.d.ts +6 -6
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +25 -1
- package/dist/types/index.d.ts +25 -1
- package/dist/voice-changer/index.cjs +143 -0
- package/dist/voice-changer/index.d.cts +9 -0
- package/dist/voice-changer/index.d.ts +9 -0
- package/dist/voice-changer/index.js +9 -0
- package/dist/voices/index.js +3 -3
- package/package.json +10 -17
- package/src/lib/index.ts +3 -0
- package/src/tts/index.ts +16 -1
- package/src/types/index.ts +31 -0
- package/src/voice-changer/index.ts +37 -0
- package/.turbo/turbo-build.log +0 -75
- package/dist/chunk-MUPVAEL7.js +0 -25
- package/tsconfig.json +0 -3
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "Cartesia",
|
|
5
5
|
"url": "https://cartesia.ai"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.1
|
|
7
|
+
"version": "1.2.1",
|
|
8
8
|
"description": "Client for the Cartesia API.",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"module": "./dist/index.js",
|
|
@@ -27,29 +27,22 @@
|
|
|
27
27
|
"cross-fetch": "^4.0.0",
|
|
28
28
|
"emittery": "^1.0.3",
|
|
29
29
|
"human-id": "^4.1.1",
|
|
30
|
-
"partysocket": "^1.0.1"
|
|
30
|
+
"partysocket": "^1.0.1",
|
|
31
|
+
"react": "^18.3.1"
|
|
31
32
|
},
|
|
32
33
|
"publishConfig": {
|
|
33
34
|
"access": "public"
|
|
34
35
|
},
|
|
35
36
|
"scripts": {
|
|
36
37
|
"build": "tsup src/ --format cjs,esm --dts",
|
|
37
|
-
"dev": "bun run build -- --watch"
|
|
38
|
-
|
|
39
|
-
"peerDependencies": {
|
|
40
|
-
"react": "^18.2.0",
|
|
41
|
-
"@types/react": "^18.2.58"
|
|
42
|
-
},
|
|
43
|
-
"peerDependenciesMeta": {
|
|
44
|
-
"react": {
|
|
45
|
-
"optional": true
|
|
46
|
-
},
|
|
47
|
-
"@types/react": {
|
|
48
|
-
"optional": true
|
|
49
|
-
}
|
|
38
|
+
"dev": "bun run build -- --watch",
|
|
39
|
+
"release": "rm -rf dist && bun run build && npm publish"
|
|
50
40
|
},
|
|
51
41
|
"devDependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
42
|
+
"@biomejs/biome": "^1.9.4",
|
|
43
|
+
"@types/node": "^22.7.9",
|
|
44
|
+
"@types/react": "^18.3.12",
|
|
45
|
+
"tsup": "^8.0.2",
|
|
46
|
+
"typescript": "^5.6.3"
|
|
54
47
|
}
|
|
55
48
|
}
|
package/src/lib/index.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import TTS from "../tts";
|
|
2
2
|
import type { ClientOptions } from "../types";
|
|
3
|
+
import VoiceChanger from "../voice-changer";
|
|
3
4
|
import Voices from "../voices";
|
|
4
5
|
import { Client } from "./client";
|
|
5
6
|
|
|
6
7
|
export class Cartesia extends Client {
|
|
7
8
|
tts: TTS;
|
|
8
9
|
voices: Voices;
|
|
10
|
+
voiceChanger: VoiceChanger;
|
|
9
11
|
|
|
10
12
|
constructor(options: ClientOptions = {}) {
|
|
11
13
|
super(options);
|
|
12
14
|
|
|
13
15
|
this.tts = new TTS(options);
|
|
14
16
|
this.voices = new Voices(options);
|
|
17
|
+
this.voiceChanger = new VoiceChanger(options);
|
|
15
18
|
}
|
|
16
19
|
}
|
package/src/tts/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from "../lib/client";
|
|
2
|
-
import type { WebSocketOptions } from "../types";
|
|
2
|
+
import type { BytesRequest, WebSocketOptions } from "../types";
|
|
3
3
|
import WebSocket from "./websocket";
|
|
4
4
|
|
|
5
5
|
export default class TTS extends Client {
|
|
@@ -14,4 +14,19 @@ export default class TTS extends Client {
|
|
|
14
14
|
baseUrl: this.baseUrl,
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generate audio bytes from text.
|
|
20
|
+
*
|
|
21
|
+
* @param options - The options for the request.
|
|
22
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
23
|
+
*/
|
|
24
|
+
async bytes(options: BytesRequest): Promise<ArrayBuffer> {
|
|
25
|
+
const response = await this._fetch("/tts/bytes", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: JSON.stringify(options),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return response.arrayBuffer();
|
|
31
|
+
}
|
|
17
32
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -56,6 +56,11 @@ export type StreamRequest = {
|
|
|
56
56
|
add_timestamps?: boolean;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
export type BytesRequest = Omit<
|
|
60
|
+
StreamRequest,
|
|
61
|
+
"continue" | "add_timestamps" | "context_id"
|
|
62
|
+
>;
|
|
63
|
+
|
|
59
64
|
export type ContinueRequest = StreamRequest & {
|
|
60
65
|
context_id: string;
|
|
61
66
|
};
|
|
@@ -126,6 +131,28 @@ export type CloneOptions =
|
|
|
126
131
|
enhance?: boolean;
|
|
127
132
|
};
|
|
128
133
|
|
|
134
|
+
export type VoiceChangerOptions = {
|
|
135
|
+
clip: File;
|
|
136
|
+
voice: { id: string }; // match VoiceSpecifier shape, but only id is supported for now
|
|
137
|
+
output_format:
|
|
138
|
+
| {
|
|
139
|
+
container: "mp3";
|
|
140
|
+
bit_rate: number;
|
|
141
|
+
sample_rate: number;
|
|
142
|
+
}
|
|
143
|
+
| {
|
|
144
|
+
container: "wav";
|
|
145
|
+
encoding: Encoding;
|
|
146
|
+
sample_rate: number;
|
|
147
|
+
bit_rate: number;
|
|
148
|
+
}
|
|
149
|
+
| {
|
|
150
|
+
container: "raw";
|
|
151
|
+
encoding: Encoding;
|
|
152
|
+
sample_rate: number;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
129
156
|
export type LocalizeOptions = {
|
|
130
157
|
mode: "embedding";
|
|
131
158
|
embedding: number[];
|
|
@@ -167,6 +194,10 @@ export type CloneResponse = {
|
|
|
167
194
|
embedding: number[];
|
|
168
195
|
};
|
|
169
196
|
|
|
197
|
+
export type VoiceChangerBytesResponse = {
|
|
198
|
+
buffer: ArrayBuffer;
|
|
199
|
+
};
|
|
200
|
+
|
|
170
201
|
export type LocalizeResponse = {
|
|
171
202
|
embedding: number[];
|
|
172
203
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Client } from "../lib/client";
|
|
2
|
+
import type { VoiceChangerBytesResponse, VoiceChangerOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export default class VoiceChanger extends Client {
|
|
5
|
+
async bytes(
|
|
6
|
+
options: VoiceChangerOptions,
|
|
7
|
+
): Promise<VoiceChangerBytesResponse> {
|
|
8
|
+
const formData = new FormData();
|
|
9
|
+
formData.append("clip", options.clip); // TODO: handle Blobs that are not Files
|
|
10
|
+
formData.append("voice[id]", options.voice.id);
|
|
11
|
+
|
|
12
|
+
const fmt = options.output_format;
|
|
13
|
+
formData.append("output_format[container]", fmt.container);
|
|
14
|
+
if ("encoding" in fmt) {
|
|
15
|
+
formData.append("output_format[encoding]", fmt.encoding);
|
|
16
|
+
}
|
|
17
|
+
if ("bit_rate" in fmt) {
|
|
18
|
+
formData.append("output_format[bit_rate]", fmt.bit_rate.toString());
|
|
19
|
+
}
|
|
20
|
+
if ("sample_rate" in fmt) {
|
|
21
|
+
formData.append("output_format[sample_rate]", fmt.sample_rate.toString());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const response = await this._fetch("/voice-changer/bytes", {
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: formData,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Voice changer error! status: ${response.status}, message: ${await response.text()}`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { buffer: await response.arrayBuffer() };
|
|
36
|
+
}
|
|
37
|
+
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
$ tsup src/ --format cjs,esm --dts
|
|
2
|
-
[34mCLI[39m Building entry: src/index.ts, src/lib/client.ts, src/lib/constants.ts, src/lib/index.ts, src/react/index.ts, src/react/utils.ts, src/tts/index.ts, src/tts/player.ts, src/tts/source.ts, src/tts/utils.ts, src/tts/websocket.ts, src/types/index.ts, src/voices/index.ts
|
|
3
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
4
|
-
[34mCLI[39m tsup v8.0.2
|
|
5
|
-
[34mCLI[39m Target: es6
|
|
6
|
-
[34mCJS[39m Build start
|
|
7
|
-
[34mESM[39m Build start
|
|
8
|
-
[32mESM[39m [1mdist/index.js [22m[32m499.00 B[39m
|
|
9
|
-
[32mESM[39m [1mdist/chunk-FXPGR372.js [22m[32m0 B[39m
|
|
10
|
-
[32mESM[39m [1mdist/lib/client.js [22m[32m132.00 B[39m
|
|
11
|
-
[32mESM[39m [1mdist/react/index.js [22m[32m7.73 KB[39m
|
|
12
|
-
[32mESM[39m [1mdist/tts/index.js [22m[32m261.00 B[39m
|
|
13
|
-
[32mESM[39m [1mdist/lib/constants.js [22m[32m183.00 B[39m
|
|
14
|
-
[32mESM[39m [1mdist/lib/index.js [22m[32m322.00 B[39m
|
|
15
|
-
[32mESM[39m [1mdist/chunk-4GEDAGVY.js [22m[32m353.00 B[39m
|
|
16
|
-
[32mESM[39m [1mdist/react/utils.js [22m[32m109.00 B[39m
|
|
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
|
-
[32mESM[39m [1mdist/chunk-2BFEKY3F.js [22m[32m366.00 B[39m
|
|
23
|
-
[32mESM[39m [1mdist/tts/player.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
|
|
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
|
-
[32mESM[39m [1mdist/tts/source.js [22m[32m144.00 B[39m
|
|
31
|
-
[32mESM[39m [1mdist/tts/utils.js [22m[32m426.00 B[39m
|
|
32
|
-
[32mESM[39m [1mdist/tts/websocket.js [22m[32m242.00 B[39m
|
|
33
|
-
[32mESM[39m ⚡️ Build success in 134ms
|
|
34
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m26.45 KB[39m
|
|
35
|
-
[32mCJS[39m [1mdist/lib/client.cjs [22m[32m4.07 KB[39m
|
|
36
|
-
[32mCJS[39m [1mdist/lib/constants.cjs [22m[32m1.43 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
|
|
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
|
-
[32mCJS[39m [1mdist/tts/utils.cjs [22m[32m4.33 KB[39m
|
|
43
|
-
[32mCJS[39m [1mdist/tts/source.cjs [22m[32m9.03 KB[39m
|
|
44
|
-
[32mCJS[39m [1mdist/types/index.cjs [22m[32m764.00 B[39m
|
|
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
|
-
[34mDTS[39m Build start
|
|
49
|
-
[32mDTS[39m ⚡️ Build success in 7238ms
|
|
50
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[32m928.00 B[39m
|
|
51
|
-
[32mDTS[39m [1mdist/lib/constants.d.cts [22m[32m564.00 B[39m
|
|
52
|
-
[32mDTS[39m [1mdist/lib/index.d.cts [22m[32m410.00 B[39m
|
|
53
|
-
[32mDTS[39m [1mdist/react/index.d.cts [22m[32m1.09 KB[39m
|
|
54
|
-
[32mDTS[39m [1mdist/react/utils.d.cts [22m[32m240.00 B[39m
|
|
55
|
-
[32mDTS[39m [1mdist/tts/index.d.cts [22m[32m471.00 B[39m
|
|
56
|
-
[32mDTS[39m [1mdist/tts/player.d.cts [22m[32m1.20 KB[39m
|
|
57
|
-
[32mDTS[39m [1mdist/tts/utils.d.cts [22m[32m2.68 KB[39m
|
|
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
|
-
[32mDTS[39m [1mdist/lib/client.d.cts [22m[32m293.00 B[39m
|
|
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
|
-
[32mDTS[39m [1mdist/lib/constants.d.ts [22m[32m564.00 B[39m
|
|
65
|
-
[32mDTS[39m [1mdist/lib/index.d.ts [22m[32m404.00 B[39m
|
|
66
|
-
[32mDTS[39m [1mdist/react/index.d.ts [22m[32m1.09 KB[39m
|
|
67
|
-
[32mDTS[39m [1mdist/react/utils.d.ts [22m[32m240.00 B[39m
|
|
68
|
-
[32mDTS[39m [1mdist/tts/index.d.ts [22m[32m467.00 B[39m
|
|
69
|
-
[32mDTS[39m [1mdist/tts/player.d.ts [22m[32m1.20 KB[39m
|
|
70
|
-
[32mDTS[39m [1mdist/tts/utils.d.ts [22m[32m2.68 KB[39m
|
|
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
|
-
[32mDTS[39m [1mdist/lib/client.d.ts [22m[32m292.00 B[39m
|
|
75
|
-
[32mDTS[39m [1mdist/types/index.d.ts [22m[32m3.96 KB[39m
|
package/dist/chunk-MUPVAEL7.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WebSocket
|
|
3
|
-
} from "./chunk-L3OMQKWL.js";
|
|
4
|
-
import {
|
|
5
|
-
Client
|
|
6
|
-
} from "./chunk-6PWLZAMS.js";
|
|
7
|
-
|
|
8
|
-
// src/tts/index.ts
|
|
9
|
-
var TTS = class extends Client {
|
|
10
|
-
/**
|
|
11
|
-
* Get a WebSocket client for streaming audio from the TTS API.
|
|
12
|
-
*
|
|
13
|
-
* @returns {WebSocket} A Cartesia WebSocket client.
|
|
14
|
-
*/
|
|
15
|
-
websocket(options) {
|
|
16
|
-
return new WebSocket(options, {
|
|
17
|
-
apiKey: this.apiKey,
|
|
18
|
-
baseUrl: this.baseUrl
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
TTS
|
|
25
|
-
};
|
package/tsconfig.json
DELETED