@cartesia/cartesia-js 1.2.2-alpha.0 → 1.3.0

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.
Files changed (45) hide show
  1. package/README.md +6 -2
  2. package/dist/{chunk-HQOC2S6C.js → chunk-CJZSHIRI.js} +28 -18
  3. package/dist/{chunk-EYRYHK3X.js → chunk-QT5LHJ3D.js} +1 -1
  4. package/dist/{chunk-62LXGS65.js → chunk-RJICGVPL.js} +0 -37
  5. package/dist/{chunk-MGVQHO25.js → chunk-RYHHRY64.js} +4 -4
  6. package/dist/index.cjs +21 -48
  7. package/dist/index.d.cts +2 -1
  8. package/dist/index.d.ts +2 -1
  9. package/dist/index.js +11 -11
  10. package/dist/lib/client.d.cts +1 -0
  11. package/dist/lib/client.d.ts +1 -0
  12. package/dist/lib/index.cjs +21 -48
  13. package/dist/lib/index.d.cts +1 -0
  14. package/dist/lib/index.d.ts +1 -0
  15. package/dist/lib/index.js +6 -6
  16. package/dist/react/index.cjs +21 -48
  17. package/dist/react/index.d.cts +1 -0
  18. package/dist/react/index.d.ts +1 -0
  19. package/dist/react/index.js +10 -10
  20. package/dist/tts/index.cjs +21 -11
  21. package/dist/tts/index.d.cts +1 -0
  22. package/dist/tts/index.d.ts +1 -0
  23. package/dist/tts/index.js +4 -4
  24. package/dist/tts/player.d.cts +1 -0
  25. package/dist/tts/player.d.ts +1 -0
  26. package/dist/tts/source.d.cts +1 -0
  27. package/dist/tts/source.d.ts +1 -0
  28. package/dist/tts/utils.d.cts +1 -0
  29. package/dist/tts/utils.d.ts +1 -0
  30. package/dist/tts/websocket.cjs +21 -11
  31. package/dist/tts/websocket.d.cts +3 -2
  32. package/dist/tts/websocket.d.ts +3 -2
  33. package/dist/tts/websocket.js +3 -3
  34. package/dist/types/index.d.cts +3 -9
  35. package/dist/types/index.d.ts +3 -9
  36. package/dist/voice-changer/index.d.cts +1 -0
  37. package/dist/voice-changer/index.d.ts +1 -0
  38. package/dist/voices/index.cjs +0 -37
  39. package/dist/voices/index.d.cts +2 -2
  40. package/dist/voices/index.d.ts +2 -2
  41. package/dist/voices/index.js +1 -1
  42. package/package.json +1 -1
  43. package/src/tts/websocket.ts +21 -9
  44. package/src/types/index.ts +3 -9
  45. package/src/voices/index.ts +0 -40
