@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.
@@ -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,60 @@ 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.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-2NA5SEML.js";
4
- import "../chunk-ASZKHN7Q.js";
5
- import "../chunk-5M33ZF3Y.js";
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";
@@ -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,60 @@ 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.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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  WebSocket
3
- } from "../chunk-ASZKHN7Q.js";
4
- import "../chunk-5M33ZF3Y.js";
3
+ } from "../chunk-IZBPLCGW.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;
@@ -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 };
@@ -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 };
@@ -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
  });
@@ -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
 
@@ -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
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Voices
3
- } from "../chunk-KUSVZXDT.js";
4
- import "../chunk-5M33ZF3Y.js";
3
+ } from "../chunk-UCYL2SOX.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.2",
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
  }
@@ -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;
@@ -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(url.toString());
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");
@@ -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
  };