@cartesia/cartesia-js 1.0.3 → 1.1.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 (48) hide show
  1. package/.turbo/turbo-build.log +34 -34
  2. package/CHANGELOG.md +6 -0
  3. package/README.md +32 -3
  4. package/dist/{chunk-NQVZNVOU.js → chunk-3FL2SNIR.js} +1 -1
  5. package/dist/{chunk-ZF6HASZT.js → chunk-4GEDAGVY.js} +3 -3
  6. package/dist/{chunk-PISCPZK4.js → chunk-6PWLZAMS.js} +1 -1
  7. package/dist/{chunk-YFN6TFR4.js → chunk-CWIJUBG6.js} +12 -4
  8. package/dist/{chunk-EUW2435M.js → chunk-L3OMQKWL.js} +34 -10
  9. package/dist/{chunk-LZO6K34D.js → chunk-MNOPO7G6.js} +2 -2
  10. package/dist/{chunk-NWCW6C7H.js → chunk-MUPVAEL7.js} +2 -2
  11. package/dist/{chunk-BHY7MNGT.js → chunk-VCZESWYA.js} +1 -1
  12. package/dist/{chunk-6YQ6KDIQ.js → chunk-VVDJR3OA.js} +32 -1
  13. package/dist/{chunk-GHY2WEOK.js → chunk-WIFMLPT5.js} +0 -13
  14. package/dist/index.cjs +71 -19
  15. package/dist/index.d.cts +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +9 -9
  18. package/dist/lib/client.js +2 -2
  19. package/dist/lib/constants.js +1 -1
  20. package/dist/lib/index.cjs +71 -19
  21. package/dist/lib/index.js +8 -8
  22. package/dist/react/index.cjs +74 -19
  23. package/dist/react/index.js +13 -10
  24. package/dist/react/utils.js +2 -2
  25. package/dist/tts/index.cjs +61 -17
  26. package/dist/tts/index.js +6 -6
  27. package/dist/tts/player.js +4 -4
  28. package/dist/tts/source.cjs +31 -0
  29. package/dist/tts/source.d.cts +9 -0
  30. package/dist/tts/source.d.ts +9 -0
  31. package/dist/tts/source.js +2 -2
  32. package/dist/tts/utils.js +3 -3
  33. package/dist/tts/websocket.cjs +61 -17
  34. package/dist/tts/websocket.d.cts +9 -3
  35. package/dist/tts/websocket.d.ts +9 -3
  36. package/dist/tts/websocket.js +5 -5
  37. package/dist/types/index.d.cts +18 -3
  38. package/dist/types/index.d.ts +18 -3
  39. package/dist/voices/index.cjs +10 -2
  40. package/dist/voices/index.d.cts +2 -1
  41. package/dist/voices/index.d.ts +2 -1
  42. package/dist/voices/index.js +3 -3
  43. package/package.json +1 -1
  44. package/src/react/index.ts +4 -0
  45. package/src/tts/source.ts +35 -0
  46. package/src/tts/websocket.ts +33 -2
  47. package/src/types/index.ts +29 -2
  48. package/src/voices/index.ts +12 -3
@@ -22,18 +22,6 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
24
  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
25
  var __export = (target, all) => {
38
26
  for (var name in all)
39
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -249,6 +237,37 @@ var Source = class {
249
237
  return read;
250
238
  });
251
239
  }
