@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
@@ -5,49 +5,49 @@ $ tsup src/ --format cjs,esm --dts
5
5
  CLI Target: es6
6
6
  CJS Build start
7
7
  ESM Build start
8
- ESM dist/chunk-FXPGR372.js 0 B
9
8
  ESM dist/index.js 499.00 B
9
+ ESM dist/chunk-FXPGR372.js 0 B
10
10
  ESM dist/lib/client.js 132.00 B
11
- ESM dist/react/index.js 7.62 KB
11
+ ESM dist/react/index.js 7.73 KB
12
12
  ESM dist/tts/index.js 261.00 B
13
13
  ESM dist/lib/constants.js 183.00 B
14
14
  ESM dist/lib/index.js 322.00 B
15
- ESM dist/chunk-ZF6HASZT.js 353.00 B
16
- ESM dist/chunk-YFN6TFR4.js 1.74 KB
15
+ ESM dist/chunk-4GEDAGVY.js 353.00 B
17
16
  ESM dist/react/utils.js 109.00 B
18
- ESM dist/chunk-NQVZNVOU.js 337.00 B
19
- ESM dist/chunk-NWCW6C7H.js 439.00 B
20
- ESM dist/chunk-EUW2435M.js 7.17 KB
21
- ESM dist/chunk-PISCPZK4.js 1.02 KB
17
+ ESM dist/chunk-CWIJUBG6.js 1.95 KB
18
+ ESM dist/chunk-3FL2SNIR.js 337.00 B
19
+ ESM dist/chunk-MUPVAEL7.js 439.00 B
20
+ ESM dist/chunk-L3OMQKWL.js 7.95 KB
21
+ ESM dist/chunk-6PWLZAMS.js 1.02 KB
22
22
  ESM dist/chunk-2BFEKY3F.js 366.00 B
23
23
  ESM dist/tts/player.js 174.00 B
24
- ESM dist/chunk-LZO6K34D.js 3.76 KB
25
- ESM dist/chunk-BHY7MNGT.js 2.11 KB
26
- ESM dist/chunk-6YQ6KDIQ.js 5.32 KB
27
- ESM dist/chunk-GHY2WEOK.js 2.70 KB
28
- ESM dist/voices/index.js 174.00 B
24
+ ESM dist/chunk-MNOPO7G6.js 3.76 KB
25
+ ESM dist/chunk-VVDJR3OA.js 6.20 KB
26
+ ESM dist/chunk-VCZESWYA.js 2.11 KB
27
+ ESM dist/chunk-WIFMLPT5.js 2.27 KB
29
28
  ESM dist/types/index.js 31.00 B
29
+ ESM dist/voices/index.js 174.00 B
30
30
  ESM dist/tts/source.js 144.00 B
31
31
  ESM dist/tts/utils.js 426.00 B
32
32
  ESM dist/tts/websocket.js 242.00 B
33
- ESM ⚡️ Build success in 72ms
34
- CJS dist/index.cjs 24.98 KB
33
+ ESM ⚡️ Build success in 134ms
34
+ CJS dist/index.cjs 26.45 KB
35
35
  CJS dist/lib/client.cjs 4.07 KB
36
36
  CJS dist/lib/constants.cjs 1.43 KB
37
- CJS dist/lib/index.cjs 20.87 KB
38
- CJS dist/react/index.cjs 32.54 KB
39
- CJS dist/react/utils.cjs 1.80 KB
40
- CJS dist/tts/index.cjs 18.96 KB
37
+ CJS dist/lib/index.cjs 22.35 KB
38
+ CJS dist/react/index.cjs 34.12 KB
39
+ CJS dist/tts/index.cjs 20.23 KB
41
40
  CJS dist/tts/player.cjs 6.96 KB
41
+ CJS dist/react/utils.cjs 1.80 KB
42
42
  CJS dist/tts/utils.cjs 4.33 KB
43
- CJS dist/tts/source.cjs 8.15 KB
43
+ CJS dist/tts/source.cjs 9.03 KB
44
44
  CJS dist/types/index.cjs 764.00 B
45
- CJS dist/tts/websocket.cjs 18.65 KB
46
- CJS dist/voices/index.cjs 5.62 KB
47
- CJS ⚡️ Build success in 73ms
45
+ CJS dist/tts/websocket.cjs 19.92 KB
46
+ CJS dist/voices/index.cjs 5.83 KB
47
+ CJS ⚡️ Build success in 142ms
48
48
  DTS Build start
