@cartesia/cartesia-js 0.0.3 → 0.0.4-alpha.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 (57) hide show
  1. package/.turbo/turbo-build.log +44 -32
  2. package/CHANGELOG.md +6 -0
  3. package/dist/audio/index.cjs +404 -0
  4. package/dist/audio/index.d.cts +5 -0
  5. package/dist/audio/index.d.ts +1 -1
  6. package/dist/audio/index.js +9 -395
  7. package/dist/audio/utils.cjs +157 -0
  8. package/dist/audio/{utils.d.mts → utils.d.cts} +3 -3
  9. package/dist/audio/utils.d.ts +1 -1
  10. package/dist/audio/utils.js +16 -147
  11. package/dist/{chunk-3CYTAFLF.mjs → chunk-4MHF74A7.js} +15 -5
  12. package/dist/{chunk-FRIBQZPN.mjs → chunk-5TSWLYOW.js} +1 -1
  13. package/dist/{chunk-XSFPHPPG.mjs → chunk-MJIFZWHS.js} +1 -1
  14. package/dist/chunk-OVI3W3GG.js +12 -0
  15. package/dist/{chunk-HNLIBHEN.mjs → chunk-R4P7LWVZ.js} +1 -11
  16. package/dist/{lib/index.mjs → chunk-S6A27RQL.js} +3 -4
  17. package/dist/chunk-XPIMIAAE.js +17 -0
  18. package/dist/{index-DSBmfK9-.d.mts → index-C2_3XFxn.d.cts} +9 -4
  19. package/dist/{index-qwAyxV5I.d.ts → index-DgwnZezj.d.ts} +8 -3
  20. package/dist/index.cjs +419 -0
  21. package/dist/index.d.cts +6 -0
  22. package/dist/index.d.ts +6 -0
  23. package/dist/index.js +13 -0
  24. package/dist/lib/client.cjs +43 -0
  25. package/dist/lib/{client.d.mts → client.d.cts} +1 -1
  26. package/dist/lib/client.js +7 -42
  27. package/dist/lib/constants.cjs +38 -0
  28. package/dist/lib/constants.js +8 -35
  29. package/dist/lib/index.cjs +418 -0
  30. package/dist/lib/{index.d.mts → index.d.cts} +3 -3
  31. package/dist/lib/index.d.ts +1 -1
  32. package/dist/lib/index.js +10 -409
  33. package/dist/react/index.cjs +597 -0
  34. package/dist/react/{index.d.mts → index.d.cts} +4 -3
  35. package/dist/react/index.d.ts +2 -1
  36. package/dist/react/index.js +71 -455
  37. package/dist/react/utils.cjs +57 -0
  38. package/dist/react/utils.d.cts +7 -0
  39. package/dist/react/utils.d.ts +7 -0
  40. package/dist/react/utils.js +7 -0
  41. package/dist/types/index.cjs +18 -0
  42. package/dist/types/index.js +1 -18
  43. package/package.json +10 -7
  44. package/src/audio/index.ts +15 -0
  45. package/src/index.ts +3 -0
  46. package/src/react/index.ts +48 -10
  47. package/src/react/utils.ts +11 -0
  48. package/dist/audio/index.d.mts +0 -5
  49. package/dist/audio/index.mjs +0 -9
  50. package/dist/audio/utils.mjs +0 -25
  51. package/dist/lib/client.mjs +0 -7
  52. package/dist/lib/constants.mjs +0 -10
  53. package/dist/react/index.mjs +0 -130
  54. package/index.ts +0 -3
  55. /package/dist/{types/index.mjs → chunk-FXPGR372.js} +0 -0
  56. /package/dist/lib/{constants.d.mts → constants.d.cts} +0 -0
  57. /package/dist/types/{index.d.mts → index.d.cts} +0 -0
@@ -1,45 +1,57 @@
1
1
  $ tsup src/ --format cjs,esm --dts