240
+ /**
241
+ * Seek in the buffer.
242
+ *
243
+ * @param offset The offset to seek to.
244
+ * @param whence The position to seek from.
245
+ * @returns The new position in the buffer.
246
+ * @throws {Error} If the seek is invalid.
247
+ */
248
+ seek(offset, whence) {
249
+ return __async(this, null, function* () {
250
+ let position = __privateGet(this, _readIndex);
251
+ switch (whence) {
252
+ case "start":
253
+ position = offset;
254
+ break;
255
+ case "current":
256
+ position += offset;
257
+ break;
258
+ case "end":
259
+ position = __privateGet(this, _writeIndex) + offset;
260
+ break;
261
+ default:
262
+ throw new Error(`Invalid seek mode: ${whence}`);
263
+ }
264
+ if (position < 0 || position > __privateGet(this, _writeIndex)) {
265
+ throw new Error("Seek out of bounds");
266
+ }
267
+ __privateSet(this, _readIndex, position);
268
+ return position;
269
+ });
270
+ }
252
271
  /**
253
272
  * Get the number of samples in a given duration.
254
273
  *
@@ -382,7 +401,7 @@ var WebSocket = class extends Client {
382
401
  /**
383
402
  * Send a message over the WebSocket to start a stream.
384
403
  *
385
- * @param inputs - Stream options. Defined in the StreamRequest type.
404
+ * @param inputs - Generation parameters. Defined in the StreamRequest type.
386
405
  * @param options - Options for the stream.
387
406
  * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
388
407
  * If set to `0`, the stream will not time out.
@@ -390,9 +409,8 @@ var WebSocket = class extends Client {
390
409
  * @returns An Emittery instance that emits messages from the WebSocket.
391
410
  * @returns An abort function that can be called to cancel the stream.
392
411
  */
393
- send(_a, { timeout = 0 } = {}) {
394
- var inputs = __objRest(_a, []);
395
- var _a2, _b, _c, _d;
412
+ send(inputs, { timeout = 0 } = {}) {
413
+ var _a, _b, _c, _d;
396
414
  if (!__privateGet(this, _isConnected)) {
397
415
  throw new Error("Not connected to WebSocket. Call .connect() first.");
398
416
  }
@@ -406,7 +424,7 @@ var WebSocket = class extends Client {
406
424
  sample_rate: __privateGet(this, _sampleRate2)
407
425
  };
408
426
  }
409
- (_a2 = this.socket) == null ? void 0 : _a2.send(
427
+ (_a = this.socket) == null ? void 0 : _a.send(
410
428
  JSON.stringify(__spreadValues({}, inputs))
411
429
  );
412
430
  const emitter = new import_emittery2.default();
@@ -476,6 +494,32 @@ var WebSocket = class extends Client {
476
494
  stop: streamCompleteController.abort.bind(streamCompleteController)
477
495
  });
478
496
  }
