@cartesia/cartesia-js 1.0.0-alpha.2 → 1.0.0-alpha.4

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.
@@ -5,50 +5,50 @@ $ tsup src/ --format cjs,esm --dts
5
5
  CLI Target: es6
6
6
  CJS Build start
7
7
  ESM Build start
8
- CJS dist/index.cjs 21.16 KB
9
- CJS dist/lib/client.cjs 3.51 KB
10
- CJS dist/react/index.cjs 27.38 KB
11
- CJS dist/tts/index.cjs 15.80 KB
12
- CJS dist/types/index.cjs 764.00 B
13
- CJS dist/voices/index.cjs 5.21 KB
14
- CJS dist/lib/constants.cjs 1.61 KB
15
- CJS dist/lib/index.cjs 17.33 KB
16
- CJS dist/react/utils.cjs 1.80 KB
17
- CJS dist/tts/player.cjs 6.66 KB
18
- CJS dist/tts/source.cjs 6.63 KB
19
- CJS dist/tts/utils.cjs 3.87 KB
20
- CJS dist/tts/websocket.cjs 15.49 KB
21
- CJS ⚡️ Build success in 134ms
22
- ESM dist/chunk-FXPGR372.js 0 B
23
- ESM dist/tts/source.js 112.00 B
24
- ESM dist/tts/utils.js 395.00 B
25
- ESM dist/tts/websocket.js 242.00 B
26
- ESM dist/types/index.js 31.00 B
27
- ESM dist/voices/index.js 174.00 B
28
8
  ESM dist/index.js 437.00 B
9
+ ESM dist/chunk-FXPGR372.js 0 B
29
10
  ESM dist/lib/client.js 132.00 B
11
+ ESM dist/react/index.js 6.22 KB
12
+ ESM dist/tts/index.js 261.00 B
30
13
  ESM dist/lib/constants.js 183.00 B
31
14
  ESM dist/lib/index.js 322.00 B
32
- ESM dist/react/index.js 6.22 KB
33
- ESM dist/chunk-T3RG6WV4.js 353.00 B
34
- ESM dist/chunk-WVTITUXX.js 1.35 KB
15
+ ESM dist/chunk-ISRU7PLL.js 353.00 B
16
+ ESM dist/chunk-SGXUEFII.js 1.35 KB
35
17
  ESM dist/react/utils.js 109.00 B
36
18
  ESM dist/chunk-3FL2SNIR.js 337.00 B
37
- ESM dist/tts/index.js 261.00 B
38
- ESM dist/chunk-KWBSQZTY.js 439.00 B
39
- ESM dist/chunk-3F5E46FT.js 5.81 KB
19
+ ESM dist/chunk-VK7LBMVI.js 439.00 B
20
+ ESM dist/chunk-IQAXBRHU.js 5.84 KB
40
21
  ESM dist/chunk-PQ6CIPFW.js 4.02 KB
41
- ESM dist/chunk-JGP5BIUV.js 841.00 B
42
- ESM dist/chunk-XHTDPLFR.js 542.00 B
22
+ ESM dist/chunk-PQ5EVEEH.js 841.00 B
23
+ ESM dist/chunk-2BFEKY3F.js 366.00 B
43
24
  ESM dist/tts/player.js 143.00 B
44
25
  ESM dist/chunk-36JBKJUN.js 3.52 KB
45
26
  ESM dist/chunk-RO7TY474.js 1.95 KB
46
27
  ESM dist/chunk-WIFMLPT5.js 2.27 KB