2
- CLI Building entry: src/audio/index.ts, src/audio/utils.ts, src/lib/client.ts, src/lib/constants.ts, src/lib/index.ts, src/react/index.ts, src/types/index.ts
2
+ CLI Building entry: src/index.ts, src/audio/index.ts, src/audio/utils.ts, src/lib/client.ts, src/lib/constants.ts, src/lib/index.ts, src/react/index.ts, src/react/utils.ts, src/types/index.ts
3
3
  CLI Using tsconfig: tsconfig.json
4
4
  CLI tsup v8.0.2
5
5
  CLI Target: es6
6
6
  CJS Build start
7
7
  ESM Build start
8
- ESM dist/types/index.mjs 0 B
9
- ESM dist/chunk-3CYTAFLF.mjs 7.43 KB
10
- ESM dist/chunk-FRIBQZPN.mjs 3.22 KB
11
- ESM dist/chunk-XSFPHPPG.mjs 386.00 B
12
- ESM dist/chunk-HNLIBHEN.mjs 2.02 KB
13
- ESM dist/audio/index.mjs 192.00 B
14
- ESM dist/lib/client.mjs 103.00 B
15
- ESM dist/react/index.mjs 3.31 KB
16
- ESM dist/audio/utils.mjs 469.00 B
17
- ESM dist/lib/constants.mjs 155.00 B
18
- ESM dist/lib/index.mjs 355.00 B
8
+ CJS dist/types/index.cjs 764.00 B
9
+ CJS dist/index.cjs 13.34 KB
10
+ CJS dist/audio/index.cjs 13.05 KB
11
+ CJS dist/audio/utils.cjs 5.24 KB
12
+ CJS dist/lib/client.cjs 1.40 KB
13
+ CJS dist/lib/constants.cjs 1.35 KB
14
+ CJS dist/lib/index.cjs 13.32 KB
15
+ CJS dist/react/index.cjs 18.78 KB
16
+ CJS dist/react/utils.cjs 1.80 KB
17
+ CJS ⚡️ Build success in 76ms
18
+ ESM dist/index.js 276.00 B
19
+ ESM dist/audio/index.js 219.00 B
20
+ ESM dist/chunk-FXPGR372.js 0 B
21
+ ESM dist/lib/client.js 132.00 B
22
+ ESM dist/react/index.js 4.31 KB
23
+ ESM dist/audio/utils.js 498.00 B
24
+ ESM dist/lib/constants.js 185.00 B
25
+ ESM dist/lib/index.js 229.00 B
26
+ ESM dist/chunk-S6A27RQL.js 288.00 B
27
+ ESM dist/chunk-4MHF74A7.js 7.88 KB
28
+ ESM dist/chunk-5TSWLYOW.js 3.22 KB
29
+ ESM dist/chunk-MJIFZWHS.js 385.00 B
30
+ ESM dist/chunk-OVI3W3GG.js 275.00 B
31
+ ESM dist/react/utils.js 109.00 B
32
+ ESM dist/chunk-XPIMIAAE.js 337.00 B
33
+ ESM dist/chunk-R4P7LWVZ.js 1.76 KB
34
+ ESM dist/types/index.js 31.00 B
19
35
  ESM ⚡️ Build success in 78ms
20
- CJS dist/audio/index.js 12.63 KB
21
- CJS dist/audio/utils.js 5.23 KB
22
- CJS dist/lib/client.js 1.40 KB
23
- CJS dist/lib/constants.js 1.35 KB
24
- CJS dist/lib/index.js 12.89 KB
25
- CJS dist/react/index.js 17.16 KB
26
- CJS dist/types/index.js 764.00 B
27
- CJS ⚡️ Build success in 79ms
28
36
  DTS Build start
