@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.
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-6PWLZAMS.js → chunk-FLWYXP5Z.js} +1 -1
  4. package/dist/chunk-GLZYI5DM.js +43 -0
  5. package/dist/{chunk-VVDJR3OA.js → chunk-I5YVYTNK.js} +16 -16
  6. package/dist/{chunk-3FL2SNIR.js → chunk-LKKWJLUG.js} +1 -1
  7. package/dist/{chunk-WIFMLPT5.js → chunk-NJDRWDQ3.js} +8 -22
  8. package/dist/{chunk-4GEDAGVY.js → chunk-QWNB544W.js} +7 -3
  9. package/dist/{chunk-CWIJUBG6.js → chunk-RJICGVPL.js} +2 -2
  10. package/dist/chunk-WLEVU3HN.js +42 -0
  11. package/dist/{chunk-L3OMQKWL.js → chunk-WSIVWXEI.js} +19 -19
  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 +10 -9
  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 +11 -10
  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 +8 -16
  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
@@ -33,18 +33,18 @@ declare class WebSocket extends Client {
33
33
  message: string;
34
34
  timestamps: WordTimestamps;
35
35
  } & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => emittery.UnsubscribeFunction;
36
- off: <Name_1 extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name_1 | readonly Name_1[], listener: (eventData: ({
36
+ off: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[], listener: (eventData: ({
37
37
  message: string;
38
38
  timestamps: WordTimestamps;
39
- } & emittery.OmnipresentEventData)[Name_1]) => void | Promise<void>) => void;
40
- once: <Name_2 extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name_2 | readonly Name_2[]) => emittery.EmitteryOncePromise<({
39
+ } & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => void;
40
+ once: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[]) => emittery.EmitteryOncePromise<({
41
41
  message: string;
42
42
  timestamps: WordTimestamps;
43
- } & emittery.OmnipresentEventData)[Name_2]>;
44
- events: <Name_3 extends "timestamps" | "message">(eventName: Name_3 | readonly Name_3[]) => AsyncIterableIterator<{
43
+ } & emittery.OmnipresentEventData)[Name]>;
44
+ events: <Name extends "timestamps" | "message">(eventName: Name | readonly Name[]) => AsyncIterableIterator<{
45
45
  message: string;
46
46
  timestamps: WordTimestamps;
47
- }[Name_3]>;
47
+ }[Name]>;
48
48
  source: Source;
49
49
  };