47
- ESM ⚡️ Build success in 140ms
28
+ ESM dist/types/index.js 31.00 B
29
+ ESM dist/voices/index.js 174.00 B
30
+ ESM dist/tts/source.js 112.00 B
31
+ ESM dist/tts/utils.js 395.00 B
32
+ ESM dist/tts/websocket.js 242.00 B
33
+ ESM ⚡️ Build success in 100ms
34
+ CJS dist/index.cjs 21.01 KB
35
+ CJS dist/lib/client.cjs 3.34 KB
36
+ CJS dist/lib/constants.cjs 1.43 KB
37
+ CJS dist/lib/index.cjs 17.18 KB
38
+ CJS dist/react/index.cjs 27.24 KB
39
+ CJS dist/react/utils.cjs 1.80 KB
40
+ CJS dist/tts/index.cjs 15.66 KB
41
+ CJS dist/tts/player.cjs 6.66 KB
42
+ CJS dist/tts/source.cjs 6.63 KB
43
+ CJS dist/tts/utils.cjs 3.87 KB
44
+ CJS dist/tts/websocket.cjs 15.34 KB
45
+ CJS dist/types/index.cjs 764.00 B
46
+ CJS dist/voices/index.cjs 5.04 KB
47
+ CJS ⚡️ Build success in 105ms
48
48
  DTS Build start
49
- DTS ⚡️ Build success in 8877ms
49
+ DTS ⚡️ Build success in 8445ms
50
50
  DTS dist/index.d.cts 509.00 B
51
- DTS dist/lib/constants.d.cts 247.00 B
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 1018.00 B
54
54
  DTS dist/react/utils.d.cts 240.00 B
@@ -61,7 +61,7 @@ $ tsup src/ --format cjs,esm --dts
61
61
  DTS dist/lib/client.d.cts 267.00 B
62
62
  DTS dist/types/index.d.cts 1.28 KB
63
63
  DTS dist/index.d.ts 501.00 B
64
- DTS dist/lib/constants.d.ts 247.00 B
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 1016.00 B
67
67
  DTS dist/react/utils.d.ts 240.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @cartesia/cartesia-js
2
2
 
