@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,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VoiceChangerWrapper = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
class VoiceChangerWrapper {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
async bytes(clip, request, requestOptions) {
|
|
10
|
+
const params = {
|
|
11
|
+
clip: clip,
|
|
12
|
+
"voice[id]": request.voiceId,
|
|
13
|
+
"output_format[container]": request.outputFormatContainer,
|
|
14
|
+
"output_format[sample_rate]": request.outputFormatSampleRate,
|
|
15
|
+
};
|
|
16
|
+
if (request.outputFormatEncoding) {
|
|
17
|
+
params["output_format[encoding]"] = request.outputFormatEncoding;
|
|
18
|
+
}
|
|
19
|
+
if (request.outputFormatBitRate) {
|
|
20
|
+
params["output_format[bit_rate]"] = request.outputFormatBitRate;
|
|
21
|
+
}
|
|
22
|
+
const options = {};
|
|
23
|
+
if (requestOptions) {
|
|
24
|
+
if (requestOptions.timeoutInSeconds) {
|
|
25
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
26
|
+
}
|
|
27
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
28
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
29
|
+
}
|
|
30
|
+
options.headers = requestOptions.headers;
|
|
31
|
+
options.signal = requestOptions.abortSignal;
|
|
32
|
+
}
|
|
33
|
+
const response = await this.client.voiceChanger.changeVoiceBytes(params, {
|
|
34
|
+
...options,
|
|
35
|
+
__binaryResponse: true,
|
|
36
|
+
});
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
if (response.body) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
return stream_1.Readable.fromWeb(response.body);
|
|
41
|
+
}
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.VoiceChangerWrapper = VoiceChangerWrapper;
|
|
46
|
+
//# sourceMappingURL=voice-changer-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voice-changer-wrapper.js","sourceRoot":"","sources":["../src/backcompat/voice-changer-wrapper.ts"],"names":[],"mappings":";;;AAIA,mCAAkC;AAWlC,MAAa,mBAAmB;IAG/B,YAAY,MAAgB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,KAAK,CACV,IAAiC,EACjC,OAA2C,EAC3C,cAAyC;QAEzC,MAAM,MAAM,GAAQ;YACnB,IAAI,EAAE,IAAkB;YACxB,WAAW,EAAE,OAAO,CAAC,OAAO;YAC5B,0BAA0B,EAAE,OAAO,CAAC,qBAAqB;YACzD,4BAA4B,EAAE,OAAO,CAAC,sBAAsB;SAC5D,CAAC;QAEF,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;YAClC,MAAM,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC;QAClE,CAAC;QACD,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;YACjC,MAAM,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC;QACjE,CAAC;QAED,MAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,IAAI,cAAc,EAAE,CAAC;YACpB,IAAI,cAAc,CAAC,gBAAgB,EAAE,CAAC;gBACrC,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAC1D,CAAC;YACD,IAAI,cAAc,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7C,OAAO,CAAC,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC;YAChD,CAAC;YACD,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC;YACzC,OAAO,CAAC,MAAM,GAAG,cAAc,CAAC,WAAW,CAAC;QAC7C,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,EAAE;YACxE,GAAG,OAAO;YACV,gBAAgB,EAAE,IAAI;SACf,CAAC,CAAC;QAEV,aAAa;QACb,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnB,aAAa;YACb,OAAO,iBAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD;AAnDD,kDAmDC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Readable } from "stream";
|
|
2
|
+
export class VoiceChangerWrapper {
|
|
3
|
+
constructor(client) {
|
|
4
|
+
this.client = client;
|
|
5
|
+
}
|
|
6
|
+
async bytes(clip, request, requestOptions) {
|
|
7
|
+
const params = {
|
|
8
|
+
clip: clip,
|
|
9
|
+
"voice[id]": request.voiceId,
|
|
10
|
+
"output_format[container]": request.outputFormatContainer,
|
|
11
|
+
"output_format[sample_rate]": request.outputFormatSampleRate,
|
|
12
|
+
};
|
|
13
|
+
if (request.outputFormatEncoding) {
|
|
14
|
+
params["output_format[encoding]"] = request.outputFormatEncoding;
|
|
15
|
+
}
|
|
16
|
+
if (request.outputFormatBitRate) {
|
|
17
|
+
params["output_format[bit_rate]"] = request.outputFormatBitRate;
|
|
18
|
+
}
|
|
19
|
+
const options = {};
|
|
20
|
+
if (requestOptions) {
|
|
21
|
+
if (requestOptions.timeoutInSeconds) {
|
|
22
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
23
|
+
}
|
|
24
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
25
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
26
|
+
}
|
|
27
|
+
options.headers = requestOptions.headers;
|
|
28
|
+
options.signal = requestOptions.abortSignal;
|
|
29
|
+
}
|
|
30
|
+
const response = await this.client.voiceChanger.changeVoiceBytes(params, {
|
|
31
|
+
...options,
|
|
32
|
+
__binaryResponse: true,
|
|
33
|
+
});
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
if (response.body) {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
return Readable.fromWeb(response.body);
|
|
38
|
+
}
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=voice-changer-wrapper.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voice-changer-wrapper.mjs","sourceRoot":"","sources":["../src/backcompat/voice-changer-wrapper.ts"],"names":[],"mappings":"OAIO,EAAE,QAAQ,EAAE,MAAM,QAAQ;AAWjC,MAAM,OAAO,mBAAmB;IAG/B,YAAY,MAAgB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,KAAK,CACV,IAAiC,EACjC,OAA2C,EAC3C,cAAyC;QAEzC,MAAM,MAAM,GAAQ;YACnB,IAAI,EAAE,IAAkB;YACxB,WAAW,EAAE,OAAO,CAAC,OAAO;YAC5B,0BAA0B,EAAE,OAAO,CAAC,qBAAqB;YACzD,4BAA4B,EAAE,OAAO,CAAC,sBAAsB;SAC5D,CAAC;QAEF,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;YAClC,MAAM,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC;QAClE,CAAC;QACD,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;YACjC,MAAM,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC;QACjE,CAAC;QAED,MAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,IAAI,cAAc,EAAE,CAAC;YACpB,IAAI,cAAc,CAAC,gBAAgB,EAAE,CAAC;gBACrC,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAC1D,CAAC;YACD,IAAI,cAAc,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7C,OAAO,CAAC,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC;YAChD,CAAC;YACD,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC;YACzC,OAAO,CAAC,MAAM,GAAG,cAAc,CAAC,WAAW,CAAC;QAC7C,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,EAAE;YACxE,GAAG,OAAO;YACV,gBAAgB,EAAE,IAAI;SACf,CAAC,CAAC;QAEV,aAAa;QACb,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnB,aAAa;YACb,OAAO,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { Cartesia } from "../client.mjs";
|
|
3
|
+
import { type VoiceMetadata, type Voice } from "../resources/voices.mjs";
|
|
4
|
+
import { BackCompatRequestOptions } from "./types.mjs";
|
|
5
|
+
export interface BackCompatCloneVoiceRequest {
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
language: string;
|
|
9
|
+
mode: "similarity" | "stability";
|
|
10
|
+
enhance?: boolean;
|
|
11
|
+
baseVoiceId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BackCompatUpdateVoiceRequest {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
export interface BackCompatLocalizeVoiceRequest {
|
|
18
|
+
voiceId: string;
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
language: "en" | "de" | "es" | "fr" | "ja" | "pt" | "zh" | "hi" | "it" | "ko" | "nl" | "pl" | "ru" | "sv" | "tr";
|
|
22
|
+
originalSpeakerGender: "male" | "female";
|
|
23
|
+
dialect?: "au" | "in" | "so" | "uk" | "us" | "mx" | "pe" | "br" | "eu" | "ca";
|
|
24
|
+
}
|
|
25
|
+
export declare class VoicesWrapper {
|
|
26
|
+
private client;
|
|
27
|
+
constructor(client: Cartesia);
|
|
28
|
+
clone(clip: File | fs.ReadStream | Blob, request: BackCompatCloneVoiceRequest, requestOptions?: BackCompatRequestOptions): Promise<VoiceMetadata>;
|
|
29
|
+
update(id: string, request: BackCompatUpdateVoiceRequest, requestOptions?: BackCompatRequestOptions): Promise<Voice>;
|
|
30
|
+
localize(request: BackCompatLocalizeVoiceRequest, requestOptions?: BackCompatRequestOptions): Promise<VoiceMetadata>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=voices-wrapper.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voices-wrapper.d.mts","sourceRoot":"","sources":["../src/backcompat/voices-wrapper.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,MAAM,IAAI;OACjB,EAAE,QAAQ,EAAE;OAEZ,EAEN,KAAK,aAAa,EAGlB,KAAK,KAAK,EAEV;OAEM,EAAE,wBAAwB,EAAE;AAEnC,MAAM,WAAW,2BAA2B;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,YAAY,GAAG,WAAW,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,4BAA4B;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,8BAA8B;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EACL,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC;IACR,qBAAqB,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzC,OAAO,CAAC,EACL,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC;CACR;AAED,qBAAa,aAAa;IACzB,OAAO,CAAC,MAAM,CAAW;gBAEb,MAAM,EAAE,QAAQ;IAItB,KAAK,CACV,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,UAAU,GAAG,IAAI,EACjC,OAAO,EAAE,2BAA2B,EACpC,cAAc,CAAC,EAAE,wBAAwB,GACvC,OAAO,CAAC,aAAa,CAAC;IA6BnB,MAAM,CACX,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,4BAA4B,EACrC,cAAc,CAAC,EAAE,wBAAwB,GACvC,OAAO,CAAC,KAAK,CAAC;IAqBX,QAAQ,CACb,OAAO,EAAE,8BAA8B,EACvC,cAAc,CAAC,EAAE,wBAAwB,GACvC,OAAO,CAAC,aAAa,CAAC;CA2BzB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { Cartesia } from "../client.js";
|
|
3
|
+
import { type VoiceMetadata, type Voice } from "../resources/voices.js";
|
|
4
|
+
import { BackCompatRequestOptions } from "./types.js";
|
|
5
|
+
export interface BackCompatCloneVoiceRequest {
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
language: string;
|
|
9
|
+
mode: "similarity" | "stability";
|
|
10
|
+
enhance?: boolean;
|
|
11
|
+
baseVoiceId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BackCompatUpdateVoiceRequest {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
export interface BackCompatLocalizeVoiceRequest {
|
|
18
|
+
voiceId: string;
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
language: "en" | "de" | "es" | "fr" | "ja" | "pt" | "zh" | "hi" | "it" | "ko" | "nl" | "pl" | "ru" | "sv" | "tr";
|
|
22
|
+
originalSpeakerGender: "male" | "female";
|
|
23
|
+
dialect?: "au" | "in" | "so" | "uk" | "us" | "mx" | "pe" | "br" | "eu" | "ca";
|
|
24
|
+
}
|
|
25
|
+
export declare class VoicesWrapper {
|
|
26
|
+
private client;
|
|
27
|
+
constructor(client: Cartesia);
|
|
28
|
+
clone(clip: File | fs.ReadStream | Blob, request: BackCompatCloneVoiceRequest, requestOptions?: BackCompatRequestOptions): Promise<VoiceMetadata>;
|
|
29
|
+
update(id: string, request: BackCompatUpdateVoiceRequest, requestOptions?: BackCompatRequestOptions): Promise<Voice>;
|
|
30
|
+
localize(request: BackCompatLocalizeVoiceRequest, requestOptions?: BackCompatRequestOptions): Promise<VoiceMetadata>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=voices-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voices-wrapper.d.ts","sourceRoot":"","sources":["../src/backcompat/voices-wrapper.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,MAAM,IAAI;OACjB,EAAE,QAAQ,EAAE;OAEZ,EAEN,KAAK,aAAa,EAGlB,KAAK,KAAK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AAC;IAqBX,QAAQ,CACb,OAAO,EAAE,8BAA8B,EACvC,cAAc,CAAC,EAAE,wBAAwB,GACvC,OAAO,CAAC,aAAa,CAAC;CA2BzB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VoicesWrapper = void 0;
|
|
4
|
+
class VoicesWrapper {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async clone(clip, request, requestOptions) {
|
|
9
|
+
const params = {
|
|
10
|
+
clip: clip,
|
|
11
|
+
name: request.name,
|
|
12
|
+
language: request.language,
|
|
13
|
+
};
|
|
14
|
+
if (request.description !== undefined) {
|
|
15
|
+
params.description = request.description;
|
|
16
|
+
}
|
|
17
|
+
if (request.baseVoiceId !== undefined) {
|
|
18
|
+
params.base_voice_id = request.baseVoiceId;
|
|
19
|
+
}
|
|
20
|
+
const options = {};
|
|
21
|
+
if (requestOptions) {
|
|
22
|
+
if (requestOptions.timeoutInSeconds) {
|
|
23
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
24
|
+
}
|
|
25
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
26
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
27
|
+
}
|
|
28
|
+
options.headers = requestOptions.headers;
|
|
29
|
+
options.signal = requestOptions.abortSignal;
|
|
30
|
+
}
|
|
31
|
+
return this.client.voices.clone(params, options);
|
|
32
|
+
}
|
|
33
|
+
async update(id, request, requestOptions) {
|
|
34
|
+
const params = {
|
|
35
|
+
name: request.name,
|
|
36
|
+
description: request.description,
|
|
37
|
+
};
|
|
38
|
+
const options = {};
|
|
39
|
+
if (requestOptions) {
|
|
40
|
+
if (requestOptions.timeoutInSeconds) {
|
|
41
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
42
|
+
}
|
|
43
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
44
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
45
|
+
}
|
|
46
|
+
options.headers = requestOptions.headers;
|
|
47
|
+
options.signal = requestOptions.abortSignal;
|
|
48
|
+
}
|
|
49
|
+
return this.client.voices.update(id, params, options);
|
|
50
|
+
}
|
|
51
|
+
async localize(request, requestOptions) {
|
|
52
|
+
const params = {
|
|
53
|
+
voice_id: request.voiceId,
|
|
54
|
+
name: request.name,
|
|
55
|
+
description: request.description,
|
|
56
|
+
language: request.language,
|
|
57
|
+
original_speaker_gender: request.originalSpeakerGender,
|
|
58
|
+
};
|
|
59
|
+
if (request.dialect) {
|
|
60
|
+
params.dialect = request.dialect; // Cast dialect as list might vary slightly or be strict
|
|
61
|
+
}
|
|
62
|
+
const options = {};
|
|
63
|
+
if (requestOptions) {
|
|
64
|
+
if (requestOptions.timeoutInSeconds) {
|
|
65
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
66
|
+
}
|
|
67
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
68
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
69
|
+
}
|
|
70
|
+
options.headers = requestOptions.headers;
|
|
71
|
+
options.signal = requestOptions.abortSignal;
|
|
72
|
+
}
|
|
73
|
+
return this.client.voices.localize(params, options);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.VoicesWrapper = VoicesWrapper;
|
|
77
|
+
//# sourceMappingURL=voices-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voices-wrapper.js","sourceRoot":"","sources":["../src/backcompat/voices-wrapper.ts"],"names":[],"mappings":";;;AA8DA,MAAa,aAAa;IAGzB,YAAY,MAAgB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,KAAK,CACV,IAAiC,EACjC,OAAoC,EACpC,cAAyC;QAEzC,MAAM,MAAM,GAAqB;YAChC,IAAI,EAAE,IAAkB;YACxB,IAAI,EAA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AC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;CACD;AA/FD,sCA+FC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export class VoicesWrapper {
|
|
2
|
+
constructor(client) {
|
|
3
|
+
this.client = client;
|
|
4
|
+
}
|
|
5
|
+
async clone(clip, request, requestOptions) {
|
|
6
|
+
const params = {
|
|
7
|
+
clip: clip,
|
|
8
|
+
name: request.name,
|
|
9
|
+
language: request.language,
|
|
10
|
+
};
|
|
11
|
+
if (request.description !== undefined) {
|
|
12
|
+
params.description = request.description;
|
|
13
|
+
}
|
|
14
|
+
if (request.baseVoiceId !== undefined) {
|
|
15
|
+
params.base_voice_id = request.baseVoiceId;
|
|
16
|
+
}
|
|
17
|
+
const options = {};
|
|
18
|
+
if (requestOptions) {
|
|
19
|
+
if (requestOptions.timeoutInSeconds) {
|
|
20
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
21
|
+
}
|
|
22
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
23
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
24
|
+
}
|
|
25
|
+
options.headers = requestOptions.headers;
|
|
26
|
+
options.signal = requestOptions.abortSignal;
|
|
27
|
+
}
|
|
28
|
+
return this.client.voices.clone(params, options);
|
|
29
|
+
}
|
|
30
|
+
async update(id, request, requestOptions) {
|
|
31
|
+
const params = {
|
|
32
|
+
name: request.name,
|
|
33
|
+
description: request.description,
|
|
34
|
+
};
|
|
35
|
+
const options = {};
|
|
36
|
+
if (requestOptions) {
|
|
37
|
+
if (requestOptions.timeoutInSeconds) {
|
|
38
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
39
|
+
}
|
|
40
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
41
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
42
|
+
}
|
|
43
|
+
options.headers = requestOptions.headers;
|
|
44
|
+
options.signal = requestOptions.abortSignal;
|
|
45
|
+
}
|
|
46
|
+
return this.client.voices.update(id, params, options);
|
|
47
|
+
}
|
|
48
|
+
async localize(request, requestOptions) {
|
|
49
|
+
const params = {
|
|
50
|
+
voice_id: request.voiceId,
|
|
51
|
+
name: request.name,
|
|
52
|
+
description: request.description,
|
|
53
|
+
language: request.language,
|
|
54
|
+
original_speaker_gender: request.originalSpeakerGender,
|
|
55
|
+
};
|
|
56
|
+
if (request.dialect) {
|
|
57
|
+
params.dialect = request.dialect; // Cast dialect as list might vary slightly or be strict
|
|
58
|
+
}
|
|
59
|
+
const options = {};
|
|
60
|
+
if (requestOptions) {
|
|
61
|
+
if (requestOptions.timeoutInSeconds) {
|
|
62
|
+
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
63
|
+
}
|
|
64
|
+
if (requestOptions.maxRetries !== undefined) {
|
|
65
|
+
options.maxRetries = requestOptions.maxRetries;
|
|
66
|
+
}
|
|
67
|
+
options.headers = requestOptions.headers;
|
|
68
|
+
options.signal = requestOptions.abortSignal;
|
|
69
|
+
}
|
|
70
|
+
return this.client.voices.localize(params, options);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=voices-wrapper.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voices-wrapper.mjs","sourceRoot":"","sources":["../src/backcompat/voices-wrapper.ts"],"names":[],"mappings":"AA8DA,MAAM,OAAO,aAAa;IAGzB,YAAY,MAAgB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,KAAK,CACV,IAAiC,EACjC,OAAoC,EACpC,cAAyC;QAEzC,MAAM,MAAM,GAAqB;YAChC,IAAI,EAAE,IAAkB;YACxB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,QAAQ,EAAE,OAAO,CAAC,QAA6B;SAC/C,CAAC;QAEF,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACvC,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC,WA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
|
|
5
|
-
|
|
6
|
-
private waiter: ((val?: any) => void) | null = null;
|
|
7
|
-
public isDone = false;
|
|
8
|
-
|
|
9
|
-
push(data: Buffer) {
|
|
10
|
-
this.buffers.push(data);
|
|
11
|
-
if (this.waiter) {
|
|
12
|
-
this.waiter();
|
|
13
|
-
this.waiter = null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
markDone() {
|
|
18
|
-
this.isDone = true;
|
|
19
|
-
if (this.waiter) {
|
|
20
|
-
this.waiter();
|
|
21
|
-
this.waiter = null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async read(outBuffer: Float32Array): Promise<number> {
|
|
26
|
-
if (this.buffers.length === 0 && !this.isDone) {
|
|
27
|
-
await new Promise<void>((resolve) => { this.waiter = resolve; });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (this.buffers.length === 0 && this.isDone) {
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let totalFloatsRead = 0;
|
|
35
|
-
let outOffset = 0;
|
|
36
|
-
const maxFloats = outBuffer.length;
|
|
37
|
-
|
|
38
|
-
while (this.buffers.length > 0 && totalFloatsRead < maxFloats) {
|
|
39
|
-
const buf = this.buffers[0] as Buffer; // ts not smart enough to check loop condition
|
|
40
|
-
const floatsInBuf = buf.length / 4;
|
|
41
|
-
const floatsNeeded = maxFloats - totalFloatsRead;
|
|
42
|
-
|
|
43
|
-
const floatsToCopy = Math.min(floatsInBuf, floatsNeeded);
|
|
44
|
-
const bytesToCopy = floatsToCopy * 4;
|
|
45
|
-
|
|
46
|
-
// Copy to outBuffer.
|
|
47
|
-
// Create a view on the buffer to read floats.
|
|
48
|
-
|
|
49
|
-
// We need to ensure byteOffset is a multiple of 4.
|
|
50
|
-
// If not, we must copy the buffer to a new one.
|
|
51
|
-
let srcFloats: Float32Array;
|
|
52
|
-
if (buf.byteOffset % 4 === 0) {
|
|
53
|
-
srcFloats = new Float32Array(buf.buffer, buf.byteOffset, floatsInBuf);
|
|
54
|
-
} else {
|
|
55
|
-
const alignedBuf = new Uint8Array(buf);
|
|
56
|
-
srcFloats = new Float32Array(alignedBuf.buffer, alignedBuf.byteOffset, floatsInBuf);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
outBuffer.set(srcFloats.subarray(0, floatsToCopy), outOffset);
|
|
60
|
-
|
|
61
|
-
totalFloatsRead += floatsToCopy;
|
|
62
|
-
outOffset += floatsToCopy;
|
|
63
|
-
|
|
64
|
-
if (floatsToCopy < floatsInBuf) {
|
|
65
|
-
// We didn't use the whole buffer. Update it.
|
|
66
|
-
this.buffers[0] = buf.subarray(bytesToCopy);
|
|
67
|
-
} else {
|
|
68
|
-
// We used the whole buffer. Remove it.
|
|
69
|
-
this.buffers.shift();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return totalFloatsRead;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
class WebSocketWrapper {
|
|
78
|
-
private client: Cartesia;
|
|
79
|
-
private config: any;
|
|
80
|
-
private socket: WebSocket | null = null;
|
|
81
|
-
private sources: Map<string, AudioSource> = new Map();
|
|
82
|
-
// Fallback source for messages without context_id or if we just want to capture everything (legacy behavior?)
|
|
83
|
-
// The original test didn't use context_id explicitly in send() but expected a response source.
|
|
84
|
-
// We'll map context_id to source.
|
|
85
|
-
private defaultSource: AudioSource | null = null;
|
|
86
|
-
|
|
87
|
-
constructor(client: Cartesia, config: any) {
|
|
88
|
-
this.client = client;
|
|
89
|
-
this.config = config;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async connect() {
|
|
93
|
-
const baseURL = this.client.baseURL;
|
|
94
|
-
// Construct WebSocket URL
|
|
95
|
-
// baseURL is like https://api.cartesia.ai
|
|
96
|
-
let urlStr = baseURL.replace(/^http/, "ws");
|
|
97
|
-
if (!urlStr.includes("/tts/websocket")) {
|
|
98
|
-
if (urlStr.endsWith("/")) {
|
|
99
|
-
urlStr += "tts/websocket";
|
|
100
|
-
} else {
|
|
101
|
-
urlStr += "/tts/websocket";
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const url = new URL(urlStr);
|
|
106
|
-
|
|
107
|
-
const headers: any = {
|
|
108
|
-
"cartesia-version": "2025-04-16",
|
|
109
|
-
};
|
|
110
|
-
if (this.client.apiKey) {
|
|
111
|
-
headers["Authorization"] = `Bearer ${this.client.apiKey}`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
this.socket = new WebSocket(url.toString(), {
|
|
115
|
-
headers: headers,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
return new Promise<void>((resolve, reject) => {
|
|
119
|
-
this.socket!.on("open", () => {
|
|
120
|
-
console.log("WebSocket connected.");
|
|
121
|
-
resolve();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
this.socket!.on("error", (err) => {
|
|
125
|
-
console.error("WebSocket error:", err);
|
|
126
|
-
reject(err);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
this.socket!.on("message", (data) => {
|
|
130
|
-
this.handleMessage(data);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
this.socket!.on("close", () => {
|
|
134
|
-
console.log("WebSocket closed.");
|
|
135
|
-
this.sources.forEach((s) => { s.markDone(); });
|
|
136
|
-
if (this.defaultSource) this.defaultSource.markDone();
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private handleMessage(data: WebSocket.Data) {
|
|
142
|
-
try {
|
|
143
|
-
const str = data.toString();
|
|
144
|
-
const msg = JSON.parse(str);
|
|
145
|
-
|
|
146
|
-
const contextId = msg.context_id;
|
|
147
|
-
let source = contextId ? this.sources.get(contextId) : this.defaultSource;
|
|
148
|
-
|
|
149
|
-
// If we received a message for a context we don't know about, and we have a default source, use it
|
|
150
|
-
if (!source && this.defaultSource) {
|
|
151
|
-
source = this.defaultSource;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (msg.type === "chunk" && msg.data) {
|
|
155
|
-
const audioData = Buffer.from(msg.data, "base64");
|
|
156
|
-
if (source) source.push(audioData);
|
|
157
|
-
} else if (msg.type === "done") {
|
|
158
|
-
if (source) source.markDone();
|
|
159
|
-
} else if (msg.type === "error") {
|
|
160
|
-
console.error("Server error:", msg);
|
|
161
|
-
if (source) source.markDone(); // Fail the stream?
|
|
162
|
-
}
|
|
163
|
-
} catch (e) {
|
|
164
|
-
console.error("Error parsing message:", e);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async send(request: any) {
|
|
169
|
-
if (!this.socket) {
|
|
170
|
-
throw new Error("WebSocket not connected");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Ensure request has a context_id so we can route the response
|
|
174
|
-
if (!request.context_id) {
|
|
175
|
-
request.context_id = uuidv4();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const source = new AudioSource();
|
|
179
|
-
this.sources.set(request.context_id, source);
|
|
180
|
-
// Also set as default source if none exists, for compatibility with simple tests
|
|
181
|
-
if (!this.defaultSource) {
|
|
182
|
-
this.defaultSource = source;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Add output format from config if not present
|
|
186
|
-
if (!request.output_format && this.config) {
|
|
187
|
-
request.output_format = {
|
|
188
|
-
container: this.config.container,
|
|
189
|
-
encoding: this.config.encoding,
|
|
190
|
-
sample_rate: this.config.sampleRate,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
// Fix camelCase to snake_case for output_format if needed
|
|
194
|
-
// The new API expects snake_case keys in JSON usually, but let's check.
|
|
195
|
-
// The GenerationRequest interface has `output_format`.
|
|
196
|
-
// The config passed to .websocket() uses `sampleRate`.
|
|
197
|
-
// We might need to map it.
|
|
198
|
-
|
|
199
|
-
if (request.output_format) {
|
|
200
|
-
// Ensure sample_rate is set (mapping from sampleRate)
|
|
201
|
-
if (request.output_format.sampleRate && !request.output_format.sample_rate) {
|
|
202
|
-
request.output_format.sample_rate = request.output_format.sampleRate;
|
|
203
|
-
delete request.output_format.sampleRate;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Map camelCase request fields to snake_case if necessary?
|
|
208
|
-
// The old test uses `modelId`, `generationConfig`.
|
|
209
|
-
// The new API expects `model_id`, `generation_config`.
|
|
210
|
-
const payload = {
|
|
211
|
-
...request,
|
|
212
|
-
model_id: request.modelId || request.model_id,
|
|
213
|
-
generation_config: request.generationConfig || request.generation_config,
|
|
214
|
-
context_id: request.context_id,
|
|
215
|
-
};
|
|
216
|
-
// Remove camelCase keys if they persist?
|
|
217
|
-
// JSON.stringify handles it, but we should clean up if we want to be strict.
|
|
218
|
-
|
|
219
|
-
// Also `voice` object. Old test: `voice: { mode: 'id', id: ... }`. New API: same.
|
|
220
|
-
|
|
221
|
-
this.socket.send(JSON.stringify(payload));
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
source: source
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
disconnect() {
|
|
229
|
-
if (this.socket) {
|
|
230
|
-
this.socket.close();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
class TTSWrapper {
|
|
236
|
-
private client: Cartesia;
|
|
237
|
-
|
|
238
|
-
constructor(client: Cartesia) {
|
|
239
|
-
this.client = client;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
websocket(config: any) {
|
|
243
|
-
return new WebSocketWrapper(this.client, config);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
async bytes(request: any, requestOptions?: any) {
|
|
247
|
-
const params: any = {
|
|
248
|
-
model_id: request.modelId,
|
|
249
|
-
transcript: request.transcript,
|
|
250
|
-
voice: request.voice,
|
|
251
|
-
generation_config: request.generationConfig,
|
|
252
|
-
context_id: request.contextId,
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
if (request.outputFormat) {
|
|
256
|
-
params.output_format = {
|
|
257
|
-
...request.outputFormat,
|
|
258
|
-
sample_rate: request.outputFormat.sampleRate,
|
|
259
|
-
bit_rate: request.outputFormat.bitRate,
|
|
260
|
-
};
|
|
261
|
-
// Remove camelCase keys
|
|
262
|
-
delete params.output_format.sampleRate;
|
|
263
|
-
delete params.output_format.bitRate;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const options: any = {};
|
|
267
|
-
if (requestOptions) {
|
|
268
|
-
if (requestOptions.timeoutInSeconds) {
|
|
269
|
-
options.timeout = requestOptions.timeoutInSeconds * 1000;
|
|
270
|
-
}
|
|
271
|
-
options.maxRetries = requestOptions.maxRetries;
|
|
272
|
-
options.headers = requestOptions.headers;
|
|
273
|
-
options.signal = requestOptions.abortSignal;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// @ts-ignore
|
|
277
|
-
return this.client.tts.synthesizeBytes(params, options);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
1
|
+
import { Cartesia, type ClientOptions } from "../client";
|
|
2
|
+
import { TTSWrapper } from "./tts-wrapper";
|
|
3
|
+
import { VoicesWrapper } from "./voices-wrapper";
|
|
4
|
+
import { VoiceChangerWrapper } from "./voice-changer-wrapper";
|
|
5
|
+
import type { CartesiaClientOptions } from "./types";
|
|
280
6
|
|
|
281
7
|
/*
|
|
282
8
|
* CartesiaClient - deprecated backcompat class.
|
|
@@ -285,18 +11,30 @@ class TTSWrapper {
|
|
|
285
11
|
export class CartesiaClient {
|
|
286
12
|
private client: Cartesia;
|
|
287
13
|
public tts: TTSWrapper;
|
|
14
|
+
public voices: VoicesWrapper;
|
|
15
|
+
public voiceChanger: VoiceChangerWrapper;
|
|
16
|
+
|
|
17
|
+
constructor(options: CartesiaClientOptions = {}) {
|
|
18
|
+
const newOptions: ClientOptions = {};
|
|
19
|
+
|
|
20
|
+
if (options.apiKey) {
|
|
21
|
+
newOptions.apiKey = options.apiKey as any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (options.baseUrl) {
|
|
25
|
+
newOptions.baseURL = options.baseUrl as any;
|
|
26
|
+
} else if (options.environment) {
|
|
27
|
+
newOptions.baseURL = options.environment as any;
|
|
28
|
+
}
|
|
288
29
|
|
|
289
|
-
|
|
290
|
-
this.client = new Cartesia(options);
|
|
30
|
+
this.client = new Cartesia(newOptions);
|
|
291
31
|
this.tts = new TTSWrapper(this.client);
|
|
32
|
+
this.voices = new VoicesWrapper(this.client);
|
|
33
|
+
this.voiceChanger = new VoiceChangerWrapper(this.client);
|
|
292
34
|
}
|
|
293
35
|
}
|
|
294
36
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
300
|
-
return v.toString(16);
|
|
301
|
-
});
|
|
302
|
-
}
|
|
37
|
+
export * from "./tts-wrapper";
|
|
38
|
+
export * from "./voices-wrapper";
|
|
39
|
+
export * from "./voice-changer-wrapper";
|
|
40
|
+
export * from "./types";
|