@cartesia/cartesia-js 1.0.3 → 1.2.1-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/CHANGELOG.md +6 -0
- package/README.md +32 -3
- package/dist/{chunk-BHY7MNGT.js → chunk-5SBAQNWQ.js} +1 -1
- package/dist/{chunk-LZO6K34D.js → chunk-CSOXALSC.js} +7 -7
- package/dist/{chunk-PISCPZK4.js → chunk-FLWYXP5Z.js} +1 -1
- package/dist/chunk-GLZYI5DM.js +43 -0
- package/dist/{chunk-6YQ6KDIQ.js → chunk-I5YVYTNK.js} +47 -16
- package/dist/{chunk-NQVZNVOU.js → chunk-LKKWJLUG.js} +1 -1
- package/dist/{chunk-GHY2WEOK.js → chunk-NJDRWDQ3.js} +8 -35
- package/dist/{chunk-ZF6HASZT.js → chunk-QWNB544W.js} +7 -3
- package/dist/{chunk-YFN6TFR4.js → chunk-RJICGVPL.js} +12 -4
- package/dist/chunk-WLEVU3HN.js +42 -0
- package/dist/{chunk-EUW2435M.js → chunk-WSIVWXEI.js} +49 -25
- package/dist/index.cjs +162 -76
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -9
- package/dist/lib/client.js +2 -2
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.cjs +157 -71
- package/dist/lib/index.d.cts +2 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +9 -8
- package/dist/react/index.cjs +165 -76
- package/dist/react/index.js +14 -10
- package/dist/react/utils.js +2 -2
- package/dist/tts/index.cjs +114 -69
- package/dist/tts/index.d.cts +8 -1
- package/dist/tts/index.d.ts +8 -1
- package/dist/tts/index.js +6 -6
- package/dist/tts/player.cjs +13 -27
- package/dist/tts/player.js +4 -4
- package/dist/tts/source.cjs +54 -37
- 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 +99 -69
- package/dist/tts/websocket.d.cts +15 -9
- package/dist/tts/websocket.d.ts +15 -9
- package/dist/tts/websocket.js +5 -5
- package/dist/types/index.d.cts +42 -3
- package/dist/types/index.d.ts +42 -3
- package/dist/voice-changer/index.cjs +143 -0
- package/dist/voice-changer/index.d.cts +9 -0
- package/dist/voice-changer/index.d.ts +9 -0
- package/dist/voice-changer/index.js +9 -0
- 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 +8 -16
- package/src/lib/index.ts +3 -0
- package/src/react/index.ts +4 -0
- package/src/tts/index.ts +16 -1
- package/src/tts/source.ts +35 -0
- package/src/tts/websocket.ts +33 -2
- package/src/types/index.ts +60 -2
- package/src/voice-changer/index.ts +37 -0
- package/src/voices/index.ts +12 -3
- package/.turbo/turbo-build.log +0 -75
- package/dist/chunk-NWCW6C7H.js +0 -25
- package/tsconfig.json +0 -3
package/dist/tts/index.cjs
CHANGED
|
@@ -9,6 +9,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
9
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
11
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __typeError = (msg) => {
|
|
13
|
+
throw TypeError(msg);
|
|
14
|
+
};
|
|
12
15
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
16
|
var __spreadValues = (a, b) => {
|
|
14
17
|
for (var prop in b || (b = {}))
|
|
@@ -22,18 +25,6 @@ var __spreadValues = (a, b) => {
|
|
|
22
25
|
return a;
|
|
23
26
|
};
|
|
24
27
|
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
28
|
var __export = (target, all) => {
|
|
38
29
|
for (var name in all)
|
|
39
30
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -55,28 +46,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
55
46
|
mod
|
|
56
47
|
));
|
|
57
48
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
var __accessCheck = (obj, member, msg) =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
__accessCheck(obj, member, "read from private field");
|
|
64
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
65
|
-
};
|
|
66
|
-
var __privateAdd = (obj, member, value) => {
|
|
67
|
-
if (member.has(obj))
|
|
68
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
69
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
70
|
-
};
|
|
71
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
72
|
-
__accessCheck(obj, member, "write to private field");
|
|
73
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
74
|
-
return value;
|
|
75
|
-
};
|
|
76
|
-
var __privateMethod = (obj, member, method) => {
|
|
77
|
-
__accessCheck(obj, member, "access private method");
|
|
78
|
-
return method;
|
|
79
|
-
};
|
|
49
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
50
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
51
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
52
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
53
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
80
54
|
var __async = (__this, __arguments, generator) => {
|
|
81
55
|
return new Promise((resolve, reject) => {
|
|
82
56
|
var fulfilled = (value) => {
|
|
@@ -157,7 +131,7 @@ var ENCODING_MAP = {
|
|
|
157
131
|
pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
|
|
158
132
|
pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
|
|
159
133
|
};
|
|
160
|
-
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container,
|
|
134
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _Source_instances, createBuffer_fn;
|
|
161
135
|
var Source = class {
|
|
162
136
|
/**
|
|
163
137
|
* Create a new Source.
|
|
@@ -170,21 +144,15 @@ var Source = class {
|
|
|
170
144
|
encoding,
|
|
171
145
|
container
|
|
172
146
|
}) {
|
|
173
|
-
|
|
174
|
-
* Create a new buffer for the source.
|
|
175
|
-
*
|
|
176
|
-
* @param size - The size of the buffer to create.
|
|
177
|
-
* @returns The new buffer as a TypedArray based on the encoding.
|
|
178
|
-
*/
|
|
179
|
-
__privateAdd(this, _createBuffer);
|
|
147
|
+
__privateAdd(this, _Source_instances);
|
|
180
148
|
__privateAdd(this, _emitter, new import_emittery.default());
|
|
181
|
-
__privateAdd(this, _buffer
|
|
149
|
+
__privateAdd(this, _buffer);
|
|
182
150
|
__privateAdd(this, _readIndex, 0);
|
|
183
151
|
__privateAdd(this, _writeIndex, 0);
|
|
184
152
|
__privateAdd(this, _closed, false);
|
|
185
|
-
__privateAdd(this, _sampleRate
|
|
186
|
-
__privateAdd(this, _encoding
|
|
187
|
-
__privateAdd(this, _container
|
|
153
|
+
__privateAdd(this, _sampleRate);
|
|
154
|
+
__privateAdd(this, _encoding);
|
|
155
|
+
__privateAdd(this, _container);
|
|
188
156
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
189
157
|
this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
|
|
190
158
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
@@ -192,7 +160,7 @@ var Source = class {
|
|
|
192
160
|
__privateSet(this, _sampleRate, sampleRate);
|
|
193
161
|
__privateSet(this, _encoding, encoding);
|
|
194
162
|
__privateSet(this, _container, container);
|
|
195
|
-
__privateSet(this, _buffer, __privateMethod(this,
|
|
163
|
+
__privateSet(this, _buffer, __privateMethod(this, _Source_instances, createBuffer_fn).call(this, 1024));
|
|
196
164
|
}
|
|
197
165
|
get sampleRate() {
|
|
198
166
|
return __privateGet(this, _sampleRate);
|
|
@@ -216,7 +184,7 @@ var Source = class {
|
|
|
216
184
|
while (newCapacity < requiredCapacity) {
|
|
217
185
|
newCapacity *= 2;
|
|
218
186
|
}
|
|
219
|
-
const newBuffer = __privateMethod(this,
|
|
187
|
+
const newBuffer = __privateMethod(this, _Source_instances, createBuffer_fn).call(this, newCapacity);
|
|
220
188
|
newBuffer.set(__privateGet(this, _buffer));
|
|
221
189
|
__privateSet(this, _buffer, newBuffer);
|
|
222
190
|
}
|
|
@@ -249,6 +217,37 @@ var Source = class {
|
|
|
249
217
|
return read;
|
|
250
218
|
});
|
|
251
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Seek in the buffer.
|
|
222
|
+
*
|
|
223
|
+
* @param offset The offset to seek to.
|
|
224
|
+
* @param whence The position to seek from.
|
|
225
|
+
* @returns The new position in the buffer.
|
|
226
|
+
* @throws {Error} If the seek is invalid.
|
|
227
|
+
*/
|
|
228
|
+
seek(offset, whence) {
|
|
229
|
+
return __async(this, null, function* () {
|
|
230
|
+
let position = __privateGet(this, _readIndex);
|
|
231
|
+
switch (whence) {
|
|
232
|
+
case "start":
|
|
233
|
+
position = offset;
|
|
234
|
+
break;
|
|
235
|
+
case "current":
|
|
236
|
+
position += offset;
|
|
237
|
+
break;
|
|
238
|
+
case "end":
|
|
239
|
+
position = __privateGet(this, _writeIndex) + offset;
|
|
240
|
+
break;
|
|
241
|
+
default:
|
|
242
|
+
throw new Error(`Invalid seek mode: ${whence}`);
|
|
243
|
+
}
|
|
244
|
+
if (position < 0 || position > __privateGet(this, _writeIndex)) {
|
|
245
|
+
throw new Error("Seek out of bounds");
|
|
246
|
+
}
|
|
247
|
+
__privateSet(this, _readIndex, position);
|
|
248
|
+
return position;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
252
251
|
/**
|
|
253
252
|
* Get the number of samples in a given duration.
|
|
254
253
|
*
|
|
@@ -290,7 +289,13 @@ _closed = new WeakMap();
|
|
|
290
289
|
_sampleRate = new WeakMap();
|
|
291
290
|
_encoding = new WeakMap();
|
|
292
291
|
_container = new WeakMap();
|
|
293
|
-
|
|
292
|
+
_Source_instances = new WeakSet();
|
|
293
|
+
/**
|
|
294
|
+
* Create a new buffer for the source.
|
|
295
|
+
*
|
|
296
|
+
* @param size - The size of the buffer to create.
|
|
297
|
+
* @returns The new buffer as a TypedArray based on the encoding.
|
|
298
|
+
*/
|
|
294
299
|
createBuffer_fn = function(size) {
|
|
295
300
|
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
296
301
|
return new ArrayType(size);
|
|
@@ -353,7 +358,7 @@ function getEmitteryCallbacks(emitter) {
|
|
|
353
358
|
}
|
|
354
359
|
|
|
355
360
|
// src/tts/websocket.ts
|
|
356
|
-
var _isConnected, _sampleRate2, _container2, _encoding2,
|
|
361
|
+
var _isConnected, _sampleRate2, _container2, _encoding2, _WebSocket_instances, generateId_fn;
|
|
357
362
|
var WebSocket = class extends Client {
|
|
358
363
|
/**
|
|
359
364
|
* Create a new WebSocket client.
|
|
@@ -362,19 +367,11 @@ var WebSocket = class extends Client {
|
|
|
362
367
|
*/
|
|
363
368
|
constructor({ sampleRate, container, encoding }, ...args) {
|
|
364
369
|
super(...args);
|
|
365
|
-
|
|
366
|
-
* Generate a unique ID suitable for a streaming context.
|
|
367
|
-
*
|
|
368
|
-
* Not suitable for security purposes or as a primary key, since
|
|
369
|
-
* it lacks the amount of entropy required for those use cases.
|
|
370
|
-
*
|
|
371
|
-
* @returns A unique ID.
|
|
372
|
-
*/
|
|
373
|
-
__privateAdd(this, _generateId);
|
|
370
|
+
__privateAdd(this, _WebSocket_instances);
|
|
374
371
|
__privateAdd(this, _isConnected, false);
|
|
375
|
-
__privateAdd(this, _sampleRate2
|
|
376
|
-
__privateAdd(this, _container2
|
|
377
|
-
__privateAdd(this, _encoding2
|
|
372
|
+
__privateAdd(this, _sampleRate2);
|
|
373
|
+
__privateAdd(this, _container2);
|
|
374
|
+
__privateAdd(this, _encoding2);
|
|
378
375
|
__privateSet(this, _sampleRate2, sampleRate);
|
|
379
376
|
__privateSet(this, _container2, container != null ? container : "raw");
|
|
380
377
|
__privateSet(this, _encoding2, encoding != null ? encoding : "pcm_f32le");
|
|
@@ -382,7 +379,7 @@ var WebSocket = class extends Client {
|
|
|
382
379
|
/**
|
|
383
380
|
* Send a message over the WebSocket to start a stream.
|
|
384
381
|
*
|
|
385
|
-
* @param inputs -
|
|
382
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type.
|
|
386
383
|
* @param options - Options for the stream.
|
|
387
384
|
* @param options.timeout - The maximum time to wait for a chunk before cancelling the stream.
|
|
388
385
|
* If set to `0`, the stream will not time out.
|
|
@@ -390,14 +387,13 @@ var WebSocket = class extends Client {
|
|
|
390
387
|
* @returns An Emittery instance that emits messages from the WebSocket.
|
|
391
388
|
* @returns An abort function that can be called to cancel the stream.
|
|
392
389
|
*/
|
|
393
|
-
send(
|
|
394
|
-
var
|
|
395
|
-
var _a2, _b, _c, _d;
|
|
390
|
+
send(inputs, { timeout = 0 } = {}) {
|
|
391
|
+
var _a, _b, _c, _d;
|
|
396
392
|
if (!__privateGet(this, _isConnected)) {
|
|
397
393
|
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
398
394
|
}
|
|
399
395
|
if (!inputs.context_id) {
|
|
400
|
-
inputs.context_id = __privateMethod(this,
|
|
396
|
+
inputs.context_id = __privateMethod(this, _WebSocket_instances, generateId_fn).call(this);
|
|
401
397
|
}
|
|
402
398
|
if (!inputs.output_format) {
|
|
403
399
|
inputs.output_format = {
|
|
@@ -406,7 +402,7 @@ var WebSocket = class extends Client {
|
|
|
406
402
|
sample_rate: __privateGet(this, _sampleRate2)
|
|
407
403
|
};
|
|
408
404
|
}
|
|
409
|
-
(
|
|
405
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
410
406
|
JSON.stringify(__spreadValues({}, inputs))
|
|
411
407
|
);
|
|
412
408
|
const emitter = new import_emittery2.default();
|
|
@@ -476,6 +472,32 @@ var WebSocket = class extends Client {
|
|
|
476
472
|
stop: streamCompleteController.abort.bind(streamCompleteController)
|
|
477
473
|
});
|
|
478
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Continue a stream.
|
|
477
|
+
*
|
|
478
|
+
* @param inputs - Generation parameters. Defined in the StreamRequest type, but must include a `context_id` field. `continue` is set to true by default.
|
|
479
|
+
*/
|
|
480
|
+
continue(inputs) {
|
|
481
|
+
var _a;
|
|
482
|
+
if (!__privateGet(this, _isConnected)) {
|
|
483
|
+
throw new Error("Not connected to WebSocket. Call .connect() first.");
|
|
484
|
+
}
|
|
485
|
+
if (!inputs.context_id) {
|
|
486
|
+
throw new Error("context_id is required to continue a context.");
|
|
487
|
+
}
|
|
488
|
+
if (!inputs.output_format) {
|
|
489
|
+
inputs.output_format = {
|
|
490
|
+
container: __privateGet(this, _container2),
|
|
491
|
+
encoding: __privateGet(this, _encoding2),
|
|
492
|
+
sample_rate: __privateGet(this, _sampleRate2)
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
(_a = this.socket) == null ? void 0 : _a.send(
|
|
496
|
+
JSON.stringify(__spreadValues({
|
|
497
|
+
continue: true
|
|
498
|
+
}, inputs))
|
|
499
|
+
);
|
|
500
|
+
}
|
|
479
501
|
/**
|
|
480
502
|
* Authenticate and connect to a Cartesia streaming WebSocket.
|
|
481
503
|
*
|
|
@@ -551,7 +573,15 @@ _isConnected = new WeakMap();
|
|
|
551
573
|
_sampleRate2 = new WeakMap();
|
|
552
574
|
_container2 = new WeakMap();
|
|
553
575
|
_encoding2 = new WeakMap();
|
|
554
|
-
|
|
576
|
+
_WebSocket_instances = new WeakSet();
|
|
577
|
+
/**
|
|
578
|
+
* Generate a unique ID suitable for a streaming context.
|
|
579
|
+
*
|
|
580
|
+
* Not suitable for security purposes or as a primary key, since
|
|
581
|
+
* it lacks the amount of entropy required for those use cases.
|
|
582
|
+
*
|
|
583
|
+
* @returns A unique ID.
|
|
584
|
+
*/
|
|
555
585
|
generateId_fn = function() {
|
|
556
586
|
return (0, import_human_id.humanId)({
|
|
557
587
|
separator: "-",
|
|
@@ -572,4 +602,19 @@ var TTS = class extends Client {
|
|
|
572
602
|
baseUrl: this.baseUrl
|
|
573
603
|
});
|
|
574
604
|
}
|
|
605
|
+
/**
|
|
606
|
+
* Generate audio bytes from text.
|
|
607
|
+
*
|
|
608
|
+
* @param options - The options for the request.
|
|
609
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
610
|
+
*/
|
|
611
|
+
bytes(options) {
|
|
612
|
+
return __async(this, null, function* () {
|
|
613
|
+
const response = yield this._fetch("/tts/bytes", {
|
|
614
|
+
method: "POST",
|
|
615
|
+
body: JSON.stringify(options)
|
|
616
|
+
});
|
|
617
|
+
return response.arrayBuffer();
|
|
618
|
+
});
|
|
619
|
+
}
|
|
575
620
|
};
|
package/dist/tts/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from '../lib/client.cjs';
|
|
2
|
-
import { WebSocketOptions } from '../types/index.cjs';
|
|
2
|
+
import { WebSocketOptions, BytesRequest } from '../types/index.cjs';
|
|
3
3
|
import WebSocket from './websocket.cjs';
|
|
4
4
|
import 'emittery';
|
|
5
5
|
import 'partysocket';
|
|
@@ -12,6 +12,13 @@ declare class TTS extends Client {
|
|
|
12
12
|
* @returns {WebSocket} A Cartesia WebSocket client.
|
|
13
13
|
*/
|
|
14
14
|
websocket(options: WebSocketOptions): WebSocket;
|
|
15
|
+
/**
|
|
16
|
+
* Generate audio bytes from text.
|
|
17
|
+
*
|
|
18
|
+
* @param options - The options for the request.
|
|
19
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
20
|
+
*/
|
|
21
|
+
bytes(options: BytesRequest): Promise<ArrayBuffer>;
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
export { TTS as default };
|
package/dist/tts/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from '../lib/client.js';
|
|
2
|
-
import { WebSocketOptions } from '../types/index.js';
|
|
2
|
+
import { WebSocketOptions, BytesRequest } from '../types/index.js';
|
|
3
3
|
import WebSocket from './websocket.js';
|
|
4
4
|
import 'emittery';
|
|
5
5
|
import 'partysocket';
|
|
@@ -12,6 +12,13 @@ declare class TTS extends Client {
|
|
|
12
12
|
* @returns {WebSocket} A Cartesia WebSocket client.
|
|
13
13
|
*/
|
|
14
14
|
websocket(options: WebSocketOptions): WebSocket;
|
|
15
|
+
/**
|
|
16
|
+
* Generate audio bytes from text.
|
|
17
|
+
*
|
|
18
|
+
* @param options - The options for the request.
|
|
19
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to an ArrayBuffer containing the audio bytes.
|
|
20
|
+
*/
|
|
21
|
+
bytes(options: BytesRequest): Promise<ArrayBuffer>;
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
export { TTS as default };
|
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-GLZYI5DM.js";
|
|
4
|
+
import "../chunk-WSIVWXEI.js";
|
|
5
|
+
import "../chunk-FLWYXP5Z.js";
|
|
6
6
|
import "../chunk-2BFEKY3F.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-5SBAQNWQ.js";
|
|
8
|
+
import "../chunk-I5YVYTNK.js";
|
|
9
|
+
import "../chunk-NJDRWDQ3.js";
|
|
10
10
|
export {
|
|
11
11
|
TTS as default
|
|
12
12
|
};
|
package/dist/tts/player.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -26,28 +29,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
29
|
mod
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var __accessCheck = (obj, member, msg) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
__accessCheck(obj, member, "read from private field");
|
|
35
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
36
|
-
};
|
|
37
|
-
var __privateAdd = (obj, member, value) => {
|
|
38
|
-
if (member.has(obj))
|
|
39
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
40
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
41
|
-
};
|
|
42
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
43
|
-
__accessCheck(obj, member, "write to private field");
|
|
44
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
45
|
-
return value;
|
|
46
|
-
};
|
|
47
|
-
var __privateMethod = (obj, member, method) => {
|
|
48
|
-
__accessCheck(obj, member, "access private method");
|
|
49
|
-
return method;
|
|
50
|
-
};
|
|
32
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
33
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
34
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
35
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
36
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
51
37
|
var __async = (__this, __arguments, generator) => {
|
|
52
38
|
return new Promise((resolve, reject) => {
|
|
53
39
|
var fulfilled = (value) => {
|
|
@@ -98,7 +84,7 @@ function playAudioBuffer(floats, context, startAt, sampleRate) {
|
|
|
98
84
|
}
|
|
99
85
|
|
|
100
86
|
// src/tts/player.ts
|
|
101
|
-
var _context, _startNextPlaybackAt, _bufferDuration,
|
|
87
|
+
var _context, _startNextPlaybackAt, _bufferDuration, _Player_instances, playBuffer_fn;
|
|
102
88
|
var Player = class {
|
|
103
89
|
/**
|
|
104
90
|
* Create a new Player.
|
|
@@ -107,10 +93,10 @@ var Player = class {
|
|
|
107
93
|
* @param options.bufferDuration - The duration of the audio buffer to play.
|
|
108
94
|
*/
|
|
109
95
|
constructor({ bufferDuration }) {
|
|
110
|
-
__privateAdd(this,
|
|
96
|
+
__privateAdd(this, _Player_instances);
|
|
111
97
|
__privateAdd(this, _context, null);
|
|
112
98
|
__privateAdd(this, _startNextPlaybackAt, 0);
|
|
113
|
-
__privateAdd(this, _bufferDuration
|
|
99
|
+
__privateAdd(this, _bufferDuration);
|
|
114
100
|
__privateSet(this, _bufferDuration, bufferDuration);
|
|
115
101
|
}
|
|
116
102
|
/**
|
|
@@ -130,7 +116,7 @@ var Player = class {
|
|
|
130
116
|
while (true) {
|
|
131
117
|
const read = yield source.read(buffer);
|
|
132
118
|
const playableAudio = buffer.subarray(0, read);
|
|
133
|
-
plays.push(__privateMethod(this,
|
|
119
|
+
plays.push(__privateMethod(this, _Player_instances, playBuffer_fn).call(this, playableAudio, source.sampleRate));
|
|
134
120
|
if (read < buffer.length) {
|
|
135
121
|
break;
|
|
136
122
|
}
|
|
@@ -199,7 +185,7 @@ var Player = class {
|
|
|
199
185
|
_context = new WeakMap();
|
|
200
186
|
_startNextPlaybackAt = new WeakMap();
|
|
201
187
|
_bufferDuration = new WeakMap();
|
|
202
|
-
|
|
188
|
+
_Player_instances = new WeakSet();
|
|
203
189
|
playBuffer_fn = function(buf, sampleRate) {
|
|
204
190
|
return __async(this, null, function* () {
|
|
205
191
|
if (!__privateGet(this, _context)) {
|
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-CSOXALSC.js";
|
|
4
|
+
import "../chunk-5SBAQNWQ.js";
|
|
5
|
+
import "../chunk-I5YVYTNK.js";
|
|
6
|
+
import "../chunk-NJDRWDQ3.js";
|
|
7
7
|
export {
|
|
8
8
|
Player as default
|
|
9
9
|
};
|
package/dist/tts/source.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -26,28 +29,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
29
|
mod
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var __accessCheck = (obj, member, msg) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
__accessCheck(obj, member, "read from private field");
|
|
35
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
36
|
-
};
|
|
37
|
-
var __privateAdd = (obj, member, value) => {
|
|
38
|
-
if (member.has(obj))
|
|
39
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
40
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
41
|
-
};
|
|
42
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
43
|
-
__accessCheck(obj, member, "write to private field");
|
|
44
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
45
|
-
return value;
|
|
46
|
-
};
|
|
47
|
-
var __privateMethod = (obj, member, method) => {
|
|
48
|
-
__accessCheck(obj, member, "access private method");
|
|
49
|
-
return method;
|
|
50
|
-
};
|
|
32
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
33
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
34
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
35
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
36
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
51
37
|
var __async = (__this, __arguments, generator) => {
|
|
52
38
|
return new Promise((resolve, reject) => {
|
|
53
39
|
var fulfilled = (value) => {
|
|
@@ -83,7 +69,7 @@ var ENCODING_MAP = {
|
|
|
83
69
|
pcm_alaw: { arrayType: Uint8Array, bytesPerElement: 1 },
|
|
84
70
|
pcm_mulaw: { arrayType: Uint8Array, bytesPerElement: 1 }
|
|
85
71
|
};
|
|
86
|
-
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container,
|
|
72
|
+
var _emitter, _buffer, _readIndex, _writeIndex, _closed, _sampleRate, _encoding, _container, _Source_instances, createBuffer_fn;
|
|
87
73
|
var Source = class {
|
|
88
74
|
/**
|
|
89
75
|
* Create a new Source.
|
|
@@ -96,21 +82,15 @@ var Source = class {
|
|
|
96
82
|
encoding,
|
|
97
83
|
container
|
|
98
84
|
}) {
|
|
99
|
-
|
|
100
|
-
* Create a new buffer for the source.
|
|
101
|
-
*
|
|
102
|
-
* @param size - The size of the buffer to create.
|
|
103
|
-
* @returns The new buffer as a TypedArray based on the encoding.
|
|
104
|
-
*/
|
|
105
|
-
__privateAdd(this, _createBuffer);
|
|
85
|
+
__privateAdd(this, _Source_instances);
|
|
106
86
|
__privateAdd(this, _emitter, new import_emittery.default());
|
|
107
|
-
__privateAdd(this, _buffer
|
|
87
|
+
__privateAdd(this, _buffer);
|
|
108
88
|
__privateAdd(this, _readIndex, 0);
|
|
109
89
|
__privateAdd(this, _writeIndex, 0);
|
|
110
90
|
__privateAdd(this, _closed, false);
|
|
111
|
-
__privateAdd(this, _sampleRate
|
|
112
|
-
__privateAdd(this, _encoding
|
|
113
|
-
__privateAdd(this, _container
|
|
91
|
+
__privateAdd(this, _sampleRate);
|
|
92
|
+
__privateAdd(this, _encoding);
|
|
93
|
+
__privateAdd(this, _container);
|
|
114
94
|
this.on = __privateGet(this, _emitter).on.bind(__privateGet(this, _emitter));
|
|
115
95
|
this.once = __privateGet(this, _emitter).once.bind(__privateGet(this, _emitter));
|
|
116
96
|
this.events = __privateGet(this, _emitter).events.bind(__privateGet(this, _emitter));
|
|
@@ -118,7 +98,7 @@ var Source = class {
|
|
|
118
98
|
__privateSet(this, _sampleRate, sampleRate);
|
|
119
99
|
__privateSet(this, _encoding, encoding);
|
|
120
100
|
__privateSet(this, _container, container);
|
|
121
|
-
__privateSet(this, _buffer, __privateMethod(this,
|
|
101
|
+
__privateSet(this, _buffer, __privateMethod(this, _Source_instances, createBuffer_fn).call(this, 1024));
|
|
122
102
|
}
|
|
123
103
|
get sampleRate() {
|
|
124
104
|
return __privateGet(this, _sampleRate);
|
|
@@ -142,7 +122,7 @@ var Source = class {
|
|
|
142
122
|
while (newCapacity < requiredCapacity) {
|
|
143
123
|
newCapacity *= 2;
|
|
144
124
|
}
|
|
145
|
-
const newBuffer = __privateMethod(this,
|
|
125
|
+
const newBuffer = __privateMethod(this, _Source_instances, createBuffer_fn).call(this, newCapacity);
|
|
146
126
|
newBuffer.set(__privateGet(this, _buffer));
|
|
147
127
|
__privateSet(this, _buffer, newBuffer);
|
|
148
128
|
}
|
|
@@ -175,6 +155,37 @@ var Source = class {
|
|
|
175
155
|
return read;
|
|
176
156
|
});
|
|
177
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Seek in the buffer.
|
|
160
|
+
*
|
|
161
|
+
* @param offset The offset to seek to.
|
|
162
|
+
* @param whence The position to seek from.
|
|
163
|
+
* @returns The new position in the buffer.
|
|
164
|
+
* @throws {Error} If the seek is invalid.
|
|
165
|
+
*/
|
|
166
|
+
seek(offset, whence) {
|
|
167
|
+
return __async(this, null, function* () {
|
|
168
|
+
let position = __privateGet(this, _readIndex);
|
|
169
|
+
switch (whence) {
|
|
170
|
+
case "start":
|
|
171
|
+
position = offset;
|
|
172
|
+
break;
|
|
173
|
+
case "current":
|
|
174
|
+
position += offset;
|
|
175
|
+
break;
|
|
176
|
+
case "end":
|
|
177
|
+
position = __privateGet(this, _writeIndex) + offset;
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
throw new Error(`Invalid seek mode: ${whence}`);
|
|
181
|
+
}
|
|
182
|
+
if (position < 0 || position > __privateGet(this, _writeIndex)) {
|
|
183
|
+
throw new Error("Seek out of bounds");
|
|
184
|
+
}
|
|
185
|
+
__privateSet(this, _readIndex, position);
|
|
186
|
+
return position;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
178
189
|
/**
|
|
179
190
|
* Get the number of samples in a given duration.
|
|
180
191
|
*
|
|
@@ -216,7 +227,13 @@ _closed = new WeakMap();
|
|
|
216
227
|
_sampleRate = new WeakMap();
|
|
217
228
|
_encoding = new WeakMap();
|
|
218
229
|
_container = new WeakMap();
|
|
219
|
-
|
|
230
|
+
_Source_instances = new WeakSet();
|
|
231
|
+
/**
|
|
232
|
+
* Create a new buffer for the source.
|
|
233
|
+
*
|
|
234
|
+
* @param size - The size of the buffer to create.
|
|
235
|
+
* @returns The new buffer as a TypedArray based on the encoding.
|
|
236
|
+
*/
|
|
220
237
|
createBuffer_fn = function(size) {
|
|
221
238
|
const { arrayType: ArrayType } = ENCODING_MAP[__privateGet(this, _encoding)];
|
|
222
239
|
return new ArrayType(size);
|
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-5SBAQNWQ.js";
|
|
11
|
+
import "../chunk-I5YVYTNK.js";
|
|
12
|
+
import "../chunk-NJDRWDQ3.js";
|
|
13
13
|
export {
|
|
14
14
|
base64ToArray,
|
|
15
15
|
createMessageHandlerForContextId,
|