3
+ ## 1.0.0-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - c98a0c7: Fix typo in README
8
+
9
+ ## 1.0.0-alpha.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 38af01f: Fix how URLs are constructed, solving WebSocket connection failure
14
+
3
15
  ## 1.0.0-alpha.2
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -126,7 +126,7 @@ import { useTTS } from '@cartesia/cartesia-js/react';
126
126
  function TextToSpeech() {
127
127
  const tts = useTTS({
128
128
  apiKey: "your-api-key",
129
- samplingRate: 44100,
129
+ sampleRate: 44100,
130
130
  })
131
131
 
132
132
  const [text, setText] = useState("");
@@ -134,7 +134,7 @@ function TextToSpeech() {
134
134
  const handlePlay = async () => {
135
135
  // Begin buffering the audio.
136
136
  const response = await tts.buffer({
137
- model: "upbeat-moon",
137
+ model_id: "upbeat-moon",
138
138
  voice: {
139
139
  mode: "embedding",
140
140
  embedding: Array(192).fill(1.0),
@@ -0,0 +1,16 @@
1
+ // src/lib/constants.ts
2
+ var BASE_URL = "https://api.cartesia.ai";
3
+ var CARTESIA_VERSION = "2024-06-10";
4
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
5
+ const url = new URL(path, baseUrl);
6
+ if (websocket) {
7
+ url.protocol = baseUrl.replace(/^http/, "ws");
8
+ }
9
+ return url;
10
+ };
11
+
12
+ export {
13
+ BASE_URL,
14
+ CARTESIA_VERSION,
15
+ constructApiUrl
16
+ };
@@ -3,11 +3,11 @@ import {
3
3
  } from "./chunk-PQ6CIPFW.js";
4
4
  import {
5
5
  Client
6
- } from "./chunk-JGP5BIUV.js";
6
+ } from "./chunk-PQ5EVEEH.js";
7
7
  import {
8
8
  CARTESIA_VERSION,
9
9
  constructApiUrl
10
- } from "./chunk-XHTDPLFR.js";
10
+ } from "./chunk-2BFEKY3F.js";
11
11
  import {
12
12
  base64ToArray,
13
13
  createMessageHandlerForContextId,
@@ -137,12 +137,11 @@ var WebSocket = class extends Client {
137
137
  * @throws {Error} If the WebSocket fails to connect.
138
138
  */
139
139
  connect() {
140
- const url = constructApiUrl(
141
- this.baseUrl,
142
- `/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
143
- "ws"
144
- );
140
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
141
+ websocket: true
142
+ });
145
143
  url.searchParams.set("api_key", this.apiKey);
144
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
146
145
  const emitter = new Emittery();
147
146
  this.socket = new PartySocketWebSocket(url.toString());
148
147
  this.socket.onopen = () => {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  Voices
3
- } from "./chunk-WVTITUXX.js";
3
+ } from "./chunk-SGXUEFII.js";
4
4
  import {
5
5
  TTS
6
- } from "./chunk-KWBSQZTY.js";
6
+ } from "./chunk-VK7LBMVI.js";
7
7
  import {
8
8
  Client
9
- } from "./chunk-JGP5BIUV.js";
9
+ } from "./chunk-PQ5EVEEH.js";
10
10
 
11
11
  // src/lib/index.ts
12
12
  var Cartesia = class extends Client {
@@ -2,7 +2,7 @@ import {
2
2
  BASE_URL,
3
3
  CARTESIA_VERSION,
4
4
  constructApiUrl
5
- } from "./chunk-XHTDPLFR.js";
5
+ } from "./chunk-2BFEKY3F.js";
6
6
  import {
7
7
  __spreadProps,
8
8
  __spreadValues
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Client
3
- } from "./chunk-JGP5BIUV.js";
3
+ } from "./chunk-PQ5EVEEH.js";
4
4
  import {
5
5
  __async
6
6
  } from "./chunk-WIFMLPT5.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  WebSocket
3
- } from "./chunk-3F5E46FT.js";
3
+ } from "./chunk-IQAXBRHU.js";
4
4
  import {
5
5
  Client
6
- } from "./chunk-JGP5BIUV.js";
6
+ } from "./chunk-PQ5EVEEH.js";
7
7
 
8
8
  // src/tts/index.ts
9
9
  var TTS = class extends Client {
package/dist/index.cjs CHANGED
@@ -99,17 +99,14 @@ module.exports = __toCommonJS(src_exports);
99
99
  var import_cross_fetch = __toESM(require("cross-fetch"), 1);
100
100
 
101
101
  // src/lib/constants.ts
102
- var BASE_URL = "https://api.cartesia.ai/";
102
+ var BASE_URL = "https://api.cartesia.ai";
103
103
  var CARTESIA_VERSION = "2024-06-10";
104
- var constructApiUrl = (baseUrl, path, protocol) => {
105
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
106
- if (!protocol) {
107
- return new URL(`${baseUrl}${normalizedPath}`);
104
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
105
+ const url = new URL(path, baseUrl);
106
+ if (websocket) {
107
+ url.protocol = baseUrl.replace(/^http/, "ws");
108
108
  }
109
- if (!["http", "ws"].includes(protocol)) {
110
- throw new Error(`Invalid protocol: ${protocol}`);
111
- }
112
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
109
+ return url;
113
110
  };
114
111
 
115
112
  // src/lib/client.ts
@@ -425,12 +422,11 @@ var WebSocket = class extends Client {
425
422
  * @throws {Error} If the WebSocket fails to connect.
426
423
  */
427
424
  connect() {
428
- const url = constructApiUrl(
429
- this.baseUrl,
430
- `/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
431
- "ws"
432
- );
425
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
426
+ websocket: true
427
+ });
433
428
  url.searchParams.set("api_key", this.apiKey);
429
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
434
430
  const emitter = new import_emittery2.default();
435
431
  this.socket = new import_partysocket.WebSocket(url.toString());
436
432
  this.socket.onopen = () => {
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import "./chunk-FXPGR372.js";
2
2
  import {
3
3
  Cartesia
4
- } from "./chunk-T3RG6WV4.js";
5
- import "./chunk-WVTITUXX.js";
6
- import "./chunk-KWBSQZTY.js";
7
- import "./chunk-3F5E46FT.js";
4
+ } from "./chunk-ISRU7PLL.js";
5
+ import "./chunk-SGXUEFII.js";
6
+ import "./chunk-VK7LBMVI.js";
7
+ import "./chunk-IQAXBRHU.js";
8
8
  import "./chunk-PQ6CIPFW.js";
9
- import "./chunk-JGP5BIUV.js";
10
- import "./chunk-XHTDPLFR.js";
9
+ import "./chunk-PQ5EVEEH.js";
10
+ import "./chunk-2BFEKY3F.js";
11
11
  import {
12
12
  Player
13
13
  } from "./chunk-36JBKJUN.js";
@@ -53,17 +53,14 @@ module.exports = __toCommonJS(client_exports);
53
53
  var import_cross_fetch = __toESM(require("cross-fetch"), 1);
54
54
 
55
55
  // src/lib/constants.ts
56
- var BASE_URL = "https://api.cartesia.ai/";
56
+ var BASE_URL = "https://api.cartesia.ai";
57
57
  var CARTESIA_VERSION = "2024-06-10";
58
- var constructApiUrl = (baseUrl, path, protocol) => {
59
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
60
- if (!protocol) {
61
- return new URL(`${baseUrl}${normalizedPath}`);
58
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
59
+ const url = new URL(path, baseUrl);
60
+ if (websocket) {
61
+ url.protocol = baseUrl.replace(/^http/, "ws");
62
62
  }
63
- if (!["http", "ws"].includes(protocol)) {
64
- throw new Error(`Invalid protocol: ${protocol}`);
65
- }
66
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
63
+ return url;
67
64
  };
68
65
 
69
66
  // src/lib/client.ts
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Client
3
- } from "../chunk-JGP5BIUV.js";
4
- import "../chunk-XHTDPLFR.js";
3
+ } from "../chunk-PQ5EVEEH.js";
4
+ import "../chunk-2BFEKY3F.js";
5
5
  import "../chunk-WIFMLPT5.js";
6
6
  export {
7
7
  Client
@@ -25,17 +25,14 @@ __export(constants_exports, {
25
25
  constructApiUrl: () => constructApiUrl
26
26
  });
27
27
  module.exports = __toCommonJS(constants_exports);
28
- var BASE_URL = "https://api.cartesia.ai/";
28
+ var BASE_URL = "https://api.cartesia.ai";
29
29
  var CARTESIA_VERSION = "2024-06-10";
30
- var constructApiUrl = (baseUrl, path, protocol) => {
31
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
32
- if (!protocol) {
33
- return new URL(`${baseUrl}${normalizedPath}`);
30
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
31
+ const url = new URL(path, baseUrl);
32
+ if (websocket) {
33
+ url.protocol = baseUrl.replace(/^http/, "ws");
34
34
  }
35
- if (!["http", "ws"].includes(protocol)) {
36
- throw new Error(`Invalid protocol: ${protocol}`);
37
- }
38
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
35
+ return url;
39
36
  };
40
37
  // Annotate the CommonJS export names for ESM import in node:
41
38
  0 && (module.exports = {
@@ -1,5 +1,16 @@
1
- declare const BASE_URL = "https://api.cartesia.ai/";
1
+ declare const BASE_URL = "https://api.cartesia.ai";
2
2
  declare const CARTESIA_VERSION = "2024-06-10";
3
- declare const constructApiUrl: (baseUrl: string, path: string, protocol?: string) => URL;
3
+ /**
4
+ * Construct a URL for the Cartesia API.
5
+ *
6
+ * @param baseUrl The base URL for the API.
7
+ * @param path The path to append to the base URL.
8
+ * @param options Options for the URL.
9
+ * @param options.websocket Whether to use the WebSocket protocol.
10
+ * @returns A URL object.
11
+ */
12
+ declare const constructApiUrl: (baseUrl: string, path: string, { websocket }?: {
13
+ websocket?: boolean | undefined;
14
+ }) => URL;
4
15
 
5
16
  export { BASE_URL, CARTESIA_VERSION, constructApiUrl };
@@ -1,5 +1,16 @@
1
- declare const BASE_URL = "https://api.cartesia.ai/";
1
+ declare const BASE_URL = "https://api.cartesia.ai";
2
2
  declare const CARTESIA_VERSION = "2024-06-10";
3
- declare const constructApiUrl: (baseUrl: string, path: string, protocol?: string) => URL;
3
+ /**
4
+ * Construct a URL for the Cartesia API.
5
+ *
6
+ * @param baseUrl The base URL for the API.
7
+ * @param path The path to append to the base URL.
8
+ * @param options Options for the URL.
9
+ * @param options.websocket Whether to use the WebSocket protocol.
10
+ * @returns A URL object.
11
+ */
12
+ declare const constructApiUrl: (baseUrl: string, path: string, { websocket }?: {
13
+ websocket?: boolean | undefined;
14
+ }) => URL;
4
15
 
5
16
  export { BASE_URL, CARTESIA_VERSION, constructApiUrl };
@@ -2,7 +2,7 @@ import {
2
2
  BASE_URL,
3
3
  CARTESIA_VERSION,
4
4
  constructApiUrl
5
- } from "../chunk-XHTDPLFR.js";
5
+ } from "../chunk-2BFEKY3F.js";
6
6
  import "../chunk-WIFMLPT5.js";
7
7
  export {
8
8
  BASE_URL,
@@ -97,17 +97,14 @@ module.exports = __toCommonJS(lib_exports);
97
97
  var import_cross_fetch = __toESM(require("cross-fetch"), 1);
98
98
 
99
99
  // src/lib/constants.ts
100
- var BASE_URL = "https://api.cartesia.ai/";
100
+ var BASE_URL = "https://api.cartesia.ai";
101
101
  var CARTESIA_VERSION = "2024-06-10";
102
- var constructApiUrl = (baseUrl, path, protocol) => {
103
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
104
- if (!protocol) {
105
- return new URL(`${baseUrl}${normalizedPath}`);
102
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
103
+ const url = new URL(path, baseUrl);
104
+ if (websocket) {
105
+ url.protocol = baseUrl.replace(/^http/, "ws");
106
106
  }
107
- if (!["http", "ws"].includes(protocol)) {
108
- throw new Error(`Invalid protocol: ${protocol}`);
109
- }
110
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
107
+ return url;
111
108
  };
112
109
 
113
110
  // src/lib/client.ts
@@ -410,12 +407,11 @@ var WebSocket = class extends Client {
410
407
  * @throws {Error} If the WebSocket fails to connect.
411
408
  */
412
409
  connect() {
413
- const url = constructApiUrl(
414
- this.baseUrl,
415
- `/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
416
- "ws"
417
- );
410
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
411
+ websocket: true
412
+ });
418
413
  url.searchParams.set("api_key", this.apiKey);
414
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
419
415
  const emitter = new import_emittery2.default();
420
416
  this.socket = new import_partysocket.WebSocket(url.toString());
421
417
  this.socket.onopen = () => {
package/dist/lib/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  Cartesia
3
- } from "../chunk-T3RG6WV4.js";
4
- import "../chunk-WVTITUXX.js";
5
- import "../chunk-KWBSQZTY.js";
6
- import "../chunk-3F5E46FT.js";
3
+ } from "../chunk-ISRU7PLL.js";
4
+ import "../chunk-SGXUEFII.js";
5
+ import "../chunk-VK7LBMVI.js";
6
+ import "../chunk-IQAXBRHU.js";
7
7
  import "../chunk-PQ6CIPFW.js";
8
- import "../chunk-JGP5BIUV.js";
9
- import "../chunk-XHTDPLFR.js";
8
+ import "../chunk-PQ5EVEEH.js";
9
+ import "../chunk-2BFEKY3F.js";
10
10
  import "../chunk-RO7TY474.js";
11
11
  import "../chunk-WIFMLPT5.js";
12
12
  export {
@@ -98,17 +98,14 @@ var import_react = require("react");
98
98
  var import_cross_fetch = __toESM(require("cross-fetch"), 1);
99
99
 
100
100
  // src/lib/constants.ts
101
- var BASE_URL = "https://api.cartesia.ai/";
101
+ var BASE_URL = "https://api.cartesia.ai";
102
102
  var CARTESIA_VERSION = "2024-06-10";
103
- var constructApiUrl = (baseUrl, path, protocol) => {
104
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
105
- if (!protocol) {
106
- return new URL(`${baseUrl}${normalizedPath}`);
103
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
104
+ const url = new URL(path, baseUrl);
105
+ if (websocket) {
106
+ url.protocol = baseUrl.replace(/^http/, "ws");
107
107
  }
108
- if (!["http", "ws"].includes(protocol)) {
109
- throw new Error(`Invalid protocol: ${protocol}`);
110
- }
111
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
108
+ return url;
112
109
  };
113
110
 
114
111
  // src/lib/client.ts
@@ -424,12 +421,11 @@ var WebSocket = class extends Client {
424
421
  * @throws {Error} If the WebSocket fails to connect.
425
422
  */
426
423
  connect() {
427
- const url = constructApiUrl(
428
- this.baseUrl,
429
- `/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
430
- "ws"
431
- );
424
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
425
+ websocket: true
426
+ });
432
427
  url.searchParams.set("api_key", this.apiKey);
428
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
433
429
  const emitter = new import_emittery2.default();
434
430
  this.socket = new import_partysocket.WebSocket(url.toString());
435
431
  this.socket.onopen = () => {
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  Cartesia
3
- } from "../chunk-T3RG6WV4.js";
4
- import "../chunk-WVTITUXX.js";
3
+ } from "../chunk-ISRU7PLL.js";
4
+ import "../chunk-SGXUEFII.js";
5
5
  import {
6
6
  pingServer
7
7
  } from "../chunk-3FL2SNIR.js";
8
- import "../chunk-KWBSQZTY.js";
9
- import "../chunk-3F5E46FT.js";
8
+ import "../chunk-VK7LBMVI.js";
9
+ import "../chunk-IQAXBRHU.js";
10
10
  import "../chunk-PQ6CIPFW.js";
11
- import "../chunk-JGP5BIUV.js";
12
- import "../chunk-XHTDPLFR.js";
11
+ import "../chunk-PQ5EVEEH.js";
12
+ import "../chunk-2BFEKY3F.js";
13
13
  import {
14
14
  Player
15
15
  } from "../chunk-36JBKJUN.js";
@@ -97,17 +97,14 @@ module.exports = __toCommonJS(tts_exports);
97
97
  var import_cross_fetch = __toESM(require("cross-fetch"), 1);
98
98
 
99
99
  // src/lib/constants.ts
100
- var BASE_URL = "https://api.cartesia.ai/";
100
+ var BASE_URL = "https://api.cartesia.ai";
101
101
  var CARTESIA_VERSION = "2024-06-10";
102
- var constructApiUrl = (baseUrl, path, protocol) => {
103
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
104
- if (!protocol) {
105
- return new URL(`${baseUrl}${normalizedPath}`);
102
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
103
+ const url = new URL(path, baseUrl);
104
+ if (websocket) {
105
+ url.protocol = baseUrl.replace(/^http/, "ws");
106
106
  }
107
- if (!["http", "ws"].includes(protocol)) {
108
- throw new Error(`Invalid protocol: ${protocol}`);
109
- }
110
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
107
+ return url;
111
108
  };
112
109
 
113
110
  // src/lib/client.ts
@@ -410,12 +407,11 @@ var WebSocket = class extends Client {
410
407
  * @throws {Error} If the WebSocket fails to connect.
411
408
  */
412
409
  connect() {
413
- const url = constructApiUrl(
414
- this.baseUrl,
415
- `/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
416
- "ws"
417
- );
410
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
411
+ websocket: true
412
+ });
418
413
  url.searchParams.set("api_key", this.apiKey);
414
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
419
415
  const emitter = new import_emittery2.default();
420
416
  this.socket = new import_partysocket.WebSocket(url.toString());
421
417
  this.socket.onopen = () => {
package/dist/tts/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  TTS
3
- } from "../chunk-KWBSQZTY.js";
4
- import "../chunk-3F5E46FT.js";
3
+ } from "../chunk-VK7LBMVI.js";
4
+ import "../chunk-IQAXBRHU.js";
5
5
  import "../chunk-PQ6CIPFW.js";
6
- import "../chunk-JGP5BIUV.js";
7
- import "../chunk-XHTDPLFR.js";
6
+ import "../chunk-PQ5EVEEH.js";
7
+ import "../chunk-2BFEKY3F.js";
8
8
  import "../chunk-RO7TY474.js";
9
9
  import "../chunk-WIFMLPT5.js";
10
10
  export {
@@ -100,17 +100,14 @@ var import_partysocket = require("partysocket");
100
100
  var import_cross_fetch = __toESM(require("cross-fetch"), 1);
101
101
 
102
102
  // src/lib/constants.ts
103
- var BASE_URL = "https://api.cartesia.ai/";
103
+ var BASE_URL = "https://api.cartesia.ai";
104
104
  var CARTESIA_VERSION = "2024-06-10";
105
- var constructApiUrl = (baseUrl, path, protocol) => {
106
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
107
- if (!protocol) {
108
- return new URL(`${baseUrl}${normalizedPath}`);
105
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
106
+ const url = new URL(path, baseUrl);
107
+ if (websocket) {
108
+ url.protocol = baseUrl.replace(/^http/, "ws");
109
109
  }
110
- if (!["http", "ws"].includes(protocol)) {
111
- throw new Error(`Invalid protocol: ${protocol}`);
112
- }
113
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
110
+ return url;
114
111
  };
115
112
 
116
113
  // src/lib/client.ts
@@ -408,12 +405,11 @@ var WebSocket = class extends Client {
408
405
  * @throws {Error} If the WebSocket fails to connect.
409
406
  */
410
407
  connect() {
411
- const url = constructApiUrl(
412
- this.baseUrl,
413
- `/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
414
- "ws"
415
- );
408
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
409
+ websocket: true
410
+ });
416
411
  url.searchParams.set("api_key", this.apiKey);
412
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
417
413
  const emitter = new import_emittery2.default();
418
414
  this.socket = new import_partysocket.WebSocket(url.toString());
419
415
  this.socket.onopen = () => {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  WebSocket
3
- } from "../chunk-3F5E46FT.js";
3
+ } from "../chunk-IQAXBRHU.js";
4
4
  import "../chunk-PQ6CIPFW.js";
5
- import "../chunk-JGP5BIUV.js";
6
- import "../chunk-XHTDPLFR.js";
5
+ import "../chunk-PQ5EVEEH.js";
6
+ import "../chunk-2BFEKY3F.js";
7
7
  import "../chunk-RO7TY474.js";
8
8
  import "../chunk-WIFMLPT5.js";
9
9
  export {
@@ -75,17 +75,14 @@ module.exports = __toCommonJS(voices_exports);
75
75
  var import_cross_fetch = __toESM(require("cross-fetch"), 1);
76
76
 
77
77
  // src/lib/constants.ts
78
- var BASE_URL = "https://api.cartesia.ai/";
78
+ var BASE_URL = "https://api.cartesia.ai";
79
79
  var CARTESIA_VERSION = "2024-06-10";
80
- var constructApiUrl = (baseUrl, path, protocol) => {
81
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
82
- if (!protocol) {
83
- return new URL(`${baseUrl}${normalizedPath}`);
80
+ var constructApiUrl = (baseUrl, path, { websocket = false } = {}) => {
81
+ const url = new URL(path, baseUrl);
82
+ if (websocket) {
83
+ url.protocol = baseUrl.replace(/^http/, "ws");
84
84
  }
85
- if (!["http", "ws"].includes(protocol)) {
86
- throw new Error(`Invalid protocol: ${protocol}`);
87
- }
88
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
85
+ return url;
89
86
  };
90
87
 
91
88
  // src/lib/client.ts
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Voices
3
- } from "../chunk-WVTITUXX.js";
4
- import "../chunk-JGP5BIUV.js";
5
- import "../chunk-XHTDPLFR.js";
3
+ } from "../chunk-SGXUEFII.js";
4
+ import "../chunk-PQ5EVEEH.js";
5
+ import "../chunk-2BFEKY3F.js";
6
6
  import "../chunk-WIFMLPT5.js";
7
7
  export {
8
8
  Voices as default
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Cartesia",
5
5
  "url": "https://cartesia.ai"
6
6
  },
7
- "version": "1.0.0-alpha.2",
7
+ "version": "1.0.0-alpha.4",
8
8
  "description": "Client for the Cartesia API.",
9
9
  "type": "module",
10
10
  "module": "./dist/index.js",
@@ -1,17 +1,25 @@
1
- export const BASE_URL = "https://api.cartesia.ai/";
1
+ export const BASE_URL = "https://api.cartesia.ai";
2
2
  export const CARTESIA_VERSION = "2024-06-10";
3
3
 
4
+ /**
5
+ * Construct a URL for the Cartesia API.
6
+ *
7
+ * @param baseUrl The base URL for the API.
8
+ * @param path The path to append to the base URL.
9
+ * @param options Options for the URL.
10
+ * @param options.websocket Whether to use the WebSocket protocol.
11
+ * @returns A URL object.
12
+ */
4
13
  export const constructApiUrl = (
5
14
  baseUrl: string,
6
15
  path: string,
7
- protocol?: string,
16
+ { websocket = false } = {},
8
17
  ) => {
9
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
10
- if (!protocol) {
11
- return new URL(`${baseUrl}${normalizedPath}`);
18
+ const url = new URL(path, baseUrl);
19
+ if (websocket) {
20
+ // Using find-and-replace ensures that if the base URL uses TLS, the
21
+ // new protocol does too.
22
+ url.protocol = baseUrl.replace(/^http/, "ws");
12
23
  }
13
- if (!["http", "ws"].includes(protocol)) {
14
- throw new Error(`Invalid protocol: ${protocol}`);
15
- }
16
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
24
+ return url;
17
25
  };
@@ -150,12 +150,11 @@ export default class WebSocket extends Client {
150
150
  * @throws {Error} If the WebSocket fails to connect.
151
151
  */
152
152
  connect() {
153
- const url = constructApiUrl(
154
- this.baseUrl,
155
- `/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
156
- "ws",
157
- );
153
+ const url = constructApiUrl(this.baseUrl, "/tts/websocket", {
154
+ websocket: true,
155
+ });
158
156
  url.searchParams.set("api_key", this.apiKey);
157
+ url.searchParams.set("cartesia_version", CARTESIA_VERSION);
159
158
  const emitter = new Emittery<ConnectionEventData>();
160
159
  this.socket = new PartySocketWebSocket(url.toString());
161
160
  this.socket.onopen = () => {
@@ -1,19 +0,0 @@
1
- // src/lib/constants.ts
2
- var BASE_URL = "https://api.cartesia.ai/";
3
- var CARTESIA_VERSION = "2024-06-10";
4
- var constructApiUrl = (baseUrl, path, protocol) => {
5
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
6
- if (!protocol) {
7
- return new URL(`${baseUrl}${normalizedPath}`);
8
- }
9
- if (!["http", "ws"].includes(protocol)) {
10
- throw new Error(`Invalid protocol: ${protocol}`);
11
- }
12
- return new URL(`${baseUrl.replace(/^http/, protocol)}${normalizedPath}`);
13
- };
14
-
15
- export {
16
- BASE_URL,
17
- CARTESIA_VERSION,
18
- constructApiUrl
19
- };