@cartesia/cartesia-js 1.1.0 → 1.2.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-VCZESWYA.js → chunk-5SBAQNWQ.js} +1 -1
- package/dist/{chunk-MNOPO7G6.js → chunk-CSOXALSC.js} +7 -7
- package/dist/{chunk-6PWLZAMS.js → chunk-FLWYXP5Z.js} +1 -1
- package/dist/chunk-GLZYI5DM.js +43 -0
- package/dist/{chunk-VVDJR3OA.js → chunk-I5YVYTNK.js} +16 -16
- package/dist/{chunk-3FL2SNIR.js → chunk-LKKWJLUG.js} +1 -1
- package/dist/{chunk-WIFMLPT5.js → chunk-NJDRWDQ3.js} +8 -22
- package/dist/{chunk-4GEDAGVY.js → chunk-QWNB544W.js} +7 -3
- package/dist/{chunk-CWIJUBG6.js → chunk-RJICGVPL.js} +2 -2
- package/dist/chunk-WLEVU3HN.js +42 -0
- package/dist/{chunk-L3OMQKWL.js → chunk-WSIVWXEI.js} +19 -19
- package/dist/index.cjs +91 -57
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -9
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +86 -52
- package/dist/lib/index.d.cts +2 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +9 -8
- package/dist/react/index.cjs +91 -57
- package/dist/react/index.js +11 -10
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +53 -52
- package/dist/tts/index.d.cts +8 -1
- package/dist/tts/index.d.ts +8 -1
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.cjs +13 -27
- package/dist/tts/player.js +4 -4
- package/dist/tts/source.cjs +23 -37
- package/dist/tts/source.js +2 -2
- package/dist/tts/utils.js +3 -3
- package/dist/tts/websocket.cjs +38 -52
- package/dist/tts/websocket.d.cts +6 -6
- package/dist/tts/websocket.d.ts +6 -6
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +25 -1
- package/dist/types/index.d.ts +25 -1
- package/dist/voice-changer/index.cjs +143 -0
- package/dist/voice-changer/index.d.cts +9 -0
- package/dist/voice-changer/index.d.ts +9 -0
- package/dist/voice-changer/index.js +9 -0
- package/dist/voices/index.js +3 -3
- package/package.json +8 -16
- package/src/lib/index.ts +3 -0
- package/src/tts/index.ts +16 -1
- package/src/types/index.ts +31 -0
- package/src/voice-changer/index.ts +37 -0
- package/.turbo/turbo-build.log +0 -75
- package/dist/chunk-MUPVAEL7.js +0 -25
- package/tsconfig.json +0 -3
package/dist/tts/websocket.d.cts
CHANGED
|
@@ -33,18 +33,18 @@ declare class WebSocket extends Client {
|
|
|
33
33
|
message: string;
|
|
34
34
|
timestamps: WordTimestamps;
|
|
35
35
|
} & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => emittery.UnsubscribeFunction;
|
|
36
|
-
off: <
|
|
36
|
+
off: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[], listener: (eventData: ({
|
|
37
37
|
message: string;
|
|
38
38
|
timestamps: WordTimestamps;
|
|
39
|
-
} & emittery.OmnipresentEventData)[
|
|
40
|
-
once: <
|
|
39
|
+
} & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => void;
|
|
40
|
+
once: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[]) => emittery.EmitteryOncePromise<({
|
|
41
41
|
message: string;
|
|
42
42
|
timestamps: WordTimestamps;
|
|
43
|
-
} & emittery.OmnipresentEventData)[
|
|
44
|
-
events: <
|
|
43
|
+
} & emittery.OmnipresentEventData)[Name]>;
|
|
44
|
+
events: <Name extends "timestamps" | "message">(eventName: Name | readonly Name[]) => AsyncIterableIterator<{
|
|
45
45
|
message: string;
|
|
46
46
|
timestamps: WordTimestamps;
|
|
47
|
-
}[
|
|
47
|
+
}[Name]>;
|
|
48
48
|
source: Source;
|
|
49
49
|
};
|
|
50
50
|
/**
|
package/dist/tts/websocket.d.ts
CHANGED
|
@@ -33,18 +33,18 @@ declare class WebSocket extends Client {
|
|
|
33
33
|
message: string;
|
|
34
34
|
timestamps: WordTimestamps;
|
|
35
35
|
} & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => emittery.UnsubscribeFunction;
|
|
36
|
-
off: <
|
|
36
|
+
off: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[], listener: (eventData: ({
|
|
37
37
|
message: string;
|
|
38
38
|
timestamps: WordTimestamps;
|
|
39
|
-
} & emittery.OmnipresentEventData)[
|
|
40
|
-
once: <
|
|
39
|
+
} & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => void;
|
|
40
|
+
once: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[]) => emittery.EmitteryOncePromise<({
|
|
41
41
|
message: string;
|
|
42
42
|
timestamps: WordTimestamps;
|
|
43
|
-
} & emittery.OmnipresentEventData)[
|
|
44
|
-
events: <
|
|
43
|
+
} & emittery.OmnipresentEventData)[Name]>;
|
|
44
|
+
events: <Name extends "timestamps" | "message">(eventName: Name | readonly Name[]) => AsyncIterableIterator<{
|
|
45
45
|
message: string;
|
|
46
46
|
timestamps: WordTimestamps;
|
|
47
|
-
}[
|
|
47
|
+
}[Name]>;
|
|
48
48
|
source: Source;
|
|
49
49
|
};
|
|
50
50
|
/**
|
package/dist/tts/websocket.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebSocket
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-WSIVWXEI.js";
|
|
4
|
+
import "../chunk-FLWYXP5Z.js";
|
|
5
5
|
import "../chunk-2BFEKY3F.js";
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-5SBAQNWQ.js";
|
|
7
|
+
import "../chunk-I5YVYTNK.js";
|
|
8
|
+
import "../chunk-NJDRWDQ3.js";
|
|
9
9
|
export {
|
|
10
10
|
WebSocket as default
|
|
11
11
|
};
|
package/dist/types/index.d.cts
CHANGED
|
@@ -41,6 +41,7 @@ type StreamRequest = {
|
|
|
41
41
|
language?: Language;
|
|
42
42
|
add_timestamps?: boolean;
|
|
43
43
|
};
|
|
44
|
+
type BytesRequest = Omit<StreamRequest, "continue" | "add_timestamps" | "context_id">;
|
|
44
45
|
type ContinueRequest = StreamRequest & {
|
|
45
46
|
context_id: string;
|
|
46
47
|
};
|
|
@@ -87,6 +88,26 @@ type CloneOptions = {
|
|
|
87
88
|
clip: Blob;
|
|
88
89
|
enhance?: boolean;
|
|
89
90
|
};
|
|
91
|
+
type VoiceChangerOptions = {
|
|
92
|
+
clip: File;
|
|
93
|
+
voice: {
|
|
94
|
+
id: string;
|
|
95
|
+
};
|
|
96
|
+
output_format: {
|
|
97
|
+
container: "mp3";
|
|
98
|
+
bit_rate: number;
|
|
99
|
+
sample_rate: number;
|
|
100
|
+
} | {
|
|
101
|
+
container: "wav";
|
|
102
|
+
encoding: Encoding;
|
|
103
|
+
sample_rate: number;
|
|
104
|
+
bit_rate: number;
|
|
105
|
+
} | {
|
|
106
|
+
container: "raw";
|
|
107
|
+
encoding: Encoding;
|
|
108
|
+
sample_rate: number;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
90
111
|
type LocalizeOptions = {
|
|
91
112
|
mode: "embedding";
|
|
92
113
|
embedding: number[];
|
|
@@ -118,6 +139,9 @@ type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
|
|
|
118
139
|
type CloneResponse = {
|
|
119
140
|
embedding: number[];
|
|
120
141
|
};
|
|
142
|
+
type VoiceChangerBytesResponse = {
|
|
143
|
+
buffer: ArrayBuffer;
|
|
144
|
+
};
|
|
121
145
|
type LocalizeResponse = {
|
|
122
146
|
embedding: number[];
|
|
123
147
|
};
|
|
@@ -138,4 +162,4 @@ type SourceEventData = {
|
|
|
138
162
|
type TypedArray = Float32Array | Int16Array | Uint8Array;
|
|
139
163
|
type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
140
164
|
|
|
141
|
-
export type { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
|
|
165
|
+
export type { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceChangerBytesResponse, VoiceChangerOptions, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ type StreamRequest = {
|
|
|
41
41
|
language?: Language;
|
|
42
42
|
add_timestamps?: boolean;
|
|
43
43
|
};
|
|
44
|
+
type BytesRequest = Omit<StreamRequest, "continue" | "add_timestamps" | "context_id">;
|
|
44
45
|
type ContinueRequest = StreamRequest & {
|
|
45
46
|
context_id: string;
|
|
46
47
|
};
|
|
@@ -87,6 +88,26 @@ type CloneOptions = {
|
|
|
87
88
|
clip: Blob;
|
|
88
89
|
enhance?: boolean;
|
|
89
90
|
};
|
|
91
|
+
type VoiceChangerOptions = {
|
|
92
|
+
clip: File;
|
|
93
|
+
voice: {
|
|
94
|
+
id: string;
|
|
95
|
+
};
|
|
96
|
+
output_format: {
|
|
97
|
+
container: "mp3";
|
|
98
|
+
bit_rate: number;
|
|
99
|
+
sample_rate: number;
|
|
100
|
+
} | {
|
|
101
|
+
container: "wav";
|
|
102
|
+
encoding: Encoding;
|
|
103
|
+
sample_rate: number;
|
|
104
|
+
bit_rate: number;
|
|
105
|
+
} | {
|
|
106
|
+
container: "raw";
|
|
107
|
+
encoding: Encoding;
|
|
108
|
+
sample_rate: number;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
90
111
|
type LocalizeOptions = {
|
|
91
112
|
mode: "embedding";
|
|
92
113
|
embedding: number[];
|
|
@@ -118,6 +139,9 @@ type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
|
|
|
118
139
|
type CloneResponse = {
|
|
119
140
|
embedding: number[];
|
|
120
141
|
};
|
|
142
|
+
type VoiceChangerBytesResponse = {
|
|
143
|
+
buffer: ArrayBuffer;
|
|
144
|
+
};
|
|
121
145
|
type LocalizeResponse = {
|
|
122
146
|
embedding: number[];
|
|
123
147
|
};
|
|
@@ -138,4 +162,4 @@ type SourceEventData = {
|
|
|
138
162
|
type TypedArray = Float32Array | Int16Array | Uint8Array;
|
|
139
163
|
type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
140
164
|
|
|
141
|
-
export type { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
|
|
165
|
+
export type { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceChangerBytesResponse, VoiceChangerOptions, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
+
mod
|
|
44
|
+
));
|
|
45
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
var __async = (__this, __arguments, generator) => {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
var fulfilled = (value) => {
|
|
49
|
+
try {
|
|
50
|
+
step(generator.next(value));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var rejected = (value) => {
|
|
56
|
+
try {
|
|
57
|
+
step(generator.throw(value));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
reject(e);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/voice-changer/index.ts
|
|
68
|
+
var voice_changer_exports = {};
|
|
69
|
+
__export(voice_changer_exports, {
|
|
70
|
+
default: () => VoiceChanger
|
|
71
|
+
});
|
|
72
|
+
module.exports = __toCommonJS(voice_changer_exports);
|
|
73
|
+
|
|
74
|
+
// src/lib/client.ts
|
|
75
|
+
var import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
76
|
+
|
|
77
|
+
// src/lib/constants.ts
|
|
78
|
+
var BASE_URL = "https://api.cartesia.ai";
|
|
79
|
+
var CARTESIA_VERSION = "2024-06-10";
|
|
80
|
+
var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
|
|
81
|
+
const url = new URL(path, baseUrl);
|
|
82
|
+
if (websocket) {
|
|
83
|
+
url.protocol = baseUrl.replace(/^http/, "ws");
|
|
84
|
+
}
|
|
85
|
+
return url;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/lib/client.ts
|
|
89
|
+
var Client = class {
|
|
90
|
+
constructor(options = {}) {
|
|
91
|
+
const apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
|
|
92
|
+
if (!apiKey) {
|
|
93
|
+
throw new Error("Missing Cartesia API key.");
|
|
94
|
+
}
|
|
95
|
+
this.apiKey = typeof apiKey === "function" ? apiKey : () => __async(this, null, function* () {
|
|
96
|
+
return apiKey;
|
|
97
|
+
});
|
|
98
|
+
this.baseUrl = options.baseUrl || BASE_URL;
|
|
99
|
+
}
|
|
100
|
+
_fetch(_0) {
|
|
101
|
+
return __async(this, arguments, function* (path, options = {}) {
|
|
102
|
+
const url = constructApiUrl(this.baseUrl, path);
|
|
103
|
+
const headers = new Headers(options.headers);
|
|
104
|
+
headers.set("X-API-Key", yield this.apiKey());
|
|
105
|
+
headers.set("Cartesia-Version", CARTESIA_VERSION);
|
|
106
|
+
return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
|
|
107
|
+
headers
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/voice-changer/index.ts
|
|
114
|
+
var VoiceChanger = class extends Client {
|
|
115
|
+
bytes(options) {
|
|
116
|
+
return __async(this, null, function* () {
|
|
117
|
+
const formData = new FormData();
|
|
118
|
+
formData.append("clip", options.clip);
|
|
119
|
+
formData.append("voice[id]", options.voice.id);
|
|
120
|
+
const fmt = options.output_format;
|
|
121
|
+
formData.append("output_format[container]", fmt.container);
|
|
122
|
+
if ("encoding" in fmt) {
|
|
123
|
+
formData.append("output_format[encoding]", fmt.encoding);
|
|
124
|
+
}
|
|
125
|
+
if ("bit_rate" in fmt) {
|
|
126
|
+
formData.append("output_format[bit_rate]", fmt.bit_rate.toString());
|
|
127
|
+
}
|
|
128
|
+
if ("sample_rate" in fmt) {
|
|
129
|
+
formData.append("output_format[sample_rate]", fmt.sample_rate.toString());
|
|
130
|
+
}
|
|
131
|
+
const response = yield this._fetch("/voice-changer/bytes", {
|
|
132
|
+
method: "POST",
|
|
133
|
+
body: formData
|
|
134
|
+
});
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Voice changer error! status: ${response.status}, message: ${yield response.text()}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return { buffer: yield response.arrayBuffer() };
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from '../lib/client.cjs';
|
|
2
|
+
import { VoiceChangerOptions, VoiceChangerBytesResponse } from '../types/index.cjs';
|
|
3
|
+
import 'emittery';
|
|
4
|
+
|
|
5
|
+
declare class VoiceChanger extends Client {
|
|
6
|
+
bytes(options: VoiceChangerOptions): Promise<VoiceChangerBytesResponse>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { VoiceChanger as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from '../lib/client.js';
|
|
2
|
+
import { VoiceChangerOptions, VoiceChangerBytesResponse } from '../types/index.js';
|
|
3
|
+
import 'emittery';
|
|
4
|
+
|
|
5
|
+
declare class VoiceChanger extends Client {
|
|
6
|
+
bytes(options: VoiceChangerOptions): Promise<VoiceChangerBytesResponse>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { VoiceChanger as default };
|
package/dist/voices/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Voices
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-RJICGVPL.js";
|
|
4
|
+
import "../chunk-FLWYXP5Z.js";
|
|
5
5
|
import "../chunk-2BFEKY3F.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-NJDRWDQ3.js";
|
|
7
7
|
export {
|
|
8
8
|
Voices as default
|
|
9
9
|
};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "Cartesia",
|
|
5
5
|
"url": "https://cartesia.ai"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.1.
|
|
7
|
+
"version": "1.2.1-alpha.2",
|
|
8
8
|
"description": "Client for the Cartesia API.",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"module": "./dist/index.js",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"cross-fetch": "^4.0.0",
|
|
28
28
|
"emittery": "^1.0.3",
|
|
29
29
|
"human-id": "^4.1.1",
|
|
30
|
-
"partysocket": "^1.0.1"
|
|
30
|
+
"partysocket": "^1.0.1",
|
|
31
|
+
"react": "^18.3.1"
|
|
31
32
|
},
|
|
32
33
|
"publishConfig": {
|
|
33
34
|
"access": "public"
|
|
@@ -36,20 +37,11 @@
|
|
|
36
37
|
"build": "tsup src/ --format cjs,esm --dts",
|
|
37
38
|
"dev": "bun run build -- --watch"
|
|
38
39
|
},
|
|
39
|
-
"peerDependencies": {
|
|
40
|
-
"react": "^18.2.0",
|
|
41
|
-
"@types/react": "^18.2.58"
|
|
42
|
-
},
|
|
43
|
-
"peerDependenciesMeta": {
|
|
44
|
-
"react": {
|
|
45
|
-
"optional": true
|
|
46
|
-
},
|
|
47
|
-
"@types/react": {
|
|
48
|
-
"optional": true
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
40
|
"devDependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
41
|
+
"@biomejs/biome": "^1.9.4",
|
|
42
|
+
"@types/node": "^22.7.9",
|
|
43
|
+
"@types/react": "^18.3.12",
|
|
44
|
+
"tsup": "^8.0.2",
|
|
45
|
+
"typescript": "^5.6.3"
|
|
54
46
|
}
|
|
55
47
|
}
|
package/src/lib/index.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import TTS from "../tts";
|
|
2
2
|
import type { ClientOptions } from "../types";
|
|
3
|
+
import VoiceChanger from "../voice-changer";
|
|
3
4
|
import Voices from "../voices";
|
|
4
5
|
import { Client } from "./client";
|
|
5
6
|
|
|
6
7
|
export class Cartesia extends Client {
|
|
7
8
|
tts: TTS;
|
|
8
9
|
voices: Voices;
|
|
10
|
+
voiceChanger: VoiceChanger;
|
|
9
11
|
|
|
10
12
|
constructor(options: ClientOptions = {}) {
|
|
11
13
|
super(options);
|
|
12
14
|
|
|
13
15
|
this.tts = new TTS(options);
|
|
14
16
|
this.voices = new Voices(options);
|
|
17
|
+
this.voiceChanger = new VoiceChanger(options);
|
|
15
18
|
}
|
|
16
19
|
}
|
package/src/tts/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from "../lib/client";
|
|
2
|
-
import type { WebSocketOptions } from "../types";
|
|
2
|
+
import type { BytesRequest, WebSocketOptions } from "../types";
|
|
3
3
|
import WebSocket from "./websocket";
|
|
4
4
|
|
|
5
5
|
export default class TTS extends Client {
|
|
@@ -14,4 +14,19 @@ export default class TTS extends Client {
|
|
|
14
14
|
baseUrl: this.baseUrl,
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generate audio bytes from text.
|
|
20
|
+
*
|
|
21
|
+
* @param options - The options for the request.
|
|
22
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
23
|
+
*/
|
|
24
|
+
async bytes(options: BytesRequest): Promise<ArrayBuffer> {
|
|
25
|
+
const response = await this._fetch("/tts/bytes", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: JSON.stringify(options),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return response.arrayBuffer();
|
|
31
|
+
}
|
|
17
32
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -56,6 +56,11 @@ export type StreamRequest = {
|
|
|
56
56
|
add_timestamps?: boolean;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
export type BytesRequest = Omit<
|
|
60
|
+
StreamRequest,
|
|
61
|
+
"continue" | "add_timestamps" | "context_id"
|
|
62
|
+
>;
|
|
63
|
+
|
|
59
64
|
export type ContinueRequest = StreamRequest & {
|
|
60
65
|
context_id: string;
|
|
61
66
|
};
|
|
@@ -126,6 +131,28 @@ export type CloneOptions =
|
|
|
126
131
|
enhance?: boolean;
|
|
127
132
|
};
|
|
128
133
|
|
|
134
|
+
export type VoiceChangerOptions = {
|
|
135
|
+
clip: File;
|
|
136
|
+
voice: { id: string }; // match VoiceSpecifier shape, but only id is supported for now
|
|
137
|
+
output_format:
|
|
138
|
+
| {
|
|
139
|
+
container: "mp3";
|
|
140
|
+
bit_rate: number;
|
|
141
|
+
sample_rate: number;
|
|
142
|
+
}
|
|
143
|
+
| {
|
|
144
|
+
container: "wav";
|
|
145
|
+
encoding: Encoding;
|
|
146
|
+
sample_rate: number;
|
|
147
|
+
bit_rate: number;
|
|
148
|
+
}
|
|
149
|
+
| {
|
|
150
|
+
container: "raw";
|
|
151
|
+
encoding: Encoding;
|
|
152
|
+
sample_rate: number;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
129
156
|
export type LocalizeOptions = {
|
|
130
157
|
mode: "embedding";
|
|
131
158
|
embedding: number[];
|
|
@@ -167,6 +194,10 @@ export type CloneResponse = {
|
|
|
167
194
|
embedding: number[];
|
|
168
195
|
};
|
|
169
196
|
|
|
197
|
+
export type VoiceChangerBytesResponse = {
|
|
198
|
+
buffer: ArrayBuffer;
|
|
199
|
+
};
|
|
200
|
+
|
|
170
201
|
export type LocalizeResponse = {
|
|
171
202
|
embedding: number[];
|
|
172
203
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Client } from "../lib/client";
|
|
2
|
+
import type { VoiceChangerBytesResponse, VoiceChangerOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export default class VoiceChanger extends Client {
|
|
5
|
+
async bytes(
|
|
6
|
+
options: VoiceChangerOptions,
|
|
7
|
+
): Promise<VoiceChangerBytesResponse> {
|
|
8
|
+
const formData = new FormData();
|
|
9
|
+
formData.append("clip", options.clip); // TODO: handle Blobs that are not Files
|
|
10
|
+
formData.append("voice[id]", options.voice.id);
|
|
11
|
+
|
|
12
|
+
const fmt = options.output_format;
|
|
13
|
+
formData.append("output_format[container]", fmt.container);
|
|
14
|
+
if ("encoding" in fmt) {
|
|
15
|
+
formData.append("output_format[encoding]", fmt.encoding);
|
|
16
|
+
}
|
|
17
|
+
if ("bit_rate" in fmt) {
|
|
18
|
+
formData.append("output_format[bit_rate]", fmt.bit_rate.toString());
|
|
19
|
+
}
|
|
20
|
+
if ("sample_rate" in fmt) {
|
|
21
|
+
formData.append("output_format[sample_rate]", fmt.sample_rate.toString());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const response = await this._fetch("/voice-changer/bytes", {
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: formData,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Voice changer error! status: ${response.status}, message: ${await response.text()}`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { buffer: await response.arrayBuffer() };
|
|
36
|
+
}
|
|
37
|
+
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
$ tsup src/ --format cjs,esm --dts
|
|
2
|
-
[34mCLI[39m Building entry: src/index.ts, src/lib/client.ts, src/lib/constants.ts, src/lib/index.ts, src/react/index.ts, src/react/utils.ts, src/tts/index.ts, src/tts/player.ts, src/tts/source.ts, src/tts/utils.ts, src/tts/websocket.ts, src/types/index.ts, src/voices/index.ts
|
|
3
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
4
|
-
[34mCLI[39m tsup v8.0.2
|
|
5
|
-
[34mCLI[39m Target: es6
|
|
6
|
-
[34mCJS[39m Build start
|
|
7
|
-
[34mESM[39m Build start
|
|
8
|
-
[32mESM[39m [1mdist/index.js [22m[32m499.00 B[39m
|
|
9
|
-
[32mESM[39m [1mdist/chunk-FXPGR372.js [22m[32m0 B[39m
|
|
10
|
-
[32mESM[39m [1mdist/lib/client.js [22m[32m132.00 B[39m
|
|
11
|
-
[32mESM[39m [1mdist/react/index.js [22m[32m7.73 KB[39m
|
|
12
|
-
[32mESM[39m [1mdist/tts/index.js [22m[32m261.00 B[39m
|
|
13
|
-
[32mESM[39m [1mdist/lib/constants.js [22m[32m183.00 B[39m
|
|
14
|
-
[32mESM[39m [1mdist/lib/index.js [22m[32m322.00 B[39m
|
|
15
|
-
[32mESM[39m [1mdist/chunk-4GEDAGVY.js [22m[32m353.00 B[39m
|
|
16
|
-
[32mESM[39m [1mdist/react/utils.js [22m[32m109.00 B[39m
|
|
17
|
-
[32mESM[39m [1mdist/chunk-CWIJUBG6.js [22m[32m1.95 KB[39m
|
|
18
|
-
[32mESM[39m [1mdist/chunk-3FL2SNIR.js [22m[32m337.00 B[39m
|
|
19
|
-
[32mESM[39m [1mdist/chunk-MUPVAEL7.js [22m[32m439.00 B[39m
|
|
20
|
-
[32mESM[39m [1mdist/chunk-L3OMQKWL.js [22m[32m7.95 KB[39m
|
|
21
|
-
[32mESM[39m [1mdist/chunk-6PWLZAMS.js [22m[32m1.02 KB[39m
|
|
22
|
-
[32mESM[39m [1mdist/chunk-2BFEKY3F.js [22m[32m366.00 B[39m
|
|
23
|
-
[32mESM[39m [1mdist/tts/player.js [22m[32m174.00 B[39m
|
|
24
|
-
[32mESM[39m [1mdist/chunk-MNOPO7G6.js [22m[32m3.76 KB[39m
|
|
25
|
-
[32mESM[39m [1mdist/chunk-VVDJR3OA.js [22m[32m6.20 KB[39m
|
|
26
|
-
[32mESM[39m [1mdist/chunk-VCZESWYA.js [22m[32m2.11 KB[39m
|
|
27
|
-
[32mESM[39m [1mdist/chunk-WIFMLPT5.js [22m[32m2.27 KB[39m
|
|
28
|
-
[32mESM[39m [1mdist/types/index.js [22m[32m31.00 B[39m
|
|
29
|
-
[32mESM[39m [1mdist/voices/index.js [22m[32m174.00 B[39m
|
|
30
|
-
[32mESM[39m [1mdist/tts/source.js [22m[32m144.00 B[39m
|
|
31
|
-
[32mESM[39m [1mdist/tts/utils.js [22m[32m426.00 B[39m
|
|
32
|
-
[32mESM[39m [1mdist/tts/websocket.js [22m[32m242.00 B[39m
|
|
33
|
-
[32mESM[39m ⚡️ Build success in 134ms
|
|
34
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m26.45 KB[39m
|
|
35
|
-
[32mCJS[39m [1mdist/lib/client.cjs [22m[32m4.07 KB[39m
|
|
36
|
-
[32mCJS[39m [1mdist/lib/constants.cjs [22m[32m1.43 KB[39m
|
|
37
|
-
[32mCJS[39m [1mdist/lib/index.cjs [22m[32m22.35 KB[39m
|
|
38
|
-
[32mCJS[39m [1mdist/react/index.cjs [22m[32m34.12 KB[39m
|
|
39
|
-
[32mCJS[39m [1mdist/tts/index.cjs [22m[32m20.23 KB[39m
|
|
40
|
-
[32mCJS[39m [1mdist/tts/player.cjs [22m[32m6.96 KB[39m
|
|
41
|
-
[32mCJS[39m [1mdist/react/utils.cjs [22m[32m1.80 KB[39m
|
|
42
|
-
[32mCJS[39m [1mdist/tts/utils.cjs [22m[32m4.33 KB[39m
|
|
43
|
-
[32mCJS[39m [1mdist/tts/source.cjs [22m[32m9.03 KB[39m
|
|
44
|
-
[32mCJS[39m [1mdist/types/index.cjs [22m[32m764.00 B[39m
|
|
45
|
-
[32mCJS[39m [1mdist/tts/websocket.cjs [22m[32m19.92 KB[39m
|
|
46
|
-
[32mCJS[39m [1mdist/voices/index.cjs [22m[32m5.83 KB[39m
|
|
47
|
-
[32mCJS[39m ⚡️ Build success in 142ms
|
|
48
|
-
[34mDTS[39m Build start
|
|
49
|
-
[32mDTS[39m ⚡️ Build success in 7238ms
|
|
50
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[32m928.00 B[39m
|
|
51
|
-
[32mDTS[39m [1mdist/lib/constants.d.cts [22m[32m564.00 B[39m
|
|
52
|
-
[32mDTS[39m [1mdist/lib/index.d.cts [22m[32m410.00 B[39m
|
|
53
|
-
[32mDTS[39m [1mdist/react/index.d.cts [22m[32m1.09 KB[39m
|
|
54
|
-
[32mDTS[39m [1mdist/react/utils.d.cts [22m[32m240.00 B[39m
|
|
55
|
-
[32mDTS[39m [1mdist/tts/index.d.cts [22m[32m471.00 B[39m
|
|
56
|
-
[32mDTS[39m [1mdist/tts/player.d.cts [22m[32m1.20 KB[39m
|
|
57
|
-
[32mDTS[39m [1mdist/tts/utils.d.cts [22m[32m2.68 KB[39m
|
|
58
|
-
[32mDTS[39m [1mdist/tts/websocket.d.cts [22m[32m3.21 KB[39m
|
|
59
|
-
[32mDTS[39m [1mdist/tts/source.d.cts [22m[32m2.86 KB[39m
|
|
60
|
-
[32mDTS[39m [1mdist/voices/index.d.cts [22m[32m675.00 B[39m
|
|
61
|
-
[32mDTS[39m [1mdist/lib/client.d.cts [22m[32m293.00 B[39m
|
|
62
|
-
[32mDTS[39m [1mdist/types/index.d.cts [22m[32m3.96 KB[39m
|
|
63
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m920.00 B[39m
|
|
64
|
-
[32mDTS[39m [1mdist/lib/constants.d.ts [22m[32m564.00 B[39m
|
|
65
|
-
[32mDTS[39m [1mdist/lib/index.d.ts [22m[32m404.00 B[39m
|
|
66
|
-
[32mDTS[39m [1mdist/react/index.d.ts [22m[32m1.09 KB[39m
|
|
67
|
-
[32mDTS[39m [1mdist/react/utils.d.ts [22m[32m240.00 B[39m
|
|
68
|
-
[32mDTS[39m [1mdist/tts/index.d.ts [22m[32m467.00 B[39m
|
|
69
|
-
[32mDTS[39m [1mdist/tts/player.d.ts [22m[32m1.20 KB[39m
|
|
70
|
-
[32mDTS[39m [1mdist/tts/utils.d.ts [22m[32m2.68 KB[39m
|
|
71
|
-
[32mDTS[39m [1mdist/tts/websocket.d.ts [22m[32m3.20 KB[39m
|
|
72
|
-
[32mDTS[39m [1mdist/tts/source.d.ts [22m[32m2.86 KB[39m
|
|
73
|
-
[32mDTS[39m [1mdist/voices/index.d.ts [22m[32m673.00 B[39m
|
|
74
|
-
[32mDTS[39m [1mdist/lib/client.d.ts [22m[32m292.00 B[39m
|
|
75
|
-
[32mDTS[39m [1mdist/types/index.d.ts [22m[32m3.96 KB[39m
|
package/dist/chunk-MUPVAEL7.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WebSocket
|
|
3
|
-
} from "./chunk-L3OMQKWL.js";
|
|
4
|
-
import {
|
|
5
|
-
Client
|
|
6
|
-
} from "./chunk-6PWLZAMS.js";
|
|
7
|
-
|
|
8
|
-
// src/tts/index.ts
|
|
9
|
-
var TTS = class extends Client {
|
|
10
|
-
/**
|
|
11
|
-
* Get a WebSocket client for streaming audio from the TTS API.
|
|
12
|
-
*
|
|
13
|
-
* @returns {WebSocket} A Cartesia WebSocket client.
|
|
14
|
-
*/
|
|
15
|
-
websocket(options) {
|
|
16
|
-
return new WebSocket(options, {
|
|
17
|
-
apiKey: this.apiKey,
|
|
18
|
-
baseUrl: this.baseUrl
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
TTS
|
|
25
|
-
};
|
package/tsconfig.json
DELETED