497
+ /**
498
+ * Continue a stream.
499
+ *
500
+ * @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
501
+ */
502
+ continue(inputs) {
503
+ var _a;
504
+ if (!__privateGet(this, _isConnected)) {
505
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
506
+ }
507
+ if (!inputs.context_id) {
508
+ throw new Error("context_id is required to continue a context.");
509
+ }
510
+ if (!inputs.output_format) {
511
+ inputs.output_format = {
512
+ container: __privateGet(this, _container2),
513
+ encoding: __privateGet(this, _encoding2),
514
+ sample_rate: __privateGet(this, _sampleRate2)
515
+ };
516
+ }
517
+ (_a = this.socket) == null ? void 0 : _a.send(
518
+ JSON.stringify(__spreadValues({
519
+ continue: true
520
+ }, inputs))
521
+ );
522
+ }
479
523
  /**
480
524
  * Authenticate and connect to a Cartesia streaming WebSocket.
481
525
  *
@@ -625,10 +669,18 @@ var Voices = class extends Client {
625
669
  }
626
670
  mix(options) {
627
671
  return __async(this, null, function* () {
628
- const request = options;
629
672
  const response = yield this._fetch("/voices/mix", {
630
673
  method: "POST",
631
- body: JSON.stringify(request)
674
+ body: JSON.stringify(options)
675
+ });
676
+ return response.json();
677
+ });
678
+ }
679
+ localize(options) {
680
+ return __async(this, null, function* () {
681
+ const response = yield this._fetch("/voices/localize", {
682
+ method: "POST",
683
+ body: JSON.stringify(options)
632
684
  });
633
685
  return response.json();
634
686
  });
package/dist/lib/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  Cartesia
3
- } from "../chunk-ZF6HASZT.js";
4
- import "../chunk-YFN6TFR4.js";
5
- import "../chunk-NWCW6C7H.js";
6
- import "../chunk-EUW2435M.js";
7
- import "../chunk-PISCPZK4.js";
3
+ } from "../chunk-4GEDAGVY.js";
4
+ import "../chunk-CWIJUBG6.js";
5
+ import "../chunk-MUPVAEL7.js";
6
+ import "../chunk-L3OMQKWL.js";
7
+ import "../chunk-6PWLZAMS.js";
8
8
  import "../chunk-2BFEKY3F.js";
9
- import "../chunk-BHY7MNGT.js";
10
- import "../chunk-6YQ6KDIQ.js";
11
- import "../chunk-GHY2WEOK.js";
9
+ import "../chunk-VCZESWYA.js";
10
+ import "../chunk-VVDJR3OA.js";
11
+ import "../chunk-WIFMLPT5.js";
12
12
  export {
13
13
  Cartesia
14
14
  };
@@ -22,18 +22,6 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
24
  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
25
  var __export = (target, all) => {
38
26
  for (var name in all)
39
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -250,6 +238,37 @@ var Source = class {
250
238
  return read;
251
239
  });
252
240
  }
241
+ /**
242
+ * Seek in the buffer.
243
+ *
244
+ * @param offset The offset to seek to.
245
+ * @param whence The position to seek from.
246
+ * @returns The new position in the buffer.
247
+ * @throws {Error} If the seek is invalid.
248
+ */
249
+ seek(offset, whence) {
250
+ return __async(this, null, function* () {
251
+ let position = __privateGet(this, _readIndex);
252
+ switch (whence) {
253
+ case "start":
254
+ position = offset;
255
+ break;
256
+ case "current":
257
+ position += offset;
258
+ break;
259
+ case "end":
260
+ position = __privateGet(this, _writeIndex) + offset;
261
+ break;
262
+ default:
263
+ throw new Error(`Invalid seek mode: ${whence}`);
264
+ }
265
+ if (position < 0 || position > __privateGet(this, _writeIndex)) {
266
+ throw new Error("Seek out of bounds");
267
+ }
268
+ __privateSet(this, _readIndex, position);
269
+ return position;
270
+ });
271
+ }
253
272
  /**
254
273
  * Get the number of samples in a given duration.
255
274
  *
@@ -396,7 +415,7 @@ var WebSocket = class extends Client {
396
415
  /**
397
416
  * Send a message over the WebSocket to start a stream.
398
417
  *
399
- * @param inputs - Stream options. Defined in the StreamRequest type.
418
+ * @param inputs - Generation parameters. Defined in the StreamRequest type.
400
419
  * @param options - Options for the stream.
401
420
  * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
402
421
  * If set to `0`, the stream will not time out.
@@ -404,9 +423,8 @@ var WebSocket = class extends Client {
404
423
  * @returns An Emittery instance that emits messages from the WebSocket.
405
424
  * @returns An abort function that can be called to cancel the stream.
406
425
  */
407
- send(_a, { timeout = 0 } = {}) {
408
- var inputs = __objRest(_a, []);
409
- var _a2, _b, _c, _d;
426
+ send(inputs, { timeout = 0 } = {}) {
427
+ var _a, _b, _c, _d;
410
428
  if (!__privateGet(this, _isConnected)) {
411
429
  throw new Error("Not connected to WebSocket. Call .connect() first.");
412
430
  }
@@ -420,7 +438,7 @@ var WebSocket = class extends Client {
420
438
  sample_rate: __privateGet(this, _sampleRate2)
421
439
  };
422
440
  }
423
- (_a2 = this.socket) == null ? void 0 : _a2.send(
441
+ (_a = this.socket) == null ? void 0 : _a.send(
424
442
  JSON.stringify(__spreadValues({}, inputs))
425
443
  );
426
444
  const emitter = new import_emittery2.default();
@@ -490,6 +508,32 @@ var WebSocket = class extends Client {
490
508
  stop: streamCompleteController.abort.bind(streamCompleteController)
491
509
  });
492
510
  }