49
- DTS ⚡️ Build success in 8468ms
50
- DTS dist/index.d.cts 866.00 B
49
+ DTS ⚡️ Build success in 7238ms
50
+ DTS dist/index.d.cts 928.00 B
51
51
  DTS dist/lib/constants.d.cts 564.00 B
52
52
  DTS dist/lib/index.d.cts 410.00 B
53
53
  DTS dist/react/index.d.cts 1.09 KB
@@ -55,12 +55,12 @@ $ tsup src/ --format cjs,esm --dts
55
55
  DTS dist/tts/index.d.cts 471.00 B
56
56
  DTS dist/tts/player.d.cts 1.20 KB
57
57
  DTS dist/tts/utils.d.cts 2.68 KB
58
- DTS dist/tts/websocket.d.cts 2.94 KB
59
- DTS dist/tts/source.d.cts 2.55 KB
60
- DTS dist/voices/index.d.cts 573.00 B
58
+ DTS dist/tts/websocket.d.cts 3.21 KB
59
+ DTS dist/tts/source.d.cts 2.86 KB
60
+ DTS dist/voices/index.d.cts 675.00 B
61
61
  DTS dist/lib/client.d.cts 293.00 B
62
- DTS dist/types/index.d.cts 3.50 KB
63
- DTS dist/index.d.ts 858.00 B
62
+ DTS dist/types/index.d.cts 3.96 KB
63
+ DTS dist/index.d.ts 920.00 B
64
64
  DTS dist/lib/constants.d.ts 564.00 B
65
65
  DTS dist/lib/index.d.ts 404.00 B
66
66
  DTS dist/react/index.d.ts 1.09 KB
@@ -68,8 +68,8 @@ $ tsup src/ --format cjs,esm --dts
68
68
  DTS dist/tts/index.d.ts 467.00 B
69
69
  DTS dist/tts/player.d.ts 1.20 KB
70
70
  DTS dist/tts/utils.d.ts 2.68 KB
71
- DTS dist/tts/websocket.d.ts 2.94 KB
72
- DTS dist/tts/source.d.ts 2.55 KB
73
- DTS dist/voices/index.d.ts 571.00 B
71
+ DTS dist/tts/websocket.d.ts 3.20 KB
72
+ DTS dist/tts/source.d.ts 2.86 KB
73
+ DTS dist/voices/index.d.ts 673.00 B
74
74
  DTS dist/lib/client.d.ts 292.00 B
75
- DTS dist/types/index.d.ts 3.50 KB
75
+ DTS dist/types/index.d.ts 3.96 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @cartesia/cartesia-js
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ed6be65: Add WebSocket continue method for input streaming with contexts
8
+
3
9
  ## 1.0.3
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Cartesia JavaScript Client
2
2
 
