@cartesia/cartesia-js 1.0.1 → 1.0.3

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.
@@ -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
- if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
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 = options.apiKey || process.env.CARTESIA_API_KEY;
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
- fetch(path, options = {}) {
132
- const url = constructApiUrl(this.baseUrl, path);
133
- return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
134
- headers: __spreadValues({
135
- "X-API-Key": this.apiKey,
136
- "Cartesia-Version": CARTESIA_VERSION
137
- }, options.headers)
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,61 @@ var WebSocket = class extends Client {
478
483
  * @throws {Error} If the WebSocket fails to connect.
479
484
  */
480
485
  connect() {
481
- const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
482
- websocket: true
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.binaryType = "arraybuffer";
497
+ this.socket.onopen = () => {
498
+ __privateSet(this, _isConnected, true);
499
+ emitter.emit("open");
500
+ };
501
+ this.socket.onclose = () => {
502
+ __privateSet(this, _isConnected, false);
503
+ emitter.emit("close");
504
+ };
505
+ return new Promise(
506
+ (resolve, reject) => {
507
+ var _a, _b, _c;
508
+ (_a = this.socket) == null ? void 0 : _a.addEventListener(
509
+ "open",
510
+ () => {
511
+ resolve(getEmitteryCallbacks(emitter));
512
+ },
513
+ {
514
+ once: true
515
+ }
516
+ );
517
+ const aborter = new AbortController();
518
+ (_b = this.socket) == null ? void 0 : _b.addEventListener(
519
+ "error",
520
+ () => {
521
+ aborter.abort();
522
+ reject(new Error("WebSocket failed to connect."));
523
+ },
524
+ {
525
+ signal: aborter.signal
526
+ }
527
+ );
528
+ (_c = this.socket) == null ? void 0 : _c.addEventListener(
529
+ "close",
530
+ () => {
531
+ aborter.abort();
532
+ reject(new Error("WebSocket closed before it could connect."));
533
+ },
534
+ {
535
+ signal: aborter.signal
536
+ }
537
+ );
538
+ }
539
+ );
483
540
  });
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
541
  }
532
542
  /**
533
543
  * 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-2NA5SEML.js";
4
- import "../chunk-ASZKHN7Q.js";
5
- import "../chunk-5M33ZF3Y.js";
3
+ } from "../chunk-NWCW6C7H.js";
4
+ import "../chunk-EUW2435M.js";
5
+ import "../chunk-PISCPZK4.js";
6
6
  import "../chunk-2BFEKY3F.js";
7
7
  import "../chunk-BHY7MNGT.js";
8
8
  import "../chunk-6YQ6KDIQ.js";
@@ -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
- if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
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 = options.apiKey || process.env.CARTESIA_API_KEY;
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
- fetch(path, options = {}) {
135
- const url = constructApiUrl(this.baseUrl, path);
136
- return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
137
- headers: __spreadValues({
138
- "X-API-Key": this.apiKey,
139
- "Cartesia-Version": CARTESIA_VERSION
140
- }, options.headers)
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,61 @@ var WebSocket = class extends Client {
476
481
  * @throws {Error} If the WebSocket fails to connect.
477
482
  */
478
483
  connect() {
479
- const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
480
- websocket: true
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.binaryType = "arraybuffer";
495
+ this.socket.onopen = () => {
496
+ __privateSet(this, _isConnected, true);
497
+ emitter.emit("open");
498
+ };
499
+ this.socket.onclose = () => {
500
+ __privateSet(this, _isConnected, false);
501
+ emitter.emit("close");
502
+ };
503
+ return new Promise(
504
+ (resolve, reject) => {
505
+ var _a, _b, _c;
506
+ (_a = this.socket) == null ? void 0 : _a.addEventListener(
507
+ "open",
508
+ () => {
509
+ resolve(getEmitteryCallbacks(emitter));
510
+ },
511
+ {
512
+ once: true
513
+ }
514
+ );
515
+ const aborter = new AbortController();
516
+ (_b = this.socket) == null ? void 0 : _b.addEventListener(
517
+ "error",
518
+ () => {
519
+ aborter.abort();
520
+ reject(new Error("WebSocket failed to connect."));
521
+ },
522
+ {
523
+ signal: aborter.signal
524
+ }
525
+ );
526
+ (_c = this.socket) == null ? void 0 : _c.addEventListener(
527
+ "close",
528
+ () => {
529
+ aborter.abort();
530
+ reject(new Error("WebSocket closed before it could connect."));
531
+ },
532
+ {
533
+ signal: aborter.signal
534
+ }
535
+ );
536
+ }
537
+ );
481
538
  });
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
539
  }