511
+ /**
512
+ * Continue a stream.
513
+ *
514
+ * @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
515
+ */
516
+ continue(inputs) {
517
+ var _a;
518
+ if (!__privateGet(this, _isConnected)) {
519
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
520
+ }
521
+ if (!inputs.context_id) {
522
+ throw new Error("context_id is required to continue a context.");
523
+ }
524
+ if (!inputs.output_format) {
525
+ inputs.output_format = {
526
+ container: __privateGet(this, _container2),
527
+ encoding: __privateGet(this, _encoding2),
528
+ sample_rate: __privateGet(this, _sampleRate2)
529
+ };
530
+ }
531
+ (_a = this.socket) == null ? void 0 : _a.send(
532
+ JSON.stringify(__spreadValues({
533
+ continue: true
534
+ }, inputs))
535
+ );
536
+ }
493
537
  /**
494
538
  * Authenticate and connect to a Cartesia streaming WebSocket.
495
539
  *
@@ -639,10 +683,18 @@ var Voices = class extends Client {
639
683
  }
640
684
  mix(options) {
641
685
  return __async(this, null, function* () {
642
- const request = options;
643
686
  const response = yield this._fetch("/voices/mix", {
644
687
  method: "POST",
645
- body: JSON.stringify(request)
688
+ body: JSON.stringify(options)
689
+ });
690
+ return response.json();
691
+ });
692
+ }
693
+ localize(options) {
694
+ return __async(this, null, function* () {
695
+ const response = yield this._fetch("/voices/localize", {
696
+ method: "POST",
697
+ body: JSON.stringify(options)
646
698
  });
647
699
  return response.json();
648
700
  });
@@ -943,6 +995,9 @@ function useTTS({
943
995
  if (player.current) {
944
996
  yield player.current.stop();
945
997
  }
998
+ if (playbackStatus === "finished") {
999
+ websocketReturn.current.source.seek(0, "start");
1000
+ }
946
1001
  setPlaybackStatus("playing");
947
1002
  const unsubscribes = [];
948
1003
  unsubscribes.push(
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  Cartesia
3
- } from "../chunk-ZF6HASZT.js";
4
- import "../chunk-YFN6TFR4.js";
3
+ } from "../chunk-4GEDAGVY.js";
4
+ import "../chunk-CWIJUBG6.js";
5
5
  import {
6
6
  pingServer
7
- } from "../chunk-NQVZNVOU.js";
8
- import "../chunk-NWCW6C7H.js";
9
- import "../chunk-EUW2435M.js";
10
- import "../chunk-PISCPZK4.js";
7
+ } from "../chunk-3FL2SNIR.js";
8
+ import "../chunk-MUPVAEL7.js";
9
+ import "../chunk-L3OMQKWL.js";
10
+ import "../chunk-6PWLZAMS.js";
11
11
  import "../chunk-2BFEKY3F.js";
12
12
  import {
13
13
  Player
14
- } from "../chunk-LZO6K34D.js";
15
- import "../chunk-BHY7MNGT.js";
16
- import "../chunk-6YQ6KDIQ.js";
14
+ } from "../chunk-MNOPO7G6.js";
15
+ import "../chunk-VCZESWYA.js";
16
+ import "../chunk-VVDJR3OA.js";
17
17
  import {
18
18
  __async
19
- } from "../chunk-GHY2WEOK.js";
19
+ } from "../chunk-WIFMLPT5.js";
20
20
 
21
21
  // src/react/index.ts
22
22
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -176,6 +176,9 @@ function useTTS({
176
176
  if (player.current) {
177
177
  yield player.current.stop();
178
178
  }
179
+ if (playbackStatus === "finished") {
180
+ websocketReturn.current.source.seek(0, "start");
181
+ }
179
182
  setPlaybackStatus("playing");
180
183
  const unsubscribes = [];
181
184
  unsubscribes.push(
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  pingServer
3
- } from "../chunk-NQVZNVOU.js";
4
- import "../chunk-GHY2WEOK.js";
3
+ } from "../chunk-3FL2SNIR.js";
4
+ import "../chunk-WIFMLPT5.js";
5
5
  export {
6
6
  pingServer
7
7
  };
@@ -22,18 +22,6 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
24
  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
25
  var __export = (target, all) => {
38
26
  for (var name in all)
39
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -249,6 +237,37 @@ var Source = class {
249
237
  return read;
250
238
  });
251
239
  }
240
+ /**
241
+ * Seek in the buffer.
242
+ *
243
+ * @param offset The offset to seek to.
244
+ * @param whence The position to seek from.
245
+ * @returns The new position in the buffer.
246
+ * @throws {Error} If the seek is invalid.
247
+ */
248
+ seek(offset, whence) {
249
+ return __async(this, null, function* () {
250
+ let position = __privateGet(this, _readIndex);
251
+ switch (whence) {
252
+ case "start":
253
+ position = offset;
254
+ break;
255
+ case "current":
256
+ position += offset;
257
+ break;
258
+ case "end":
259
+ position = __privateGet(this, _writeIndex) + offset;
260
+ break;
261
+ default:
262
+ throw new Error(`Invalid seek mode: ${whence}`);
263
+ }
264
+ if (position < 0 || position > __privateGet(this, _writeIndex)) {
265
+ throw new Error("Seek out of bounds");
266
+ }
267
+ __privateSet(this, _readIndex, position);
268
+ return position;
269
+ });
270
+ }
252
271
  /**
253
272
  * Get the number of samples in a given duration.
254
273
  *
@@ -382,7 +401,7 @@ var WebSocket = class extends Client {
382
401
  /**
383
402
  * Send a message over the WebSocket to start a stream.
384
403
  *
385
- * @param inputs - Stream options. Defined in the StreamRequest type.
404
+ * @param inputs - Generation parameters. Defined in the StreamRequest type.
386
405
  * @param options - Options for the stream.
387
406
  * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
388
407
  * If set to `0`, the stream will not time out.
@@ -390,9 +409,8 @@ var WebSocket = class extends Client {
390
409
  * @returns An Emittery instance that emits messages from the WebSocket.
391
410
  * @returns An abort function that can be called to cancel the stream.
392
411
  */