29
- DTS ⚡️ Build success in 5506ms
37
+ DTS ⚡️ Build success in 7157ms
38
+ DTS dist/lib/constants.d.cts 211.00 B
39
+ DTS dist/react/index.d.cts 749.00 B
40
+ DTS dist/lib/client.d.cts 181.00 B
41
+ DTS dist/react/utils.d.cts 240.00 B
42
+ DTS dist/types/index.d.cts 103.00 B
43
+ DTS dist/lib/index.d.cts 327.00 B
44
+ DTS dist/audio/utils.d.cts 400.00 B
45
+ DTS dist/audio/index.d.cts 232.00 B
46
+ DTS dist/index.d.cts 215.00 B
47
+ DTS dist/index-C2_3XFxn.d.cts 6.59 KB
30
48
  DTS dist/lib/constants.d.ts 211.00 B
31
- DTS dist/lib/index.d.ts 324.00 B
32
- DTS dist/react/index.d.ts 720.00 B
49
+ DTS dist/react/index.d.ts 746.00 B
33
50
  DTS dist/lib/client.d.ts 180.00 B
51
+ DTS dist/react/utils.d.ts 240.00 B
34
52
  DTS dist/types/index.d.ts 103.00 B
53
+ DTS dist/lib/index.d.ts 324.00 B
35
54
  DTS dist/audio/utils.d.ts 397.00 B
36
55
  DTS dist/audio/index.d.ts 229.00 B
37
- DTS dist/index-qwAyxV5I.d.ts 6.49 KB
38
- DTS dist/lib/constants.d.mts 211.00 B
39
- DTS dist/lib/index.d.mts 327.00 B
40
- DTS dist/react/index.d.mts 723.00 B
41
- DTS dist/lib/client.d.mts 181.00 B
42
- DTS dist/types/index.d.mts 103.00 B
43
- DTS dist/audio/utils.d.mts 400.00 B
44
- DTS dist/audio/index.d.mts 232.00 B
45
- DTS dist/index-DSBmfK9-.d.mts 6.49 KB
56
+ DTS dist/index.d.ts 211.00 B
57
+ DTS dist/index-DgwnZezj.d.ts 6.59 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @cartesia/cartesia-js
2
2
 
