@cartesia/cartesia-js 1.0.3 → 1.2.1-alpha.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +32 -3
  3. package/dist/{chunk-BHY7MNGT.js → chunk-5SBAQNWQ.js} +1 -1
  4. package/dist/{chunk-LZO6K34D.js → chunk-CSOXALSC.js} +7 -7
  5. package/dist/{chunk-PISCPZK4.js → chunk-FLWYXP5Z.js} +1 -1
  6. package/dist/chunk-GLZYI5DM.js +43 -0
  7. package/dist/{chunk-6YQ6KDIQ.js → chunk-I5YVYTNK.js} +47 -16
  8. package/dist/{chunk-NQVZNVOU.js → chunk-LKKWJLUG.js} +1 -1
  9. package/dist/{chunk-GHY2WEOK.js → chunk-NJDRWDQ3.js} +8 -35
  10. package/dist/{chunk-ZF6HASZT.js → chunk-QWNB544W.js} +7 -3
  11. package/dist/{chunk-YFN6TFR4.js → chunk-RJICGVPL.js} +12 -4
  12. package/dist/chunk-WLEVU3HN.js +42 -0
  13. package/dist/{chunk-EUW2435M.js → chunk-WSIVWXEI.js} +49 -25
  14. package/dist/index.cjs +162 -76
  15. package/dist/index.d.cts +2 -1
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.js +10 -9
  18. package/dist/lib/client.js +2 -2
  19. package/dist/lib/constants.js +1 -1
  20. package/dist/lib/index.cjs +157 -71
  21. package/dist/lib/index.d.cts +2 -0
  22. package/dist/lib/index.d.ts +2 -0
  23. package/dist/lib/index.js +9 -8
  24. package/dist/react/index.cjs +165 -76
  25. package/dist/react/index.js +14 -10
  26. package/dist/react/utils.js +2 -2
  27. package/dist/tts/index.cjs +114 -69
  28. package/dist/tts/index.d.cts +8 -1
  29. package/dist/tts/index.d.ts +8 -1
  30. package/dist/tts/index.js +6 -6
  31. package/dist/tts/player.cjs +13 -27
  32. package/dist/tts/player.js +4 -4
  33. package/dist/tts/source.cjs +54 -37
  34. package/dist/tts/source.d.cts +9 -0
  35. package/dist/tts/source.d.ts +9 -0
  36. package/dist/tts/source.js +2 -2
  37. package/dist/tts/utils.js +3 -3
  38. package/dist/tts/websocket.cjs +99 -69
  39. package/dist/tts/websocket.d.cts +15 -9
  40. package/dist/tts/websocket.d.ts +15 -9
  41. package/dist/tts/websocket.js +5 -5
  42. package/dist/types/index.d.cts +42 -3
  43. package/dist/types/index.d.ts +42 -3
  44. package/dist/voice-changer/index.cjs +143 -0
  45. package/dist/voice-changer/index.d.cts +9 -0
  46. package/dist/voice-changer/index.d.ts +9 -0
  47. package/dist/voice-changer/index.js +9 -0
  48. package/dist/voices/index.cjs +10 -2
  49. package/dist/voices/index.d.cts +2 -1
  50. package/dist/voices/index.d.ts +2 -1
  51. package/dist/voices/index.js +3 -3
  52. package/package.json +8 -16
  53. package/src/lib/index.ts +3 -0
  54. package/src/react/index.ts +4 -0
  55. package/src/tts/index.ts +16 -1
  56. package/src/tts/source.ts +35 -0
  57. package/src/tts/websocket.ts +33 -2
  58. package/src/types/index.ts +60 -2
  59. package/src/voice-changer/index.ts +37 -0
  60. package/src/voices/index.ts +12 -3
  61. package/.turbo/turbo-build.log +0 -75
  62. package/dist/chunk-NWCW6C7H.js +0 -25
  63. package/tsconfig.json +0 -3
@@ -9,6 +9,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
9
  var __getProtoOf = Object.getPrototypeOf;
