@cartesia/cartesia-js 3.0.0-b5 → 3.0.0-b7
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 +8 -0
- package/backcompat/errors.d.mts +16 -0
- package/backcompat/errors.d.mts.map +1 -0
- package/backcompat/errors.d.ts +16 -0
- package/backcompat/errors.d.ts.map +1 -0
- package/backcompat/errors.js +46 -0
- package/backcompat/errors.js.map +1 -0
- package/backcompat/errors.mjs +40 -0
- package/backcompat/errors.mjs.map +1 -0
- package/backcompat/index.d.mts +17 -31
- package/backcompat/index.d.mts.map +1 -1
- package/backcompat/index.d.ts +17 -31
- package/backcompat/index.d.ts.map +1 -1
- package/backcompat/index.js +26 -254
- package/backcompat/index.js.map +1 -1
- package/backcompat/index.mjs +25 -253
- package/backcompat/index.mjs.map +1 -1
- package/backcompat/tts-wrapper.d.mts +69 -0
- package/backcompat/tts-wrapper.d.mts.map +1 -0
- package/backcompat/tts-wrapper.d.ts +69 -0
- package/backcompat/tts-wrapper.d.ts.map +1 -0
- package/backcompat/tts-wrapper.js +264 -0
- package/backcompat/tts-wrapper.js.map +1 -0
- package/backcompat/tts-wrapper.mjs +258 -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 +19 -0
- package/backcompat/voice-changer-wrapper.d.mts.map +1 -0
- package/backcompat/voice-changer-wrapper.d.ts +19 -0
- package/backcompat/voice-changer-wrapper.d.ts.map +1 -0
- package/backcompat/voice-changer-wrapper.js +49 -0
- package/backcompat/voice-changer-wrapper.js.map +1 -0
- package/backcompat/voice-changer-wrapper.mjs +45 -0
- package/backcompat/voice-changer-wrapper.mjs.map +1 -0
- package/backcompat/voices-wrapper.d.mts +36 -0
- package/backcompat/voices-wrapper.d.mts.map +1 -0
- package/backcompat/voices-wrapper.d.ts +36 -0
- package/backcompat/voices-wrapper.d.ts.map +1 -0
- package/backcompat/voices-wrapper.js +82 -0
- package/backcompat/voices-wrapper.js.map +1 -0
- package/backcompat/voices-wrapper.mjs +78 -0
- package/backcompat/voices-wrapper.mjs.map +1 -0
- package/index.d.mts +1 -1
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backcompat/errors.ts +52 -0
- package/src/backcompat/index.ts +31 -291
- package/src/backcompat/tts-wrapper.ts +328 -0
- package/src/backcompat/types.ts +19 -0
- package/src/backcompat/voice-changer-wrapper.ts +70 -0
- package/src/backcompat/voices-wrapper.ts +163 -0
- package/src/index.ts +1 -1
- 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
package/backcompat/index.mjs
CHANGED
|
@@ -1,261 +1,33 @@
|
|
|
1
|
-
import WebSocket from "ws";
|
|
2
1
|
import { Cartesia } from "../client.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
markDone() {
|
|
17
|
-
this.isDone = true;
|
|
18
|
-
if (this.waiter) {
|
|
19
|
-
this.waiter();
|
|
20
|
-
this.waiter = null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
async read(outBuffer) {
|
|
24
|
-
if (this.buffers.length === 0 && !this.isDone) {
|
|
25
|
-
await new Promise((resolve) => { this.waiter = resolve; });
|
|
26
|
-
}
|
|
27
|
-
if (this.buffers.length === 0 && this.isDone) {
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
let totalFloatsRead = 0;
|
|
31
|
-
let outOffset = 0;
|
|
32
|
-
const maxFloats = outBuffer.length;
|
|
33
|
-
while (this.buffers.length > 0 && totalFloatsRead < maxFloats) {
|
|
34
|
-
const buf = this.buffers[0]; // ts not smart enough to check loop condition
|
|
35
|
-
const floatsInBuf = buf.length / 4;
|
|
36
|
-
const floatsNeeded = maxFloats - totalFloatsRead;
|
|
37
|
-
const floatsToCopy = Math.min(floatsInBuf, floatsNeeded);
|
|
38
|
-
const bytesToCopy = floatsToCopy * 4;
|
|
39
|
-
// Copy to outBuffer.
|
|
40
|
-
// Create a view on the buffer to read floats.
|
|
41
|
-
// We need to ensure byteOffset is a multiple of 4.
|
|
42
|
-
// If not, we must copy the buffer to a new one.
|
|
43
|
-
let srcFloats;
|
|
44
|
-
if (buf.byteOffset % 4 === 0) {
|
|
45
|
-
srcFloats = new Float32Array(buf.buffer, buf.byteOffset, floatsInBuf);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
const alignedBuf = new Uint8Array(buf);
|
|
49
|
-
srcFloats = new Float32Array(alignedBuf.buffer, alignedBuf.byteOffset, floatsInBuf);
|
|
50
|
-
}
|
|
51
|
-
outBuffer.set(srcFloats.subarray(0, floatsToCopy), outOffset);
|
|
52
|
-
totalFloatsRead += floatsToCopy;
|
|
53
|
-
outOffset += floatsToCopy;
|
|
54
|
-
if (floatsToCopy < floatsInBuf) {
|
|
55
|
-
// We didn't use the whole buffer. Update it.
|
|
56
|
-
this.buffers[0] = buf.subarray(bytesToCopy);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// We used the whole buffer. Remove it.
|
|
60
|
-
this.buffers.shift();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return totalFloatsRead;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
class WebSocketWrapper {
|
|
67
|
-
constructor(client, config) {
|
|
68
|
-
this.socket = null;
|
|
69
|
-
this.sources = new Map();
|
|
70
|
-
// Fallback source for messages without context_id or if we just want to capture everything (legacy behavior?)
|
|
71
|
-
// The original test didn't use context_id explicitly in send() but expected a response source.
|
|
72
|
-
// We'll map context_id to source.
|
|
73
|
-
this.defaultSource = null;
|
|
74
|
-
this.client = client;
|
|
75
|
-
this.config = config;
|
|
76
|
-
}
|
|
77
|
-
async connect() {
|
|
78
|
-
const baseURL = this.client.baseURL;
|
|
79
|
-
// Construct WebSocket URL
|
|
80
|
-
// baseURL is like https://api.cartesia.ai
|
|
81
|
-
let urlStr = baseURL.replace(/^http/, "ws");
|
|
82
|
-
if (!urlStr.includes("/tts/websocket")) {
|
|
83
|
-
if (urlStr.endsWith("/")) {
|
|
84
|
-
urlStr += "tts/websocket";
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
urlStr += "/tts/websocket";
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const url = new URL(urlStr);
|
|
91
|
-
const headers = {
|
|
92
|
-
"cartesia-version": "2025-04-16",
|
|
93
|
-
};
|
|
94
|
-
if (this.client.apiKey) {
|
|
95
|
-
headers["Authorization"] = `Bearer ${this.client.apiKey}`;
|
|
96
|
-
}
|
|
97
|
-
this.socket = new WebSocket(url.toString(), {
|
|
98
|
-
headers: headers,
|
|
99
|
-
});
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
this.socket.on("open", () => {
|
|
102
|
-
console.log("WebSocket connected.");
|
|
103
|
-
resolve();
|
|
104
|
-
});
|
|
105
|
-
this.socket.on("error", (err) => {
|
|
106
|
-
console.error("WebSocket error:", err);
|
|
107
|
-
reject(err);
|
|
108
|
-
});
|
|
109
|
-
this.socket.on("message", (data) => {
|
|
110
|
-
this.handleMessage(data);
|
|
111
|
-
});
|
|
112
|
-
this.socket.on("close", () => {
|
|
113
|
-
console.log("WebSocket closed.");
|
|
114
|
-
this.sources.forEach((s) => { s.markDone(); });
|
|
115
|
-
if (this.defaultSource)
|
|
116
|
-
this.defaultSource.markDone();
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
handleMessage(data) {
|
|
121
|
-
try {
|
|
122
|
-
const str = data.toString();
|
|
123
|
-
const msg = JSON.parse(str);
|
|
124
|
-
const contextId = msg.context_id;
|
|
125
|
-
let source = contextId ? this.sources.get(contextId) : this.defaultSource;
|
|
126
|
-
// If we received a message for a context we don't know about, and we have a default source, use it
|
|
127
|
-
if (!source && this.defaultSource) {
|
|
128
|
-
source = this.defaultSource;
|
|
129
|
-
}
|
|
130
|
-
if (msg.type === "chunk" && msg.data) {
|
|
131
|
-
const audioData = Buffer.from(msg.data, "base64");
|
|
132
|
-
if (source)
|
|
133
|
-
source.push(audioData);
|
|
134
|
-
}
|
|
135
|
-
else if (msg.type === "done") {
|
|
136
|
-
if (source)
|
|
137
|
-
source.markDone();
|
|
138
|
-
}
|
|
139
|
-
else if (msg.type === "error") {
|
|
140
|
-
console.error("Server error:", msg);
|
|
141
|
-
if (source)
|
|
142
|
-
source.markDone(); // Fail the stream?
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
console.error("Error parsing message:", e);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
async send(request) {
|
|
150
|
-
if (!this.socket) {
|
|
151
|
-
throw new Error("WebSocket not connected");
|
|
152
|
-
}
|
|
153
|
-
// Ensure request has a context_id so we can route the response
|
|
154
|
-
if (!request.context_id) {
|
|
155
|
-
request.context_id = uuidv4();
|
|
156
|
-
}
|
|
157
|
-
const source = new AudioSource();
|
|
158
|
-
this.sources.set(request.context_id, source);
|
|
159
|
-
// Also set as default source if none exists, for compatibility with simple tests
|
|
160
|
-
if (!this.defaultSource) {
|
|
161
|
-
this.defaultSource = source;
|
|
2
|
+
import { TTSWrapper } from "./tts-wrapper.mjs";
|
|
3
|
+
import { VoicesWrapper } from "./voices-wrapper.mjs";
|
|
4
|
+
import { VoiceChangerWrapper } from "./voice-changer-wrapper.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use the {@link Cartesia} class directly instead.
|
|
7
|
+
*
|
|
8
|
+
* This class is provided for backward compatibility with the legacy SDK and may be removed in a future release.
|
|
9
|
+
*/
|
|
10
|
+
export class CartesiaClient {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
const newOptions = {};
|
|
13
|
+
if (options.apiKey) {
|
|
14
|
+
newOptions.apiKey = options.apiKey;
|
|
162
15
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
request.output_format = {
|
|
166
|
-
container: this.config.container,
|
|
167
|
-
encoding: this.config.encoding,
|
|
168
|
-
sample_rate: this.config.sampleRate,
|
|
169
|
-
};
|
|
16
|
+
if (options.baseUrl) {
|
|
17
|
+
newOptions.baseURL = options.baseUrl;
|
|
170
18
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// The GenerationRequest interface has `output_format`.
|
|
174
|
-
// The config passed to .websocket() uses `sampleRate`.
|
|
175
|
-
// We might need to map it.
|
|
176
|
-
if (request.output_format) {
|
|
177
|
-
// Ensure sample_rate is set (mapping from sampleRate)
|
|
178
|
-
if (request.output_format.sampleRate && !request.output_format.sample_rate) {
|
|
179
|
-
request.output_format.sample_rate = request.output_format.sampleRate;
|
|
180
|
-
delete request.output_format.sampleRate;
|
|
181
|
-
}
|
|
19
|
+
else if (options.environment) {
|
|
20
|
+
newOptions.baseURL = options.environment;
|
|
182
21
|
}
|
|
183
|
-
|
|
184
|
-
// The old test uses `modelId`, `generationConfig`.
|
|
185
|
-
// The new API expects `model_id`, `generation_config`.
|
|
186
|
-
const payload = {
|
|
187
|
-
...request,
|
|
188
|
-
model_id: request.modelId || request.model_id,
|
|
189
|
-
generation_config: request.generationConfig || request.generation_config,
|
|
190
|
-
context_id: request.context_id,
|
|
191
|
-
};
|
|
192
|
-
// Remove camelCase keys if they persist?
|
|
193
|
-
// JSON.stringify handles it, but we should clean up if we want to be strict.
|
|
194
|
-
// Also `voice` object. Old test: `voice: { mode: 'id', id: ... }`. New API: same.
|
|
195
|
-
this.socket.send(JSON.stringify(payload));
|
|
196
|
-
return {
|
|
197
|
-
source: source
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
disconnect() {
|
|
201
|
-
if (this.socket) {
|
|
202
|
-
this.socket.close();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
class TTSWrapper {
|
|
207
|
-
constructor(client) {
|
|
208
|
-
this.client = client;
|
|
209
|
-
}
|
|
210
|
-
websocket(config) {
|
|
211
|
-
return new WebSocketWrapper(this.client, config);
|
|
212
|
-
}
|
|
213
|
-
async bytes(request, requestOptions) {
|
|
214
|
-
const params = {
|
|
215
|
-
model_id: request.modelId,
|
|
216
|
-
transcript: request.transcript,
|
|
217
|
-
voice: request.voice,
|
|
218
|
-
generation_config: request.generationConfig,
|
|
219
|
-
context_id: request.contextId,
|
|
220
|
-
};
|
|
221
|
-
if (request.outputFormat) {
|
|
222
|
-
params.output_format = {
|
|
223
|
-
...request.outputFormat,
|
|
224
|
-
sample_rate: request.outputFormat.sampleRate,
|
|
225
|
-
bit_rate: request.outputFormat.bitRate,
|
|
226
|
-
};
|
|
227
|
-
// Remove camelCase keys
|
|
228
|
-
delete params.output_format.sampleRate;
|
|
229
|
-
delete params.output_format.bitRate;
|
|
230
|
-
}
|
|
231
|
-
const options = {};
|
|
232
|
-
if (requestOptions) {
|
|
233
|
-
if (requestOptions.timeoutInSeconds) {
|
|
234
|
-
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
235
|
-
}
|
|
236
|
-
options.maxRetries = requestOptions.maxRetries;
|
|
237
|
-
options.headers = requestOptions.headers;
|
|
238
|
-
options.signal = requestOptions.abortSignal;
|
|
239
|
-
}
|
|
240
|
-
// @ts-ignore
|
|
241
|
-
return this.client.tts.synthesizeBytes(params, options);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
/*
|
|
245
|
-
* CartesiaClient - deprecated backcompat class.
|
|
246
|
-
* New code should use Cartesia class directly instead.
|
|
247
|
-
*/
|
|
248
|
-
export class CartesiaClient {
|
|
249
|
-
constructor(options) {
|
|
250
|
-
this.client = new Cartesia(options);
|
|
22
|
+
this.client = new Cartesia(newOptions);
|
|
251
23
|
this.tts = new TTSWrapper(this.client);
|
|
24
|
+
this.voices = new VoicesWrapper(this.client);
|
|
25
|
+
this.voiceChanger = new VoiceChangerWrapper(this.client);
|
|
252
26
|
}
|
|
253
27
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
});
|
|
260
|
-
}
|
|
28
|
+
export * from "./tts-wrapper.mjs";
|
|
29
|
+
export * from "./voices-wrapper.mjs";
|
|
30
|
+
export * from "./voice-changer-wrapper.mjs";
|
|
31
|
+
export * from "./types.mjs";
|
|
32
|
+
export * from "./errors.mjs";
|
|
261
33
|
//# sourceMappingURL=index.mjs.map
|
package/backcompat/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/backcompat/index.ts"],"names":[],"mappings":"OAAO,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/backcompat/index.ts"],"names":[],"mappings":"OAAO,EAAE,QAAQ,EAAsB;OAChC,EAAE,UAAU,EAAE;OACd,EAAE,aAAa,EAAE;OACjB,EAAE,mBAAmB,EAAE;AAG9B;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAM1B,YAAY,UAAiC,EAAE;QAC9C,MAAM,UAAU,GAAkB,EAAE,CAAC;QAErC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,UAAU,CAAC,MAAM,GAAG,OAAO,CAAC,MAAa,CAAC;QAC3C,CAAC;QAED,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC,OAAc,CAAC;QAC7C,CAAC;aAAM,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YAChC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC,WAAkB,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;QACvC,IAAI,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC;CACD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Cartesia } from "../client.mjs";
|
|
2
|
+
import { BackCompatRequestOptions } from "./types.mjs";
|
|
3
|
+
export interface BackCompatWebSocketOptions {
|
|
4
|
+
container?: "raw" | "wav" | "mp3";
|
|
5
|
+
encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
6
|
+
sampleRate: number;
|
|
7
|
+
}
|
|
8
|
+
export type BackCompatTtsRequestVoiceSpecifier = {
|
|
9
|
+
mode: "id";
|
|
10
|
+
id: string;
|
|
11
|
+
} | {
|
|
12
|
+
mode: "embedding";
|
|
13
|
+
embedding: number[];
|
|
14
|
+
};
|
|
15
|
+
export interface BackCompatGenerationConfig {
|
|
16
|
+
volume?: number;
|
|
17
|
+
speed?: number;
|
|
18
|
+
emotion?: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface BackCompatWebSocketTtsRequest {
|
|
21
|
+
modelId: string;
|
|
22
|
+
transcript: string;
|
|
23
|
+
voice: BackCompatTtsRequestVoiceSpecifier;
|
|
24
|
+
generationConfig?: BackCompatGenerationConfig;
|
|
25
|
+
outputFormat?: {
|
|
26
|
+
container?: "raw" | "wav" | "mp3";
|
|
27
|
+
encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
28
|
+
sampleRate?: number;
|
|
29
|
+
bitRate?: number;
|
|
30
|
+
};
|
|
31
|
+
contextId?: string;
|
|
32
|
+
continue?: boolean;
|
|
33
|
+
duration?: number;
|
|
34
|
+
addTimestamps?: boolean;
|
|
35
|
+
addPhonemeTimestamps?: boolean;
|
|
36
|
+
}
|
|
37
|
+
declare class AudioSource {
|
|
38
|
+
private buffers;
|
|
39
|
+
private waiter;
|
|
40
|
+
isDone: boolean;
|
|
41
|
+
push(data: Buffer): void;
|
|
42
|
+
markDone(): void;
|
|
43
|
+
read(outBuffer: Float32Array): Promise<number>;
|
|
44
|
+
}
|
|
45
|
+
export declare class WebSocketWrapper {
|
|
46
|
+
private client;
|
|
47
|
+
private config;
|
|
48
|
+
private socket;
|
|
49
|
+
private sources;
|
|
50
|
+
private defaultSource;
|
|
51
|
+
constructor(client: Cartesia, config: BackCompatWebSocketOptions);
|
|
52
|
+
connect(): Promise<void>;
|
|
53
|
+
private handleMessage;
|
|
54
|
+
send(request: BackCompatWebSocketTtsRequest): Promise<{
|
|
55
|
+
source: AudioSource;
|
|
56
|
+
}>;
|
|
57
|
+
disconnect(): void;
|
|
58
|
+
}
|
|
59
|
+
/** @deprecated Use the new SDK's tts methods on the {@link Cartesia} instance instead. */
|
|
60
|
+
export declare class TTSWrapper {
|
|
61
|
+
private client;
|
|
62
|
+
constructor(client: Cartesia);
|
|
63
|
+
/** @deprecated Use {@link Cartesia.tts.websocket} instead. */
|
|
64
|
+
websocket(config: BackCompatWebSocketOptions): WebSocketWrapper;
|
|
65
|
+
/** @deprecated Use {@link Cartesia.tts.synthesizeBytes} instead. */
|
|
66
|
+
bytes(request: any, requestOptions?: BackCompatRequestOptions): Promise<unknown>;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=tts-wrapper.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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AC,EAAE,OAAO,CAAC;CAC/B;AAUD,cAAM,WAAW;IAChB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAAsC;IAC7C,MAAM,UAAS;IAEtB,IAAI,CAAC,IAAI,EAAE,MAAM;IAQjB,QAAQ;IAQF,IAAI,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;CAkDpD;AAED,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,OAAO,CAAuC;IAItD,OAAO,CAAC,aAAa,CAA4B;gBAErC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,0BAA0B;IAK1D,OAAO;IAiDb,OAAO,CAAC,aAAa;IA2Bf,IAAI,CAAC,OAAO,EAAE,6BAA6B;;;IAyDjD,UAAU;CAKV;AAED,0FAA0F;AAC1F,qBAAa,UAAU;IACtB,OAAO,CAAC,MAAM,CAAW;gBAEb,MAAM,EAAE,QAAQ;IAI5B,8DAA8D;IAC9D,SAAS,CAAC,MAAM,EAAE,0BAA0B;IAI5C,oEAAoE;IAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,wBAAwB;CAmCnE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Cartesia } from "../client.js";
|
|
2
|
+
import { BackCompatRequestOptions } from "./types.js";
|
|
3
|
+
export interface BackCompatWebSocketOptions {
|
|
4
|
+
container?: "raw" | "wav" | "mp3";
|
|
5
|
+
encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
6
|
+
sampleRate: number;
|
|
7
|
+
}
|
|
8
|
+
export type BackCompatTtsRequestVoiceSpecifier = {
|
|
9
|
+
mode: "id";
|
|
10
|
+
id: string;
|
|
11
|
+
} | {
|
|
12
|
+
mode: "embedding";
|
|
13
|
+
embedding: number[];
|
|
14
|
+
};
|
|
15
|
+
export interface BackCompatGenerationConfig {
|
|
16
|
+
volume?: number;
|
|
17
|
+
speed?: number;
|
|
18
|
+
emotion?: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface BackCompatWebSocketTtsRequest {
|
|
21
|
+
modelId: string;
|
|
22
|
+
transcript: string;
|
|
23
|
+
voice: BackCompatTtsRequestVoiceSpecifier;
|
|
24
|
+
generationConfig?: BackCompatGenerationConfig;
|
|
25
|
+
outputFormat?: {
|
|
26
|
+
container?: "raw" | "wav" | "mp3";
|
|
27
|
+
encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
28
|
+
sampleRate?: number;
|
|
29
|
+
bitRate?: number;
|
|
30
|
+
};
|
|
31
|
+
contextId?: string;
|
|
32
|
+
continue?: boolean;
|
|
33
|
+
duration?: number;
|
|
34
|
+
addTimestamps?: boolean;
|
|
35
|
+
addPhonemeTimestamps?: boolean;
|
|
36
|
+
}
|
|
37
|
+
declare class AudioSource {
|
|
38
|
+
private buffers;
|
|
39
|
+
private waiter;
|
|
40
|
+
isDone: boolean;
|
|
41
|
+
push(data: Buffer): void;
|
|
42
|
+
markDone(): void;
|
|
43
|
+
read(outBuffer: Float32Array): Promise<number>;
|
|
44
|
+
}
|
|
45
|
+
export declare class WebSocketWrapper {
|
|
46
|
+
private client;
|
|
47
|
+
private config;
|
|
48
|
+
private socket;
|
|
49
|
+
private sources;
|
|
50
|
+
private defaultSource;
|
|
51
|
+
constructor(client: Cartesia, config: BackCompatWebSocketOptions);
|
|
52
|
+
connect(): Promise<void>;
|
|
53
|
+
private handleMessage;
|
|
54
|
+
send(request: BackCompatWebSocketTtsRequest): Promise<{
|
|
55
|
+
source: AudioSource;
|
|
56
|
+
}>;
|
|
57
|
+
disconnect(): void;
|
|
58
|
+
}
|
|
59
|
+
/** @deprecated Use the new SDK's tts methods on the {@link Cartesia} instance instead. */
|
|
60
|
+
export declare class TTSWrapper {
|
|
61
|
+
private client;
|
|
62
|
+
constructor(client: Cartesia);
|
|
63
|
+
/** @deprecated Use {@link Cartesia.tts.websocket} instead. */
|
|
64
|
+
websocket(config: BackCompatWebSocketOptions): WebSocketWrapper;
|
|
65
|
+
/** @deprecated Use {@link Cartesia.tts.synthesizeBytes} instead. */
|
|
66
|
+
bytes(request: any, requestOptions?: BackCompatRequestOptions): Promise<unknown>;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=tts-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tts-wrapper.d.ts","sourceRoot":"","sources":["../src/backcompat/tts-wrapper.ts"],"names":[],"mappings":"OACO,EAAE,QAAQ,EAAE;OAEZ,EAAE,wBAAwB,EAAE;AAInC,MAAM,WAAW,0BAA0B;IAC1C,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IAClC,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;IAChE,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,kCAAkC,GAC3C;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE9C,MAAM,WAAW,0BAA0B;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,6BAA6B;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,kCAAkC,CAAC;IAC1C,gBAAgB,CAAC,EAAE,0BAA0B,CAAC;IAC9C,YAAY,CAAC,EAAE;QACd,SAAS,CAAC,EAAE,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