530
540
  /**
531
541
  * Disconnect from the Cartesia streaming WebSocket.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  WebSocket
3
- } from "../chunk-ASZKHN7Q.js";
4
- import "../chunk-5M33ZF3Y.js";
3
+ } from "../chunk-EUW2435M.js";
4
+ import "../chunk-PISCPZK4.js";
5
5
  import "../chunk-2BFEKY3F.js";
6
6
  import "../chunk-BHY7MNGT.js";
7
7
  import "../chunk-6YQ6KDIQ.js";
@@ -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;
@@ -11,10 +11,10 @@ type ConnectionEventData = {
11
11
  close: never;
12
12
  };
13
13
  type VoiceSpecifier = {
14
- mode: "id";
14
+ mode?: "id";
15
15
  id: string;
16
16
  } | {
17
- mode: "embedding";
17
+ mode?: "embedding";
18
18
  embedding: number[];
19
19
  };
20
20
  type Emotion = "anger" | "sadness" | "positivity" | "curiosity" | "surprise";
@@ -22,7 +22,7 @@ type Intensity = "lowest" | "low" | "high" | "highest";
22
22
  type EmotionControl = Emotion | `${Emotion}:${Intensity}`;
23
23
  type VoiceOptions = VoiceSpecifier & {
24
24
  __experimental_controls?: {
25
- speed?: "slowest" | "slow" | "normal" | "fast" | "fastest";
25
+ speed?: "slowest" | "slow" | "normal" | "fast" | "fastest" | number;
26
26
  emotion?: EmotionControl[];
27
27
  };
28
28
  };
@@ -77,10 +77,20 @@ 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
  };
86
+ interface VoiceToMix {
87
+ id?: string;
88
+ embedding?: number[];
89
+ weight: number;
90
+ }
91
+ interface MixVoicesOptions {
92
+ voices: VoiceToMix[];
93
+ }
84
94
  type Voice = {
85
95
  id: string;
86
96
  name: string;
@@ -89,11 +99,16 @@ type Voice = {
89
99
  is_public: boolean;
90
100
  user_id: string;
91
101
  created_at: string;
102
+ language: string;
92
103
  };
93
104
  type CreateVoice = Pick<Voice, "name" | "description" | "embedding"> & Partial<Omit<Voice, "name" | "description" | "embedding">>;
105
+ type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
94
106
  type CloneResponse = {
95
107
  embedding: number[];
96
108
  };
109
+ type MixVoicesResponse = {
110
+ embedding: number[];
111
+ };
97
112
  type WebSocketOptions = {
98
113
  container?: string;
99
114
  encoding?: string;
@@ -108,4 +123,4 @@ type SourceEventData = {
108
123
  type TypedArray = Float32Array | Int16Array | Uint8Array;
109
124
  type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
110
125
 
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 };
126
+ export type { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
@@ -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;
@@ -11,10 +11,10 @@ type ConnectionEventData = {
11
11
  close: never;
12
12
  };
13
13
  type VoiceSpecifier = {
14
- mode: "id";
14
+ mode?: "id";
15
15
  id: string;
16
16
  } | {
17
- mode: "embedding";
17
+ mode?: "embedding";
18
18
  embedding: number[];
19
19
  };
20
20
  type Emotion = "anger" | "sadness" | "positivity" | "curiosity" | "surprise";
@@ -22,7 +22,7 @@ type Intensity = "lowest" | "low" | "high" | "highest";
22
22
  type EmotionControl = Emotion | `${Emotion}:${Intensity}`;
23
23
  type VoiceOptions = VoiceSpecifier & {
24
24
  __experimental_controls?: {
25
- speed?: "slowest" | "slow" | "normal" | "fast" | "fastest";
25
+ speed?: "slowest" | "slow" | "normal" | "fast" | "fastest" | number;
26
26
  emotion?: EmotionControl[];
27
27
  };
28
28
  };
@@ -77,10 +77,20 @@ 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
  };
86
+ interface VoiceToMix {
87
+ id?: string;
88
+ embedding?: number[];
89
+ weight: number;
90
+ }
91
+ interface MixVoicesOptions {
92
+ voices: VoiceToMix[];
93
+ }
84
94
  type Voice = {
85
95
  id: string;
86
96
  name: string;
@@ -89,11 +99,16 @@ type Voice = {
89
99
  is_public: boolean;
90
100
  user_id: string;
91
101
  created_at: string;
102
+ language: string;
92
103
  };
93
104
  type CreateVoice = Pick<Voice, "name" | "description" | "embedding"> & Partial<Omit<Voice, "name" | "description" | "embedding">>;
105
+ type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
94
106
  type CloneResponse = {
95
107
  embedding: number[];
96
108
  };
109
+ type MixVoicesResponse = {
110
+ embedding: number[];
111
+ };
97
112
  type WebSocketOptions = {
98
113
  container?: string;
99
114
  encoding?: string;
@@ -108,4 +123,4 @@ type SourceEventData = {
108
123
  type TypedArray = Float32Array | Int16Array | Uint8Array;
109
124
  type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
110
125
 
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 };
126
+ export type { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, VoiceOptions, VoiceSpecifier, VoiceToMix, WebSocketBaseResponse, WebSocketChunkResponse, WebSocketErrorResponse, WebSocketOptions, WebSocketResponse, WebSocketTimestampsResponse, WordTimestamps };
@@ -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
- if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
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 = options.apiKey || process.env.CARTESIA_API_KEY;
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
- fetch(path, options = {}) {
98
- const url = constructApiUrl(this.baseUrl, path);
99
- return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
100
- headers: __spreadValues({
101
- "X-API-Key": this.apiKey,
102
- "Cartesia-Version": CARTESIA_VERSION
103
- }, options.headers)
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.fetch("/voices");
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.fetch(`/voices/${voiceId}`);
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.fetch("/voices", {
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
- const response = yield this.fetch("/voices/clone/clip", {
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
  });
@@ -151,4 +159,14 @@ var Voices = class extends Client {
151
159
  throw new Error("Invalid mode for clone()");
152
160
  });
153
161
  }
162
+ mix(options) {
163
+ return __async(this, null, function* () {
164
+ const request = options;
165
+ const response = yield this._fetch("/voices/mix", {
166
+ method: "POST",
167
+ body: JSON.stringify(request)
168
+ });
169
+ return response.json();
170
+ });
171
+ }
154
172
  };
@@ -1,12 +1,14 @@
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, MixVoicesOptions, MixVoicesResponse } 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>;
11
+ mix(options: MixVoicesOptions): Promise<MixVoicesResponse>;
10
12
  }
11
13
 
12
14
  export { Voices as default };
@@ -1,12 +1,14 @@
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, MixVoicesOptions, MixVoicesResponse } 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>;
11
+ mix(options: MixVoicesOptions): Promise<MixVoicesResponse>;
10
12
  }
11
13
 
12
14
  export { Voices as default };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Voices
3
- } from "../chunk-KUSVZXDT.js";
4
- import "../chunk-5M33ZF3Y.js";
3
+ } from "../chunk-YFN6TFR4.js";
4
+ import "../chunk-PISCPZK4.js";
5
5
  import "../chunk-2BFEKY3F.js";
6
6
  import "../chunk-GHY2WEOK.js";
7
7
  export {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Cartesia",
5
5
  "url": "https://cartesia.ai"
6
6
  },
7
- "version": "1.0.1",
7
+ "version": "1.0.3",
8
8
  "description": "Client for the Cartesia API.",
9
9
  "type": "module",
10
10
  "module": "./dist/index.js",
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
- if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
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
- // biome-ignore lint/style/noNonNullAssertion: Guaranteed to be defined by the check above.
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
- fetch(path: string, options: RequestInit = {}) {
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
  }