@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.
- package/.turbo/turbo-build.log +34 -34
- package/CHANGELOG.md +6 -0
- package/README.md +32 -3
- package/dist/{chunk-NQVZNVOU.js → chunk-3FL2SNIR.js} +1 -1
- package/dist/{chunk-ZF6HASZT.js → chunk-4GEDAGVY.js} +3 -3
- package/dist/{chunk-PISCPZK4.js → chunk-6PWLZAMS.js} +1 -1
- package/dist/{chunk-YFN6TFR4.js → chunk-CWIJUBG6.js} +12 -4
- package/dist/{chunk-EUW2435M.js → chunk-L3OMQKWL.js} +34 -10
- package/dist/{chunk-LZO6K34D.js → chunk-MNOPO7G6.js} +2 -2
- package/dist/{chunk-NWCW6C7H.js → chunk-MUPVAEL7.js} +2 -2
- package/dist/{chunk-BHY7MNGT.js → chunk-VCZESWYA.js} +1 -1
- package/dist/{chunk-6YQ6KDIQ.js → chunk-VVDJR3OA.js} +32 -1
- package/dist/{chunk-GHY2WEOK.js → chunk-WIFMLPT5.js} +0 -13
- package/dist/index.cjs +71 -19
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +71 -19
- package/dist/lib/index.js +8 -8
- package/dist/react/index.cjs +74 -19
- package/dist/react/index.js +13 -10
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +61 -17
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.js +4 -4
- package/dist/tts/source.cjs +31 -0
- package/dist/tts/source.d.cts +9 -0
- package/dist/tts/source.d.ts +9 -0
- package/dist/tts/source.js +2 -2
- package/dist/tts/utils.js +3 -3
- package/dist/tts/websocket.cjs +61 -17
- package/dist/tts/websocket.d.cts +9 -3
- package/dist/tts/websocket.d.ts +9 -3
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +18 -3
- package/dist/types/index.d.ts +18 -3
- package/dist/voices/index.cjs +10 -2
- package/dist/voices/index.d.cts +2 -1
- package/dist/voices/index.d.ts +2 -1
- package/dist/voices/index.js +3 -3
- package/package.json +1 -1
- package/src/react/index.ts +4 -0
- package/src/tts/source.ts +35 -0
- package/src/tts/websocket.ts +33 -2
- package/src/types/index.ts +29 -2
- package/src/voices/index.ts +12 -3
package/dist/lib/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 });
|
|
@@ -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 -
|
|
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(
|
|
394
|
-
var
|
|
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
|
-
(
|
|
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(
|
|
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-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
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-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-VCZESWYA.js";
|
|
10
|
+
import "../chunk-VVDJR3OA.js";
|
|
11
|
+
import "../chunk-WIFMLPT5.js";
|
|
12
12
|
export {
|
|
13
13
|
Cartesia
|
|
14
14
|
};
|
package/dist/react/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 });
|
|
@@ -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 -
|
|
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(
|
|
408
|
-
var
|
|
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
|
-
(
|
|
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(
|
|
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(
|
package/dist/react/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Cartesia
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-4GEDAGVY.js";
|
|
4
|
+
import "../chunk-CWIJUBG6.js";
|
|
5
5
|
import {
|
|
6
6
|
pingServer
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
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-
|
|
15
|
-
import "../chunk-
|
|
16
|
-
import "../chunk-
|
|
14
|
+
} from "../chunk-MNOPO7G6.js";
|
|
15
|
+
import "../chunk-VCZESWYA.js";
|
|
16
|
+
import "../chunk-VVDJR3OA.js";
|
|
17
17
|
import {
|
|
18
18
|
__async
|
|
19
|
-
} from "../chunk-
|
|
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(
|
package/dist/react/utils.js
CHANGED
package/dist/tts/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 });
|
|
@@ -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 -
|
|
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(
|
|
394
|
-
var
|
|
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
|
-
(
|
|
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-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-MUPVAEL7.js";
|
|
4
|
+
import "../chunk-L3OMQKWL.js";
|
|
5
|
+
import "../chunk-6PWLZAMS.js";
|
|
6
6
|
import "../chunk-2BFEKY3F.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
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
|
};
|
package/dist/tts/player.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Player
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
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
|
};
|
package/dist/tts/source.cjs
CHANGED
|
@@ -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
|
*
|
package/dist/tts/source.d.cts
CHANGED
|
@@ -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
|
*
|
package/dist/tts/source.d.ts
CHANGED
|
@@ -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
|
*
|
package/dist/tts/source.js
CHANGED
package/dist/tts/utils.js
CHANGED
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
isComplete,
|
|
8
8
|
isSentinel,
|
|
9
9
|
playAudioBuffer
|
|
10
|
-
} from "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
10
|
+
} from "../chunk-VCZESWYA.js";
|
|
11
|
+
import "../chunk-VVDJR3OA.js";
|
|
12
|
+
import "../chunk-WIFMLPT5.js";
|
|
13
13
|
export {
|
|
14
14
|
base64ToArray,
|
|
15
15
|
createMessageHandlerForContextId,
|