@cartesia/cartesia-js 1.0.0-alpha.1 → 1.0.0-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.
- package/.turbo/turbo-build.log +36 -36
- package/CHANGELOG.md +6 -0
- package/dist/{chunk-WE63M7PJ.js → chunk-36JBKJUN.js} +2 -2
- package/dist/{chunk-NDNN326Q.js → chunk-3F5E46FT.js} +10 -5
- package/dist/{chunk-BCQ63627.js → chunk-JGP5BIUV.js} +4 -2
- package/dist/{chunk-4RMSIQLG.js → chunk-KWBSQZTY.js} +2 -2
- package/dist/{chunk-JOHSCOLW.js → chunk-PQ6CIPFW.js} +20 -6
- package/dist/{chunk-LYPTISWL.js → chunk-RO7TY474.js} +13 -7
- package/dist/{chunk-X7SJMF2R.js → chunk-T3RG6WV4.js} +3 -3
- package/dist/{chunk-WBK6LLXX.js → chunk-WVTITUXX.js} +1 -1
- package/dist/{chunk-3GBZUGUD.js → chunk-XHTDPLFR.js} +3 -1
- package/dist/index.cjs +43 -17
- package/dist/index.js +9 -9
- package/dist/lib/client.cjs +4 -2
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.cjs +4 -1
- package/dist/lib/constants.d.cts +3 -2
- package/dist/lib/constants.d.ts +3 -2
- package/dist/lib/constants.js +3 -1
- package/dist/lib/index.cjs +42 -16
- package/dist/lib/index.js +8 -8
- package/dist/react/index.cjs +59 -25
- package/dist/react/index.js +25 -17
- package/dist/tts/index.cjs +42 -16
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.cjs +1 -1
- package/dist/tts/player.js +2 -2
- package/dist/tts/source.cjs +20 -6
- package/dist/tts/source.js +1 -1
- package/dist/tts/utils.cjs +13 -7
- package/dist/tts/utils.js +1 -1
- package/dist/tts/websocket.cjs +42 -16
- package/dist/tts/websocket.js +5 -5
- package/dist/voices/index.cjs +4 -2
- package/dist/voices/index.js +3 -3
- package/package.json +1 -1
- package/src/lib/client.ts +3 -2
- package/src/lib/constants.ts +2 -1
- package/src/react/index.ts +20 -8
- package/src/tts/player.ts +2 -1
- package/src/tts/source.ts +22 -5
- package/src/tts/utils.ts +15 -7
- package/src/tts/websocket.ts +6 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -5,50 +5,50 @@ $ tsup src/ --format cjs,esm --dts
|
|
|
5
5
|
[34mCLI[39m Target: es6
|
|
6
6
|
[34mCJS[39m Build start
|
|
7
7
|
[34mESM[39m Build start
|
|
8
|
-
[
|
|
8
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m21.16 KB[39m
|
|
9
|
+
[32mCJS[39m [1mdist/lib/client.cjs [22m[32m3.51 KB[39m
|
|
10
|
+
[32mCJS[39m [1mdist/react/index.cjs [22m[32m27.38 KB[39m
|
|
11
|
+
[32mCJS[39m [1mdist/tts/index.cjs [22m[32m15.80 KB[39m
|
|
12
|
+
[32mCJS[39m [1mdist/types/index.cjs [22m[32m764.00 B[39m
|
|
13
|
+
[32mCJS[39m [1mdist/voices/index.cjs [22m[32m5.21 KB[39m
|
|
14
|
+
[32mCJS[39m [1mdist/lib/constants.cjs [22m[32m1.61 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/lib/index.cjs [22m[32m17.33 KB[39m
|
|
16
|
+
[32mCJS[39m [1mdist/react/utils.cjs [22m[32m1.80 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/tts/player.cjs [22m[32m6.66 KB[39m
|
|
18
|
+
[32mCJS[39m [1mdist/tts/source.cjs [22m[32m6.63 KB[39m
|
|
19
|
+
[32mCJS[39m [1mdist/tts/utils.cjs [22m[32m3.87 KB[39m
|
|
20
|
+
[32mCJS[39m [1mdist/tts/websocket.cjs [22m[32m15.49 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 134ms
|
|
9
22
|
[32mESM[39m [1mdist/chunk-FXPGR372.js [22m[32m0 B[39m
|
|
23
|
+
[32mESM[39m [1mdist/tts/source.js [22m[32m112.00 B[39m
|
|
24
|
+
[32mESM[39m [1mdist/tts/utils.js [22m[32m395.00 B[39m
|
|
25
|
+
[32mESM[39m [1mdist/tts/websocket.js [22m[32m242.00 B[39m
|
|
26
|
+
[32mESM[39m [1mdist/types/index.js [22m[32m31.00 B[39m
|
|
27
|
+
[32mESM[39m [1mdist/voices/index.js [22m[32m174.00 B[39m
|
|
28
|
+
[32mESM[39m [1mdist/index.js [22m[32m437.00 B[39m
|
|
10
29
|
[32mESM[39m [1mdist/lib/client.js [22m[32m132.00 B[39m
|
|
11
|
-
[32mESM[39m [1mdist/
|
|
12
|
-
[32mESM[39m [1mdist/tts/index.js [22m[32m261.00 B[39m
|
|
13
|
-
[32mESM[39m [1mdist/lib/constants.js [22m[32m143.00 B[39m
|
|
30
|
+
[32mESM[39m [1mdist/lib/constants.js [22m[32m183.00 B[39m
|
|
14
31
|
[32mESM[39m [1mdist/lib/index.js [22m[32m322.00 B[39m
|
|
15
|
-
[32mESM[39m [1mdist/
|
|
16
|
-
[32mESM[39m [1mdist/chunk-
|
|
32
|
+
[32mESM[39m [1mdist/react/index.js [22m[32m6.22 KB[39m
|
|
33
|
+
[32mESM[39m [1mdist/chunk-T3RG6WV4.js [22m[32m353.00 B[39m
|
|
34
|
+
[32mESM[39m [1mdist/chunk-WVTITUXX.js [22m[32m1.35 KB[39m
|
|
17
35
|
[32mESM[39m [1mdist/react/utils.js [22m[32m109.00 B[39m
|
|
18
36
|
[32mESM[39m [1mdist/chunk-3FL2SNIR.js [22m[32m337.00 B[39m
|
|
19
|
-
[32mESM[39m [1mdist/
|
|
20
|
-
[32mESM[39m [1mdist/chunk-
|
|
21
|
-
[32mESM[39m [1mdist/chunk-
|
|
22
|
-
[32mESM[39m [1mdist/chunk-
|
|
23
|
-
[32mESM[39m [1mdist/chunk-
|
|
37
|
+
[32mESM[39m [1mdist/tts/index.js [22m[32m261.00 B[39m
|
|
38
|
+
[32mESM[39m [1mdist/chunk-KWBSQZTY.js [22m[32m439.00 B[39m
|
|
39
|
+
[32mESM[39m [1mdist/chunk-3F5E46FT.js [22m[32m5.81 KB[39m
|
|
40
|
+
[32mESM[39m [1mdist/chunk-PQ6CIPFW.js [22m[32m4.02 KB[39m
|
|
41
|
+
[32mESM[39m [1mdist/chunk-JGP5BIUV.js [22m[32m841.00 B[39m
|
|
42
|
+
[32mESM[39m [1mdist/chunk-XHTDPLFR.js [22m[32m542.00 B[39m
|
|
24
43
|
[32mESM[39m [1mdist/tts/player.js [22m[32m143.00 B[39m
|
|
25
|
-
[32mESM[39m [1mdist/chunk-
|
|
26
|
-
[32mESM[39m [1mdist/chunk-
|
|
44
|
+
[32mESM[39m [1mdist/chunk-36JBKJUN.js [22m[32m3.52 KB[39m
|
|
45
|
+
[32mESM[39m [1mdist/chunk-RO7TY474.js [22m[32m1.95 KB[39m
|
|
27
46
|
[32mESM[39m [1mdist/chunk-WIFMLPT5.js [22m[32m2.27 KB[39m
|
|
28
|
-
[32mESM[39m
|
|
29
|
-
[32mESM[39m [1mdist/voices/index.js [22m[32m174.00 B[39m
|
|
30
|
-
[32mESM[39m [1mdist/tts/source.js [22m[32m112.00 B[39m
|
|
31
|
-
[32mESM[39m [1mdist/tts/utils.js [22m[32m395.00 B[39m
|
|
32
|
-
[32mESM[39m [1mdist/tts/websocket.js [22m[32m242.00 B[39m
|
|
33
|
-
[32mESM[39m ⚡️ Build success in 115ms
|
|
34
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m20.24 KB[39m
|
|
35
|
-
[32mCJS[39m [1mdist/lib/client.cjs [22m[32m3.43 KB[39m
|
|
36
|
-
[32mCJS[39m [1mdist/lib/constants.cjs [22m[32m1.51 KB[39m
|
|
37
|
-
[32mCJS[39m [1mdist/lib/index.cjs [22m[32m16.42 KB[39m
|
|
38
|
-
[32mCJS[39m [1mdist/react/index.cjs [22m[32m26.25 KB[39m
|
|
39
|
-
[32mCJS[39m [1mdist/react/utils.cjs [22m[32m1.80 KB[39m
|
|
40
|
-
[32mCJS[39m [1mdist/tts/index.cjs [22m[32m14.89 KB[39m
|
|
41
|
-
[32mCJS[39m [1mdist/tts/player.cjs [22m[32m6.66 KB[39m
|
|
42
|
-
[32mCJS[39m [1mdist/tts/source.cjs [22m[32m5.99 KB[39m
|
|
43
|
-
[32mCJS[39m [1mdist/tts/utils.cjs [22m[32m3.73 KB[39m
|
|
44
|
-
[32mCJS[39m [1mdist/tts/websocket.cjs [22m[32m14.58 KB[39m
|
|
45
|
-
[32mCJS[39m [1mdist/types/index.cjs [22m[32m764.00 B[39m
|
|
46
|
-
[32mCJS[39m [1mdist/voices/index.cjs [22m[32m5.13 KB[39m
|
|
47
|
-
[32mCJS[39m ⚡️ Build success in 117ms
|
|
47
|
+
[32mESM[39m ⚡️ Build success in 140ms
|
|
48
48
|
[34mDTS[39m Build start
|
|
49
|
-
[32mDTS[39m ⚡️ Build success in
|
|
49
|
+
[32mDTS[39m ⚡️ Build success in 8877ms
|
|
50
50
|
[32mDTS[39m [1mdist/index.d.cts [22m[32m509.00 B[39m
|
|
51
|
-
[32mDTS[39m [1mdist/lib/constants.d.cts [22m[
|
|
51
|
+
[32mDTS[39m [1mdist/lib/constants.d.cts [22m[32m247.00 B[39m
|
|
52
52
|
[32mDTS[39m [1mdist/lib/index.d.cts [22m[32m410.00 B[39m
|
|
53
53
|
[32mDTS[39m [1mdist/react/index.d.cts [22m[32m1018.00 B[39m
|
|
54
54
|
[32mDTS[39m [1mdist/react/utils.d.cts [22m[32m240.00 B[39m
|
|
@@ -61,7 +61,7 @@ $ tsup src/ --format cjs,esm --dts
|
|
|
61
61
|
[32mDTS[39m [1mdist/lib/client.d.cts [22m[32m267.00 B[39m
|
|
62
62
|
[32mDTS[39m [1mdist/types/index.d.cts [22m[32m1.28 KB[39m
|
|
63
63
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m501.00 B[39m
|
|
64
|
-
[32mDTS[39m [1mdist/lib/constants.d.ts [22m[
|
|
64
|
+
[32mDTS[39m [1mdist/lib/constants.d.ts [22m[32m247.00 B[39m
|
|
65
65
|
[32mDTS[39m [1mdist/lib/index.d.ts [22m[32m404.00 B[39m
|
|
66
66
|
[32mDTS[39m [1mdist/react/index.d.ts [22m[32m1016.00 B[39m
|
|
67
67
|
[32mDTS[39m [1mdist/react/utils.d.ts [22m[32m240.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
playAudioBuffer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-RO7TY474.js";
|
|
4
4
|
import {
|
|
5
5
|
__async,
|
|
6
6
|
__privateAdd,
|
|
@@ -43,7 +43,7 @@ var Player = class {
|
|
|
43
43
|
const plays = [];
|
|
44
44
|
while (true) {
|
|
45
45
|
const read = yield source.read(buffer);
|
|
46
|
-
const playableAudio = buffer.
|
|
46
|
+
const playableAudio = buffer.subarray(0, read);
|
|
47
47
|
plays.push(__privateMethod(this, _playBuffer, playBuffer_fn).call(this, playableAudio, source.sampleRate));
|
|
48
48
|
if (read < buffer.length) {
|
|
49
49
|
yield __privateGet(this, _emitter).emit("finish");
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Source
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PQ6CIPFW.js";
|
|
4
4
|
import {
|
|
5
5
|
Client
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-JGP5BIUV.js";
|
|
7
7
|
import {
|
|
8
|
+
CARTESIA_VERSION,
|
|
8
9
|
constructApiUrl
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-XHTDPLFR.js";
|
|
10
11
|
import {
|
|
11
12
|
base64ToArray,
|
|
12
13
|
createMessageHandlerForContextId,
|
|
13
14
|
getEmitteryCallbacks,
|
|
14
15
|
isSentinel
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-RO7TY474.js";
|
|
16
17
|
import {
|
|
17
18
|
__async,
|
|
18
19
|
__privateAdd,
|
|
@@ -136,7 +137,11 @@ var WebSocket = class extends Client {
|
|
|
136
137
|
* @throws {Error} If the WebSocket fails to connect.
|
|
137
138
|
*/
|
|
138
139
|
connect() {
|
|
139
|
-
const url = constructApiUrl(
|
|
140
|
+
const url = constructApiUrl(
|
|
141
|
+
this.baseUrl,
|
|
142
|
+
`/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
|
|
143
|
+
"ws"
|
|
144
|
+
);
|
|
140
145
|
url.searchParams.set("api_key", this.apiKey);
|
|
141
146
|
const emitter = new Emittery();
|
|
142
147
|
this.socket = new PartySocketWebSocket(url.toString());
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BASE_URL,
|
|
3
|
+
CARTESIA_VERSION,
|
|
3
4
|
constructApiUrl
|
|
4
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-XHTDPLFR.js";
|
|
5
6
|
import {
|
|
6
7
|
__spreadProps,
|
|
7
8
|
__spreadValues
|
|
@@ -21,7 +22,8 @@ var Client = class {
|
|
|
21
22
|
const url = constructApiUrl(this.baseUrl, path);
|
|
22
23
|
return fetch(url.toString(), __spreadProps(__spreadValues({}, options), {
|
|
23
24
|
headers: __spreadValues({
|
|
24
|
-
"X-API-
|
|
25
|
+
"X-API-Key": this.apiKey,
|
|
26
|
+
"Cartesia-Version": CARTESIA_VERSION
|
|
25
27
|
}, options.headers)
|
|
26
28
|
}));
|
|
27
29
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
// src/tts/source.ts
|
|
9
9
|
import Emittery from "emittery";
|
|
10
|
-
var _emitter, _buffer, _readIndex, _closed, _sampleRate;
|
|
10
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate;
|
|
11
11
|
var Source = class {
|
|
12
12
|
/**
|
|
13
13
|
* Create a new Source.
|
|
@@ -17,8 +17,9 @@ var Source = class {
|
|
|
17
17
|
*/
|
|
18
18
|
constructor({ sampleRate }) {
|
|
19
19
|
__privateAdd(this, _emitter, new Emittery());
|
|
20
|
-
__privateAdd(this, _buffer,
|
|
20
|
+
__privateAdd(this, _buffer, void 0);
|
|
21
21
|
__privateAdd(this, _readIndex, 0);
|
|
22
|
+
__privateAdd(this, _writeIndex, 0);
|
|
22
23
|
__privateAdd(this, _closed, false);
|
|
23
24
|
__privateAdd(this, _sampleRate, void 0);
|
|
24
25
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
@@ -26,6 +27,7 @@ var Source = class {
|
|
|
26
27
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
27
28
|
this.off = __privateGet(this, _emitter).off.bind(__privateGet(this, _emitter));
|
|
28
29
|
__privateSet(this, _sampleRate, sampleRate);
|
|
30
|
+
__privateSet(this, _buffer, new Float32Array(1024));
|
|
29
31
|
}
|
|
30
32
|
get sampleRate() {
|
|
31
33
|
return __privateGet(this, _sampleRate);
|
|
@@ -37,7 +39,18 @@ var Source = class {
|
|
|
37
39
|
*/
|
|
38
40
|
enqueue(src) {
|
|
39
41
|
return __async(this, null, function* () {
|
|
40
|
-
|
|
42
|
+
const requiredCapacity = __privateGet(this, _writeIndex) + src.length;
|
|
43
|
+
if (requiredCapacity > __privateGet(this, _buffer).length) {
|
|
44
|
+
let newCapacity = __privateGet(this, _buffer).length;
|
|
45
|
+
while (newCapacity < requiredCapacity) {
|
|
46
|
+
newCapacity *= 2;
|
|
47
|
+
}
|
|
48
|
+
const newBuffer = new Float32Array(newCapacity);
|
|
49
|
+
newBuffer.set(__privateGet(this, _buffer));
|
|
50
|
+
__privateSet(this, _buffer, newBuffer);
|
|
51
|
+
}
|
|
52
|
+
__privateGet(this, _buffer).set(src, __privateGet(this, _writeIndex));
|
|
53
|
+
__privateSet(this, _writeIndex, __privateGet(this, _writeIndex) + src.length);
|
|
41
54
|
yield __privateGet(this, _emitter).emit("enqueue");
|
|
42
55
|
});
|
|
43
56
|
}
|
|
@@ -51,7 +64,7 @@ var Source = class {
|
|
|
51
64
|
read(dst) {
|
|
52
65
|
return __async(this, null, function* () {
|
|
53
66
|
const targetReadIndex = __privateGet(this, _readIndex) + dst.length;
|
|
54
|
-
while (!__privateGet(this, _closed) && targetReadIndex > __privateGet(this,
|
|
67
|
+
while (!__privateGet(this, _closed) && targetReadIndex > __privateGet(this, _writeIndex)) {
|
|
55
68
|
yield __privateGet(this, _emitter).emit("wait");
|
|
56
69
|
yield Promise.race([
|
|
57
70
|
__privateGet(this, _emitter).once("enqueue"),
|
|
@@ -59,8 +72,8 @@ var Source = class {
|
|
|
59
72
|
]);
|
|
60
73
|
yield __privateGet(this, _emitter).emit("read");
|
|
61
74
|
}
|
|
62
|
-
const read = Math.min(dst.length, __privateGet(this,
|
|
63
|
-
dst.set(__privateGet(this, _buffer).
|
|
75
|
+
const read = Math.min(dst.length, __privateGet(this, _writeIndex) - __privateGet(this, _readIndex));
|
|
76
|
+
dst.set(__privateGet(this, _buffer).subarray(__privateGet(this, _readIndex), __privateGet(this, _readIndex) + read));
|
|
64
77
|
__privateSet(this, _readIndex, __privateGet(this, _readIndex) + read);
|
|
65
78
|
return read;
|
|
66
79
|
});
|
|
@@ -98,6 +111,7 @@ var Source = class {
|
|
|
98
111
|
_emitter = new WeakMap();
|
|
99
112
|
_buffer = new WeakMap();
|
|
100
113
|
_readIndex = new WeakMap();
|
|
114
|
+
_writeIndex = new WeakMap();
|
|
101
115
|
_closed = new WeakMap();
|
|
102
116
|
_sampleRate = new WeakMap();
|
|
103
117
|
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
// src/tts/utils.ts
|
|
2
2
|
import base64 from "base64-js";
|
|
3
3
|
function base64ToArray(b64) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const byteArrays = filterSentinel(b64).map((b) => base64.toByteArray(b));
|
|
5
|
+
const totalLength = byteArrays.reduce(
|
|
6
|
+
(acc, arr) => acc + arr.length / Float32Array.BYTES_PER_ELEMENT,
|
|
7
|
+
0
|
|
8
|
+
);
|
|
9
|
+
const result = new Float32Array(totalLength);
|
|
10
|
+
let offset = 0;
|
|
11
|
+
for (const arr of byteArrays) {
|
|
12
|
+
const floats = new Float32Array(arr.buffer);
|
|
13
|
+
result.set(floats, offset);
|
|
14
|
+
offset += floats.length;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
11
17
|
}
|
|
12
18
|
function playAudioBuffer(floats, context, startAt, sampleRate) {
|
|
13
19
|
const source = context.createBufferSource();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Voices
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WVTITUXX.js";
|
|
4
4
|
import {
|
|
5
5
|
TTS
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-KWBSQZTY.js";
|
|
7
7
|
import {
|
|
8
8
|
Client
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JGP5BIUV.js";
|
|
10
10
|
|
|
11
11
|
// src/lib/index.ts
|
|
12
12
|
var Cartesia = class extends Client {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/lib/constants.ts
|
|
2
|
-
var BASE_URL = "https://api.cartesia.ai/
|
|
2
|
+
var BASE_URL = "https://api.cartesia.ai/";
|
|
3
|
+
var CARTESIA_VERSION = "2024-06-10";
|
|
3
4
|
var constructApiUrl = (baseUrl, path, protocol) => {
|
|
4
5
|
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
5
6
|
if (!protocol) {
|
|
@@ -13,5 +14,6 @@ var constructApiUrl = (baseUrl, path, protocol) => {
|
|
|
13
14
|
|
|
14
15
|
export {
|
|
15
16
|
BASE_URL,
|
|
17
|
+
CARTESIA_VERSION,
|
|
16
18
|
constructApiUrl
|
|
17
19
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -99,7 +99,8 @@ 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
|
+
var CARTESIA_VERSION = "2024-06-10";
|
|
103
104
|
var constructApiUrl = (baseUrl, path, protocol) => {
|
|
104
105
|
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
105
106
|
if (!protocol) {
|
|
@@ -124,7 +125,8 @@ var Client = class {
|
|
|
124
125
|
const url = constructApiUrl(this.baseUrl, path);
|
|
125
126
|
return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
|
|
126
127
|
headers: __spreadValues({
|
|
127
|
-
"X-API-
|
|
128
|
+
"X-API-Key": this.apiKey,
|
|
129
|
+
"Cartesia-Version": CARTESIA_VERSION
|
|
128
130
|
}, options.headers)
|
|
129
131
|
}));
|
|
130
132
|
}
|
|
@@ -137,7 +139,7 @@ var import_partysocket = require("partysocket");
|
|
|
137
139
|
|
|
138
140
|
// src/tts/source.ts
|
|
139
141
|
var import_emittery = __toESM(require("emittery"), 1);
|
|
140
|
-
var _emitter, _buffer, _readIndex, _closed, _sampleRate;
|
|
142
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate;
|
|
141
143
|
var Source = class {
|
|
142
144
|
/**
|
|
143
145
|
* Create a new Source.
|
|
@@ -147,8 +149,9 @@ var Source = class {
|
|
|
147
149
|
*/
|
|
148
150
|
constructor({ sampleRate }) {
|
|
149
151
|
__privateAdd(this, _emitter, new import_emittery.default());
|
|
150
|
-
__privateAdd(this, _buffer,
|
|
152
|
+
__privateAdd(this, _buffer, void 0);
|
|
151
153
|
__privateAdd(this, _readIndex, 0);
|
|
154
|
+
__privateAdd(this, _writeIndex, 0);
|
|
152
155
|
__privateAdd(this, _closed, false);
|
|
153
156
|
__privateAdd(this, _sampleRate, void 0);
|
|
154
157
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
@@ -156,6 +159,7 @@ var Source = class {
|
|
|
156
159
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
157
160
|
this.off = __privateGet(this, _emitter).off.bind(__privateGet(this, _emitter));
|
|
158
161
|
__privateSet(this, _sampleRate, sampleRate);
|
|
162
|
+
__privateSet(this, _buffer, new Float32Array(1024));
|
|
159
163
|
}
|
|
160
164
|
get sampleRate() {
|
|
161
165
|
return __privateGet(this, _sampleRate);
|
|
@@ -167,7 +171,18 @@ var Source = class {
|
|
|
167
171
|
*/
|
|
168
172
|
enqueue(src) {
|
|
169
173
|
return __async(this, null, function* () {
|
|
170
|
-
|
|
174
|
+
const requiredCapacity = __privateGet(this, _writeIndex) + src.length;
|
|
175
|
+
if (requiredCapacity > __privateGet(this, _buffer).length) {
|
|
176
|
+
let newCapacity = __privateGet(this, _buffer).length;
|
|
177
|
+
while (newCapacity < requiredCapacity) {
|
|
178
|
+
newCapacity *= 2;
|
|
179
|
+
}
|
|
180
|
+
const newBuffer = new Float32Array(newCapacity);
|
|
181
|
+
newBuffer.set(__privateGet(this, _buffer));
|
|
182
|
+
__privateSet(this, _buffer, newBuffer);
|
|
183
|
+
}
|
|
184
|
+
__privateGet(this, _buffer).set(src, __privateGet(this, _writeIndex));
|
|
185
|
+
__privateSet(this, _writeIndex, __privateGet(this, _writeIndex) + src.length);
|
|
171
186
|
yield __privateGet(this, _emitter).emit("enqueue");
|
|
172
187
|
});
|
|
173
188
|
}
|
|
@@ -181,7 +196,7 @@ var Source = class {
|
|
|
181
196
|
read(dst) {
|
|
182
197
|
return __async(this, null, function* () {
|
|
183
198
|
const targetReadIndex = __privateGet(this, _readIndex) + dst.length;
|
|
184
|
-
while (!__privateGet(this, _closed) && targetReadIndex > __privateGet(this,
|
|
199
|
+
while (!__privateGet(this, _closed) && targetReadIndex > __privateGet(this, _writeIndex)) {
|
|
185
200
|
yield __privateGet(this, _emitter).emit("wait");
|
|
186
201
|
yield Promise.race([
|
|
187
202
|
__privateGet(this, _emitter).once("enqueue"),
|
|
@@ -189,8 +204,8 @@ var Source = class {
|
|
|
189
204
|
]);
|
|
190
205
|
yield __privateGet(this, _emitter).emit("read");
|
|
191
206
|
}
|
|
192
|
-
const read = Math.min(dst.length, __privateGet(this,
|
|
193
|
-
dst.set(__privateGet(this, _buffer).
|
|
207
|
+
const read = Math.min(dst.length, __privateGet(this, _writeIndex) - __privateGet(this, _readIndex));
|
|
208
|
+
dst.set(__privateGet(this, _buffer).subarray(__privateGet(this, _readIndex), __privateGet(this, _readIndex) + read));
|
|
194
209
|
__privateSet(this, _readIndex, __privateGet(this, _readIndex) + read);
|
|
195
210
|
return read;
|
|
196
211
|
});
|
|
@@ -228,19 +243,26 @@ var Source = class {
|
|
|
228
243
|
_emitter = new WeakMap();
|
|
229
244
|
_buffer = new WeakMap();
|
|
230
245
|
_readIndex = new WeakMap();
|
|
246
|
+
_writeIndex = new WeakMap();
|
|
231
247
|
_closed = new WeakMap();
|
|
232
248
|
_sampleRate = new WeakMap();
|
|
233
249
|
|
|
234
250
|
// src/tts/utils.ts
|
|
235
251
|
var import_base64_js = __toESM(require("base64-js"), 1);
|
|
236
252
|
function base64ToArray(b64) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
253
|
+
const byteArrays = filterSentinel(b64).map((b) => import_base64_js.default.toByteArray(b));
|
|
254
|
+
const totalLength = byteArrays.reduce(
|
|
255
|
+
(acc, arr) => acc + arr.length / Float32Array.BYTES_PER_ELEMENT,
|
|
256
|
+
0
|
|
257
|
+
);
|
|
258
|
+
const result = new Float32Array(totalLength);
|
|
259
|
+
let offset = 0;
|
|
260
|
+
for (const arr of byteArrays) {
|
|
261
|
+
const floats = new Float32Array(arr.buffer);
|
|
262
|
+
result.set(floats, offset);
|
|
263
|
+
offset += floats.length;
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
244
266
|
}
|
|
245
267
|
function playAudioBuffer(floats, context, startAt, sampleRate) {
|
|
246
268
|
const source = context.createBufferSource();
|
|
@@ -403,7 +425,11 @@ var WebSocket = class extends Client {
|
|
|
403
425
|
* @throws {Error} If the WebSocket fails to connect.
|
|
404
426
|
*/
|
|
405
427
|
connect() {
|
|
406
|
-
const url = constructApiUrl(
|
|
428
|
+
const url = constructApiUrl(
|
|
429
|
+
this.baseUrl,
|
|
430
|
+
`/tts/websocket?cartesia_version=${CARTESIA_VERSION}`,
|
|
431
|
+
"ws"
|
|
432
|
+
);
|
|
407
433
|
url.searchParams.set("api_key", this.apiKey);
|
|
408
434
|
const emitter = new import_emittery2.default();
|
|
409
435
|
this.socket = new import_partysocket.WebSocket(url.toString());
|
|
@@ -575,7 +601,7 @@ var Player = class {
|
|
|
575
601
|
const plays = [];
|
|
576
602
|
while (true) {
|
|
577
603
|
const read = yield source.read(buffer);
|
|
578
|
-
const playableAudio = buffer.
|
|
604
|
+
const playableAudio = buffer.subarray(0, read);
|
|
579
605
|
plays.push(__privateMethod(this, _playBuffer, playBuffer_fn).call(this, playableAudio, source.sampleRate));
|
|
580
606
|
if (read < buffer.length) {
|
|
581
607
|
yield __privateGet(this, _emitter2).emit("finish");
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import "./chunk-FXPGR372.js";
|
|
2
2
|
import {
|
|
3
3
|
Cartesia
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-T3RG6WV4.js";
|
|
5
|
+
import "./chunk-WVTITUXX.js";
|
|
6
|
+
import "./chunk-KWBSQZTY.js";
|
|
7
|
+
import "./chunk-3F5E46FT.js";
|
|
8
|
+
import "./chunk-PQ6CIPFW.js";
|
|
9
|
+
import "./chunk-JGP5BIUV.js";
|
|
10
|
+
import "./chunk-XHTDPLFR.js";
|
|
11
11
|
import {
|
|
12
12
|
Player
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-36JBKJUN.js";
|
|
14
|
+
import "./chunk-RO7TY474.js";
|
|
15
15
|
import "./chunk-WIFMLPT5.js";
|
|
16
16
|
export {
|
|
17
17
|
Cartesia,
|
package/dist/lib/client.cjs
CHANGED
|
@@ -53,7 +53,8 @@ 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
|
+
var CARTESIA_VERSION = "2024-06-10";
|
|
57
58
|
var constructApiUrl = (baseUrl, path, protocol) => {
|
|
58
59
|
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
59
60
|
if (!protocol) {
|
|
@@ -78,7 +79,8 @@ var Client = class {
|
|
|
78
79
|
const url = constructApiUrl(this.baseUrl, path);
|
|
79
80
|
return (0, import_cross_fetch.default)(url.toString(), __spreadProps(__spreadValues({}, options), {
|
|
80
81
|
headers: __spreadValues({
|
|
81
|
-
"X-API-
|
|
82
|
+
"X-API-Key": this.apiKey,
|
|
83
|
+
"Cartesia-Version": CARTESIA_VERSION
|
|
82
84
|
}, options.headers)
|
|
83
85
|
}));
|
|
84
86
|
}
|
package/dist/lib/client.js
CHANGED
package/dist/lib/constants.cjs
CHANGED
|
@@ -21,10 +21,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var constants_exports = {};
|
|
22
22
|
__export(constants_exports, {
|
|
23
23
|
BASE_URL: () => BASE_URL,
|
|
24
|
+
CARTESIA_VERSION: () => CARTESIA_VERSION,
|
|
24
25
|
constructApiUrl: () => constructApiUrl
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(constants_exports);
|
|
27
|
-
var BASE_URL = "https://api.cartesia.ai/
|
|
28
|
+
var BASE_URL = "https://api.cartesia.ai/";
|
|
29
|
+
var CARTESIA_VERSION = "2024-06-10";
|
|
28
30
|
var constructApiUrl = (baseUrl, path, protocol) => {
|
|
29
31
|
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
30
32
|
if (!protocol) {
|
|
@@ -38,5 +40,6 @@ var constructApiUrl = (baseUrl, path, protocol) => {
|
|
|
38
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
41
|
0 && (module.exports = {
|
|
40
42
|
BASE_URL,
|
|
43
|
+
CARTESIA_VERSION,
|
|
41
44
|
constructApiUrl
|
|
42
45
|
});
|
package/dist/lib/constants.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
declare const BASE_URL = "https://api.cartesia.ai/
|
|
1
|
+
declare const BASE_URL = "https://api.cartesia.ai/";
|
|
2
|
+
declare const CARTESIA_VERSION = "2024-06-10";
|
|
2
3
|
declare const constructApiUrl: (baseUrl: string, path: string, protocol?: string) => URL;
|
|
3
4
|
|
|
4
|
-
export { BASE_URL, constructApiUrl };
|
|
5
|
+
export { BASE_URL, CARTESIA_VERSION, constructApiUrl };
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
declare const BASE_URL = "https://api.cartesia.ai/
|
|
1
|
+
declare const BASE_URL = "https://api.cartesia.ai/";
|
|
2
|
+
declare const CARTESIA_VERSION = "2024-06-10";
|
|
2
3
|
declare const constructApiUrl: (baseUrl: string, path: string, protocol?: string) => URL;
|
|
3
4
|
|
|
4
|
-
export { BASE_URL, constructApiUrl };
|
|
5
|
+
export { BASE_URL, CARTESIA_VERSION, constructApiUrl };
|
package/dist/lib/constants.js
CHANGED