10
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
11
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __typeError = (msg) => {
13
+ throw TypeError(msg);
14
+ };
12
15
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
16
  var __spreadValues = (a, b) => {
14
17
  for (var prop in b || (b = {}))
@@ -22,18 +25,6 @@ var __spreadValues = (a, b) => {
22
25
  return a;
23
26
  };
24
27
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __objRest = (source, exclude) => {
26
- var target = {};
27
- for (var prop in source)
28
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
- target[prop] = source[prop];
30
- if (source != null && __getOwnPropSymbols)
31
- for (var prop of __getOwnPropSymbols(source)) {
32
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
- target[prop] = source[prop];
34
- }
35
- return target;
36
- };
37
28
  var __export = (target, all) => {
38
29
  for (var name in all)
39
30
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -55,28 +46,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
46
  mod
56
47
  ));
57
48
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
- var __accessCheck = (obj, member, msg) => {
59
- if (!member.has(obj))
60
- throw TypeError("Cannot " + msg);
61
- };
62
- var __privateGet = (obj, member, getter) => {
63
- __accessCheck(obj, member, "read from private field");
64
- return getter ? getter.call(obj) : member.get(obj);
65
- };
66
- var __privateAdd = (obj, member, value) => {
67
- if (member.has(obj))
68
- throw TypeError("Cannot add the same private member more than once");
69
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
70
- };
71
- var __privateSet = (obj, member, value, setter) => {
72
- __accessCheck(obj, member, "write to private field");
73
- setter ? setter.call(obj, value) : member.set(obj, value);
74
- return value;
75
- };
76
- var __privateMethod = (obj, member, method) => {
77
- __accessCheck(obj, member, "access private method");
78
- return method;
79
- };
49
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
50
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
51
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
52
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
53
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
80
54
  var __async = (__this, __arguments, generator) => {
81
55
  return new Promise((resolve, reject) => {
82
56
  var fulfilled = (value) => {
@@ -155,7 +129,7 @@ var ENCODING_MAP = {
155
129
  pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
156
130
  pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
157
131
  };
158
- var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _createBuffer, createBuffer_fn;
132
+ var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _Source_instances, createBuffer_fn;
159
133
  var Source = class {
160
134
  /**
161
135
  * Create a new Source.
@@ -168,21 +142,15 @@ var Source = class {
168
142
  encoding,
169
143
  container
170
144
  }) {
171
- /**
172
- * Create a new buffer for the source.
173
- *
174
- * @param size - The size of the buffer to create.
175
- * @returns The new buffer as a TypedArray based on the encoding.
176
- */
177
- __privateAdd(this, _createBuffer);
145
+ __privateAdd(this, _Source_instances);
178
146
  __privateAdd(this, _emitter, new import_emittery.default());
179
- __privateAdd(this, _buffer, void 0);
147
+ __privateAdd(this, _buffer);
180
148
  __privateAdd(this, _readIndex, 0);
181
149
  __privateAdd(this, _writeIndex, 0);
182
150
  __privateAdd(this, _closed, false);
183
- __privateAdd(this, _sampleRate, void 0);
184
- __privateAdd(this, _encoding, void 0);
185
- __privateAdd(this, _container, void 0);
151
+ __privateAdd(this, _sampleRate);
152
+ __privateAdd(this, _encoding);
153
+ __privateAdd(this, _container);
186
154
  this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
187
155
  this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
188
156
  this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
@@ -190,7 +158,7 @@ var Source = class {
190
158
  __privateSet(this, _sampleRate, sampleRate);
191
159
  __privateSet(this, _encoding, encoding);
192
160
  __privateSet(this, _container, container);
193
- __privateSet(this, _buffer, __privateMethod(this, _createBuffer, createBuffer_fn).call(this, 1024));
161
+ __privateSet(this, _buffer, __privateMethod(this, _Source_instances, createBuffer_fn).call(this, 1024));
194
162
  }
195
163
  get sampleRate() {
196
164
  return __privateGet(this, _sampleRate);
@@ -214,7 +182,7 @@ var Source = class {
214
182
  while (newCapacity < requiredCapacity) {
215
183
  newCapacity *= 2;
216
184
  }
217
- const newBuffer = __privateMethod(this, _createBuffer, createBuffer_fn).call(this, newCapacity);
185
+ const newBuffer = __privateMethod(this, _Source_instances, createBuffer_fn).call(this, newCapacity);
218
186
  newBuffer.set(__privateGet(this, _buffer));
219
187
  __privateSet(this, _buffer, newBuffer);
220
188
  }
@@ -247,6 +215,37 @@ var Source = class {
247
215
  return read;
248
216
  });
249
217
  }
218
+ /**
219
+ * Seek in the buffer.
220
+ *
221
+ * @param offset The offset to seek to.
222
+ * @param whence The position to seek from.
223
+ * @returns The new position in the buffer.
224
+ * @throws {Error} If the seek is invalid.
225
+ */
226
+ seek(offset, whence) {
227
+ return __async(this, null, function* () {
228
+ let position = __privateGet(this, _readIndex);
229
+ switch (whence) {
230
+ case "start":
231
+ position = offset;
232
+ break;
233
+ case "current":
234
+ position += offset;
235
+ break;
236
+ case "end":
237
+ position = __privateGet(this, _writeIndex) + offset;
238
+ break;
239
+ default:
240
+ throw new Error(`Invalid seek mode: ${whence}`);
241
+ }
242
+ if (position < 0 || position > __privateGet(this, _writeIndex)) {
243
+ throw new Error("Seek out of bounds");
244
+ }
245
+ __privateSet(this, _readIndex, position);
246
+ return position;
247
+ });
248
+ }
250
249
  /**
251
250
  * Get the number of samples in a given duration.
252
251
  *
@@ -288,7 +287,13 @@ _closed = new WeakMap();
288
287
  _sampleRate = new WeakMap();
289
288
  _encoding = new WeakMap();
290
289
  _container = new WeakMap();
291
- _createBuffer = new WeakSet();
290
+ _Source_instances = new WeakSet();
291
+ /**
292
+ * Create a new buffer for the source.
293
+ *
294
+ * @param size - The size of the buffer to create.
295
+ * @returns The new buffer as a TypedArray based on the encoding.
296
+ */
292
297
  createBuffer_fn = function(size) {
293
298
  const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
294
299
  return new ArrayType(size);
@@ -351,7 +356,7 @@ function getEmitteryCallbacks(emitter) {
351
356
  }
352
357
 
353
358
  // src/tts/websocket.ts
354
- var _isConnected, _sampleRate2, _container2, _encoding2, _generateId, generateId_fn;
359
+ var _isConnected, _sampleRate2, _container2, _encoding2, _WebSocket_instances, generateId_fn;
355
360
  var WebSocket = class extends Client {
356
361
  /**
357
362
  * Create a new WebSocket client.
@@ -360,19 +365,11 @@ var WebSocket = class extends Client {
360
365
  */
361
366
  constructor({ sampleRate, container, encoding }, ...args) {
362
367
  super(...args);
363
- /**
364
- * Generate a unique ID suitable for a streaming context.
365
- *
366
- * Not suitable for security purposes or as a primary key, since
367
- * it lacks the amount of entropy required for those use cases.
368
- *
369
- * @returns A unique ID.
370
- */
371
- __privateAdd(this, _generateId);
368
+ __privateAdd(this, _WebSocket_instances);
372
369
  __privateAdd(this, _isConnected, false);
373
- __privateAdd(this, _sampleRate2, void 0);
374
- __privateAdd(this, _container2, void 0);
375
- __privateAdd(this, _encoding2, void 0);
370
+ __privateAdd(this, _sampleRate2);
371
+ __privateAdd(this, _container2);
372
+ __privateAdd(this, _encoding2);
376
373
  __privateSet(this, _sampleRate2, sampleRate);
377
374
  __privateSet(this, _container2, container != null ? container : "raw");
378
375
  __privateSet(this, _encoding2, encoding != null ? encoding : "pcm_f32le");
@@ -380,7 +377,7 @@ var WebSocket = class extends Client {
380
377
  /**
381
378
  * Send a message over the WebSocket to start a stream.
382
379
  *
383
- * @param inputs - Stream options. Defined in the StreamRequest type.
380
+ * @param inputs - Generation parameters. Defined in the StreamRequest type.
384
381
  * @param options - Options for the stream.
385
382
  * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
386
383
  * If set to `0`, the stream will not time out.
@@ -388,14 +385,13 @@ var WebSocket = class extends Client {
388
385
  * @returns An Emittery instance that emits messages from the WebSocket.
389
386
  * @returns An abort function that can be called to cancel the stream.
390
387
  */
391
- send(_a, { timeout = 0 } = {}) {
392
- var inputs = __objRest(_a, []);
393
- var _a2, _b, _c, _d;
388
+ send(inputs, { timeout = 0 } = {}) {
389
+ var _a, _b, _c, _d;
394
390
  if (!__privateGet(this, _isConnected)) {
395
391
  throw new Error("Not connected to WebSocket. Call .connect() first.");
396
392
  }
397
393
  if (!inputs.context_id) {
398
- inputs.context_id = __privateMethod(this, _generateId, generateId_fn).call(this);
394
+ inputs.context_id = __privateMethod(this, _WebSocket_instances, generateId_fn).call(this);
399
395
  }
400
396
  if (!inputs.output_format) {
401
397
  inputs.output_format = {
@@ -404,7 +400,7 @@ var WebSocket = class extends Client {
404
400
  sample_rate: __privateGet(this, _sampleRate2)
405
401
  };
406
402
  }
407
- (_a2 = this.socket) == null ? void 0 : _a2.send(
403
+ (_a = this.socket) == null ? void 0 : _a.send(
408
404
  JSON.stringify(__spreadValues({}, inputs))
409
405
  );
410
406
  const emitter = new import_emittery2.default();
@@ -474,6 +470,32 @@ var WebSocket = class extends Client {
474
470
  stop: streamCompleteController.abort.bind(streamCompleteController)
475
471
  });
476
472
  }
473
+ /**
474
+ * Continue a stream.
475
+ *
476
+ * @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
477
+ */
478
+ continue(inputs) {
479
+ var _a;
480
+ if (!__privateGet(this, _isConnected)) {
481
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
482
+ }
483
+ if (!inputs.context_id) {
484
+ throw new Error("context_id is required to continue a context.");
485
+ }
486
+ if (!inputs.output_format) {
487
+ inputs.output_format = {
488
+ container: __privateGet(this, _container2),
489
+ encoding: __privateGet(this, _encoding2),
490
+ sample_rate: __privateGet(this, _sampleRate2)
491
+ };
492
+ }
493
+ (_a = this.socket) == null ? void 0 : _a.send(
494
+ JSON.stringify(__spreadValues({
495
+ continue: true
496
+ }, inputs))
497
+ );
498
+ }
477
499
  /**
478
500
  * Authenticate and connect to a Cartesia streaming WebSocket.
479
501
  *
@@ -549,7 +571,15 @@ _isConnected = new WeakMap();
549
571
  _sampleRate2 = new WeakMap();
550
572
  _container2 = new WeakMap();
551
573
  _encoding2 = new WeakMap();
552
- _generateId = new WeakSet();
574
+ _WebSocket_instances = new WeakSet();
575
+ /**
576
+ * Generate a unique ID suitable for a streaming context.
577
+ *
578
+ * Not suitable for security purposes or as a primary key, since
579
+ * it lacks the amount of entropy required for those use cases.
580
+ *
581
+ * @returns A unique ID.
582
+ */
553
583
  generateId_fn = function() {
554
584
  return (0, import_human_id.humanId)({
555
585
  separator: "-",
@@ -1,7 +1,7 @@
1
1
  import * as emittery from 'emittery';
2
2
  import { WebSocket as WebSocket$1 } from 'partysocket';
3
3
  import { Client } from '../lib/client.cjs';
4
- import { WebSocketOptions, StreamRequest, StreamOptions, WordTimestamps, EmitteryCallbacks, ConnectionEventData } from '../types/index.cjs';
4
+ import { WebSocketOptions, StreamRequest, StreamOptions, WordTimestamps, ContinueRequest, EmitteryCallbacks, ConnectionEventData } from '../types/index.cjs';
5
5
  import Source from './source.cjs';
6
6
 
7
7
  declare class WebSocket extends Client {
@@ -16,7 +16,7 @@ declare class WebSocket extends Client {
16
16
  /**
17
17
  * Send a message over the WebSocket to start a stream.
18
18
  *
19
- * @param inputs - Stream options. Defined in the StreamRequest type.
19
+ * @param inputs - Generation parameters. Defined in the StreamRequest type.
20
20
  * @param options - Options for the stream.
21
21
  * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
22
22
  * If set to `0`, the stream will not time out.
@@ -24,7 +24,7 @@ declare class WebSocket extends Client {
24
24
  * @returns An Emittery instance that emits messages from the WebSocket.
25
25
  * @returns An abort function that can be called to cancel the stream.
26
26
  */
27
- send({ ...inputs }: StreamRequest, { timeout }?: StreamOptions): {
27
+ send(inputs: StreamRequest, { timeout }?: StreamOptions): {
28
28
  stop: {
29
29
  (reason?: any): void;
30
30
  (reason?: any): void;
@@ -33,20 +33,26 @@ declare class WebSocket extends Client {
33
33
  message: string;
34
34
  timestamps: WordTimestamps;
35
35
  } & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => emittery.UnsubscribeFunction;
36
- off: <Name_1 extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name_1 | readonly Name_1[], listener: (eventData: ({
36
+ off: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[], listener: (eventData: ({
37
37
  message: string;
38
38
  timestamps: WordTimestamps;
39
- } & emittery.OmnipresentEventData)[Name_1]) => void | Promise<void>) => void;
40
- once: <Name_2 extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name_2 | readonly Name_2[]) => emittery.EmitteryOncePromise<({
39
+ } & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => void;
40
+ once: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[]) => emittery.EmitteryOncePromise<({
41
41
  message: string;
42
42
  timestamps: WordTimestamps;
43
- } & emittery.OmnipresentEventData)[Name_2]>;
44
- events: <Name_3 extends "timestamps" | "message">(eventName: Name_3 | readonly Name_3[]) => AsyncIterableIterator<{
43
+ } & emittery.OmnipresentEventData)[Name]>;
44
+ events: <Name extends "timestamps" | "message">(eventName: Name | readonly Name[]) => AsyncIterableIterator<{
45
45
  message: string;
46
46
  timestamps: WordTimestamps;
47
- }[Name_3]>;
47
+ }[Name]>;
48
48
  source: Source;
49
49
  };
50
+ /**
51
+ * Continue a stream.
52
+ *
53
+ * @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
54
+ */
55
+ continue(inputs: ContinueRequest): void;
50
56
  /**
51
57
  * Authenticate and connect to a Cartesia streaming WebSocket.
52
58
  *
@@ -1,7 +1,7 @@
1
1
  import * as emittery from 'emittery';
2
2
  import { WebSocket as WebSocket$1 } from 'partysocket';
3
3
  import { Client } from '../lib/client.js';
4
- import { WebSocketOptions, StreamRequest, StreamOptions, WordTimestamps, EmitteryCallbacks, ConnectionEventData } from '../types/index.js';
4
+ import { WebSocketOptions, StreamRequest, StreamOptions, WordTimestamps, ContinueRequest, EmitteryCallbacks, ConnectionEventData } from '../types/index.js';
5
5
  import Source from './source.js';
6
6
 
7
7
  declare class WebSocket extends Client {
@@ -16,7 +16,7 @@ declare class WebSocket extends Client {
16
16
  /**
17
17
  * Send a message over the WebSocket to start a stream.
18
18
  *
19
- * @param inputs - Stream options. Defined in the StreamRequest type.
19
+ * @param inputs - Generation parameters. Defined in the StreamRequest type.
20
20
  * @param options - Options for the stream.
21
21
  * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
22
22
  * If set to `0`, the stream will not time out.
@@ -24,7 +24,7 @@ declare class WebSocket extends Client {
24
24
  * @returns An Emittery instance that emits messages from the WebSocket.
25
25
  * @returns An abort function that can be called to cancel the stream.
26
26
  */
27
- send({ ...inputs }: StreamRequest, { timeout }?: StreamOptions): {
27
+ send(inputs: StreamRequest, { timeout }?: StreamOptions): {
28
28
  stop: {
29
29
  (reason?: any): void;
30
30
  (reason?: any): void;
@@ -33,20 +33,26 @@ declare class WebSocket extends Client {
33
33
  message: string;
34
34
  timestamps: WordTimestamps;
35
35
  } & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => emittery.UnsubscribeFunction;
36
- off: <Name_1 extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name_1 | readonly Name_1[], listener: (eventData: ({
36
+ off: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[], listener: (eventData: ({
37
37
  message: string;
38
38
  timestamps: WordTimestamps;
39
- } & emittery.OmnipresentEventData)[Name_1]) => void | Promise<void>) => void;
40
- once: <Name_2 extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name_2 | readonly Name_2[]) => emittery.EmitteryOncePromise<({
39
+ } & emittery.OmnipresentEventData)[Name]) => void | Promise<void>) => void;
40
+ once: <Name extends "timestamps" | keyof emittery.OmnipresentEventData | "message">(eventName: Name | readonly Name[]) => emittery.EmitteryOncePromise<({
41
41
  message: string;
42
42
  timestamps: WordTimestamps;
43
- } & emittery.OmnipresentEventData)[Name_2]>;
44
- events: <Name_3 extends "timestamps" | "message">(eventName: Name_3 | readonly Name_3[]) => AsyncIterableIterator<{
43
+ } & emittery.OmnipresentEventData)[Name]>;
44
+ events: <Name extends "timestamps" | "message">(eventName: Name | readonly Name[]) => AsyncIterableIterator<{
45
45
  message: string;
46
46
  timestamps: WordTimestamps;
47
- }[Name_3]>;
47
+ }[Name]>;
48
48
  source: Source;
49
49
  };
50
+ /**
51
+ * Continue a stream.
52
+ *
53
+ * @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
54
+ */
55
+ continue(inputs: ContinueRequest): void;
50
56
  /**
51
57
  * Authenticate and connect to a Cartesia streaming WebSocket.
52
58
  *
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  WebSocket
3
- } from "../chunk-EUW2435M.js";
4
- import "../chunk-PISCPZK4.js";
3
+ } from "../chunk-WSIVWXEI.js";
4
+ import "../chunk-FLWYXP5Z.js";
5
5
  import "../chunk-2BFEKY3F.js";
6
- import "../chunk-BHY7MNGT.js";
7
- import "../chunk-6YQ6KDIQ.js";
8
- import "../chunk-GHY2WEOK.js";
6
+ import "../chunk-5SBAQNWQ.js";
7
+ import "../chunk-I5YVYTNK.js";
8
+ import "../chunk-NJDRWDQ3.js";
9
9
  export {
10
10
  WebSocket as default
11
11
  };
@@ -38,9 +38,14 @@ type StreamRequest = {
38
38
  context_id?: string;
39
39
  continue?: boolean;
40
40
  duration?: number;
41
- language?: string;
41
+ language?: Language;
42
42
  add_timestamps?: boolean;
43
43
  };
44
+ type BytesRequest = Omit<StreamRequest, "continue" | "add_timestamps" | "context_id">;
45
+ type ContinueRequest = StreamRequest & {
46
+ context_id: string;
47
+ };
48
+ type Language = "en" | "es" | "fr" | "de" | "ja" | "zh" | "pt" | (string & {});
44
49
  type StreamOptions = {
45
50
  timeout?: number;
46
51
  };
@@ -83,6 +88,34 @@ type CloneOptions = {
83
88
  clip: Blob;
84
89
  enhance?: boolean;
85
90
  };
91
+ type VoiceChangerOptions = {
92
+ clip: File;
93
+ voice: {
94
+ id: string;
95
+ };
96
+ output_format: {
97
+ container: "mp3";
98
+ bit_rate: number;
99
+ sample_rate: number;
100
+ } | {
101
+ container: "wav";
102
+ encoding: Encoding;
103
+ sample_rate: number;
104
+ bit_rate: number;
105
+ } | {
106
+ container: "raw";
107
+ encoding: Encoding;
108
+ sample_rate: number;
109
+ };
110
+ };
111
+ type LocalizeOptions = {
112
+ mode: "embedding";
113
+ embedding: number[];
114
+ } & {
115
+ language: Language;
116
+ dialect: string & {};
117
+ original_speaker_gender: "male" | "female" | (string & {});
118
+ };
86
119
  interface VoiceToMix {
87
120
  id?: string;
88
121
  embedding?: number[];
@@ -99,13 +132,19 @@ type Voice = {
99
132
  is_public: boolean;
100
133
  user_id: string;
101
134
  created_at: string;
102
- language: string;
135
+ language: Language;
103
136
  };
104
137
  type CreateVoice = Pick<Voice, "name" | "description" | "embedding"> & Partial<Omit<Voice, "name" | "description" | "embedding">>;
105
138
  type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
106
139
  type CloneResponse = {
107
140
  embedding: number[];
108
141
  };
142
+ type VoiceChangerBytesResponse = {
143
+ buffer: ArrayBuffer;
144
+ };
145
+ type LocalizeResponse = {
146
+ embedding: number[];
147
+ };
109
148
  type MixVoicesResponse = {
110
149
  embedding: number[];
111
150
  };
@@ -123,4 +162,4 @@ type SourceEventData = {
123
162
  type TypedArray = Float32Array | Int16Array | Uint8Array;
124
163
  type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
125
164
 
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 };
165
+ export type { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, 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 };
@@ -38,9 +38,14 @@ type StreamRequest = {
38
38
  context_id?: string;
39
39
  continue?: boolean;
40
40
  duration?: number;
41
- language?: string;
41
+ language?: Language;
42
42
  add_timestamps?: boolean;
43
43
  };
44
+ type BytesRequest = Omit<StreamRequest, "continue" | "add_timestamps" | "context_id">;
45
+ type ContinueRequest = StreamRequest & {
46
+ context_id: string;
47
+ };
48
+ type Language = "en" | "es" | "fr" | "de" | "ja" | "zh" | "pt" | (string & {});
44
49
  type StreamOptions = {
45
50
  timeout?: number;
46
51
  };
@@ -83,6 +88,34 @@ type CloneOptions = {
83
88
  clip: Blob;
84
89
  enhance?: boolean;
85
90
  };
91
+ type VoiceChangerOptions = {
92
+ clip: File;
93
+ voice: {
94
+ id: string;
95
+ };
96
+ output_format: {
97
+ container: "mp3";
98
+ bit_rate: number;
99
+ sample_rate: number;
100
+ } | {
101
+ container: "wav";
102
+ encoding: Encoding;
103
+ sample_rate: number;
104
+ bit_rate: number;
105
+ } | {
106
+ container: "raw";
107
+ encoding: Encoding;
108
+ sample_rate: number;
109
+ };
110
+ };
111
+ type LocalizeOptions = {
112
+ mode: "embedding";
113
+ embedding: number[];
114
+ } & {
115
+ language: Language;
116
+ dialect: string & {};
117
+ original_speaker_gender: "male" | "female" | (string & {});
118
+ };
86
119
  interface VoiceToMix {
87
120
  id?: string;
88
121
  embedding?: number[];
@@ -99,13 +132,19 @@ type Voice = {
99
132
  is_public: boolean;
100
133
  user_id: string;
101
134
  created_at: string;
102
- language: string;
135
+ language: Language;
103
136
  };
104
137
  type CreateVoice = Pick<Voice, "name" | "description" | "embedding"> & Partial<Omit<Voice, "name" | "description" | "embedding">>;
105
138
  type UpdateVoice = Partial<Pick<Voice, "name" | "description" | "embedding">>;
106
139
  type CloneResponse = {
107
140
  embedding: number[];
108
141
  };
142
+ type VoiceChangerBytesResponse = {
143
+ buffer: ArrayBuffer;
144
+ };
145
+ type LocalizeResponse = {
146
+ embedding: number[];
147
+ };
109
148
  type MixVoicesResponse = {
110
149
  embedding: number[];
111
150
  };
@@ -123,4 +162,4 @@ type SourceEventData = {
123
162
  type TypedArray = Float32Array | Int16Array | Uint8Array;
124
163
  type Encoding = "pcm_f32le" | "pcm_s16le" | "pcm_alaw" | "pcm_mulaw";
125
164
 
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 };
165
+ export type { BytesRequest, Chunk, ClientOptions, CloneOptions, CloneResponse, 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 };