3
3
  ![NPM Version](https://img.shields.io/npm/v/%40cartesia%2Fcartesia-js?logo=npm)
4
- [![Discord](https://badgen.net/badge/black/Cartesia/icon?icon=discord&label)](https://discord.gg/ZVxavqHB9X)
4
+ [![Discord](https://badgen.net/badge/black/Cartesia/icon?icon=discord&label)](https://discord.gg/cartesia)
5
5
 
6
6
  This client provides convenient access to [Cartesia's TTS models](https://cartesia.ai/). Sonic is the fastest text-to-speech model around—it can generate a second of audio in just 650ms, and it can stream out the first audio chunk in just 135ms. Alongside Sonic, we also offer an extensive prebuilt voice library for a variety of use cases.
7
7
 
@@ -63,6 +63,13 @@ const mixedVoiceEmbedding = await cartesia.voices.mix({
63
63
  voices: [{ id: "<voice-id-1>", weight: 0.6 }, { id: "<voice-id-2>", weight: 0.4 }],
64
64
  });
65
65
 
66
+ // Localize a voice.
67
+ const localizedVoiceEmbedding = await cartesia.voices.localize({
68
+ embedding: Array(192).fill(1.0),
69
+ original_speaker_gender: "female",
70
+ language: "es",
71
+ });
72
+
66
73
  // Create a voice.
67
74
  const newVoice = await cartesia.voices.create({
68
75
  name: "Tim",
@@ -120,9 +127,31 @@ for await (const message of response.events('message')) {
120
127
 
121
128
  #### Input Streaming with Contexts
122
129
 
123
- You can perform input streaming with contexts as described in the [docs](https://docs.cartesia.ai/api-reference/endpoints/stream-speech-websocket#input-streaming-with-contexts). The WebSocket's `send` method is just a wrapper around sending a message on the WebSocket, so the request format specified the docs can be used directly.
130
+ ```js
131
+ const contextOptions = {
132
+ context_id: "my-context",
133
+ model_id: "sonic-english",
134
+ voice: {
135
+ mode: "id",
136
+ id: "a0e99841-438c-4a64-b679-ae501e7d6091",
137
+ },
138
+ }
139
+
140
+ // Initial request on the context uses websocket.send().
141
+ // This response object will aggregate the results of all the inputs sent on the context.
142
+ const response = await websocket.send({
143
+ ...contextOptions,
144
+ transcript: "Hello, world!",
145
+ });
146
+
147
+ // Subsequent requests on the same context use websocket.continue().
148
+ await websocket.continue({
149
+ ...contextOptions,
150
+ transcript: " How are you today?",
151
+ });
152
+ ```
124
153
 
125
- You should use the return from the first `send` call on a context to receive outputs and events for the entire context. You can ignore the return values of subsequent `send` calls.
154
+ See the [input streaming docs](https://docs.cartesia.ai/reference/web-socket/stream-speech/working-with-web-sockets#input-streaming-with-contexts) for more information.
126
155
 
127
156
  #### Timestamps
128
157
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "./chunk-GHY2WEOK.js";
3
+ } from "./chunk-WIFMLPT5.js";
4
4
 
5
5
  // src/react/utils.ts
6
6
  function pingServer(url) {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  Voices
3
- } from "./chunk-YFN6TFR4.js";
3
+ } from "./chunk-CWIJUBG6.js";
4
4
  import {
5
5
  TTS
6
- } from "./chunk-NWCW6C7H.js";
6
+ } from "./chunk-MUPVAEL7.js";
7
7
  import {
8
8
  Client
9
- } from "./chunk-PISCPZK4.js";
9
+ } from "./chunk-6PWLZAMS.js";
10
10
 
11
11
  // src/lib/index.ts
12
12
  var Cartesia = class extends Client {
@@ -7,7 +7,7 @@ import {
7
7
  __async,
8
8
  __spreadProps,
9
9
  __spreadValues
10
- } from "./chunk-GHY2WEOK.js";
10
+ } from "./chunk-WIFMLPT5.js";
11
11
 
12
12
  // src/lib/client.ts
13
13
  import fetch from "cross-fetch";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Client
3
- } from "./chunk-PISCPZK4.js";
3
+ } from "./chunk-6PWLZAMS.js";
4
4
  import {
5
5
  __async
6
- } from "./chunk-GHY2WEOK.js";
6
+ } from "./chunk-WIFMLPT5.js";
7
7
 
8
8
  // src/voices/index.ts
9
9
  var Voices = class extends Client {
@@ -56,10 +56,18 @@ var Voices = class extends Client {
56
56
  }
57
57
  mix(options) {
58
58
  return __async(this, null, function* () {
59
- const request = options;
60
59
  const response = yield this._fetch("/voices/mix", {
61
60
  method: "POST",
62
- body: JSON.stringify(request)
61
+ body: JSON.stringify(options)
62
+ });
63
+ return response.json();
64
+ });
65
+ }
66
+ localize(options) {
67
+ return __async(this, null, function* () {
68
+ const response = yield this._fetch("/voices/localize", {
69
+ method: "POST",
70
+ body: JSON.stringify(options)
63
71
  });
64
72
  return response.json();
65
73
  });
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Client
3
- } from "./chunk-PISCPZK4.js";
3
+ } from "./chunk-6PWLZAMS.js";
4
4
  import {
5
5
  CARTESIA_VERSION,
6
6
  constructApiUrl
@@ -10,20 +10,19 @@ import {
10
10
  createMessageHandlerForContextId,
11
11
  getEmitteryCallbacks,
12
12
  isSentinel
13
- } from "./chunk-BHY7MNGT.js";
13
+ } from "./chunk-VCZESWYA.js";
14
14
  import {
15
15
  Source
16
- } from "./chunk-6YQ6KDIQ.js";
16
+ } from "./chunk-VVDJR3OA.js";
17
17
  import {
18
18
  __async,
19
- __objRest,
20
19
  __privateAdd,
21
20
  __privateGet,
22
21
  __privateMethod,
23
22
  __privateSet,
24
23
  __spreadProps,
25
24
  __spreadValues
26
- } from "./chunk-GHY2WEOK.js";
25
+ } from "./chunk-WIFMLPT5.js";
27
26
 
28
27
  // src/tts/websocket.ts
29
28
  import Emittery from "emittery";
@@ -58,7 +57,7 @@ var WebSocket = class extends Client {
58
57
  /**
59
58
  * Send a message over the WebSocket to start a stream.
60
59
  *
61
- * @param inputs - Stream options. Defined in the StreamRequest type.
60
+ * @param inputs - Generation parameters. Defined in the StreamRequest type.
62
61
  * @param options - Options for the stream.
63
62
  * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
64
63
  * If set to `0`, the stream will not time out.
@@ -66,9 +65,8 @@ var WebSocket = class extends Client {
66
65
  * @returns An Emittery instance that emits messages from the WebSocket.
67
66
  * @returns An abort function that can be called to cancel the stream.
68
67
  */
69
- send(_a, { timeout = 0 } = {}) {
70
- var inputs = __objRest(_a, []);
71
- var _a2, _b, _c, _d;
68
+ send(inputs, { timeout = 0 } = {}) {
69
+ var _a, _b, _c, _d;
72
70
  if (!__privateGet(this, _isConnected)) {
73
71
  throw new Error("Not connected to WebSocket. Call .connect() first.");
74
72
  }
@@ -82,7 +80,7 @@ var WebSocket = class extends Client {
82
80
  sample_rate: __privateGet(this, _sampleRate)
83
81
  };
84
82
  }
85
- (_a2 = this.socket) == null ? void 0 : _a2.send(
83
+ (_a = this.socket) == null ? void 0 : _a.send(
86
84
  JSON.stringify(__spreadValues({}, inputs))
87
85
  );
88
86
  const emitter = new Emittery();
@@ -152,6 +150,32 @@ var WebSocket = class extends Client {
152
150
  stop: streamCompleteController.abort.bind(streamCompleteController)
153
151
  });
154
152
  }
153
+ /**
154
+ * Continue a stream.
155
+ *
156
+ * @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
157
+ */
158
+ continue(inputs) {
159
+ var _a;
160
+ if (!__privateGet(this, _isConnected)) {
161
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
162
+ }
163
+ if (!inputs.context_id) {
164
+ throw new Error("context_id is required to continue a context.");
165
+ }
166
+ if (!inputs.output_format) {
167
+ inputs.output_format = {
168
+ container: __privateGet(this, _container),
169
+ encoding: __privateGet(this, _encoding),
170
+ sample_rate: __privateGet(this, _sampleRate)
171
+ };
172
+ }
173
+ (_a = this.socket) == null ? void 0 : _a.send(
174
+ JSON.stringify(__spreadValues({
175
+ continue: true
176
+ }, inputs))
177
+ );
178
+ }
155
179
  /**
156
180
  * Authenticate and connect to a Cartesia streaming WebSocket.
157
181
  *
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  playAudioBuffer
3
- } from "./chunk-BHY7MNGT.js";
3
+ } from "./chunk-VCZESWYA.js";
4
4
  import {
5
5
  __async,
6
6
  __privateAdd,
7
7
  __privateGet,
8
8
  __privateMethod,
9
9
  __privateSet
10
- } from "./chunk-GHY2WEOK.js";
10
+ } from "./chunk-WIFMLPT5.js";
11
11
 
12
12
  // src/tts/player.ts
13
13
  var _context, _startNextPlaybackAt, _bufferDuration, _playBuffer, playBuffer_fn;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  WebSocket
3
- } from "./chunk-EUW2435M.js";
3
+ } from "./chunk-L3OMQKWL.js";
4
4
  import {
5
5
  Client
6
- } from "./chunk-PISCPZK4.js";
6
+ } from "./chunk-6PWLZAMS.js";
7
7
 
8
8
  // src/tts/index.ts
9
9
  var TTS = class extends Client {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ENCODING_MAP
3
- } from "./chunk-6YQ6KDIQ.js";
3
+ } from "./chunk-VVDJR3OA.js";
4
4
 
5
5
  // src/tts/utils.ts
6
6
  import base64 from "base64-js";
@@ -4,7 +4,7 @@ import {
4
4
  __privateGet,
5
5
  __privateMethod,
6
6
  __privateSet
7
- } from "./chunk-GHY2WEOK.js";
7
+ } from "./chunk-WIFMLPT5.js";
8
8
 
9
9
  // src/tts/source.ts
10
10
  import Emittery from "emittery";
@@ -106,6 +106,37 @@ var Source = class {
106
106
  return read;
107
107
  });
108
108
  }
109
+ /**
110
+ * Seek in the buffer.
111
+ *
112
+ * @param offset The offset to seek to.
113
+ * @param whence The position to seek from.
114
+ * @returns The new position in the buffer.
115
+ * @throws {Error} If the seek is invalid.
116
+ */
117
+ seek(offset, whence) {
118
+ return __async(this, null, function* () {
119
+ let position = __privateGet(this, _readIndex);
120
+ switch (whence) {
121
+ case "start":
122
+ position = offset;
123
+ break;
124
+ case "current":
125
+ position += offset;
126
+ break;
127
+ case "end":
128
+ position = __privateGet(this, _writeIndex) + offset;
129
+ break;
130
+ default:
131
+ throw new Error(`Invalid seek mode: ${whence}`);
132
+ }
133
+ if (position < 0 || position > __privateGet(this, _writeIndex)) {
134
+ throw new Error("Seek out of bounds");
135
+ }
136
+ __privateSet(this, _readIndex, position);
137
+ return position;
138
+ });
139
+ }
109
140
  /**
110
141
  * Get the number of samples in a given duration.
111
142
  *
@@ -17,18 +17,6 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
20
  var __accessCheck = (obj, member, msg) => {
33
21
  if (!member.has(obj))
34
22
  throw TypeError("Cannot " + msg);
@@ -75,7 +63,6 @@ var __async = (__this, __arguments, generator) => {
75
63
  export {
76
64
  __spreadValues,
77
65
  __spreadProps,
78
- __objRest,
79
66
  __privateGet,
80
67
  __privateAdd,
81
68
  __privateSet,
package/dist/index.cjs CHANGED
@@ -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 });
@@ -253,6 +241,37 @@ var Source = class {
253
241
  return read;
254
242
  });
255
243
  }
244
+ /**
245
+ * Seek in the buffer.
246
+ *
247
+ * @param offset The offset to seek to.
248
+ * @param whence The position to seek from.
249
+ * @returns The new position in the buffer.
250
+ * @throws {Error} If the seek is invalid.
251
+ */
252
+ seek(offset, whence) {
253
+ return __async(this, null, function* () {
254
+ let position = __privateGet(this, _readIndex);
255
+ switch (whence) {
256
+ case "start":
257
+ position = offset;
258
+ break;
259
+ case "current":
260
+ position += offset;
261
+ break;
262
+ case "end":
263
+ position = __privateGet(this, _writeIndex) + offset;
264
+ break;
265
+ default:
266
+ throw new Error(`Invalid seek mode: ${whence}`);
267
+ }
268
+ if (position < 0 || position > __privateGet(this, _writeIndex)) {
269
+ throw new Error("Seek out of bounds");
270
+ }
271
+ __privateSet(this, _readIndex, position);
272
+ return position;
273
+ });
274
+ }
256
275
  /**
257
276
  * Get the number of samples in a given duration.
258
277
  *
@@ -399,7 +418,7 @@ var WebSocket = class extends Client {
399
418
  /**
400
419
  * Send a message over the WebSocket to start a stream.
401
420
  *
402
- * @param inputs - Stream options. Defined in the StreamRequest type.
421
+ * @param inputs - Generation parameters. Defined in the StreamRequest type.
403
422
  * @param options - Options for the stream.
404
423
  * @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
405
424
  * If set to `0`, the stream will not time out.
@@ -407,9 +426,8 @@ var WebSocket = class extends Client {
407
426
  * @returns An Emittery instance that emits messages from the WebSocket.
408
427
  * @returns An abort function that can be called to cancel the stream.
409
428
  */
410
- send(_a, { timeout = 0 } = {}) {
411
- var inputs = __objRest(_a, []);
412
- var _a2, _b, _c, _d;
429
+ send(inputs, { timeout = 0 } = {}) {
430
+ var _a, _b, _c, _d;
413
431
  if (!__privateGet(this, _isConnected)) {
414
432
  throw new Error("Not connected to WebSocket. Call .connect() first.");
415
433
  }
@@ -423,7 +441,7 @@ var WebSocket = class extends Client {
423
441
  sample_rate: __privateGet(this, _sampleRate2)
424
442
  };
425
443
  }
426
- (_a2 = this.socket) == null ? void 0 : _a2.send(
444
+ (_a = this.socket) == null ? void 0 : _a.send(
427
445
  JSON.stringify(__spreadValues({}, inputs))
428
446
  );
429
447
  const emitter = new import_emittery2.default();
@@ -493,6 +511,32 @@ var WebSocket = class extends Client {
493
511
  stop: streamCompleteController.abort.bind(streamCompleteController)
494
512
  });
495
513
  }
514
+ /**
515
+ * Continue a stream.
516
+ *
517
+ * @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
518
+ */
519
+ continue(inputs) {
520
+ var _a;
521
+ if (!__privateGet(this, _isConnected)) {
522
+ throw new Error("Not connected to WebSocket. Call .connect() first.");
523
+ }
524
+ if (!inputs.context_id) {
525
+ throw new Error("context_id is required to continue a context.");
526
+ }
527
+ if (!inputs.output_format) {
528
+ inputs.output_format = {
529
+ container: __privateGet(this, _container2),
530
+ encoding: __privateGet(this, _encoding2),
531
+ sample_rate: __privateGet(this, _sampleRate2)
532
+ };
533
+ }
534
+ (_a = this.socket) == null ? void 0 : _a.send(
535
+ JSON.stringify(__spreadValues({
536
+ continue: true
537
+ }, inputs))
538
+ );
539
+ }
496
540
  /**
497
541
  * Authenticate and connect to a Cartesia streaming WebSocket.
498
542
  *
@@ -642,10 +686,18 @@ var Voices = class extends Client {
642
686
  }
643
687
  mix(options) {
644
688
  return __async(this, null, function* () {
645
- const request = options;
646
689
  const response = yield this._fetch("/voices/mix", {
647
690
  method: "POST",
648
- body: JSON.stringify(request)
691
+ body: JSON.stringify(options)
692
+ });
693
+ return response.json();
694
+ });
695
+ }
696
+ localize(options) {
697
+ return __async(this, null, function* () {
698
+ const response = yield this._fetch("/voices/localize", {
699
+ method: "POST",
700
+ body: JSON.stringify(options)
649
701
  });
650
702
  return response.json();
651
703
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Cartesia, Cartesia as default } from './lib/index.cjs';
2
- export { 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 } from './types/index.cjs';
2
+ export { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, 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';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Cartesia, Cartesia as default } from './lib/index.js';
2
- export { 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 } from './types/index.js';
2
+ export { Chunk, ClientOptions, CloneOptions, CloneResponse, ConnectionEventData, ContinueRequest, CreateVoice, EmitteryCallbacks, Emotion, EmotionControl, Encoding, Intensity, Language, LocalizeOptions, LocalizeResponse, MixVoicesOptions, MixVoicesResponse, Sentinel, SourceEventData, StreamOptions, StreamRequest, TypedArray, UpdateVoice, Voice, 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';
package/dist/index.js CHANGED
@@ -1,22 +1,22 @@
1
1
  import "./chunk-FXPGR372.js";
2
2
  import {
3
3
  Cartesia
4
- } from "./chunk-ZF6HASZT.js";
5
- import "./chunk-YFN6TFR4.js";
6
- import "./chunk-NWCW6C7H.js";
4
+ } from "./chunk-4GEDAGVY.js";
5
+ import "./chunk-CWIJUBG6.js";
6
+ import "./chunk-MUPVAEL7.js";
7
7
  import {
8
8
  WebSocket
9
- } from "./chunk-EUW2435M.js";
10
- import "./chunk-PISCPZK4.js";
9
+ } from "./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";
14
+ } from "./chunk-MNOPO7G6.js";
15
+ import "./chunk-VCZESWYA.js";
16
16
  import {
17
17
  Source
18
- } from "./chunk-6YQ6KDIQ.js";
19
- import "./chunk-GHY2WEOK.js";
18
+ } from "./chunk-VVDJR3OA.js";
19
+ import "./chunk-WIFMLPT5.js";
20
20
  export {
21
21
  Cartesia,
22
22
  Source,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Client
3
- } from "../chunk-PISCPZK4.js";
3
+ } from "../chunk-6PWLZAMS.js";
4
4
  import "../chunk-2BFEKY3F.js";
5
- import "../chunk-GHY2WEOK.js";
5
+ import "../chunk-WIFMLPT5.js";
6
6
  export {
7
7
  Client
8
8
  };
@@ -3,7 +3,7 @@ import {
3
3
  CARTESIA_VERSION,
4
4
  constructApiUrl
5
5
  } from "../chunk-2BFEKY3F.js";
6
- import "../chunk-GHY2WEOK.js";
6
+ import "../chunk-WIFMLPT5.js";
7
7
  export {
8
8
  BASE_URL,
9
9
  CARTESIA_VERSION,