50
50
  /**
@@ -33,18 +33,18 @@ declare class WebSocket extends Client {
33
33
  message: string;
34
34
  timestamps: WordTimestamps;
35
35
  } & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => emittery.UnsubscribeFunction;
36
- off: <Name_1 extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name_1 | readonly Name_1[], listener: (eventData: ({
36
+ off: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[], listener: (eventData: ({
37
37
  message: string;
38
38
  timestamps: WordTimestamps;
39
- } & emittery.OmnipresentEventData)[Name_1]) => void | Promise<void>) => void;
40
- once: <Name_2 extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name_2 | readonly Name_2[]) => emittery.EmitteryOncePromise<({
39
+ } & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => void;
40
+ once: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[]) => emittery.EmitteryOncePromise<({
41
41
  message: string;
42
42
  timestamps: WordTimestamps;
43
- } & emittery.OmnipresentEventData)[Name_2]>;
44
- events: <Name_3 extends "timestamps" | "message">(eventName: Name_3 | readonly Name_3[]) => AsyncIterableIterator<{
43
+ } & emittery.OmnipresentEventData)[Name]>;
44
+ events: <Name extends "timestamps" | "message">(eventName: Name | readonly Name[]) => AsyncIterableIterator<{
45
45
  message: string;
46
46
  timestamps: WordTimestamps;
47
- }[Name_3]>;
47
+ }[Name]>;
48
48
  source: Source;
49
49
  };
50
50
  /**
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  WebSocket
3
- } from "../chunk-L3OMQKWL.js";
4
- import "../chunk-6PWLZAMS.js";
3
+ } from "../chunk-WSIVWXEI.js";
4
+ import "../chunk-FLWYXP5Z.js";
5
5
  import "../chunk-2BFEKY3F.js";
6
- import "../chunk-VCZESWYA.js";
7
- import "../chunk-VVDJR3OA.js";
8
- import "../chunk-WIFMLPT5.js";
6
+ import "../chunk-5SBAQNWQ.js";
7
+ import "../chunk-I5YVYTNK.js";
8
+ import "../chunk-NJDRWDQ3.js";
9
9
  export {
10
10
  WebSocket as default
11
11
  };
@@ -41,6 +41,7 @@ type StreamRequest = {
41
41
  language?: Language;
42
42
  add_timestamps?: boolean;
43
43
  };
44
+ type BytesRequest = Omit<StreamRequest, "continue" | "add_timestamps" | "context_id">;
44
45
  type ContinueRequest = StreamRequest & {
45
46
  context_id: string;
46
47
  };
@@ -87,6 +88,26 @@ type CloneOptions = {
87
88
  clip: Blob;
88
89
  enhance?: boolean;
89
90
  };
91
+ type VoiceChangerOptions = {
92
+ clip: File;
93
+ voice: {
94
+ id: string;
95
+ };
96
+ output_format: {
97
+ container: "mp3";
98
+ bit_rate: number;
99
+ sample_rate: number;
100
+ } | {
101
+ container: "wav";
102
+ encoding: Encoding;
103
+ sample_rate: number;
104
+ bit_rate: number;
105
+ } | {
106
+ container: "raw";
107
+ encoding: Encoding;
108
+ sample_rate: number;
109
+ };
110
+ };
90
111
  type LocalizeOptions = {
91
112
  mode: "embedding";
92
113
  embedding: number[];
@@ -118,6 +139,9 @@ type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
118
139
  type CloneResponse = {
119
140
  embedding: number[];
120
141
  };
142
+ type VoiceChangerBytesResponse = {
143
+ buffer: ArrayBuffer;
144
+ };
121
145
  type LocalizeResponse = {
122
146
  embedding: number[];
123
147
  };
@@ -138,4 +162,4 @@ type SourceEventData = {
138
162
  type TypedArray = Float32Array | Int16Array | Uint8Array;
139
163
  type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
140
164
 
141
- export type { 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 };
165
+ export type { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceChangerBytesResponse, VoiceChangerOptions, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
@@ -41,6 +41,7 @@ type StreamRequest = {
41
41
  language?: Language;
42
42
  add_timestamps?: boolean;
43
43
  };
44
+ type BytesRequest = Omit<StreamRequest, "continue" | "add_timestamps" | "context_id">;
44
45
  type ContinueRequest = StreamRequest & {
45
46
  context_id: string;
46
47
  };
@@ -87,6 +88,26 @@ type CloneOptions = {
87
88
  clip: Blob;
88
89
  enhance?: boolean;
89
90
  };
91
+ type VoiceChangerOptions = {
92
+ clip: File;
93
+ voice: {
94
+ id: string;
95
+ };
96
+ output_format: {
97
+ container: "mp3";
98
+ bit_rate: number;
99
+ sample_rate: number;
100
+ } | {
101
+ container: "wav";
102
+ encoding: Encoding;
103
+ sample_rate: number;
104
+ bit_rate: number;
105
+ } | {
106
+ container: "raw";
107
+ encoding: Encoding;
108
+ sample_rate: number;
109
+ };
110
+ };
90
111
  type LocalizeOptions = {
91
112
  mode: "embedding";
92
113
  embedding: number[];
@@ -118,6 +139,9 @@ type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
118
139
  type CloneResponse = {
119
140
  embedding: number[];
120
141
  };
142
+ type VoiceChangerBytesResponse = {
143
+ buffer: ArrayBuffer;
144
+ };
121
145
  type LocalizeResponse = {
122
146
  embedding: number[];
123
147
  };
@@ -138,4 +162,4 @@ type SourceEventData = {
138
162
  type TypedArray = Float32Array | Int16Array | Uint8Array;
139
163
  type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
140
164
 
141
- export type { 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 };
165
+ export type { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceChangerBytesResponse, VoiceChangerOptions, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __async = (__this, __arguments, generator) => {
47
+ return new Promise((resolve, reject) => {
48
+ var fulfilled = (value) => {
49
+ try {
50
+ step(generator.next(value));
51
+ } catch (e) {
52
+ reject(e);
53
+ }
54
+ };
55
+ var rejected = (value) => {
56
+ try {
57
+ step(generator.throw(value));
58
+ } catch (e) {
59
+ reject(e);
60
+ }
61
+ };
62
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
+ step((generator = generator.apply(__this, __arguments)).next());
64
+ });
65
+ };
66
+
67
+ // src/voice-changer/index.ts
68
+ var voice_changer_exports = {};
69
+ __export(voice_changer_exports, {
70
+ default: () => VoiceChanger
71
+ });
72
+ module.exports = __toCommonJS(voice_changer_exports);
73
+
74
+ // src/lib/client.ts
75
+ var import_cross_fetch = __toESM(require("cross-fetch"), 1);
76
+
77
+ // src/lib/constants.ts
78
+ var BASE_URL = "https://api.cartesia.ai";
79
+ var CARTESIA_VERSION = "2024-06-10";
80
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
81
+ const url = new URL(path, baseUrl);
82
+ if (websocket) {
83
+ url.protocol = baseUrl.replace(/^http/, "ws");
84
+ }
85
+ return url;
86
+ };
87
+
88
+ // src/lib/client.ts
89
+ var Client = class {
90
+ constructor(options = {}) {
91
+ const apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
92
+ if (!apiKey) {
93
+ throw new Error("Missing Cartesia API key.");
94
+ }
95
+ this.apiKey = typeof apiKey === "function" ? apiKey : () => __async(this, null, function* () {
96
+ return apiKey;
97
+ });
98
+ this.baseUrl = options.baseUrl || BASE_URL;
99
+ }
100
+ _fetch(_0) {
101
+ return __async(this, arguments, function* (path, options = {}) {
102
+ const url = constructApiUrl(this.baseUrl, path);
103
+ const headers = new Headers(options.headers);
104
+ headers.set("X-API-Key", yield this.apiKey());
105
+ headers.set("Cartesia-Version", CARTESIA_VERSION);
106
+ return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
107
+ headers
108
+ }));
109
+ });
110
+ }
111
+ };
112
+
113
+ // src/voice-changer/index.ts
114
+ var VoiceChanger = class extends Client {
115
+ bytes(options) {
116
+ return __async(this, null, function* () {
117
+ const formData = new FormData();
118
+ formData.append("clip", options.clip);
119
+ formData.append("voice[id]", options.voice.id);
120
+ const fmt = options.output_format;
121
+ formData.append("output_format[container]", fmt.container);
122
+ if ("encoding" in fmt) {
123
+ formData.append("output_format[encoding]", fmt.encoding);
124
+ }
125
+ if ("bit_rate" in fmt) {
126
+ formData.append("output_format[bit_rate]", fmt.bit_rate.toString());
127
+ }
128
+ if ("sample_rate" in fmt) {
129
+ formData.append("output_format[sample_rate]", fmt.sample_rate.toString());
130
+ }
131
+ const response = yield this._fetch("/voice-changer/bytes", {
132
+ method: "POST",
133
+ body: formData
134
+ });
135
+ if (!response.ok) {
136
+ throw new Error(
137
+ `Voice changer error! status: ${response.status}, message: ${yield response.text()}`
138
+ );
139
+ }
140
+ return { buffer: yield response.arrayBuffer() };
141
+ });
142
+ }
143
+ };
@@ -0,0 +1,9 @@
1
+ import { Client } from '../lib/client.cjs';
2
+ import { VoiceChangerOptions, VoiceChangerBytesResponse } from '../types/index.cjs';
3
+ import 'emittery';
4
+
5
+ declare class VoiceChanger extends Client {
6
+ bytes(options: VoiceChangerOptions): Promise<VoiceChangerBytesResponse>;
7
+ }
8
+
9
+ export { VoiceChanger as default };
@@ -0,0 +1,9 @@
1
+ import { Client } from '../lib/client.js';
2
+ import { VoiceChangerOptions, VoiceChangerBytesResponse } from '../types/index.js';
3
+ import 'emittery';
4
+
5
+ declare class VoiceChanger extends Client {
6
+ bytes(options: VoiceChangerOptions): Promise<VoiceChangerBytesResponse>;
7
+ }
8
+
9
+ export { VoiceChanger as default };
@@ -0,0 +1,9 @@
1
+ import {
2
+ VoiceChanger
3
+ } from "../chunk-WLEVU3HN.js";
4
+ import "../chunk-FLWYXP5Z.js";
5
+ import "../chunk-2BFEKY3F.js";
6
+ import "../chunk-NJDRWDQ3.js";
7
+ export {
8
+ VoiceChanger as default
9
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Voices
3
- } from "../chunk-CWIJUBG6.js";
4
- import "../chunk-6PWLZAMS.js";
3
+ } from "../chunk-RJICGVPL.js";
4
+ import "../chunk-FLWYXP5Z.js";
5
5
  import "../chunk-2BFEKY3F.js";
6
- import "../chunk-WIFMLPT5.js";
6
+ import "../chunk-NJDRWDQ3.js";
7
7
  export {
8
8
  Voices as default
9
9
  };
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-alpha.2",
8
8
  "description": "Client for the Cartesia API.",
9
9
  "type": "module",
10
10
  "module": "./dist/index.js",
@@ -27,7 +27,8 @@
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"
@@ -36,20 +37,11 @@
36
37
  "build": "tsup src/ --format cjs,esm --dts",
37
38
  "dev": "bun run build -- --watch"
38
39
  },
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
- }
50
- },
51
40
  "devDependencies": {
52
- "@repo/config-typescript": "workspace:*",
53
- "tsup": "^8.0.2"
41
+ "@biomejs/biome": "^1.9.4",
42
+ "@types/node": "^22.7.9",
43
+ "@types/react": "^18.3.12",
44
+ "tsup": "^8.0.2",
45
+ "typescript": "^5.6.3"
54
46
  }
55
47
  }
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
- }