3
+ ## 0.0.4-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 8ecf940: Add provisional Node.js support
8
+
3
9
  ## 0.0.3
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,404 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __knownSymbol = (name, symbol) => {
11
+ return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
12
+ };
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __async = (__this, __arguments, generator) => {
47
+ return new Promise((resolve, reject) => {
48
+ var fulfilled = (value) => {
49
+ try {
50
+ step(generator.next(value));
51
+ } catch (e) {
52
+ reject(e);
53
+ }
54
+ };
55
+ var rejected = (value) => {
56
+ try {
57
+ step(generator.throw(value));
58
+ } catch (e) {
59
+ reject(e);
60
+ }
61
+ };
62
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
+ step((generator = generator.apply(__this, __arguments)).next());
64
+ });
65
+ };
66
+ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
67
+
68
+ // src/audio/index.ts
69
+ var audio_exports = {};
70
+ __export(audio_exports, {
71
+ default: () => audio_default
72
+ });
73
+ module.exports = __toCommonJS(audio_exports);
74
+ var import_emittery = __toESM(require("emittery"), 1);
75
+ var import_human_id = require("human-id");
76
+ var import_partysocket = require("partysocket");
77
+
78
+ // src/lib/constants.ts
79
+ var BASE_URL = "https://api.cartesia.ai/v0";
80
+ var SAMPLE_RATE = 44100;
81
+ var constructWebsocketUrl = (baseUrl) => {
82
+ return new URL(`${baseUrl.replace(/^http/, "ws")}/audio/websocket`);
83
+ };
84
+
85
+ // src/lib/client.ts
86
+ var Client = class {
87
+ constructor(options = {}) {
88
+ if (!(options.apiKey || process.env.CARTESIA_API_KEY)) {
89
+ throw new Error("Missing Cartesia API key.");
90
+ }
91
+ this.apiKey = options.apiKey || process.env.CARTESIA_API_KEY;
92
+ this.baseUrl = options.baseUrl || BASE_URL;
93
+ }
94
+ };
95
+
96
+ // src/audio/utils.ts
97
+ var import_base64_js = __toESM(require("base64-js"), 1);
98
+ function getBufferDuration(b64) {
99
+ const floats = base64ToArray(b64);
100
+ return floats.length / SAMPLE_RATE;
101
+ }
102
+ function base64ToArray(b64) {
103
+ return filterSentinel(b64).reduce((acc, b) => {
104
+ const floats = new Float32Array(import_base64_js.default.toByteArray(b).buffer);
105
+ const newAcc = new Float32Array(acc.length + floats.length);
106
+ newAcc.set(acc, 0);
107
+ newAcc.set(floats, acc.length);
108
+ return newAcc;
109
+ }, new Float32Array(0));
110
+ }
111
+ function playAudioBuffer(b64, context, maybeStartAt = null, onEnded = null) {
112
+ const startAt = maybeStartAt != null ? maybeStartAt : context.currentTime;
113
+ const floats = base64ToArray(b64);
114
+ const source = context.createBufferSource();
115
+ const buffer = context.createBuffer(1, floats.length, SAMPLE_RATE);
116
+ buffer.getChannelData(0).set(floats);
117
+ source.buffer = buffer;
118
+ source.connect(context.destination);
119
+ source.start(startAt);
120
+ source.onended = onEnded;
121
+ return buffer.duration;
122
+ }
123
+ function createMessageHandlerForContextId(contextId, handler) {
124
+ return (event) => {
125
+ const message = JSON.parse(event.data);
126
+ if (message.context_id !== contextId) {
127
+ return;
128
+ }
129
+ let chunk;
130
+ if (message.done) {
131
+ chunk = getSentinel();
132
+ } else {
133
+ chunk = message.data;
134
+ }
135
+ handler({ chunk, message });
136
+ };
137
+ }
138
+ function getSentinel() {
139
+ return null;
140
+ }
141
+ function isSentinel(x) {
142
+ return x === getSentinel();
143
+ }
144
+ function filterSentinel(collection) {
145
+ return collection.filter(
146
+ (x) => !isSentinel(x)
147
+ );
148
+ }
149
+ function isComplete(chunks) {
150
+ return isSentinel(chunks[chunks.length - 1]);
151
+ }
152
+ function getEmitteryCallbacks(emitter) {
153
+ return {
154
+ on: emitter.on.bind(emitter),
155
+ off: emitter.off.bind(emitter),
156
+ once: emitter.once.bind(emitter),
157
+ events: emitter.events.bind(emitter)
158
+ };
159
+ }
160
+
161
+ // src/audio/index.ts
162
+ var audio_default = class extends Client {
163
+ constructor() {
164
+ super(...arguments);
165
+ this.isConnected = false;
166
+ }
167
+ /**
168
+ * Stream audio from a model.
169
+ *
170
+ * @param inputs - Stream options. Includes a `model` key and some `parameters`, which
171
+ * are model-specific and can be found in the model's documentation.
172
+ * @param options - Options for the stream.
173
+ * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
174
+ * If `0`, the stream will not time out.
175
+ * @returns An object with a method `play` of type `(bufferDuration: number) => Promise<void>`
176
+ * that plays the audio as it arrives, with `bufferDuration` seconds of audio buffered before
177
+ * starting playback.
178
+ */
179
+ stream(inputs, { timeout = 0 } = {}) {
180
+ var _a, _b, _c, _d;
181
+ if (!this.isConnected) {
182
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
183
+ }
184
+ const contextId = this.generateId();
185
+ (_a = this.socket) == null ? void 0 : _a.send(
186
+ JSON.stringify({
187
+ data: inputs,
188
+ context_id: contextId
189
+ })
190
+ );
191
+ const streamCompleteController = new AbortController();
192
+ let timeoutId = null;
193
+ if (timeout > 0) {
194
+ timeoutId = setTimeout(streamCompleteController.abort, timeout);
195
+ }
196
+ const chunks = [];
197
+ const emitter = new import_emittery.default();
198
+ const handleMessage = createMessageHandlerForContextId(
199
+ contextId,
200
+ (_0) => __async(this, [_0], function* ({ chunk, message }) {
201
+ chunks.push(chunk);
202
+ yield emitter.emit("chunk", {
203
+ chunk,
204
+ chunks
205
+ });
206
+ yield emitter.emit("message", message);
207
+ if (isSentinel(chunk)) {
208
+ yield emitter.emit("streamed", {
209
+ chunks
210
+ });
211
+ streamCompleteController.abort();
212
+ } else if (timeoutId) {
213
+ clearTimeout(timeoutId);
214
+ timeoutId = setTimeout(streamCompleteController.abort, timeout);
215
+ }
216
+ })
217
+ );
218
+ (_b = this.socket) == null ? void 0 : _b.addEventListener("message", handleMessage, {
219
+ signal: streamCompleteController.signal
220
+ });
221
+ (_c = this.socket) == null ? void 0 : _c.addEventListener(
222
+ "close",
223
+ () => {
224
+ streamCompleteController.abort();
225
+ },
226
+ {
227
+ once: true
228
+ }
229
+ );
230
+ (_d = this.socket) == null ? void 0 : _d.addEventListener(
231
+ "error",
232
+ () => {
233
+ streamCompleteController.abort();
234
+ },
235
+ {
236
+ once: true
237
+ }
238
+ );
239
+ streamCompleteController.signal.addEventListener("abort", () => {
240
+ if (timeoutId) {
241
+ clearTimeout(timeoutId);
242
+ }
243
+ emitter.clearListeners();
244
+ });
245
+ const play = (_0) => __async(this, [_0], function* ({ bufferDuration }) {
246
+ const context = new AudioContext({
247
+ sampleRate: SAMPLE_RATE
248
+ });
249
+ let startNextPlaybackAt = 0;
250
+ const playLatestChunk = (chunk) => {
251
+ if (isSentinel(chunk)) {
252
+ return true;
253
+ }
254
+ startNextPlaybackAt = playAudioBuffer([chunk], context, startNextPlaybackAt) + Math.max(context.currentTime, startNextPlaybackAt);
255
+ return false;
256
+ };
257
+ const playChunks = (chunks2) => {
258
+ startNextPlaybackAt += playAudioBuffer(
259
+ chunks2,
260
+ context,
261
+ startNextPlaybackAt
262
+ );
263
+ if (isComplete(chunks2)) {
264
+ return;
265
+ }
266
+ };
267
+ const tryStart = (chunks2) => __async(this, null, function* () {
268
+ startNextPlaybackAt = context.currentTime;
269
+ if (isComplete(chunks2) || streamCompleteController.signal.aborted) {
270
+ emitter.emit("buffered");
271
+ playChunks(chunks2);
272
+ return true;
273
+ }
274
+ if (getBufferDuration(chunks2) > bufferDuration) {
275
+ emitter.emit("buffered");
276
+ playChunks(chunks2);
277
+ try {
278
+ for (var iter2 = __forAwait(emitter.events("chunk")), more2, temp2, error2; more2 = !(temp2 = yield iter2.next()).done; more2 = false) {
279
+ const { chunk } = temp2.value;
280
+ if (playLatestChunk(chunk)) {
281
+ break;
282
+ }
283
+ }
284
+ } catch (temp2) {
285
+ error2 = [temp2];
286
+ } finally {
287
+ try {
288
+ more2 && (temp2 = iter2.return) && (yield temp2.call(iter2));
289
+ } finally {
290
+ if (error2)
291
+ throw error2[0];
292
+ }
293
+ }
294
+ return true;
295
+ }
296
+ emitter.emit("buffering");
297
+ return false;
298
+ });
299
+ if (!(yield tryStart(chunks))) {
300
+ try {
301
+ for (var iter = __forAwait(emitter.events("chunk")), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
302
+ const { chunks: chunks2 } = temp.value;
303
+ if (yield tryStart(chunks2)) {
304
+ const playbackEndsIn = Math.max(0, startNextPlaybackAt - context.currentTime) * 1e3;
305
+ emitter.emit("scheduled", { playbackEndsIn });
306
+ break;
307
+ }
308
+ }
309
+ } catch (temp) {
310
+ error = [temp];
311
+ } finally {
312
+ try {
313
+ more && (temp = iter.return) && (yield temp.call(iter));
314
+ } finally {
315
+ if (error)
316
+ throw error[0];
317
+ }
318
+ }
319
+ } else {
320
+ const playbackEndsIn = Math.max(0, startNextPlaybackAt - context.currentTime) * 1e3;
321
+ emitter.emit("scheduled", { playbackEndsIn });
322
+ }
323
+ });
324
+ return __spreadValues({
325
+ play
326
+ }, getEmitteryCallbacks(emitter));
327
+ }
328
+ /**
329
+ * Generate a unique ID suitable for a streaming context.
330
+ *
331
+ * Not suitable for security purposes or as a primary key, since
332
+ * it lacks the amount of entropy required for those use cases.
333
+ *
334
+ * @returns A unique ID.
335
+ */
336
+ generateId() {
337
+ return (0, import_human_id.humanId)({
338
+ separator: "-",
339
+ capitalize: false
340
+ });
341
+ }
342
+ /**
343
+ * Authenticate and connect to a Cartesia streaming WebSocket.
344
+ *
345
+ * @returns A promise that resolves when the WebSocket is connected.
346
+ * @throws {Error} If the WebSocket fails to connect.
347
+ */
348
+ connect() {
349
+ const url = constructWebsocketUrl(this.baseUrl);
350
+ url.searchParams.set("api_key", this.apiKey);
351
+ const emitter = new import_emittery.default();
352
+ this.socket = new import_partysocket.WebSocket(url.toString());
353
+ this.socket.onopen = () => {
354
+ this.isConnected = true;
355
+ emitter.emit("open");
356
+ };
357
+ this.socket.onclose = () => {
358
+ this.isConnected = false;
359
+ emitter.emit("close");
360
+ };
361
+ return new Promise(
362
+ (resolve, reject) => {
363
+ var _a, _b, _c;
364
+ (_a = this.socket) == null ? void 0 : _a.addEventListener(
365
+ "open",
366
+ () => {
367
+ resolve(getEmitteryCallbacks(emitter));
368
+ },
369
+ {
370
+ once: true
371
+ }
372
+ );
373
+ const aborter = new AbortController();
374
+ (_b = this.socket) == null ? void 0 : _b.addEventListener(
375
+ "error",
376
+ () => {
377
+ aborter.abort();
378
+ reject(new Error("WebSocket failed to connect."));
379
+ },
380
+ {
381
+ signal: aborter.signal
382
+ }
383
+ );
384
+ (_c = this.socket) == null ? void 0 : _c.addEventListener(
385
+ "close",
386
+ () => {
387
+ aborter.abort();
388
+ reject(new Error("WebSocket closed before it could connect."));
389
+ },
390
+ {
391
+ signal: aborter.signal
392
+ }
393
+ );
394
+ }
395
+ );
396
+ }
397
+ /**
398
+ * Disconnect from the Cartesia streaming WebSocket.
399
+ */
400
+ disconnect() {
401
+ var _a;
402
+ (_a = this.socket) == null ? void 0 : _a.close();
403
+ }
404
+ };
@@ -0,0 +1,5 @@
1
+ import 'emittery';
2
+ import 'partysocket';
3
+ import '../lib/client.cjs';
4
+ export { C as Chunk, l as ConnectionEventData, S as StreamEventData, m as StreamRequest, e as default } from '../index-C2_3XFxn.cjs';
5
+ import '../types/index.cjs';
@@ -1,5 +1,5 @@
1
1
  import 'emittery';
2
2
  import 'partysocket';
3
3
  import '../lib/client.js';
4
- export { C as Chunk, l as ConnectionEventData, S as StreamEventData, m as StreamRequest, e as default } from '../index-qwAyxV5I.js';
4
+ export { C as Chunk, l as ConnectionEventData, S as StreamEventData, m as StreamRequest, e as default } from '../index-DgwnZezj.js';
5
5
  import '../types/index.js';