@cartesia/cartesia-js 1.0.1 → 1.0.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/.turbo/turbo-build.log +34 -34
- package/CHANGELOG.md +6 -0
- package/dist/{chunk-2NA5SEML.js → chunk-EDAAHENY.js} +2 -2
- package/dist/{chunk-ASZKHN7Q.js → chunk-IZBPLCGW.js} +54 -50
- package/dist/{chunk-OFH3ML4L.js → chunk-NVOCUUOF.js} +3 -3
- package/dist/chunk-PISCPZK4.js +40 -0
- package/dist/{chunk-KUSVZXDT.js → chunk-UCYL2SOX.js} +17 -14
- package/dist/index.cjs +84 -72
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/lib/client.cjs +35 -10
- package/dist/lib/client.d.cts +2 -2
- package/dist/lib/client.d.ts +2 -2
- package/dist/lib/client.js +1 -1
- package/dist/lib/index.cjs +84 -72
- package/dist/lib/index.js +5 -5
- package/dist/react/index.cjs +84 -72
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +5 -5
- package/dist/tts/index.cjs +68 -59
- package/dist/tts/index.js +3 -3
- package/dist/tts/websocket.cjs +68 -59
- package/dist/tts/websocket.js +2 -2
- package/dist/types/index.d.cts +6 -2
- package/dist/types/index.d.ts +6 -2
- package/dist/voices/index.cjs +31 -23
- package/dist/voices/index.d.cts +2 -1
- package/dist/voices/index.d.ts +2 -1
- package/dist/voices/index.js +2 -2
- package/package.json +1 -1
- package/src/lib/client.ts +10 -10
- package/src/react/index.ts +1 -1
- package/src/tts/websocket.ts +9 -7
- package/src/types/index.ts +8 -1
- package/src/voices/index.ts +22 -15
- package/dist/chunk-5M33ZF3Y.js +0 -34
package/dist/tts/index.cjs
CHANGED
|
@@ -122,20 +122,25 @@ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
|
|
|
122
122
|
// src/lib/client.ts
|
|
123
123
|
var Client = class {
|
|
124
124
|
constructor(options = {}) {
|
|
125
|
-
|
|
125
|
+
const apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
|
|
126
|
+
if (!apiKey) {
|
|
126
127
|
throw new Error("Missing Cartesia API key.");
|
|
127
128
|
}
|
|
128
|
-
this.apiKey =
|
|
129
|
+
this.apiKey = typeof apiKey === "function" ? apiKey : () => __async(this, null, function* () {
|
|
130
|
+
return apiKey;
|
|
131
|
+
});
|
|
129
132
|
this.baseUrl = options.baseUrl || BASE_URL;
|
|
130
133
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
headers
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}, options
|
|
138
|
-
|
|
134
|
+
_fetch(_0) {
|
|
135
|
+
return __async(this, arguments, function* (path, options = {}) {
|
|
136
|
+
const url = constructApiUrl(this.baseUrl, path);
|
|
137
|
+
const headers = new Headers(options.headers);
|
|
138
|
+
headers.set("X-API-Key", yield this.apiKey());
|
|
139
|
+
headers.set("Cartesia-Version", CARTESIA_VERSION);
|
|
140
|
+
return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
|
|
141
|
+
headers
|
|
142
|
+
}));
|
|
143
|
+
});
|
|
139
144
|
}
|
|
140
145
|
};
|
|
141
146
|
|
|
@@ -478,56 +483,60 @@ var WebSocket = class extends Client {
|
|
|
478
483
|
* @throws {Error} If the WebSocket fails to connect.
|
|
479
484
|
*/
|
|
480
485
|
connect() {
|
|
481
|
-
|
|
482
|
-
|
|
486
|
+
return __async(this, null, function* () {
|
|
487
|
+
const emitter = new import_emittery2.default();
|
|
488
|
+
this.socket = new import_partysocket.WebSocket(() => __async(this, null, function* () {
|
|
489
|
+
const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
|
|
490
|
+
websocket: true
|
|
491
|
+
});
|
|
492
|
+
url.searchParams.set("api_key", yield this.apiKey());
|
|
493
|
+
url.searchParams.set("cartesia_version", CARTESIA_VERSION);
|
|
494
|
+
return url.toString();
|
|
495
|
+
}));
|
|
496
|
+
this.socket.onopen = () => {
|
|
497
|
+
__privateSet(this, _isConnected, true);
|
|
498
|
+
emitter.emit("open");
|
|
499
|
+
};
|
|
500
|
+
this.socket.onclose = () => {
|
|
501
|
+
__privateSet(this, _isConnected, false);
|
|
502
|
+
emitter.emit("close");
|
|
503
|
+
};
|
|
504
|
+
return new Promise(
|
|
505
|
+
(resolve, reject) => {
|
|
506
|
+
var _a, _b, _c;
|
|
507
|
+
(_a = this.socket) == null ? void 0 : _a.addEventListener(
|
|
508
|
+
"open",
|
|
509
|
+
() => {
|
|
510
|
+
resolve(getEmitteryCallbacks(emitter));
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
once: true
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
const aborter = new AbortController();
|
|
517
|
+
(_b = this.socket) == null ? void 0 : _b.addEventListener(
|
|
518
|
+
"error",
|
|
519
|
+
() => {
|
|
520
|
+
aborter.abort();
|
|
521
|
+
reject(new Error("WebSocket failed to connect."));
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
signal: aborter.signal
|
|
525
|
+
}
|
|
526
|
+
);
|
|
527
|
+
(_c = this.socket) == null ? void 0 : _c.addEventListener(
|
|
528
|
+
"close",
|
|
529
|
+
() => {
|
|
530
|
+
aborter.abort();
|
|
531
|
+
reject(new Error("WebSocket closed before it could connect."));
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
signal: aborter.signal
|
|
535
|
+
}
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
);
|
|
483
539
|
});
|
|
484
|
-
url.searchParams.set("api_key", this.apiKey);
|
|
485
|
-
url.searchParams.set("cartesia_version", CARTESIA_VERSION);
|
|
486
|
-
const emitter = new import_emittery2.default();
|
|
487
|
-
this.socket = new import_partysocket.WebSocket(url.toString());
|
|
488
|
-
this.socket.onopen = () => {
|
|
489
|
-
__privateSet(this, _isConnected, true);
|
|
490
|
-
emitter.emit("open");
|
|
491
|
-
};
|
|
492
|
-
this.socket.onclose = () => {
|
|
493
|
-
__privateSet(this, _isConnected, false);
|
|
494
|
-
emitter.emit("close");
|
|
495
|
-
};
|
|
496
|
-
return new Promise(
|
|
497
|
-
(resolve, reject) => {
|
|
498
|
-
var _a, _b, _c;
|
|
499
|
-
(_a = this.socket) == null ? void 0 : _a.addEventListener(
|
|
500
|
-
"open",
|
|
501
|
-
() => {
|
|
502
|
-
resolve(getEmitteryCallbacks(emitter));
|
|
503
|
-
},
|
|
504
|
-
{
|
|
505
|
-
once: true
|
|
506
|
-
}
|
|
507
|
-
);
|
|
508
|
-
const aborter = new AbortController();
|
|
509
|
-
(_b = this.socket) == null ? void 0 : _b.addEventListener(
|
|
510
|
-
"error",
|
|
511
|
-
() => {
|
|
512
|
-
aborter.abort();
|
|
513
|
-
reject(new Error("WebSocket failed to connect."));
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
signal: aborter.signal
|
|
517
|
-
}
|
|
518
|
-
);
|
|
519
|
-
(_c = this.socket) == null ? void 0 : _c.addEventListener(
|
|
520
|
-
"close",
|
|
521
|
-
() => {
|
|
522
|
-
aborter.abort();
|
|
523
|
-
reject(new Error("WebSocket closed before it could connect."));
|
|
524
|
-
},
|
|
525
|
-
{
|
|
526
|
-
signal: aborter.signal
|
|
527
|
-
}
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
);
|
|
531
540
|
}
|
|
532
541
|
/**
|
|
533
542
|
* Disconnect from the Cartesia streaming WebSocket.
|
package/dist/tts/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TTS
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-EDAAHENY.js";
|
|
4
|
+
import "../chunk-IZBPLCGW.js";
|
|
5
|
+
import "../chunk-PISCPZK4.js";
|
|
6
6
|
import "../chunk-2BFEKY3F.js";
|
|
7
7
|
import "../chunk-BHY7MNGT.js";
|
|
8
8
|
import "../chunk-6YQ6KDIQ.js";
|
package/dist/tts/websocket.cjs
CHANGED
|
@@ -125,20 +125,25 @@ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
|
|
|
125
125
|
// src/lib/client.ts
|
|
126
126
|
var Client = class {
|
|
127
127
|
constructor(options = {}) {
|
|
128
|
-
|
|
128
|
+
const apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
|
|
129
|
+
if (!apiKey) {
|
|
129
130
|
throw new Error("Missing Cartesia API key.");
|
|
130
131
|
}
|
|
131
|
-
this.apiKey =
|
|
132
|
+
this.apiKey = typeof apiKey === "function" ? apiKey : () => __async(this, null, function* () {
|
|
133
|
+
return apiKey;
|
|
134
|
+
});
|
|
132
135
|
this.baseUrl = options.baseUrl || BASE_URL;
|
|
133
136
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
headers
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}, options
|
|
141
|
-
|
|
137
|
+
_fetch(_0) {
|
|
138
|
+
return __async(this, arguments, function* (path, options = {}) {
|
|
139
|
+
const url = constructApiUrl(this.baseUrl, path);
|
|
140
|
+
const headers = new Headers(options.headers);
|
|
141
|
+
headers.set("X-API-Key", yield this.apiKey());
|
|
142
|
+
headers.set("Cartesia-Version", CARTESIA_VERSION);
|
|
143
|
+
return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
|
|
144
|
+
headers
|
|
145
|
+
}));
|
|
146
|
+
});
|
|
142
147
|
}
|
|
143
148
|
};
|
|
144
149
|
|
|
@@ -476,56 +481,60 @@ var WebSocket = class extends Client {
|
|
|
476
481
|
* @throws {Error} If the WebSocket fails to connect.
|
|
477
482
|
*/
|
|
478
483
|
connect() {
|
|
479
|
-
|
|
480
|
-
|
|
484
|
+
return __async(this, null, function* () {
|
|
485
|
+
const emitter = new import_emittery2.default();
|
|
486
|
+
this.socket = new import_partysocket.WebSocket(() => __async(this, null, function* () {
|
|
487
|
+
const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
|
|
488
|
+
websocket: true
|
|
489
|
+
});
|
|
490
|
+
url.searchParams.set("api_key", yield this.apiKey());
|
|
491
|
+
url.searchParams.set("cartesia_version", CARTESIA_VERSION);
|
|
492
|
+
return url.toString();
|
|
493
|
+
}));
|
|
494
|
+
this.socket.onopen = () => {
|
|
495
|
+
__privateSet(this, _isConnected, true);
|
|
496
|
+
emitter.emit("open");
|
|
497
|
+
};
|
|
498
|
+
this.socket.onclose = () => {
|
|
499
|
+
__privateSet(this, _isConnected, false);
|
|
500
|
+
emitter.emit("close");
|
|
501
|
+
};
|
|
502
|
+
return new Promise(
|
|
503
|
+
(resolve, reject) => {
|
|
504
|
+
var _a, _b, _c;
|
|
505
|
+
(_a = this.socket) == null ? void 0 : _a.addEventListener(
|
|
506
|
+
"open",
|
|
507
|
+
() => {
|
|
508
|
+
resolve(getEmitteryCallbacks(emitter));
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
once: true
|
|
512
|
+
}
|
|
513
|
+
);
|
|
514
|
+
const aborter = new AbortController();
|
|
515
|
+
(_b = this.socket) == null ? void 0 : _b.addEventListener(
|
|
516
|
+
"error",
|
|
517
|
+
() => {
|
|
518
|
+
aborter.abort();
|
|
519
|
+
reject(new Error("WebSocket failed to connect."));
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
signal: aborter.signal
|
|
523
|
+
}
|
|
524
|
+
);
|
|
525
|
+
(_c = this.socket) == null ? void 0 : _c.addEventListener(
|
|
526
|
+
"close",
|
|
527
|
+
() => {
|
|
528
|
+
aborter.abort();
|
|
529
|
+
reject(new Error("WebSocket closed before it could connect."));
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
signal: aborter.signal
|
|
533
|
+
}
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
);
|
|
481
537
|
});
|
|
482
|
-
url.searchParams.set("api_key", this.apiKey);
|
|
483
|
-
url.searchParams.set("cartesia_version", CARTESIA_VERSION);
|
|
484
|
-
const emitter = new import_emittery2.default();
|
|
485
|
-
this.socket = new import_partysocket.WebSocket(url.toString());
|
|
486
|
-
this.socket.onopen = () => {
|
|
487
|
-
__privateSet(this, _isConnected, true);
|
|
488
|
-
emitter.emit("open");
|
|
489
|
-
};
|
|
490
|
-
this.socket.onclose = () => {
|
|
491
|
-
__privateSet(this, _isConnected, false);
|
|
492
|
-
emitter.emit("close");
|
|
493
|
-
};
|
|
494
|
-
return new Promise(
|
|
495
|
-
(resolve, reject) => {
|
|
496
|
-
var _a, _b, _c;
|
|
497
|
-
(_a = this.socket) == null ? void 0 : _a.addEventListener(
|
|
498
|
-
"open",
|
|
499
|
-
() => {
|
|
500
|
-
resolve(getEmitteryCallbacks(emitter));
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
once: true
|
|
504
|
-
}
|
|
505
|
-
);
|
|
506
|
-
const aborter = new AbortController();
|
|
507
|
-
(_b = this.socket) == null ? void 0 : _b.addEventListener(
|
|
508
|
-
"error",
|
|
509
|
-
() => {
|
|
510
|
-
aborter.abort();
|
|
511
|
-
reject(new Error("WebSocket failed to connect."));
|
|
512
|
-
},
|
|
513
|
-
{
|
|
514
|
-
signal: aborter.signal
|
|
515
|
-
}
|
|
516
|
-
);
|
|
517
|
-
(_c = this.socket) == null ? void 0 : _c.addEventListener(
|
|
518
|
-
"close",
|
|
519
|
-
() => {
|
|
520
|
-
aborter.abort();
|
|
521
|
-
reject(new Error("WebSocket closed before it could connect."));
|
|
522
|
-
},
|
|
523
|
-
{
|
|
524
|
-
signal: aborter.signal
|
|
525
|
-
}
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
);
|
|
529
538
|
}
|
|
530
539
|
/**
|
|
531
540
|
* Disconnect from the Cartesia streaming WebSocket.
|
package/dist/tts/websocket.js
CHANGED
package/dist/types/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import emittery__default from 'emittery';
|
|
2
2
|
|
|
3
3
|
interface ClientOptions {
|
|
4
|
-
apiKey?: string;
|
|
4
|
+
apiKey?: string | (() => Promise<string>);
|
|
5
5
|
baseUrl?: string;
|
|
6
6
|
}
|
|
7
7
|
type Sentinel = null;
|
|
@@ -77,9 +77,11 @@ type EmitteryCallbacks<T> = {
|
|
|
77
77
|
type CloneOptions = {
|
|
78
78
|
mode: "url";
|
|
79
79
|
link: string;
|
|
80
|
+
enhance?: boolean;
|
|
80
81
|
} | {
|
|
81
82
|
mode: "clip";
|
|
82
83
|
clip: Blob;
|
|
84
|
+
enhance?: boolean;
|
|
83
85
|
};
|
|
84
86
|
type Voice = {
|
|
85
87
|
id: string;
|
|
@@ -89,8 +91,10 @@ type Voice = {
|
|
|
89
91
|
is_public: boolean;
|
|
90
92
|
user_id: string;
|
|
91
93
|
created_at: string;
|
|
94
|
+
language: string;
|
|
92
95
|
};
|
|
93
96
|
type CreateVoice = Pick<Voice, "name" | "description" | "embedding"> & Partial<Omit<Voice, "name" | "description" | "embedding">>;
|
|
97
|
+
type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
|
|
94
98
|
type CloneResponse = {
|
|
95
99
|
embedding: number[];
|
|
96
100
|
};
|
|
@@ -108,4 +112,4 @@ type SourceEventData = {
|
|
|
108
112
|
type TypedArray = Float32Array | Int16Array | Uint8Array;
|
|
109
113
|
type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
110
114
|
|
|
111
|
-
export type { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, Voice, VoiceOptions, VoiceSpecifier, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
|
|
115
|
+
export type { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import emittery__default from 'emittery';
|
|
2
2
|
|
|
3
3
|
interface ClientOptions {
|
|
4
|
-
apiKey?: string;
|
|
4
|
+
apiKey?: string | (() => Promise<string>);
|
|
5
5
|
baseUrl?: string;
|
|
6
6
|
}
|
|
7
7
|
type Sentinel = null;
|
|
@@ -77,9 +77,11 @@ type EmitteryCallbacks<T> = {
|
|
|
77
77
|
type CloneOptions = {
|
|
78
78
|
mode: "url";
|
|
79
79
|
link: string;
|
|
80
|
+
enhance?: boolean;
|
|
80
81
|
} | {
|
|
81
82
|
mode: "clip";
|
|
82
83
|
clip: Blob;
|
|
84
|
+
enhance?: boolean;
|
|
83
85
|
};
|
|
84
86
|
type Voice = {
|
|
85
87
|
id: string;
|
|
@@ -89,8 +91,10 @@ type Voice = {
|
|
|
89
91
|
is_public: boolean;
|
|
90
92
|
user_id: string;
|
|
91
93
|
created_at: string;
|
|
94
|
+
language: string;
|
|
92
95
|
};
|
|
93
96
|
type CreateVoice = Pick<Voice, "name" | "description" | "embedding"> & Partial<Omit<Voice, "name" | "description" | "embedding">>;
|
|
97
|
+
type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
|
|
94
98
|
type CloneResponse = {
|
|
95
99
|
embedding: number[];
|
|
96
100
|
};
|
|
@@ -108,4 +112,4 @@ type SourceEventData = {
|
|
|
108
112
|
type TypedArray = Float32Array | Int16Array | Uint8Array;
|
|
109
113
|
type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
|
|
110
114
|
|
|
111
|
-
export type { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, Voice, VoiceOptions, VoiceSpecifier, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
|
|
115
|
+
export type { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
|
package/dist/voices/index.cjs
CHANGED
|
@@ -88,20 +88,25 @@ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
|
|
|
88
88
|
// src/lib/client.ts
|
|
89
89
|
var Client = class {
|
|
90
90
|
constructor(options = {}) {
|
|
91
|
-
|
|
91
|
+
const apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
|
|
92
|
+
if (!apiKey) {
|
|
92
93
|
throw new Error("Missing Cartesia API key.");
|
|
93
94
|
}
|
|
94
|
-
this.apiKey =
|
|
95
|
+
this.apiKey = typeof apiKey === "function" ? apiKey : () => __async(this, null, function* () {
|
|
96
|
+
return apiKey;
|
|
97
|
+
});
|
|
95
98
|
this.baseUrl = options.baseUrl || BASE_URL;
|
|
96
99
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
headers
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}, options
|
|
104
|
-
|
|
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
|
+
});
|
|
105
110
|
}
|
|
106
111
|
};
|
|
107
112
|
|
|
@@ -109,40 +114,43 @@ var Client = class {
|
|
|
109
114
|
var Voices = class extends Client {
|
|
110
115
|
list() {
|
|
111
116
|
return __async(this, null, function* () {
|
|
112
|
-
const response = yield this.
|
|
117
|
+
const response = yield this._fetch("/voices");
|
|
113
118
|
return response.json();
|
|
114
119
|
});
|
|
115
120
|
}
|
|
116
121
|
get(voiceId) {
|
|
117
122
|
return __async(this, null, function* () {
|
|
118
|
-
const response = yield this.
|
|
123
|
+
const response = yield this._fetch(`/voices/${voiceId}`);
|
|
119
124
|
return response.json();
|
|
120
125
|
});
|
|
121
126
|
}
|
|
122
127
|
create(voice) {
|
|
123
128
|
return __async(this, null, function* () {
|
|
124
|
-
const response = yield this.
|
|
129
|
+
const response = yield this._fetch("/voices", {
|
|
125
130
|
method: "POST",
|
|
126
131
|
body: JSON.stringify(voice)
|
|
127
132
|
});
|
|
128
133
|
return response.json();
|
|
129
134
|
});
|
|
130
135
|
}
|
|
136
|
+
update(id, voice) {
|
|
137
|
+
return __async(this, null, function* () {
|
|
138
|
+
const response = yield this._fetch(`/voices/${id}`, {
|
|
139
|
+
method: "PATCH",
|
|
140
|
+
body: JSON.stringify(voice)
|
|
141
|
+
});
|
|
142
|
+
return response.json();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
131
145
|
clone(options) {
|
|
132
146
|
return __async(this, null, function* () {
|
|
133
|
-
if (options.mode === "url") {
|
|
134
|
-
const response = yield this.fetch(
|
|
135
|
-
`/voices/clone/url?link=${options.link}`,
|
|
136
|
-
{
|
|
137
|
-
method: "POST"
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
return response.json();
|
|
141
|
-
}
|
|
142
147
|
if (options.mode === "clip") {
|
|
143
148
|
const formData = new FormData();
|
|
144
149
|
formData.append("clip", options.clip);
|
|
145
|
-
|
|
150
|
+
if (options.enhance !== void 0) {
|
|
151
|
+
formData.append("enhance", options.enhance.toString());
|
|
152
|
+
}
|
|
153
|
+
const response = yield this._fetch("/voices/clone/clip", {
|
|
146
154
|
method: "POST",
|
|
147
155
|
body: formData
|
|
148
156
|
});
|
package/dist/voices/index.d.cts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Client } from '../lib/client.cjs';
|
|
2
|
-
import { Voice, CreateVoice, CloneOptions, CloneResponse } from '../types/index.cjs';
|
|
2
|
+
import { Voice, CreateVoice, UpdateVoice, CloneOptions, CloneResponse } from '../types/index.cjs';
|
|
3
3
|
import 'emittery';
|
|
4
4
|
|
|
5
5
|
declare class Voices extends Client {
|
|
6
6
|
list(): Promise<Voice[]>;
|
|
7
7
|
get(voiceId: string): Promise<Voice>;
|
|
8
8
|
create(voice: CreateVoice): Promise<Voice>;
|
|
9
|
+
update(id: string, voice: UpdateVoice): Promise<Voice>;
|
|
9
10
|
clone(options: CloneOptions): Promise<CloneResponse>;
|
|
10
11
|
}
|
|
11
12
|
|
package/dist/voices/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Client } from '../lib/client.js';
|
|
2
|
-
import { Voice, CreateVoice, CloneOptions, CloneResponse } from '../types/index.js';
|
|
2
|
+
import { Voice, CreateVoice, UpdateVoice, CloneOptions, CloneResponse } from '../types/index.js';
|
|
3
3
|
import 'emittery';
|
|
4
4
|
|
|
5
5
|
declare class Voices extends Client {
|
|
6
6
|
list(): Promise<Voice[]>;
|
|
7
7
|
get(voiceId: string): Promise<Voice>;
|
|
8
8
|
create(voice: CreateVoice): Promise<Voice>;
|
|
9
|
+
update(id: string, voice: UpdateVoice): Promise<Voice>;
|
|
9
10
|
clone(options: CloneOptions): Promise<CloneResponse>;
|
|
10
11
|
}
|
|
11
12
|
|
package/dist/voices/index.js
CHANGED
package/package.json
CHANGED
package/src/lib/client.ts
CHANGED
|
@@ -3,29 +3,29 @@ import type { ClientOptions } from "../types";
|
|
|
3
3
|
import { BASE_URL, CARTESIA_VERSION, constructApiUrl } from "./constants";
|
|
4
4
|
|
|
5
5
|
export class Client {
|
|
6
|
-
apiKey: string
|
|
6
|
+
apiKey: () => Promise<string>;
|
|
7
7
|
baseUrl: string;
|
|
8
8
|
|
|
9
9
|
constructor(options: ClientOptions = {}) {
|
|
10
|
-
|
|
10
|
+
const apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
|
|
11
|
+
if (!apiKey) {
|
|
11
12
|
throw new Error("Missing Cartesia API key.");
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
this.apiKey = (options.apiKey || process.env.CARTESIA_API_KEY)!;
|
|
15
|
+
this.apiKey = typeof apiKey === "function" ? apiKey : async () => apiKey;
|
|
16
16
|
this.baseUrl = options.baseUrl || BASE_URL;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
protected async _fetch(path: string, options: RequestInit = {}) {
|
|
20
20
|
const url = constructApiUrl(this.baseUrl, path);
|
|
21
|
+
const headers = new Headers(options.headers);
|
|
22
|
+
|
|
23
|
+
headers.set("X-API-Key", await this.apiKey());
|
|
24
|
+
headers.set("Cartesia-Version", CARTESIA_VERSION);
|
|
21
25
|
|
|
22
26
|
return fetch(url.toString(), {
|
|
23
27
|
...options,
|
|
24
|
-
headers
|
|
25
|
-
"X-API-Key": this.apiKey,
|
|
26
|
-
"Cartesia-Version": CARTESIA_VERSION,
|
|
27
|
-
...options.headers,
|
|
28
|
-
},
|
|
28
|
+
headers,
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/react/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { StreamRequest } from "../types";
|
|
|
8
8
|
import { pingServer } from "./utils";
|
|
9
9
|
|
|
10
10
|
export type UseTTSOptions = {
|
|
11
|
-
apiKey: string | null;
|
|
11
|
+
apiKey: string | (() => Promise<string>) | null;
|
|
12
12
|
baseUrl?: string;
|
|
13
13
|
sampleRate: number;
|
|
14
14
|
onError?: (error: Error) => void;
|
package/src/tts/websocket.ts
CHANGED
|
@@ -172,14 +172,16 @@ export default class WebSocket extends Client {
|
|
|
172
172
|
* @returns A promise that resolves when the WebSocket is connected.
|
|
173
173
|
* @throws {Error} If the WebSocket fails to connect.
|
|
174
174
|
*/
|
|
175
|
-
connect() {
|
|
176
|
-
const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
|
|
177
|
-
websocket: true,
|
|
178
|
-
});
|
|
179
|
-
url.searchParams.set("api_key", this.apiKey);
|
|
180
|
-
url.searchParams.set("cartesia_version", CARTESIA_VERSION);
|
|
175
|
+
async connect() {
|
|
181
176
|
const emitter = new Emittery<ConnectionEventData>();
|
|
182
|
-
this.socket = new PartySocketWebSocket(
|
|
177
|
+
this.socket = new PartySocketWebSocket(async () => {
|
|
178
|
+
const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
|
|
179
|
+
websocket: true,
|
|
180
|
+
});
|
|
181
|
+
url.searchParams.set("api_key", await this.apiKey());
|
|
182
|
+
url.searchParams.set("cartesia_version", CARTESIA_VERSION);
|
|
183
|
+
return url.toString();
|
|
184
|
+
});
|
|
183
185
|
this.socket.onopen = () => {
|
|
184
186
|
this.#isConnected = true;
|
|
185
187
|
emitter.emit("open");
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Emittery from "emittery";
|
|
2
2
|
|
|
3
3
|
export interface ClientOptions {
|
|
4
|
-
apiKey?: string;
|
|
4
|
+
apiKey?: string | (() => Promise<string>);
|
|
5
5
|
baseUrl?: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -104,10 +104,12 @@ export type CloneOptions =
|
|
|
104
104
|
| {
|
|
105
105
|
mode: "url";
|
|
106
106
|
link: string;
|
|
107
|
+
enhance?: boolean;
|
|
107
108
|
}
|
|
108
109
|
| {
|
|
109
110
|
mode: "clip";
|
|
110
111
|
clip: Blob;
|
|
112
|
+
enhance?: boolean;
|
|
111
113
|
};
|
|
112
114
|
|
|
113
115
|
export type Voice = {
|
|
@@ -118,11 +120,16 @@ export type Voice = {
|
|
|
118
120
|
is_public: boolean;
|
|
119
121
|
user_id: string;
|
|
120
122
|
created_at: string;
|
|
123
|
+
language: string;
|
|
121
124
|
};
|
|
122
125
|
|
|
123
126
|
export type CreateVoice = Pick<Voice, "name" | "description" | "embedding"> &
|
|
124
127
|
Partial<Omit<Voice, "name" | "description" | "embedding">>;
|
|
125
128
|
|
|
129
|
+
export type UpdateVoice = Partial<
|
|
130
|
+
Pick<Voice, "name" | "description" | "embedding">
|
|
131
|
+
>;
|
|
132
|
+
|
|
126
133
|
export type CloneResponse = {
|
|
127
134
|
embedding: number[];
|
|
128
135
|
};
|