@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.
Files changed (52) hide show
  1. package/dist/{chunk-VCZESWYA.js → chunk-5SBAQNWQ.js} +1 -1
  2. package/dist/{chunk-MNOPO7G6.js → chunk-CSOXALSC.js} +7 -7
  3. package/dist/chunk-EYRYHK3X.js +43 -0
  4. package/dist/{chunk-6PWLZAMS.js → chunk-FLWYXP5Z.js} +1 -1
  5. package/dist/{chunk-L3OMQKWL.js → chunk-HQOC2S6C.js} +25 -25
  6. package/dist/{chunk-VVDJR3OA.js → chunk-I5YVYTNK.js} +16 -16
  7. package/dist/{chunk-3FL2SNIR.js → chunk-LKKWJLUG.js} +1 -1
  8. package/dist/{chunk-WIFMLPT5.js → chunk-NJDRWDQ3.js} +8 -22
  9. package/dist/{chunk-CWIJUBG6.js → chunk-RJICGVPL.js} +2 -2
  10. package/dist/chunk-WLEVU3HN.js +42 -0
  11. package/dist/{chunk-4GEDAGVY.js → chunk-YUGIYUMT.js} +8 -4
  12. package/dist/index.cjs +91 -57
  13. package/dist/index.d.cts +2 -1
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.js +14 -13
  16. package/dist/lib/client.js +2 -2
  17. package/dist/lib/constants.js +1 -1
  18. package/dist/lib/index.cjs +86 -52
  19. package/dist/lib/index.d.cts +2 -0
  20. package/dist/lib/index.d.ts +2 -0
  21. package/dist/lib/index.js +9 -8
  22. package/dist/react/index.cjs +91 -57
  23. package/dist/react/index.js +13 -12
  24. package/dist/react/utils.js +2 -2
  25. package/dist/tts/index.cjs +53 -52
  26. package/dist/tts/index.d.cts +8 -1
  27. package/dist/tts/index.d.ts +8 -1
  28. package/dist/tts/index.js +6 -6
  29. package/dist/tts/player.cjs +13 -27
  30. package/dist/tts/player.js +4 -4
  31. package/dist/tts/source.cjs +23 -37
  32. package/dist/tts/source.js +2 -2
  33. package/dist/tts/utils.js +3 -3
  34. package/dist/tts/websocket.cjs +38 -52
  35. package/dist/tts/websocket.d.cts +6 -6
  36. package/dist/tts/websocket.d.ts +6 -6
  37. package/dist/tts/websocket.js +5 -5
  38. package/dist/types/index.d.cts +25 -1
  39. package/dist/types/index.d.ts +25 -1
  40. package/dist/voice-changer/index.cjs +143 -0
  41. package/dist/voice-changer/index.d.cts +9 -0
  42. package/dist/voice-changer/index.d.ts +9 -0
  43. package/dist/voice-changer/index.js +9 -0
  44. package/dist/voices/index.js +3 -3
  45. package/package.json +10 -17
  46. package/src/lib/index.ts +3 -0
  47. package/src/tts/index.ts +16 -1
  48. package/src/types/index.ts +31 -0
  49. package/src/voice-changer/index.ts +37 -0
  50. package/.turbo/turbo-build.log +0 -75
  51. package/dist/chunk-MUPVAEL7.js +0 -25
  52. 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.0",
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
- "@repo/config-typescript": "workspace:*",
53
- "tsup": "^8.0.2"
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
  }