package/README.md CHANGED
@@ -92,11 +92,15 @@ const cartesia = new Cartesia({
92
92
  const websocket = cartesia.tts.websocket({
93
93
  container: "raw",
94
94
  encoding: "pcm_f32le",
95
- sampleRate: 44100
95
+ sampleRate: 44100,
96
96
  });
97
97
 
98
98
  try {
99
- await websocket.connect();
99
+ await websocket.connect({
100
+ // If using Node.js, you can pass a custom WebSocket constructor, such as from `ws`.
101
+ // This is not needed for browser usage, so you can call connect() without any arguments.
102
+ WebSocket: WS,
103
+ });
100
104
  } catch (error) {
101
105
  console.error(`Failed to connect to Cartesia: ${error}`);
102
106
  }
@@ -1,3 +1,10 @@
1
+ import {
2
+ Client
3
+ } from "./chunk-FLWYXP5Z.js";
4
+ import {
5
+ CARTESIA_VERSION,
6
+ constructApiUrl
7
+ } from "./chunk-2BFEKY3F.js";
1
8
  import {
2
9
  base64ToArray,
3
10
  createMessageHandlerForContextId,
@@ -7,13 +14,6 @@ import {
7
14
  import {
8
15
  Source
9
16
  } from "./chunk-I5YVYTNK.js";
10
- import {
11
- Client
12
- } from "./chunk-FLWYXP5Z.js";
13
- import {
14
- CARTESIA_VERSION,
15
- constructApiUrl
16
- } from "./chunk-2BFEKY3F.js";
17
17
  import {
18
18
  __async,
19
19
  __privateAdd,
@@ -118,7 +118,8 @@ var WebSocket = class extends Client {
118
118
  streamCompleteController.abort();
119
119
  },
120
120
  {
121
- once: true
121
+ once: true,
122
+ signal: streamCompleteController.signal
122
123
  }
123
124
  );
124
125
  (_d = this.socket) == null ? void 0 : _d.addEventListener(
@@ -127,7 +128,8 @@ var WebSocket = class extends Client {
127
128
  streamCompleteController.abort();
128
129
  },
129
130
  {
130
- once: true
131
+ once: true,
132
+ signal: streamCompleteController.signal
131
133
  }
132
134
  );
133
135
  streamCompleteController.signal.addEventListener("abort", () => {
@@ -135,6 +137,7 @@ var WebSocket = class extends Client {
135
137
  if (timeoutId) {
136
138
  clearTimeout(timeoutId);
137
139
  }
140
+ emitter.clearListeners();
138
141
  });
139
142
  return __spreadProps(__spreadValues({
140
143
  source
@@ -175,16 +178,23 @@ var WebSocket = class extends Client {
175
178
  * @throws {Error} If the WebSocket fails to connect.
176
179
  */
177
180
  connect() {
178
- return __async(this, null, function* () {
181
+ return __async(this, arguments, function* (options = {}) {
182
+ if (__privateGet(this, _isConnected)) {
183
+ throw new Error("WebSocket is already connected.");
184
+ }
179
185
  const emitter = new Emittery();
180
- this.socket = new PartySocketWebSocket(() => __async(this, null, function* () {
181
- const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
182
- websocket: true
183
- });
184
- url.searchParams.set("api_key", yield this.apiKey());
185
- url.searchParams.set("cartesia_version", CARTESIA_VERSION);
186
- return url.toString();
187
- }));
186
+ this.socket = new PartySocketWebSocket(
187
+ () => __async(this, null, function* () {
188
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
189
+ websocket: true
190
+ });
191
+ url.searchParams.set("api_key", yield this.apiKey());
192
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
193
+ return url.toString();
194
+ }),
195
+ void 0,
196
+ options
197
+ );
188
198
  this.socket.binaryType = "arraybuffer";
189
199
  this.socket.onopen = () => {
190
200
  __privateSet(this, _isConnected, true);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  WebSocket
3
- } from "./chunk-HQOC2S6C.js";
3
+ } from "./chunk-CJZSHIRI.js";
4
4
  import {
5
5
  Client
6
6
  } from "./chunk-FLWYXP5Z.js";
@@ -54,43 +54,6 @@ var Voices = class extends Client {
54
54
  throw new Error("Invalid mode for clone()");
55
55
  });
56
56
  }
57
- hifiClone(options) {
58
- return __async(this, null, function* () {
59
- var _a;
60
- if (options.mode !== "clip") {
61
- throw new Error("Invalid mode for hifiClone()");
62
- }
63
- const formData = new FormData();
64
- formData.append("clip", options.clip);
65
- formData.append("name", options.name);
66
- formData.append("description", options.description);
67
- formData.append("language", options.language);
68
- formData.append("model_id", options.model_id);
69
- if (options.enhance !== void 0) {
70
- formData.append("enhance", options.enhance.toString());
71
- }
72
- if (options.transcript) {
73
- formData.append("transcript", options.transcript);
74
- }
75
- if (options.base_voice_id) {
76
- formData.append("base_voice_id", options.base_voice_id);
77
- }
78
- const response = yield this._fetch("/voices/clone/hifi", {
79
- method: "POST",
80
- body: formData
81
- });
82
- if (!response.ok) {
83
- if ((_a = response.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
84
- const errorData = yield response.json();
85
- throw new Error(errorData.message || "HiFi clone failed");
86
- }
87
- const errorText = yield response.text();
88
- throw new Error(errorText || "HiFi clone failed");
89
- }
90
- const data = yield response.json();
91
- return data;
92
- });
93
- }
94
57
  mix(options) {
95
58
  return __async(this, null, function* () {
96
59
  const response = yield this._fetch("/voices/mix", {
@@ -1,12 +1,12 @@
1
- import {
2
- TTS
3
- } from "./chunk-EYRYHK3X.js";
4
1
  import {
5
2
  Voices
6
- } from "./chunk-62LXGS65.js";
3
+ } from "./chunk-RJICGVPL.js";
7
4
  import {
8
5
  VoiceChanger
9
6
  } from "./chunk-WLEVU3HN.js";
7
+ import {
8
+ TTS
9
+ } from "./chunk-QT5LHJ3D.js";
10
10
  import {
11
11
  Client
12
12
  } from "./chunk-FLWYXP5Z.js";
package/dist/index.cjs CHANGED
@@ -465,7 +465,8 @@ var WebSocket = class extends Client {
465
465
  streamCompleteController.abort();
466
466
  },
467
467
  {
468
- once: true
468
+ once: true,
469
+ signal: streamCompleteController.signal
469
470
  }
470
471
  );
471
472
  (_d = this.socket) == null ? void 0 : _d.addEventListener(
@@ -474,7 +475,8 @@ var WebSocket = class extends Client {
474
475
  streamCompleteController.abort();
475
476
  },
476
477
  {
477
- once: true
478
+ once: true,
479
+ signal: streamCompleteController.signal
478
480
  }
479
481
  );
480
482
  streamCompleteController.signal.addEventListener("abort", () => {
@@ -482,6 +484,7 @@ var WebSocket = class extends Client {
482
484
  if (timeoutId) {
483
485
  clearTimeout(timeoutId);
484
486
  }
487
+ emitter.clearListeners();
485
488
  });
486
489
  return __spreadProps(__spreadValues({
487
490
  source
@@ -522,16 +525,23 @@ var WebSocket = class extends Client {
522
525
  * @throws {Error} If the WebSocket fails to connect.
523
526
  */
524
527
  connect() {
525
- return __async(this, null, function* () {
528
+ return __async(this, arguments, function* (options = {}) {
529
+ if (__privateGet(this, _isConnected)) {
530
+ throw new Error("WebSocket is already connected.");
531
+ }
526
532
  const emitter = new import_emittery2.default();
527
- this.socket = new import_partysocket.WebSocket(() => __async(this, null, function* () {
528
- const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
529
- websocket: true
530
- });
531
- url.searchParams.set("api_key", yield this.apiKey());
532
- url.searchParams.set("cartesia_version", CARTESIA_VERSION);
533
- return url.toString();
534
- }));
533
+ this.socket = new import_partysocket.WebSocket(
534
+ () => __async(this, null, function* () {
535
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
536
+ websocket: true
537
+ });
538
+ url.searchParams.set("api_key", yield this.apiKey());
539
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
540
+ return url.toString();
541
+ }),
542
+ void 0,
543
+ options
544
+ );
535
545
  this.socket.binaryType = "arraybuffer";
536
546
  this.socket.onopen = () => {
537
547
  __privateSet(this, _isConnected, true);
@@ -717,43 +727,6 @@ var Voices = class extends Client {
717
727
  throw new Error("Invalid mode for clone()");
718
728
  });
719
729
  }
720
- hifiClone(options) {
721
- return __async(this, null, function* () {
722
- var _a;
723
- if (options.mode !== "clip") {
724
- throw new Error("Invalid mode for hifiClone()");
725
- }
726
- const formData = new FormData();
727
- formData.append("clip", options.clip);
728
- formData.append("name", options.name);
729
- formData.append("description", options.description);
730
- formData.append("language", options.language);
731
- formData.append("model_id", options.model_id);
732
- if (options.enhance !== void 0) {
733
- formData.append("enhance", options.enhance.toString());
734
- }
735
- if (options.transcript) {
736
- formData.append("transcript", options.transcript);
737
- }
738
- if (options.base_voice_id) {
739
- formData.append("base_voice_id", options.base_voice_id);
740
- }
741
- const response = yield this._fetch("/voices/clone/hifi", {
742
- method: "POST",
743
- body: formData
744
- });
745
- if (!response.ok) {
746
- if ((_a = response.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
747
- const errorData = yield response.json();
748
- throw new Error(errorData.message || "HiFi clone failed");
749
- }
750
- const errorText = yield response.text();
751
- throw new Error(errorText || "HiFi clone failed");
752
- }
753
- const data = yield response.json();
754
- return data;
755
- });
756
- }
757
730
  mix(options) {
758
731
  return __async(this, null, function* () {
759
732
  const response = yield this._fetch("/voices/mix", {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Cartesia, Cartesia as default } from './lib/index.cjs';
2
- export { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, HifiCloneOptions, 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 } from './types/index.cjs';
2
+ export { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectOptions, 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 } from './types/index.cjs';
3
3
  export { default as WebPlayer } from './tts/player.cjs';
4
4
  export { default as Source } from './tts/source.cjs';
5
5
  export { default as WebSocket } from './tts/websocket.cjs';
@@ -8,4 +8,5 @@ import './lib/client.cjs';
8
8
  import './voice-changer/index.cjs';
9
9
  import './voices/index.cjs';
10
10
  import 'emittery';
11
+ import 'partysocket/ws';
11
12
  import 'partysocket';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Cartesia, Cartesia as default } from './lib/index.js';
2
- export { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, HifiCloneOptions, 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 } from './types/index.js';
2
+ export { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectOptions, 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 } from './types/index.js';
3
3
  export { default as WebPlayer } from './tts/player.js';
4
4
  export { default as Source } from './tts/source.js';
5
5
  export { default as WebSocket } from './tts/websocket.js';
@@ -8,4 +8,5 @@ import './lib/client.js';
8
8
  import './voice-changer/index.js';
9
9
  import './voices/index.js';
10
10
  import 'emittery';
11
+ import 'partysocket/ws';
11
12
  import 'partysocket';
package/dist/index.js CHANGED
@@ -1,22 +1,22 @@
1
- import {
2
- Player
3
- } from "./chunk-CSOXALSC.js";
1
+ import "./chunk-FXPGR372.js";
4
2
  import {
5
3
  Cartesia
6
- } from "./chunk-MGVQHO25.js";
7
- import "./chunk-EYRYHK3X.js";
4
+ } from "./chunk-RYHHRY64.js";
5
+ import "./chunk-RJICGVPL.js";
6
+ import "./chunk-WLEVU3HN.js";
7
+ import "./chunk-QT5LHJ3D.js";
8
8
  import {
9
9
  WebSocket
10
- } from "./chunk-HQOC2S6C.js";
10
+ } from "./chunk-CJZSHIRI.js";
11
+ import "./chunk-FLWYXP5Z.js";
12
+ import "./chunk-2BFEKY3F.js";
13
+ import {
14
+ Player
15
+ } from "./chunk-CSOXALSC.js";
11
16
  import "./chunk-5SBAQNWQ.js";
12
17
  import {
13
18
  Source
14
19
  } from "./chunk-I5YVYTNK.js";
15
- import "./chunk-62LXGS65.js";
16
- import "./chunk-FXPGR372.js";
17
- import "./chunk-WLEVU3HN.js";
18
- import "./chunk-FLWYXP5Z.js";
19
- import "./chunk-2BFEKY3F.js";
20
20
  import "./chunk-NJDRWDQ3.js";
21
21
  export {
22
22
  Cartesia,
@@ -1,5 +1,6 @@
1
1
  import { ClientOptions } from '../types/index.cjs';
2
2
  import 'emittery';
3
+ import 'partysocket/ws';
3
4
 
4
5
  declare class Client {
5
6
  apiKey: () => Promise<string>;
@@ -1,5 +1,6 @@
1
1
  import { ClientOptions } from '../types/index.js';
2
2
  import 'emittery';
3
+ import 'partysocket/ws';
3
4
 
4
5
  declare class Client {
5
6
  apiKey: () => Promise<string>;
@@ -448,7 +448,8 @@ var WebSocket = class extends Client {
448
448
  streamCompleteController.abort();
449
449
  },
450
450
  {
451
- once: true
451
+ once: true,
452
+ signal: streamCompleteController.signal
452
453
  }
453
454
  );
454
455
  (_d = this.socket) == null ? void 0 : _d.addEventListener(
@@ -457,7 +458,8 @@ var WebSocket = class extends Client {
457
458
  streamCompleteController.abort();
458
459
  },
459
460
  {
460
- once: true
461
+ once: true,
462
+ signal: streamCompleteController.signal
461
463
  }
462
464
  );
463
465
  streamCompleteController.signal.addEventListener("abort", () => {
@@ -465,6 +467,7 @@ var WebSocket = class extends Client {
465
467
  if (timeoutId) {
466
468
  clearTimeout(timeoutId);
467
469
  }
470
+ emitter.clearListeners();
468
471
  });
469
472
  return __spreadProps(__spreadValues({
470
473
  source
@@ -505,16 +508,23 @@ var WebSocket = class extends Client {
505
508
  * @throws {Error} If the WebSocket fails to connect.
506
509
  */
507
510
  connect() {
508
- return __async(this, null, function* () {
511
+ return __async(this, arguments, function* (options = {}) {
512
+ if (__privateGet(this, _isConnected)) {
513
+ throw new Error("WebSocket is already connected.");
514
+ }
509
515
  const emitter = new import_emittery2.default();
510
- this.socket = new import_partysocket.WebSocket(() => __async(this, null, function* () {
511
- const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
512
- websocket: true
513
- });
514
- url.searchParams.set("api_key", yield this.apiKey());
515
- url.searchParams.set("cartesia_version", CARTESIA_VERSION);
516
- return url.toString();
517
- }));
516
+ this.socket = new import_partysocket.WebSocket(
517
+ () => __async(this, null, function* () {
518
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
519
+ websocket: true
520
+ });
521
+ url.searchParams.set("api_key", yield this.apiKey());
522
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
523
+ return url.toString();
524
+ }),
525
+ void 0,
526
+ options
527
+ );
518
528
  this.socket.binaryType = "arraybuffer";
519
529
  this.socket.onopen = () => {
520
530
  __privateSet(this, _isConnected, true);
@@ -700,43 +710,6 @@ var Voices = class extends Client {
700
710
  throw new Error("Invalid mode for clone()");
701
711
  });
702
712
  }
703
- hifiClone(options) {
704
- return __async(this, null, function* () {
705
- var _a;
706
- if (options.mode !== "clip") {
707
- throw new Error("Invalid mode for hifiClone()");
708
- }
709
- const formData = new FormData();
710
- formData.append("clip", options.clip);
711
- formData.append("name", options.name);
712
- formData.append("description", options.description);
713
- formData.append("language", options.language);
714
- formData.append("model_id", options.model_id);
715
- if (options.enhance !== void 0) {
716
- formData.append("enhance", options.enhance.toString());
717
- }
718
- if (options.transcript) {
719
- formData.append("transcript", options.transcript);
720
- }
721
- if (options.base_voice_id) {
722
- formData.append("base_voice_id", options.base_voice_id);
723
- }
724
- const response = yield this._fetch("/voices/clone/hifi", {
725
- method: "POST",
726
- body: formData
727
- });
728
- if (!response.ok) {
729
- if ((_a = response.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
730
- const errorData = yield response.json();
731
- throw new Error(errorData.message || "HiFi clone failed");
732
- }
733
- const errorText = yield response.text();
734
- throw new Error(errorText || "HiFi clone failed");
735
- }
736
- const data = yield response.json();
737
- return data;
738
- });
739
- }
740
713
  mix(options) {
741
714
  return __async(this, null, function* () {
742
715
  const response = yield this._fetch("/voices/mix", {
@@ -7,6 +7,7 @@ import '../tts/websocket.cjs';
7
7
  import 'emittery';
8
8
  import 'partysocket';
9
9
  import '../tts/source.cjs';
10
+ import 'partysocket/ws';
10
11
 
11
12
  declare class Cartesia extends Client {
12
13
  tts: TTS;
@@ -7,6 +7,7 @@ import '../tts/websocket.js';
7
7
  import 'emittery';
8
8
  import 'partysocket';
9
9
  import '../tts/source.js';
10
+ import 'partysocket/ws';
10
11
 
11
12
  declare class Cartesia extends Client {
12
13
  tts: TTS;
package/dist/lib/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  Cartesia
3
- } from "../chunk-MGVQHO25.js";
4
- import "../chunk-EYRYHK3X.js";
5
- import "../chunk-HQOC2S6C.js";
6
- import "../chunk-5SBAQNWQ.js";
7
- import "../chunk-I5YVYTNK.js";
8
- import "../chunk-62LXGS65.js";
3
+ } from "../chunk-RYHHRY64.js";
4
+ import "../chunk-RJICGVPL.js";
9
5
  import "../chunk-WLEVU3HN.js";
6
+ import "../chunk-QT5LHJ3D.js";
7
+ import "../chunk-CJZSHIRI.js";
10
8
  import "../chunk-FLWYXP5Z.js";
11
9
  import "../chunk-2BFEKY3F.js";
10
+ import "../chunk-5SBAQNWQ.js";
11
+ import "../chunk-I5YVYTNK.js";
12
12
  import "../chunk-NJDRWDQ3.js";
13
13
  export {
14
14
  Cartesia
@@ -462,7 +462,8 @@ var WebSocket = class extends Client {
462
462
  streamCompleteController.abort();
463
463
  },
464
464
  {
465
- once: true
465
+ once: true,
466
+ signal: streamCompleteController.signal
466
467
  }
467
468
  );
468
469
  (_d = this.socket) == null ? void 0 : _d.addEventListener(
@@ -471,7 +472,8 @@ var WebSocket = class extends Client {
471
472
  streamCompleteController.abort();
472
473
  },
473
474
  {
474
- once: true
475
+ once: true,
476
+ signal: streamCompleteController.signal
475
477
  }
476
478
  );
477
479
  streamCompleteController.signal.addEventListener("abort", () => {
@@ -479,6 +481,7 @@ var WebSocket = class extends Client {
479
481
  if (timeoutId) {
480
482
  clearTimeout(timeoutId);
481
483
  }
484
+ emitter.clearListeners();
482
485
  });
483
486
  return __spreadProps(__spreadValues({
484
487
  source
@@ -519,16 +522,23 @@ var WebSocket = class extends Client {
519
522
  * @throws {Error} If the WebSocket fails to connect.
520
523
  */
521
524
  connect() {
522
- return __async(this, null, function* () {
525
+ return __async(this, arguments, function* (options = {}) {
526
+ if (__privateGet(this, _isConnected)) {
527
+ throw new Error("WebSocket is already connected.");
528
+ }
523
529
  const emitter = new import_emittery2.default();
524
- this.socket = new import_partysocket.WebSocket(() => __async(this, null, function* () {
525
- const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
526
- websocket: true
527
- });
528
- url.searchParams.set("api_key", yield this.apiKey());
529
- url.searchParams.set("cartesia_version", CARTESIA_VERSION);
530
- return url.toString();
531
- }));
530
+ this.socket = new import_partysocket.WebSocket(
531
+ () => __async(this, null, function* () {
532
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
533
+ websocket: true
534
+ });
535
+ url.searchParams.set("api_key", yield this.apiKey());
536
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
537
+ return url.toString();
538
+ }),
539
+ void 0,
540
+ options
541
+ );
532
542
  this.socket.binaryType = "arraybuffer";
533
543
  this.socket.onopen = () => {
534
544
  __privateSet(this, _isConnected, true);
@@ -714,43 +724,6 @@ var Voices = class extends Client {
714
724
  throw new Error("Invalid mode for clone()");
715
725
  });
716
726
  }
717
- hifiClone(options) {
718
- return __async(this, null, function* () {
719
- var _a;
720
- if (options.mode !== "clip") {
721
- throw new Error("Invalid mode for hifiClone()");
722
- }
723
- const formData = new FormData();
724
- formData.append("clip", options.clip);
725
- formData.append("name", options.name);
726
- formData.append("description", options.description);
727
- formData.append("language", options.language);
728
- formData.append("model_id", options.model_id);
729
- if (options.enhance !== void 0) {
730
- formData.append("enhance", options.enhance.toString());
731
- }
732
- if (options.transcript) {
733
- formData.append("transcript", options.transcript);
734
- }
735
- if (options.base_voice_id) {
736
- formData.append("base_voice_id", options.base_voice_id);
737
- }
738
- const response = yield this._fetch("/voices/clone/hifi", {
739
- method: "POST",
740
- body: formData
741
- });
742
- if (!response.ok) {
743
- if ((_a = response.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
744
- const errorData = yield response.json();
745
- throw new Error(errorData.message || "HiFi clone failed");
746
- }
747
- const errorText = yield response.text();
748
- throw new Error(errorText || "HiFi clone failed");
749
- }
750
- const data = yield response.json();
751
- return data;
752
- });
753
- }
754
727
  mix(options) {
755
728
  return __async(this, null, function* () {
756
729
  const response = yield this._fetch("/voices/mix", {
@@ -1,6 +1,7 @@
1
1
  import Source from '../tts/source.cjs';
2
2
  import { StreamRequest } from '../types/index.cjs';
3
3
  import 'emittery';
4
+ import 'partysocket/ws';
4
5
 
5
6
  type UseTTSOptions = {
6
7
  apiKey: string | (() => Promise<string>) | null;
@@ -1,6 +1,7 @@
1
1
  import Source from '../tts/source.js';
2
2
  import { StreamRequest } from '../types/index.js';
3
3
  import 'emittery';
4
+ import 'partysocket/ws';
4
5
 
5
6
  type UseTTSOptions = {
6
7
  apiKey: string | (() => Promise<string>) | null;
@@ -1,20 +1,20 @@
1
1
  import {
2
- Player
3
- } from "../chunk-CSOXALSC.js";
2
+ Cartesia
3
+ } from "../chunk-RYHHRY64.js";
4
+ import "../chunk-RJICGVPL.js";
5
+ import "../chunk-WLEVU3HN.js";
4
6
  import {
5
7
  pingServer
6
8
  } from "../chunk-LKKWJLUG.js";
9
+ import "../chunk-QT5LHJ3D.js";
10
+ import "../chunk-CJZSHIRI.js";
11
+ import "../chunk-FLWYXP5Z.js";
12
+ import "../chunk-2BFEKY3F.js";
7
13
  import {
8
- Cartesia
9
- } from "../chunk-MGVQHO25.js";
10
- import "../chunk-EYRYHK3X.js";
11
- import "../chunk-HQOC2S6C.js";
14
+ Player
15
+ } from "../chunk-CSOXALSC.js";
12
16
  import "../chunk-5SBAQNWQ.js";
13
17
  import "../chunk-I5YVYTNK.js";
14
- import "../chunk-62LXGS65.js";
15
- import "../chunk-WLEVU3HN.js";
16
- import "../chunk-FLWYXP5Z.js";
17
- import "../chunk-2BFEKY3F.js";
18
18
  import {
19
19
  __async
20
20
  } from "../chunk-NJDRWDQ3.js";