393
- send(_a, { timeout = 0 } = {}) {
394
- var inputs = __objRest(_a, []);
395
- var _a2, _b, _c, _d;
412
+ send(inputs, { timeout = 0 } = {}) {
413
+ var _a, _b, _c, _d;
396
414
  if (!__privateGet(this, _isConnected)) {
397
415
  throw new Error("Not connected to WebSocket. Call .connect() first.");
398
416
  }
@@ -406,7 +424,7 @@ var WebSocket = class extends Client {
406
424
  sample_rate: __privateGet(this, _sampleRate2)
407
425
  };
408
426
  }
409
- (_a2 = this.socket) == null ? void 0 : _a2.send(
427
+ (_a = this.socket) == null ? void 0 : _a.send(
410
428
  JSON.stringify(__spreadValues({}, inputs))
411
429
  );
412
430
  const emitter = new import_emittery2.default();
@@ -476,6 +494,32 @@ var WebSocket = class extends Client {
476
494
  stop: streamCompleteController.abort.bind(streamCompleteController)
477
495
  });
478
496
  }
497
+ /**
498
+ * Continue a stream.
499
+ *
500
+ * @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
501
+ */
502
+ continue(inputs) {
503
+ var _a;
504
+ if (!__privateGet(this, _isConnected)) {
505
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
506
+ }
507
+ if (!inputs.context_id) {
508
+ throw new Error("context_id is required to continue a context.");
509
+ }
510
+ if (!inputs.output_format) {
511
+ inputs.output_format = {
512
+ container: __privateGet(this, _container2),
513
+ encoding: __privateGet(this, _encoding2),
514
+ sample_rate: __privateGet(this, _sampleRate2)
515
+ };
516
+ }
517
+ (_a = this.socket) == null ? void 0 : _a.send(
518
+ JSON.stringify(__spreadValues({
519
+ continue: true
520
+ }, inputs))
521
+ );
522
+ }
479
523
  /**
480
524
  * Authenticate and connect to a Cartesia streaming WebSocket.
481
525
  *
package/dist/tts/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  TTS
3
- } from "../chunk-NWCW6C7H.js";
4
- import "../chunk-EUW2435M.js";
5
- import "../chunk-PISCPZK4.js";
3
+ } from "../chunk-MUPVAEL7.js";
4
+ import "../chunk-L3OMQKWL.js";
5
+ import "../chunk-6PWLZAMS.js";
6
6
  import "../chunk-2BFEKY3F.js";
7
- import "../chunk-BHY7MNGT.js";
8
- import "../chunk-6YQ6KDIQ.js";
9
- import "../chunk-GHY2WEOK.js";
7
+ import "../chunk-VCZESWYA.js";
8
+ import "../chunk-VVDJR3OA.js";
9
+ import "../chunk-WIFMLPT5.js";
10
10
  export {
11
11
  TTS as default
12
12
  };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Player
3
- } from "../chunk-LZO6K34D.js";
4
- import "../chunk-BHY7MNGT.js";
5
- import "../chunk-6YQ6KDIQ.js";
6
- import "../chunk-GHY2WEOK.js";
3
+ } from "../chunk-MNOPO7G6.js";
4
+ import "../chunk-VCZESWYA.js";
5
+ import "../chunk-VVDJR3OA.js";
6
+ import "../chunk-WIFMLPT5.js";
7
7
  export {
8
8
  Player as default
9
9
  };
@@ -175,6 +175,37 @@ var Source = class {
175
175
  return read;
176
176
  });
177
177
  }
178
+ /**
179
+ * Seek in the buffer.
180
+ *
181
+ * @param offset The offset to seek to.
182
+ * @param whence The position to seek from.
183
+ * @returns The new position in the buffer.
184
+ * @throws {Error} If the seek is invalid.
185
+ */
186
+ seek(offset, whence) {
187
+ return __async(this, null, function* () {
188
+ let position = __privateGet(this, _readIndex);
189
+ switch (whence) {
190
+ case "start":
191
+ position = offset;
192
+ break;
193
+ case "current":
194
+ position += offset;
195
+ break;
196
+ case "end":
197
+ position = __privateGet(this, _writeIndex) + offset;
198
+ break;
199
+ default:
200
+ throw new Error(`Invalid seek mode: ${whence}`);
201
+ }
202
+ if (position < 0 || position > __privateGet(this, _writeIndex)) {
203
+ throw new Error("Seek out of bounds");
204
+ }
205
+ __privateSet(this, _readIndex, position);
206
+ return position;
207
+ });
208
+ }
178
209
  /**
179
210
  * Get the number of samples in a given duration.
180
211
  *
@@ -40,6 +40,15 @@ declare class Source {
40
40
  * less than the length of the provided buffer.
41
41
  */
