@cartesia/cartesia-js 3.0.0-b4 → 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 +12 -0
- package/README.md +25 -21
- package/backcompat/index.d.mts +16 -0
- package/backcompat/index.d.mts.map +1 -0
- package/backcompat/index.d.ts +16 -0
- package/backcompat/index.d.ts.map +1 -0
- package/backcompat/index.js +36 -0
- package/backcompat/index.js.map +1 -0
- package/backcompat/index.mjs +31 -0
- package/backcompat/index.mjs.map +1 -0
- 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/index.d.mts +1 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/internal/tslib.js +4 -0
- package/package.json +11 -1
- package/src/backcompat/index.ts +40 -0
- 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/index.ts +1 -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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.0.0-b6 (2026-01-09)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v3.0.0-b5...v3.0.0-b6](https://github.com/cartesia-ai/cartesia-js-internal/compare/v3.0.0-b5...v3.0.0-b6)
|
|
6
|
+
|
|
7
|
+
## 3.0.0-b5 (2026-01-07)
|
|
8
|
+
|
|
9
|
+
Full Changelog: [v3.0.0-b4...v3.0.0-b5](https://github.com/cartesia-ai/cartesia-js-internal/compare/v3.0.0-b4...v3.0.0-b5)
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **api:** fix readme ([91bd83c](https://github.com/cartesia-ai/cartesia-js-internal/commit/91bd83cb75d8b92778928cf7aebab908f7723b79))
|
|
14
|
+
|
|
3
15
|
## 3.0.0-b4 (2026-01-07)
|
|
4
16
|
|
|
5
17
|
Full Changelog: [v3.0.0-b3...v3.0.0-b4](https://github.com/cartesia-ai/cartesia-js-internal/compare/v3.0.0-b3...v3.0.0-b4)
|
package/README.md
CHANGED
|
@@ -23,12 +23,13 @@ The full API of this library can be found in [api.md](api.md).
|
|
|
23
23
|
import Cartesia from '@cartesia/cartesia-js';
|
|
24
24
|
|
|
25
25
|
const client = new Cartesia({
|
|
26
|
-
|
|
26
|
+
apiKey: 'My API Key',
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const page = await client.voices.list();
|
|
30
|
+
const voice = page.data[0];
|
|
30
31
|
|
|
31
|
-
console.log(
|
|
32
|
+
console.log(voice.id);
|
|
32
33
|
```
|
|
33
34
|
|
|
34
35
|
### Request & Response types
|
|
@@ -40,10 +41,10 @@ This library includes TypeScript definitions for all request params and response
|
|
|
40
41
|
import Cartesia from '@cartesia/cartesia-js';
|
|
41
42
|
|
|
42
43
|
const client = new Cartesia({
|
|
43
|
-
|
|
44
|
+
apiKey: 'My API Key',
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
const
|
|
47
|
+
const [voice]: [Cartesia.Voice] = await client.voices.list();
|
|
47
48
|
```
|
|
48
49
|
|
|
49
50
|
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
|
|
@@ -85,7 +86,7 @@ a subclass of `APIError` will be thrown:
|
|
|
85
86
|
|
|
86
87
|
<!-- prettier-ignore -->
|
|
87
88
|
```ts
|
|
88
|
-
const
|
|
89
|
+
const page = await client.voices.list().catch(async (err) => {
|
|
89
90
|
if (err instanceof Cartesia.APIError) {
|
|
90
91
|
console.log(err.status); // 400
|
|
91
92
|
console.log(err.name); // BadRequestError
|
|
@@ -125,7 +126,7 @@ const client = new Cartesia({
|
|
|
125
126
|
});
|
|
126
127
|
|
|
127
128
|
// Or, configure per-request:
|
|
128
|
-
await client.
|
|
129
|
+
await client.voices.list({
|
|
129
130
|
maxRetries: 5,
|
|
130
131
|
});
|
|
131
132
|
```
|
|
@@ -142,7 +143,7 @@ const client = new Cartesia({
|
|
|
142
143
|
});
|
|
143
144
|
|
|
144
145
|
// Override per-request:
|
|
145
|
-
await client.
|
|
146
|
+
await client.voices.list({
|
|
146
147
|
timeout: 5 * 1000,
|
|
147
148
|
});
|
|
148
149
|
```
|
|
@@ -157,22 +158,22 @@ List methods in the Cartesia API are paginated.
|
|
|
157
158
|
You can use the `for await … of` syntax to iterate through items across all pages:
|
|
158
159
|
|
|
159
160
|
```ts
|
|
160
|
-
async function
|
|
161
|
-
const
|
|
161
|
+
async function fetchAllVoices(params) {
|
|
162
|
+
const allVoices = [];
|
|
162
163
|
// Automatically fetches more pages as needed.
|
|
163
|
-
for await (const
|
|
164
|
-
|
|
164
|
+
for await (const voice of client.voices.list()) {
|
|
165
|
+
allVoices.push(voice);
|
|
165
166
|
}
|
|
166
|
-
return
|
|
167
|
+
return allVoices;
|
|
167
168
|
}
|
|
168
169
|
```
|
|
169
170
|
|
|
170
171
|
Alternatively, you can request a single page at a time:
|
|
171
172
|
|
|
172
173
|
```ts
|
|
173
|
-
let page = await client.
|
|
174
|
-
for (const
|
|
175
|
-
console.log(
|
|
174
|
+
let page = await client.voices.list();
|
|
175
|
+
for (const voice of page.data) {
|
|
176
|
+
console.log(voice);
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
// Convenience methods are provided for manually paginating:
|
|
@@ -193,7 +194,8 @@ import Cartesia from '@cartesia/cartesia-js';
|
|
|
193
194
|
|
|
194
195
|
const client = new Cartesia();
|
|
195
196
|
|
|
196
|
-
const
|
|
197
|
+
const page = await client.voices.list({ headers: { 'cartesia-version': 'My-Custom-Value' } });
|
|
198
|
+
const voice = page.data[0];
|
|
197
199
|
```
|
|
198
200
|
|
|
199
201
|
## Advanced Usage
|
|
@@ -210,13 +212,15 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
|
|
|
210
212
|
```ts
|
|
211
213
|
const client = new Cartesia();
|
|
212
214
|
|
|
213
|
-
const response = await client.
|
|
215
|
+
const response = await client.voices.list().asResponse();
|
|
214
216
|
console.log(response.headers.get('X-My-Header'));
|
|
215
217
|
console.log(response.statusText); // access the underlying Response object
|
|
216
218
|
|
|
217
|
-
const { data:
|
|
219
|
+
const { data: page, response: raw } = await client.voices.list().withResponse();
|
|
218
220
|
console.log(raw.headers.get('X-My-Header'));
|
|
219
|
-
|
|
221
|
+
for await (const voice of page) {
|
|
222
|
+
console.log(voice.id);
|
|
223
|
+
}
|
|
220
224
|
```
|
|
221
225
|
|
|
222
226
|
### Logging
|
|
@@ -296,7 +300,7 @@ parameter. This library doesn't validate at runtime that the request matches the
|
|
|
296
300
|
send will be sent as-is.
|
|
297
301
|
|
|
298
302
|
```ts
|
|
299
|
-
client.
|
|
303
|
+
client.voices.list({
|
|
300
304
|
// ...
|
|
301
305
|
// @ts-expect-error baz is not yet public
|
|
302
306
|
baz: 'undocumented option',
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TTSWrapper } from "./tts-wrapper.mjs";
|
|
2
|
+
import { VoicesWrapper } from "./voices-wrapper.mjs";
|
|
3
|
+
import { VoiceChangerWrapper } from "./voice-changer-wrapper.mjs";
|
|
4
|
+
import type { CartesiaClientOptions } from "./types.mjs";
|
|
5
|
+
export declare class CartesiaClient {
|
|
6
|
+
private client;
|
|
7
|
+
tts: TTSWrapper;
|
|
8
|
+
voices: VoicesWrapper;
|
|
9
|
+
voiceChanger: VoiceChangerWrapper;
|
|
10
|
+
constructor(options?: CartesiaClientOptions);
|
|
11
|
+
}
|
|
12
|
+
export * from "./tts-wrapper.mjs";
|
|
13
|
+
export * from "./voices-wrapper.mjs";
|
|
14
|
+
export * from "./voice-changer-wrapper.mjs";
|
|
15
|
+
export * from "./types.mjs";
|
|
16
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/backcompat/index.ts"],"names":[],"mappings":"OACO,EAAE,UAAU,EAAE;OACd,EAAE,aAAa,EAAE;OACjB,EAAE,mBAAmB,EAAE;OACvB,KAAK,EAAE,qBAAqB,EAAE;AAMrC,qBAAa,cAAc;IAC1B,OAAO,CAAC,MAAM,CAAW;IAClB,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,YAAY,EAAE,mBAAmB,CAAC;gBAE7B,OAAO,GAAE,qBAA0B;CAkB/C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TTSWrapper } from "./tts-wrapper.js";
|
|
2
|
+
import { VoicesWrapper } from "./voices-wrapper.js";
|
|
3
|
+
import { VoiceChangerWrapper } from "./voice-changer-wrapper.js";
|
|
4
|
+
import type { CartesiaClientOptions } from "./types.js";
|
|
5
|
+
export declare class CartesiaClient {
|
|
6
|
+
private client;
|
|
7
|
+
tts: TTSWrapper;
|
|
8
|
+
voices: VoicesWrapper;
|
|
9
|
+
voiceChanger: VoiceChangerWrapper;
|
|
10
|
+
constructor(options?: CartesiaClientOptions);
|
|
11
|
+
}
|
|
12
|
+
export * from "./tts-wrapper.js";
|
|
13
|
+
export * from "./voices-wrapper.js";
|
|
14
|
+
export * from "./voice-changer-wrapper.js";
|
|
15
|
+
export * from "./types.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/backcompat/index.ts"],"names":[],"mappings":"OACO,EAAE,UAAU,EAAE;OACd,EAAE,aAAa,EAAE;OACjB,EAAE,mBAAmB,EAAE;OACvB,KAAK,EAAE,qBAAqB,EAAE;AAMrC,qBAAa,cAAc;IAC1B,OAAO,CAAC,MAAM,CAAW;IAClB,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,YAAY,EAAE,mBAAmB,CAAC;gBAE7B,OAAO,GAAE,qBAA0B;CAkB/C"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CartesiaClient = void 0;
|
|
4
|
+
const tslib_1 = require("../internal/tslib.js");
|
|
5
|
+
const client_1 = require("../client.js");
|
|
6
|
+
const tts_wrapper_1 = require("./tts-wrapper.js");
|
|
7
|
+
const voices_wrapper_1 = require("./voices-wrapper.js");
|
|
8
|
+
const voice_changer_wrapper_1 = require("./voice-changer-wrapper.js");
|
|
9
|
+
/*
|
|
10
|
+
* CartesiaClient - deprecated backcompat class.
|
|
11
|
+
* New code should use Cartesia class directly instead.
|
|
12
|
+
*/
|
|
13
|
+
class CartesiaClient {
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
const newOptions = {};
|
|
16
|
+
if (options.apiKey) {
|
|
17
|
+
newOptions.apiKey = options.apiKey;
|
|
18
|
+
}
|
|
19
|
+
if (options.baseUrl) {
|
|
20
|
+
newOptions.baseURL = options.baseUrl;
|
|
21
|
+
}
|
|
22
|
+
else if (options.environment) {
|
|
23
|
+
newOptions.baseURL = options.environment;
|
|
24
|
+
}
|
|
25
|
+
this.client = new client_1.Cartesia(newOptions);
|
|
26
|
+
this.tts = new tts_wrapper_1.TTSWrapper(this.client);
|
|
27
|
+
this.voices = new voices_wrapper_1.VoicesWrapper(this.client);
|
|
28
|
+
this.voiceChanger = new voice_changer_wrapper_1.VoiceChangerWrapper(this.client);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.CartesiaClient = CartesiaClient;
|
|
32
|
+
tslib_1.__exportStar(require("./tts-wrapper.js"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./voices-wrapper.js"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./voice-changer-wrapper.js"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/backcompat/index.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AACzD,kDAA2C;AAC3C,wDAAiD;AACjD,sEAA8D;AAG9D;;;GAGG;AACH,MAAa,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,iBAAQ,CAAC,UAAU,CAAC,CAAC;QACvC,IAAI,CAAC,GAAG,GAAG,IAAI,wBAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,IAAI,8BAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,2CAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC;CACD;AAxBD,wCAwBC;AAED,2DAA8B;AAC9B,8DAAiC;AACjC,qEAAwC;AACxC,qDAAwB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Cartesia } from "../client.mjs";
|
|
2
|
+
import { TTSWrapper } from "./tts-wrapper.mjs";
|
|
3
|
+
import { VoicesWrapper } from "./voices-wrapper.mjs";
|
|
4
|
+
import { VoiceChangerWrapper } from "./voice-changer-wrapper.mjs";
|
|
5
|
+
/*
|
|
6
|
+
* CartesiaClient - deprecated backcompat class.
|
|
7
|
+
* New code should use Cartesia class directly instead.
|
|
8
|
+
*/
|
|
9
|
+
export class CartesiaClient {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
const newOptions = {};
|
|
12
|
+
if (options.apiKey) {
|
|
13
|
+
newOptions.apiKey = options.apiKey;
|
|
14
|
+
}
|
|
15
|
+
if (options.baseUrl) {
|
|
16
|
+
newOptions.baseURL = options.baseUrl;
|
|
17
|
+
}
|
|
18
|
+
else if (options.environment) {
|
|
19
|
+
newOptions.baseURL = options.environment;
|
|
20
|
+
}
|
|
21
|
+
this.client = new Cartesia(newOptions);
|
|
22
|
+
this.tts = new TTSWrapper(this.client);
|
|
23
|
+
this.voices = new VoicesWrapper(this.client);
|
|
24
|
+
this.voiceChanger = new VoiceChangerWrapper(this.client);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export * from "./tts-wrapper.mjs";
|
|
28
|
+
export * from "./voices-wrapper.mjs";
|
|
29
|
+
export * from "./voice-changer-wrapper.mjs";
|
|
30
|
+
export * from "./types.mjs";
|
|
31
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;GAGG;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,66 @@
|
|
|
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
|
+
export declare class TTSWrapper {
|
|
60
|
+
private client;
|
|
61
|
+
constructor(client: Cartesia);
|
|
62
|
+
websocket(config: BackCompatWebSocketOptions): WebSocketWrapper;
|
|
63
|
+
bytes(request: any, requestOptions?: BackCompatRequestOptions): Promise<any>;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=tts-wrapper.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tts-wrapper.d.mts","sourceRoot":"","sources":["../src/backcompat/tts-wrapper.ts"],"names":[],"mappings":"OACO,EAAE,QAAQ,EAAE;OAEZ,EAAE,wBAAwB,EAAE;AAGnC,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,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;QAClC,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;QAChE,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,oBAAoB,CAAC,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,qBAAa,UAAU;IACtB,OAAO,CAAC,MAAM,CAAW;gBAEb,MAAM,EAAE,QAAQ;IAI5B,SAAS,CAAC,MAAM,EAAE,0BAA0B;IAItC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,wBAAwB;CAmCnE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
export declare class TTSWrapper {
|
|
60
|
+
private client;
|
|
61
|
+
constructor(client: Cartesia);
|
|
62
|
+
websocket(config: BackCompatWebSocketOptions): WebSocketWrapper;
|
|
63
|
+
bytes(request: any, requestOptions?: BackCompatRequestOptions): Promise<any>;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
66
|
+
//# 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;AAGnC,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,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;QAClC,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;QAChE,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,oBAAoB,CAAC,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,qBAAa,UAAU;IACtB,OAAO,CAAC,MAAM,CAAW;gBAEb,MAAM,EAAE,QAAQ;IAI5B,SAAS,CAAC,MAAM,EAAE,0BAA0B;IAItC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,wBAAwB;CAmCnE"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TTSWrapper = exports.WebSocketWrapper = void 0;
|
|
4
|
+
const tslib_1 = require("../internal/tslib.js");
|
|
5
|
+
const ws_1 = tslib_1.__importDefault(require("ws"));
|
|
6
|
+
// Helper for generating UUIDs. Not cryptographically secure.
|
|
7
|
+
function uuidv4() {
|
|
8
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
9
|
+
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
10
|
+
return v.toString(16);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
class AudioSource {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.buffers = [];
|
|
16
|
+
this.waiter = null;
|
|
17
|
+
this.isDone = false;
|
|
18
|
+
}
|
|
19
|
+
push(data) {
|
|
20
|
+
this.buffers.push(data);
|
|
21
|
+
if (this.waiter) {
|
|
22
|
+
this.waiter();
|
|
23
|
+
this.waiter = null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
markDone() {
|
|
27
|
+
this.isDone = true;
|
|
28
|
+
if (this.waiter) {
|
|
29
|
+
this.waiter();
|
|
30
|
+
this.waiter = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async read(outBuffer) {
|
|
34
|
+
if (this.buffers.length === 0 && !this.isDone) {
|
|
35
|
+
await new Promise((resolve) => { this.waiter = resolve; });
|
|
36
|
+
}
|
|
37
|
+
if (this.buffers.length === 0 && this.isDone) {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
let totalFloatsRead = 0;
|
|
41
|
+
let outOffset = 0;
|
|
42
|
+
const maxFloats = outBuffer.length;
|
|
43
|
+
while (this.buffers.length > 0 && totalFloatsRead < maxFloats) {
|
|
44
|
+
const buf = this.buffers[0]; // ts not smart enough to check loop condition
|
|
45
|
+
const floatsInBuf = buf.length / 4;
|
|
46
|
+
const floatsNeeded = maxFloats - totalFloatsRead;
|
|
47
|
+
const floatsToCopy = Math.min(floatsInBuf, floatsNeeded);
|
|
48
|
+
const bytesToCopy = floatsToCopy * 4;
|
|
49
|
+
// Copy to outBuffer.
|
|
50
|
+
// Create a view on the buffer to read floats.
|
|
51
|
+
// We need to ensure byteOffset is a multiple of 4.
|
|
52
|
+
// If not, we must copy the buffer to a new one.
|
|
53
|
+
let srcFloats;
|
|
54
|
+
if (buf.byteOffset % 4 === 0) {
|
|
55
|
+
srcFloats = new Float32Array(buf.buffer, buf.byteOffset, floatsInBuf);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const alignedBuf = new Uint8Array(buf);
|
|
59
|
+
srcFloats = new Float32Array(alignedBuf.buffer, alignedBuf.byteOffset, floatsInBuf);
|
|
60
|
+
}
|
|
61
|
+
outBuffer.set(srcFloats.subarray(0, floatsToCopy), outOffset);
|
|
62
|
+
totalFloatsRead += floatsToCopy;
|
|
63
|
+
outOffset += floatsToCopy;
|
|
64
|
+
if (floatsToCopy < floatsInBuf) {
|
|
65
|
+
// We didn't use the whole buffer. Update it.
|
|
66
|
+
this.buffers[0] = buf.subarray(bytesToCopy);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// We used the whole buffer. Remove it.
|
|
70
|
+
this.buffers.shift();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return totalFloatsRead;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
class WebSocketWrapper {
|
|
77
|
+
constructor(client, config) {
|
|
78
|
+
this.socket = null;
|
|
79
|
+
this.sources = new Map();
|
|
80
|
+
// Fallback source for messages without context_id or if we just want to capture everything (legacy behavior?)
|
|
81
|
+
// The original test didn't use context_id explicitly in send() but expected a response source.
|
|
82
|
+
// We'll map context_id to source.
|
|
83
|
+
this.defaultSource = null;
|
|
84
|
+
this.client = client;
|
|
85
|
+
this.config = config;
|
|
86
|
+
}
|
|
87
|
+
async connect() {
|
|
88
|
+
const baseURL = this.client.baseURL;
|
|
89
|
+
// Construct WebSocket URL
|
|
90
|
+
// baseURL is like https://api.cartesia.ai
|
|
91
|
+
let urlStr = baseURL.replace(/^http/, "ws");
|
|
92
|
+
if (!urlStr.includes("/tts/websocket")) {
|
|
93
|
+
if (urlStr.endsWith("/")) {
|
|
94
|
+
urlStr += "tts/websocket";
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
urlStr += "/tts/websocket";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const url = new URL(urlStr);
|
|
101
|
+
const headers = {
|
|
102
|
+
"cartesia-version": "2025-04-16",
|
|
103
|
+
};
|
|
104
|
+
if (this.client.apiKey) {
|
|
105
|
+
headers["Authorization"] = `Bearer ${this.client.apiKey}`;
|
|
106
|
+
}
|
|
107
|
+
this.socket = new ws_1.default(url.toString(), {
|
|
108
|
+
headers: headers,
|
|
109
|
+
});
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
this.socket.on("open", () => {
|
|
112
|
+
console.log("WebSocket connected.");
|
|
113
|
+
resolve();
|
|
114
|
+
});
|
|
115
|
+
this.socket.on("error", (err) => {
|
|
116
|
+
console.error("WebSocket error:", err);
|
|
117
|
+
reject(err);
|
|
118
|
+
});
|
|
119
|
+
this.socket.on("message", (data) => {
|
|
120
|
+
this.handleMessage(data);
|
|
121
|
+
});
|
|
122
|
+
this.socket.on("close", () => {
|
|
123
|
+
console.log("WebSocket closed.");
|
|
124
|
+
this.sources.forEach((s) => { s.markDone(); });
|
|
125
|
+
if (this.defaultSource)
|
|
126
|
+
this.defaultSource.markDone();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
handleMessage(data) {
|
|
131
|
+
try {
|
|
132
|
+
const str = data.toString();
|
|
133
|
+
const msg = JSON.parse(str);
|
|
134
|
+
const contextId = msg.context_id;
|
|
135
|
+
let source = contextId ? this.sources.get(contextId) : this.defaultSource;
|
|
136
|
+
// If we received a message for a context we don't know about, and we have a default source, use it
|
|
137
|
+
if (!source && this.defaultSource) {
|
|
138
|
+
source = this.defaultSource;
|
|
139
|
+
}
|
|
140
|
+
if (msg.type === "chunk" && msg.data) {
|
|
141
|
+
const audioData = Buffer.from(msg.data, "base64");
|
|
142
|
+
if (source)
|
|
143
|
+
source.push(audioData);
|
|
144
|
+
}
|
|
145
|
+
else if (msg.type === "done") {
|
|
146
|
+
if (source)
|
|
147
|
+
source.markDone();
|
|
148
|
+
}
|
|
149
|
+
else if (msg.type === "error") {
|
|
150
|
+
console.error("Server error:", msg);
|
|
151
|
+
if (source)
|
|
152
|
+
source.markDone(); // Fail the stream?
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
console.error("Error parsing message:", e);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async send(request) {
|
|
160
|
+
if (!this.socket) {
|
|
161
|
+
throw new Error("WebSocket not connected");
|
|
162
|
+
}
|
|
163
|
+
// Ensure request has a context_id so we can route the response
|
|
164
|
+
const contextId = request.contextId || uuidv4();
|
|
165
|
+
const source = new AudioSource();
|
|
166
|
+
this.sources.set(contextId, source);
|
|
167
|
+
// Also set as default source if none exists, for compatibility with simple tests
|
|
168
|
+
if (!this.defaultSource) {
|
|
169
|
+
this.defaultSource = source;
|
|
170
|
+
}
|
|
171
|
+
// Construct payload
|
|
172
|
+
const payload = {
|
|
173
|
+
model_id: request.modelId,
|
|
174
|
+
transcript: request.transcript,
|
|
175
|
+
voice: request.voice,
|
|
176
|
+
context_id: contextId,
|
|
177
|
+
};
|
|
178
|
+
// Output Format
|
|
179
|
+
if (request.outputFormat) {
|
|
180
|
+
payload.output_format = {
|
|
181
|
+
container: request.outputFormat.container,
|
|
182
|
+
encoding: request.outputFormat.encoding,
|
|
183
|
+
sample_rate: request.outputFormat.sampleRate,
|
|
184
|
+
bit_rate: request.outputFormat.bitRate,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
else if (this.config) {
|
|
188
|
+
payload.output_format = {
|
|
189
|
+
container: this.config.container,
|
|
190
|
+
encoding: this.config.encoding,
|
|
191
|
+
sample_rate: this.config.sampleRate,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
// Generation Config
|
|
195
|
+
if (request.generationConfig) {
|
|
196
|
+
payload.generation_config = request.generationConfig;
|
|
197
|
+
}
|
|
198
|
+
// Other fields
|
|
199
|
+
if (request.continue !== undefined)
|
|
200
|
+
payload.continue = request.continue;
|
|
201
|
+
if (request.duration !== undefined)
|
|
202
|
+
payload.duration = request.duration;
|
|
203
|
+
if (request.addTimestamps !== undefined)
|
|
204
|
+
payload.add_timestamps = request.addTimestamps;
|
|
205
|
+
if (request.addPhonemeTimestamps !== undefined)
|
|
206
|
+
payload.add_phoneme_timestamps = request.addPhonemeTimestamps;
|
|
207
|
+
this.socket.send(JSON.stringify(payload));
|
|
208
|
+
return {
|
|
209
|
+
source: source
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
disconnect() {
|
|
213
|
+
if (this.socket) {
|
|
214
|
+
this.socket.close();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.WebSocketWrapper = WebSocketWrapper;
|
|
219
|
+
class TTSWrapper {
|
|
220
|
+
constructor(client) {
|
|
221
|
+
this.client = client;
|
|
222
|
+
}
|
|
223
|
+
websocket(config) {
|
|
224
|
+
return new WebSocketWrapper(this.client, config);
|
|
225
|
+
}
|
|
226
|
+
async bytes(request, requestOptions) {
|
|
227
|
+
const params = {
|
|
228
|
+
model_id: request.modelId,
|
|
229
|
+
transcript: request.transcript,
|
|
230
|
+
voice: request.voice,
|
|
231
|
+
generation_config: request.generationConfig,
|
|
232
|
+
context_id: request.contextId,
|
|
233
|
+
};
|
|
234
|
+
if (request.outputFormat) {
|
|
235
|
+
params.output_format = {
|
|
236
|
+
...request.outputFormat,
|
|
237
|
+
sample_rate: request.outputFormat.sampleRate,
|
|
238
|
+
bit_rate: request.outputFormat.bitRate,
|
|
239
|
+
};
|
|
240
|
+
// Remove camelCase keys
|
|
241
|
+
delete params.output_format.sampleRate;
|
|
242
|
+
delete params.output_format.bitRate;
|
|
243
|
+
}
|
|
244
|
+
const options = {};
|
|
245
|
+
if (requestOptions) {
|
|
246
|
+
if (requestOptions.timeoutInSeconds) {
|
|
247
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
248
|
+
}
|
|
249
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
250
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
251
|
+
}
|
|
252
|
+
options.headers = requestOptions.headers;
|
|
253
|
+
options.signal = requestOptions.abortSignal;
|
|
254
|
+
}
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
return this.client.tts.synthesizeBytes(params, options);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
exports.TTSWrapper = TTSWrapper;
|
|
260
|
+
//# sourceMappingURL=tts-wrapper.js.map
|