@cartesia/cartesia-js 3.0.0-b5 → 3.0.0-b6
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 +4 -0
- package/backcompat/index.d.mts +11 -31
- package/backcompat/index.d.mts.map +1 -1
- package/backcompat/index.d.ts +11 -31
- package/backcompat/index.d.ts.map +1 -1
- package/backcompat/index.js +22 -252
- package/backcompat/index.js.map +1 -1
- package/backcompat/index.mjs +21 -251
- package/backcompat/index.mjs.map +1 -1
- package/backcompat/tts-wrapper.d.mts +66 -0
- package/backcompat/tts-wrapper.d.mts.map +1 -0
- package/backcompat/tts-wrapper.d.ts +66 -0
- package/backcompat/tts-wrapper.d.ts.map +1 -0
- package/backcompat/tts-wrapper.js +260 -0
- package/backcompat/tts-wrapper.js.map +1 -0
- package/backcompat/tts-wrapper.mjs +254 -0
- package/backcompat/tts-wrapper.mjs.map +1 -0
- package/backcompat/types.d.mts +18 -0
- package/backcompat/types.d.mts.map +1 -0
- package/backcompat/types.d.ts +18 -0
- package/backcompat/types.d.ts.map +1 -0
- package/backcompat/types.js +3 -0
- package/backcompat/types.js.map +1 -0
- package/backcompat/types.mjs +2 -0
- package/backcompat/types.mjs.map +1 -0
- package/backcompat/voice-changer-wrapper.d.mts +17 -0
- package/backcompat/voice-changer-wrapper.d.mts.map +1 -0
- package/backcompat/voice-changer-wrapper.d.ts +17 -0
- package/backcompat/voice-changer-wrapper.d.ts.map +1 -0
- package/backcompat/voice-changer-wrapper.js +46 -0
- package/backcompat/voice-changer-wrapper.js.map +1 -0
- package/backcompat/voice-changer-wrapper.mjs +42 -0
- package/backcompat/voice-changer-wrapper.mjs.map +1 -0
- package/backcompat/voices-wrapper.d.mts +32 -0
- package/backcompat/voices-wrapper.d.mts.map +1 -0
- package/backcompat/voices-wrapper.d.ts +32 -0
- package/backcompat/voices-wrapper.d.ts.map +1 -0
- package/backcompat/voices-wrapper.js +77 -0
- package/backcompat/voices-wrapper.js.map +1 -0
- package/backcompat/voices-wrapper.mjs +73 -0
- package/backcompat/voices-wrapper.mjs.map +1 -0
- package/package.json +1 -1
- package/src/backcompat/index.ts +27 -289
- package/src/backcompat/tts-wrapper.ts +324 -0
- package/src/backcompat/types.ts +19 -0
- package/src/backcompat/voice-changer-wrapper.ts +67 -0
- package/src/backcompat/voices-wrapper.ts +158 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
import { Cartesia } from "../client";
|
|
3
|
+
import { type RequestOptions as InternalRequestOptions } from "../internal/request-options";
|
|
4
|
+
import { BackCompatRequestOptions } from "./types";
|
|
5
|
+
|
|
6
|
+
// Define compatible interfaces to match the old SDK types for WebSocket
|
|
7
|
+
export interface BackCompatWebSocketOptions {
|
|
8
|
+
container?: "raw" | "wav" | "mp3";
|
|
9
|
+
encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
10
|
+
sampleRate: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type BackCompatTtsRequestVoiceSpecifier =
|
|
14
|
+
| { mode: "id"; id: string }
|
|
15
|
+
| { mode: "embedding"; embedding: number[] };
|
|
16
|
+
|
|
17
|
+
export interface BackCompatGenerationConfig {
|
|
18
|
+
volume?: number;
|
|
19
|
+
speed?: number;
|
|
20
|
+
emotion?: string[]; // Simplified from strict union for backcompat flexibility
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BackCompatWebSocketTtsRequest {
|
|
24
|
+
modelId: string;
|
|
25
|
+
transcript: string;
|
|
26
|
+
voice: BackCompatTtsRequestVoiceSpecifier;
|
|
27
|
+
generationConfig?: BackCompatGenerationConfig;
|
|
28
|
+
outputFormat?: {
|
|
29
|
+
container?: "raw" | "wav" | "mp3";
|
|
30
|
+
encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
31
|
+
sampleRate?: number;
|
|
32
|
+
bitRate?: number;
|
|
33
|
+
};
|
|
34
|
+
contextId?: string; // Backcompat might pass this in request?
|
|
35
|
+
// Add other fields as needed
|
|
36
|
+
continue?: boolean;
|
|
37
|
+
duration?: number;
|
|
38
|
+
addTimestamps?: boolean;
|
|
39
|
+
addPhonemeTimestamps?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Helper for generating UUIDs. Not cryptographically secure.
|
|
43
|
+
function uuidv4() {
|
|
44
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
45
|
+
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
46
|
+
return v.toString(16);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class AudioSource {
|
|
51
|
+
private buffers: Buffer[] = [];
|
|
52
|
+
private waiter: ((val?: any) => void) | null = null;
|
|
53
|
+
public isDone = false;
|
|
54
|
+
|
|
55
|
+
push(data: Buffer) {
|
|
56
|
+
this.buffers.push(data);
|
|
57
|
+
if (this.waiter) {
|
|
58
|
+
this.waiter();
|
|
59
|
+
this.waiter = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
markDone() {
|
|
64
|
+
this.isDone = true;
|
|
65
|
+
if (this.waiter) {
|
|
66
|
+
this.waiter();
|
|
67
|
+
this.waiter = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async read(outBuffer: Float32Array): Promise<number> {
|
|
72
|
+
if (this.buffers.length === 0 && !this.isDone) {
|
|
73
|
+
await new Promise<void>((resolve) => { this.waiter = resolve; });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (this.buffers.length === 0 && this.isDone) {
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let totalFloatsRead = 0;
|
|
81
|
+
let outOffset = 0;
|
|
82
|
+
const maxFloats = outBuffer.length;
|
|
83
|
+
|
|
84
|
+
while (this.buffers.length > 0 && totalFloatsRead < maxFloats) {
|
|
85
|
+
const buf = this.buffers[0] as Buffer; // ts not smart enough to check loop condition
|
|
86
|
+
const floatsInBuf = buf.length / 4;
|
|
87
|
+
const floatsNeeded = maxFloats - totalFloatsRead;
|
|
88
|
+
|
|
89
|
+
const floatsToCopy = Math.min(floatsInBuf, floatsNeeded);
|
|
90
|
+
const bytesToCopy = floatsToCopy * 4;
|
|
91
|
+
|
|
92
|
+
// Copy to outBuffer.
|
|
93
|
+
// Create a view on the buffer to read floats.
|
|
94
|
+
|
|
95
|
+
// We need to ensure byteOffset is a multiple of 4.
|
|
96
|
+
// If not, we must copy the buffer to a new one.
|
|
97
|
+
let srcFloats: Float32Array;
|
|
98
|
+
if (buf.byteOffset % 4 === 0) {
|
|
99
|
+
srcFloats = new Float32Array(buf.buffer, buf.byteOffset, floatsInBuf);
|
|
100
|
+
} else {
|
|
101
|
+
const alignedBuf = new Uint8Array(buf);
|
|
102
|
+
srcFloats = new Float32Array(alignedBuf.buffer, alignedBuf.byteOffset, floatsInBuf);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
outBuffer.set(srcFloats.subarray(0, floatsToCopy), outOffset);
|
|
106
|
+
|
|
107
|
+
totalFloatsRead += floatsToCopy;
|
|
108
|
+
outOffset += floatsToCopy;
|
|
109
|
+
|
|
110
|
+
if (floatsToCopy < floatsInBuf) {
|
|
111
|
+
// We didn't use the whole buffer. Update it.
|
|
112
|
+
this.buffers[0] = buf.subarray(bytesToCopy);
|
|
113
|
+
} else {
|
|
114
|
+
// We used the whole buffer. Remove it.
|
|
115
|
+
this.buffers.shift();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return totalFloatsRead;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export class WebSocketWrapper {
|
|
124
|
+
private client: Cartesia;
|
|
125
|
+
private config: BackCompatWebSocketOptions;
|
|
126
|
+
private socket: WebSocket | null = null;
|
|
127
|
+
private sources: Map<string, AudioSource> = new Map();
|
|
128
|
+
// Fallback source for messages without context_id or if we just want to capture everything (legacy behavior?)
|
|
129
|
+
// The original test didn't use context_id explicitly in send() but expected a response source.
|
|
130
|
+
// We'll map context_id to source.
|
|
131
|
+
private defaultSource: AudioSource | null = null;
|
|
132
|
+
|
|
133
|
+
constructor(client: Cartesia, config: BackCompatWebSocketOptions) {
|
|
134
|
+
this.client = client;
|
|
135
|
+
this.config = config;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async connect() {
|
|
139
|
+
const baseURL = this.client.baseURL;
|
|
140
|
+
// Construct WebSocket URL
|
|
141
|
+
// baseURL is like https://api.cartesia.ai
|
|
142
|
+
let urlStr = baseURL.replace(/^http/, "ws");
|
|
143
|
+
if (!urlStr.includes("/tts/websocket")) {
|
|
144
|
+
if (urlStr.endsWith("/")) {
|
|
145
|
+
urlStr += "tts/websocket";
|
|
146
|
+
} else {
|
|
147
|
+
urlStr += "/tts/websocket";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const url = new URL(urlStr);
|
|
152
|
+
|
|
153
|
+
const headers: any = {
|
|
154
|
+
"cartesia-version": "2025-04-16",
|
|
155
|
+
};
|
|
156
|
+
if (this.client.apiKey) {
|
|
157
|
+
headers["Authorization"] = `Bearer ${this.client.apiKey}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this.socket = new WebSocket(url.toString(), {
|
|
161
|
+
headers: headers,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return new Promise<void>((resolve, reject) => {
|
|
165
|
+
this.socket!.on("open", () => {
|
|
166
|
+
console.log("WebSocket connected.");
|
|
167
|
+
resolve();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
this.socket!.on("error", (err) => {
|
|
171
|
+
console.error("WebSocket error:", err);
|
|
172
|
+
reject(err);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
this.socket!.on("message", (data) => {
|
|
176
|
+
this.handleMessage(data);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
this.socket!.on("close", () => {
|
|
180
|
+
console.log("WebSocket closed.");
|
|
181
|
+
this.sources.forEach((s) => { s.markDone(); });
|
|
182
|
+
if (this.defaultSource) this.defaultSource.markDone();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private handleMessage(data: WebSocket.Data) {
|
|
188
|
+
try {
|
|
189
|
+
const str = data.toString();
|
|
190
|
+
const msg = JSON.parse(str);
|
|
191
|
+
|
|
192
|
+
const contextId = msg.context_id;
|
|
193
|
+
let source = contextId ? this.sources.get(contextId) : this.defaultSource;
|
|
194
|
+
|
|
195
|
+
// If we received a message for a context we don't know about, and we have a default source, use it
|
|
196
|
+
if (!source && this.defaultSource) {
|
|
197
|
+
source = this.defaultSource;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (msg.type === "chunk" && msg.data) {
|
|
201
|
+
const audioData = Buffer.from(msg.data, "base64");
|
|
202
|
+
if (source) source.push(audioData);
|
|
203
|
+
} else if (msg.type === "done") {
|
|
204
|
+
if (source) source.markDone();
|
|
205
|
+
} else if (msg.type === "error") {
|
|
206
|
+
console.error("Server error:", msg);
|
|
207
|
+
if (source) source.markDone(); // Fail the stream?
|
|
208
|
+
}
|
|
209
|
+
} catch (e) {
|
|
210
|
+
console.error("Error parsing message:", e);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async send(request: BackCompatWebSocketTtsRequest) {
|
|
215
|
+
if (!this.socket) {
|
|
216
|
+
throw new Error("WebSocket not connected");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Ensure request has a context_id so we can route the response
|
|
220
|
+
const contextId = request.contextId || uuidv4();
|
|
221
|
+
|
|
222
|
+
const source = new AudioSource();
|
|
223
|
+
this.sources.set(contextId, source);
|
|
224
|
+
// Also set as default source if none exists, for compatibility with simple tests
|
|
225
|
+
if (!this.defaultSource) {
|
|
226
|
+
this.defaultSource = source;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Construct payload
|
|
230
|
+
const payload: any = {
|
|
231
|
+
model_id: request.modelId,
|
|
232
|
+
transcript: request.transcript,
|
|
233
|
+
voice: request.voice,
|
|
234
|
+
context_id: contextId,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// Output Format
|
|
238
|
+
if (request.outputFormat) {
|
|
239
|
+
payload.output_format = {
|
|
240
|
+
container: request.outputFormat.container,
|
|
241
|
+
encoding: request.outputFormat.encoding,
|
|
242
|
+
sample_rate: request.outputFormat.sampleRate,
|
|
243
|
+
bit_rate: request.outputFormat.bitRate,
|
|
244
|
+
};
|
|
245
|
+
} else if (this.config) {
|
|
246
|
+
payload.output_format = {
|
|
247
|
+
container: this.config.container,
|
|
248
|
+
encoding: this.config.encoding,
|
|
249
|
+
sample_rate: this.config.sampleRate,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Generation Config
|
|
254
|
+
if (request.generationConfig) {
|
|
255
|
+
payload.generation_config = request.generationConfig;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Other fields
|
|
259
|
+
if (request.continue !== undefined) payload.continue = request.continue;
|
|
260
|
+
if (request.duration !== undefined) payload.duration = request.duration;
|
|
261
|
+
if (request.addTimestamps !== undefined) payload.add_timestamps = request.addTimestamps;
|
|
262
|
+
if (request.addPhonemeTimestamps !== undefined) payload.add_phoneme_timestamps = request.addPhonemeTimestamps;
|
|
263
|
+
|
|
264
|
+
this.socket.send(JSON.stringify(payload));
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
source: source
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
disconnect() {
|
|
272
|
+
if (this.socket) {
|
|
273
|
+
this.socket.close();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export class TTSWrapper {
|
|
279
|
+
private client: Cartesia;
|
|
280
|
+
|
|
281
|
+
constructor(client: Cartesia) {
|
|
282
|
+
this.client = client;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
websocket(config: BackCompatWebSocketOptions) {
|
|
286
|
+
return new WebSocketWrapper(this.client, config);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async bytes(request: any, requestOptions?: BackCompatRequestOptions) {
|
|
290
|
+
const params: any = {
|
|
291
|
+
model_id: request.modelId,
|
|
292
|
+
transcript: request.transcript,
|
|
293
|
+
voice: request.voice,
|
|
294
|
+
generation_config: request.generationConfig,
|
|
295
|
+
context_id: request.contextId,
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
if (request.outputFormat) {
|
|
299
|
+
params.output_format = {
|
|
300
|
+
...request.outputFormat,
|
|
301
|
+
sample_rate: request.outputFormat.sampleRate,
|
|
302
|
+
bit_rate: request.outputFormat.bitRate,
|
|
303
|
+
};
|
|
304
|
+
// Remove camelCase keys
|
|
305
|
+
delete params.output_format.sampleRate;
|
|
306
|
+
delete params.output_format.bitRate;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const options: any = {};
|
|
310
|
+
if (requestOptions) {
|
|
311
|
+
if (requestOptions.timeoutInSeconds) {
|
|
312
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
313
|
+
}
|
|
314
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
315
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
316
|
+
}
|
|
317
|
+
options.headers = requestOptions.headers;
|
|
318
|
+
options.signal = requestOptions.abortSignal;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// @ts-ignore
|
|
322
|
+
return this.client.tts.synthesizeBytes(params, options);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type Supplier<T> = T | Promise<T> | (() => T | Promise<T>);
|
|
2
|
+
|
|
3
|
+
export interface CartesiaClientOptions {
|
|
4
|
+
environment?: Supplier<"https://api.cartesia.ai" | string>;
|
|
5
|
+
/** Specify a custom URL to connect the client to. */
|
|
6
|
+
baseUrl?: Supplier<string>;
|
|
7
|
+
apiKey?: Supplier<string | undefined>;
|
|
8
|
+
/** Override the Cartesia-Version header */
|
|
9
|
+
cartesiaVersion?: string;
|
|
10
|
+
fetcher?: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface BackCompatRequestOptions {
|
|
14
|
+
timeoutInSeconds?: number;
|
|
15
|
+
maxRetries?: number;
|
|
16
|
+
abortSignal?: AbortSignal;
|
|
17
|
+
cartesiaVersion?: string;
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { Cartesia } from "../client";
|
|
3
|
+
import { type Uploadable } from "../core/uploads";
|
|
4
|
+
import { type RequestOptions as InternalRequestOptions } from "../internal/request-options";
|
|
5
|
+
import { Readable } from "stream";
|
|
6
|
+
import { BackCompatRequestOptions } from "./types";
|
|
7
|
+
|
|
8
|
+
export interface BackCompatVoiceChangerBytesRequest {
|
|
9
|
+
voiceId: string;
|
|
10
|
+
outputFormatContainer: "raw" | "wav" | "mp3";
|
|
11
|
+
outputFormatSampleRate: 8000 | 16000 | 22050 | 24000 | 44100 | 48000;
|
|
12
|
+
outputFormatEncoding?: "pcm_f32le" | "pcm_s16le" | "mulaw" | "alaw";
|
|
13
|
+
outputFormatBitRate?: 32000 | 64000 | 96000 | 128000 | 192000;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class VoiceChangerWrapper {
|
|
17
|
+
private client: Cartesia;
|
|
18
|
+
|
|
19
|
+
constructor(client: Cartesia) {
|
|
20
|
+
this.client = client;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async bytes(
|
|
24
|
+
clip: File | fs.ReadStream | Blob,
|
|
25
|
+
request: BackCompatVoiceChangerBytesRequest,
|
|
26
|
+
requestOptions?: BackCompatRequestOptions
|
|
27
|
+
) {
|
|
28
|
+
const params: any = {
|
|
29
|
+
clip: clip as Uploadable,
|
|
30
|
+
"voice[id]": request.voiceId,
|
|
31
|
+
"output_format[container]": request.outputFormatContainer,
|
|
32
|
+
"output_format[sample_rate]": request.outputFormatSampleRate,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (request.outputFormatEncoding) {
|
|
36
|
+
params["output_format[encoding]"] = request.outputFormatEncoding;
|
|
37
|
+
}
|
|
38
|
+
if (request.outputFormatBitRate) {
|
|
39
|
+
params["output_format[bit_rate]"] = request.outputFormatBitRate;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const options: InternalRequestOptions = {};
|
|
43
|
+
if (requestOptions) {
|
|
44
|
+
if (requestOptions.timeoutInSeconds) {
|
|
45
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
46
|
+
}
|
|
47
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
48
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
49
|
+
}
|
|
50
|
+
options.headers = requestOptions.headers;
|
|
51
|
+
options.signal = requestOptions.abortSignal;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const response = await this.client.voiceChanger.changeVoiceBytes(params, {
|
|
55
|
+
...options,
|
|
56
|
+
__binaryResponse: true,
|
|
57
|
+
} as any);
|
|
58
|
+
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
if (response.body) {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
return Readable.fromWeb(response.body);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return response;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { Cartesia } from "../client";
|
|
3
|
+
import { type Uploadable } from "../core/uploads";
|
|
4
|
+
import {
|
|
5
|
+
type VoiceCloneParams,
|
|
6
|
+
type VoiceMetadata,
|
|
7
|
+
type SupportedLanguage,
|
|
8
|
+
type VoiceUpdateParams,
|
|
9
|
+
type Voice,
|
|
10
|
+
type VoiceLocalizeParams,
|
|
11
|
+
} from "../resources/voices";
|
|
12
|
+
import { type RequestOptions as InternalRequestOptions } from "../internal/request-options";
|
|
13
|
+
import { BackCompatRequestOptions } from "./types";
|
|
14
|
+
|
|
15
|
+
export interface BackCompatCloneVoiceRequest {
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
language: string;
|
|
19
|
+
mode: "similarity" | "stability";
|
|
20
|
+
enhance?: boolean;
|
|
21
|
+
baseVoiceId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface BackCompatUpdateVoiceRequest {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface BackCompatLocalizeVoiceRequest {
|
|
30
|
+
voiceId: string;
|
|
31
|
+
name: string;
|
|
32
|
+
description: string;
|
|
33
|
+
language:
|
|
34
|
+
| "en"
|
|
35
|
+
| "de"
|
|
36
|
+
| "es"
|
|
37
|
+
| "fr"
|
|
38
|
+
| "ja"
|
|
39
|
+
| "pt"
|
|
40
|
+
| "zh"
|
|
41
|
+
| "hi"
|
|
42
|
+
| "it"
|
|
43
|
+
| "ko"
|
|
44
|
+
| "nl"
|
|
45
|
+
| "pl"
|
|
46
|
+
| "ru"
|
|
47
|
+
| "sv"
|
|
48
|
+
| "tr";
|
|
49
|
+
originalSpeakerGender: "male" | "female";
|
|
50
|
+
dialect?:
|
|
51
|
+
| "au"
|
|
52
|
+
| "in"
|
|
53
|
+
| "so"
|
|
54
|
+
| "uk"
|
|
55
|
+
| "us"
|
|
56
|
+
| "mx"
|
|
57
|
+
| "pe"
|
|
58
|
+
| "br"
|
|
59
|
+
| "eu"
|
|
60
|
+
| "ca";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class VoicesWrapper {
|
|
64
|
+
private client: Cartesia;
|
|
65
|
+
|
|
66
|
+
constructor(client: Cartesia) {
|
|
67
|
+
this.client = client;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async clone(
|
|
71
|
+
clip: File | fs.ReadStream | Blob,
|
|
72
|
+
request: BackCompatCloneVoiceRequest,
|
|
73
|
+
requestOptions?: BackCompatRequestOptions
|
|
74
|
+
): Promise<VoiceMetadata> {
|
|
75
|
+
const params: VoiceCloneParams = {
|
|
76
|
+
clip: clip as Uploadable,
|
|
77
|
+
name: request.name,
|
|
78
|
+
language: request.language as SupportedLanguage,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
if (request.description !== undefined) {
|
|
82
|
+
params.description = request.description;
|
|
83
|
+
}
|
|
84
|
+
if (request.baseVoiceId !== undefined) {
|
|
85
|
+
params.base_voice_id = request.baseVoiceId;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const options: InternalRequestOptions = {};
|
|
89
|
+
if (requestOptions) {
|
|
90
|
+
if (requestOptions.timeoutInSeconds) {
|
|
91
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
92
|
+
}
|
|
93
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
94
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
95
|
+
}
|
|
96
|
+
options.headers = requestOptions.headers;
|
|
97
|
+
options.signal = requestOptions.abortSignal;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return this.client.voices.clone(params, options);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async update(
|
|
104
|
+
id: string,
|
|
105
|
+
request: BackCompatUpdateVoiceRequest,
|
|
106
|
+
requestOptions?: BackCompatRequestOptions
|
|
107
|
+
): Promise<Voice> {
|
|
108
|
+
const params: VoiceUpdateParams = {
|
|
109
|
+
name: request.name,
|
|
110
|
+
description: request.description,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const options: InternalRequestOptions = {};
|
|
114
|
+
if (requestOptions) {
|
|
115
|
+
if (requestOptions.timeoutInSeconds) {
|
|
116
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
117
|
+
}
|
|
118
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
119
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
120
|
+
}
|
|
121
|
+
options.headers = requestOptions.headers;
|
|
122
|
+
options.signal = requestOptions.abortSignal;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return this.client.voices.update(id, params, options);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async localize(
|
|
129
|
+
request: BackCompatLocalizeVoiceRequest,
|
|
130
|
+
requestOptions?: BackCompatRequestOptions
|
|
131
|
+
): Promise<VoiceMetadata> {
|
|
132
|
+
const params: VoiceLocalizeParams = {
|
|
133
|
+
voice_id: request.voiceId,
|
|
134
|
+
name: request.name,
|
|
135
|
+
description: request.description,
|
|
136
|
+
language: request.language as any,
|
|
137
|
+
original_speaker_gender: request.originalSpeakerGender,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
if (request.dialect) {
|
|
141
|
+
params.dialect = request.dialect as any; // Cast dialect as list might vary slightly or be strict
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const options: InternalRequestOptions = {};
|
|
145
|
+
if (requestOptions) {
|
|
146
|
+
if (requestOptions.timeoutInSeconds) {
|
|
147
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
148
|
+
}
|
|
149
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
150
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
151
|
+
}
|
|
152
|
+
options.headers = requestOptions.headers;
|
|
153
|
+
options.signal = requestOptions.abortSignal;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return this.client.voices.localize(params, options);
|
|
157
|
+
}
|
|
158
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '3.0.0-
|
|
1
|
+
export const VERSION = '3.0.0-b6'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "3.0.0-
|
|
1
|
+
export declare const VERSION = "3.0.0-b6";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "3.0.0-
|
|
1
|
+
export declare const VERSION = "3.0.0-b6";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '3.0.0-
|
|
1
|
+
export const VERSION = '3.0.0-b6'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|