42
42
  read(dst: TypedArray): Promise<number>;
43
+ /**
44
+ * Seek in the buffer.
45
+ *
46
+ * @param offset The offset to seek to.
47
+ * @param whence The position to seek from.
48
+ * @returns The new position in the buffer.
49
+ * @throws {Error} If the seek is invalid.
50
+ */
51
+ seek(offset: number, whence: "start" | "current" | "end"): Promise<number>;
43
52
  /**
44
53
  * Get the number of samples in a given duration.
45
54
  *
@@ -40,6 +40,15 @@ declare class Source {
40
40
  * less than the length of the provided buffer.
41
41
  */
42
42
  read(dst: TypedArray): Promise<number>;
43
+ /**
44
+ * Seek in the buffer.
45
+ *
46
+ * @param offset The offset to seek to.
47
+ * @param whence The position to seek from.
48
+ * @returns The new position in the buffer.
49
+ * @throws {Error} If the seek is invalid.
50
+ */
51
+ seek(offset: number, whence: "start" | "current" | "end"): Promise<number>;
43
52
  /**
44
53
  * Get the number of samples in a given duration.
45
54
  *
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  ENCODING_MAP,
3
3
  Source
4
- } from "../chunk-6YQ6KDIQ.js";
5
- import "../chunk-GHY2WEOK.js";
4
+ } from "../chunk-VVDJR3OA.js";
5
+ import "../chunk-WIFMLPT5.js";
6
6
  export {
7
7
  ENCODING_MAP,
8
8
  Source as default
package/dist/tts/utils.js CHANGED
@@ -7,9 +7,9 @@ import {
7
7
  isComplete,
8
8
  isSentinel,
9
9
  playAudioBuffer
10
- } from "../chunk-BHY7MNGT.js";
11
- import "../chunk-6YQ6KDIQ.js";
12
- import "../chunk-GHY2WEOK.js";
10
+ } from "../chunk-VCZESWYA.js";
11
+ import "../chunk-VVDJR3OA.js";
12
+ import "../chunk-WIFMLPT5.js";
13
13
  export {
14
14
  base64ToArray,
15
15
  createMessageHandlerForContextId,