@@ -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
+ }
@@ -1,75 +0,0 @@
1
- $ tsup src/ --format cjs,esm --dts
2
- CLI 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
- CLI Using tsconfig: tsconfig.json
4
- CLI tsup v8.0.2
5
- CLI Target: es6
6
- CJS Build start
7
- ESM Build start
8
- ESM dist/index.js 499.00 B
9
- ESM dist/chunk-FXPGR372.js 0 B
10
- ESM dist/lib/client.js 132.00 B
11
- ESM dist/react/index.js 7.73 KB
12
- ESM dist/tts/index.js 261.00 B
13
- ESM dist/lib/constants.js 183.00 B
14
- ESM dist/lib/index.js 322.00 B
15
- ESM dist/chunk-4GEDAGVY.js 353.00 B
16
- ESM dist/react/utils.js 109.00 B
17
- ESM dist/chunk-CWIJUBG6.js 1.95 KB
18
- ESM dist/chunk-3FL2SNIR.js 337.00 B
19
- ESM dist/chunk-MUPVAEL7.js 439.00 B
20
- ESM dist/chunk-L3OMQKWL.js 7.95 KB
21
- ESM dist/chunk-6PWLZAMS.js 1.02 KB
22
- ESM dist/chunk-2BFEKY3F.js 366.00 B
23
- ESM dist/tts/player.js 174.00 B
24
- ESM dist/chunk-MNOPO7G6.js 3.76 KB
25
- ESM dist/chunk-VVDJR3OA.js 6.20 KB
26
- ESM dist/chunk-VCZESWYA.js 2.11 KB
27
- ESM dist/chunk-WIFMLPT5.js 2.27 KB
28
- ESM dist/types/index.js 31.00 B
29
- ESM dist/voices/index.js 174.00 B
30
- ESM dist/tts/source.js 144.00 B
31
- ESM dist/tts/utils.js 426.00 B
32
- ESM dist/tts/websocket.js 242.00 B
33
- ESM ⚡️ Build success in 134ms
34
- CJS dist/index.cjs 26.45 KB
35
- CJS dist/lib/client.cjs 4.07 KB
36
- CJS dist/lib/constants.cjs 1.43 KB
37
- CJS dist/lib/index.cjs 22.35 KB
38
- CJS dist/react/index.cjs 34.12 KB
39
- CJS dist/tts/index.cjs 20.23 KB
40
- CJS dist/tts/player.cjs 6.96 KB
41
- CJS dist/react/utils.cjs 1.80 KB
42
- CJS dist/tts/utils.cjs 4.33 KB
43
- CJS dist/tts/source.cjs 9.03 KB
44
- CJS dist/types/index.cjs 764.00 B
45
- CJS dist/tts/websocket.cjs 19.92 KB
46
- CJS dist/voices/index.cjs 5.83 KB
47
- CJS ⚡️ Build success in 142ms
48
- DTS Build start
49
- DTS ⚡️ Build success in 7238ms
50
- DTS dist/index.d.cts 928.00 B
51
- DTS dist/lib/constants.d.cts 564.00 B
52
- DTS dist/lib/index.d.cts 410.00 B
53
- DTS dist/react/index.d.cts 1.09 KB
54
- DTS dist/react/utils.d.cts 240.00 B
55
- DTS dist/tts/index.d.cts 471.00 B
56
- DTS dist/tts/player.d.cts 1.20 KB
57
- DTS dist/tts/utils.d.cts 2.68 KB
58
- DTS dist/tts/websocket.d.cts 3.21 KB
59
- DTS dist/tts/source.d.cts 2.86 KB
60
- DTS dist/voices/index.d.cts 675.00 B
61
- DTS dist/lib/client.d.cts 293.00 B
62
- DTS dist/types/index.d.cts 3.96 KB
63
- DTS dist/index.d.ts 920.00 B
64
- DTS dist/lib/constants.d.ts 564.00 B
65
- DTS dist/lib/index.d.ts 404.00 B
66
- DTS dist/react/index.d.ts 1.09 KB
67
- DTS dist/react/utils.d.ts 240.00 B
68
- DTS dist/tts/index.d.ts 467.00 B
69
- DTS dist/tts/player.d.ts 1.20 KB
70
- DTS dist/tts/utils.d.ts 2.68 KB
71
- DTS dist/tts/websocket.d.ts 3.20 KB
72
- DTS dist/tts/source.d.ts 2.86 KB
73
- DTS dist/voices/index.d.ts 673.00 B
74
- DTS dist/lib/client.d.ts 292.00 B
75
- DTS dist/types/index.d.ts 3.96 KB
@@ -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
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "@repo/config-typescript/react-library.json"
3
- }