@met4citizen/headtts 1.0.1 → 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/README.md +7 -4
- package/modules/headtts.mjs +22 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ a lot of memory. WebGPU support in onnxruntime-node is still experimental
|
|
|
21
21
|
and not released, so server-side inference is relatively slow. English
|
|
22
22
|
is currently the only supported language.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
**👉 If you're using a Chrome or Edge desktop browser, check out the
|
|
25
25
|
[In-browser Demo](https://met4citizen.github.io/HeadTTS/)!**
|
|
26
26
|
|
|
27
27
|
The project uses [websockets/ws](https://github.com/websockets/ws) (MIT License),
|
|
@@ -62,7 +62,8 @@ Option | Description | Default value
|
|
|
62
62
|
--- | --- | ---
|
|
63
63
|
`endpoints` | List of WebSocket/RESTful servers or backends `webgpu` or `wasm`, in order of priority. If one fails, the next is used. | `["webgpu",`<br>` "wasm"]`
|
|
64
64
|
`audioCtx` | Audio context for creating audio buffers. If `null`, a new one is created. | `null`
|
|
65
|
-
`
|
|
65
|
+
`workerModule` | URL of the HeadTTS Web Worker module. Enables use from a CDN. If set to `null`, the relative path/file `./worker-tts.mjs` is used. | `null`
|
|
66
|
+
`transformersModule` | URL of the `transformers.js` module to load. | `"https://cdn.jsdelivr.net/npm/`<br>`@huggingface/transformers@3.7.2`<br>`/dist/transformers.min.js"`
|
|
66
67
|
`model` | Kokoro text-to-speech ONNX model (timestamped) used for in-browser inference. | `"onnx-community/`<br>`Kokoro-82M-v1.0-ONNX-timestamped"`
|
|
67
68
|
`dtypeWebgpu` | Data type precision for WebGPU inference: `"fp32"` (recommended), `"fp16"`, `"q8"`, `"q4"`, or `"q4f16"`. | `"fp32"`
|
|
68
69
|
`dtypeWasm` | Data type precision for WASM inference: `"fp32"`, `"fp16"`, `"q8"`, `"q4"`, or `"q4f16"`. | `"q4"`
|
|
@@ -235,7 +236,7 @@ Method | Description
|
|
|
235
236
|
`connect( settings=null, onprogress=null, onerror=null )` | Connects to the specified set of `endpoints` set in constructor or within the optinal `settings` object. If the `settings` parameter is provided, it forces a reconnection. The `onprogress` callback handles `ProgressEvent` events, while the `onerror` callback handles system-level error events. Returns a promise. **Note:** When connecting to a RESTful server, the method sends a hello message and considers the connection established only if a text response starting with `HeadTTS` is received.
|
|
236
237
|
`clear()` | Clears all work queues and resolves all promises.
|
|
237
238
|
`setup( data, onerror=null )` | Adds a new setup request to the work queue. See the API section for the supported `data` properties. Returns a promise.
|
|
238
|
-
`synthesize( data, onmessage=null, onerror=null )` | Adds a new
|
|
239
|
+
`synthesize( data, onmessage=null, onerror=null )` | Adds a new synthesis request to the work queue. The `data` object supports the `input` and `userData` properties. The `userData` property is returned in the output as `message.userData` unchanged. If event handlers are provided, they override the default handlers. Returns a promise that resolves with a sorted array of related messages of type `"audio"` or `"error"`.
|
|
239
240
|
`custom( data, onmessage=null, onerror=null )` | Adds a new custom message to the work queue. If event handlers are provided, they override other handlers. Returns a promise that resolves with the related message of the type `"custom"`.
|
|
240
241
|
|
|
241
242
|
</details>
|
|
@@ -274,6 +275,8 @@ node ./modules/headtts-node.mjs --trace 16
|
|
|
274
275
|
|
|
275
276
|
</details>
|
|
276
277
|
|
|
278
|
+
By default, the server uses the `./headtts-node.json` configuration file.
|
|
279
|
+
|
|
277
280
|
<details>
|
|
278
281
|
<summary>CLICK HERE to see the configurable PROPERTIES.</summary>
|
|
279
282
|
|
|
@@ -507,7 +510,7 @@ ALUMIINI FOLI KATT OKSI PAPE SEOS VENE VUOK
|
|
|
507
510
|
|
|
508
511
|
# Appendix C: Latency
|
|
509
512
|
|
|
510
|
-
In-browser TTS on WebGPU is 3x
|
|
513
|
+
In-browser TTS on WebGPU is 3x faster than
|
|
511
514
|
real-time and approximately 10x faster than WASM. CPU inference on
|
|
512
515
|
a Node.js server performs surprisingly well, but increasing the thread
|
|
513
516
|
pool size worsens performance, so we need to wait for WebGPU support.
|
package/modules/headtts.mjs
CHANGED
|
@@ -36,7 +36,8 @@ class HeadTTS {
|
|
|
36
36
|
endpoints: ["webgpu", "wasm"],
|
|
37
37
|
audioCtx: null,
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
workerModule: null,
|
|
40
|
+
transformersModule: "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.2/dist/transformers.min.js",
|
|
40
41
|
|
|
41
42
|
model: "onnx-community/Kokoro-82M-v1.0-ONNX-timestamped",
|
|
42
43
|
dtypeWebgpu: "fp32", // "fp32" | "fp16" | "q8" | "q4" | "q4f16"
|
|
@@ -265,8 +266,20 @@ class HeadTTS {
|
|
|
265
266
|
await new Promise((resolve, reject) => {
|
|
266
267
|
|
|
267
268
|
// Start the TTS web worker
|
|
268
|
-
|
|
269
|
-
|
|
269
|
+
if ( this.settings.workerModule ) {
|
|
270
|
+
const code = `import "${this.settings.workerModule}";`;
|
|
271
|
+
const blob = new Blob([code], { type: "application/javascript" });
|
|
272
|
+
const url = URL.createObjectURL(blob);
|
|
273
|
+
this.ww = new Worker(url, { type: "module" });
|
|
274
|
+
const origTerminate = this.ww.terminate;
|
|
275
|
+
this.ww.terminate = function () {
|
|
276
|
+
URL.revokeObjectURL(url);
|
|
277
|
+
origTerminate.call(this);
|
|
278
|
+
};
|
|
279
|
+
} else {
|
|
280
|
+
const url = new URL("./worker-tts.mjs", import.meta.url);
|
|
281
|
+
this.ww = new Worker(url, { type: 'module' });
|
|
282
|
+
}
|
|
270
283
|
|
|
271
284
|
// Handle progress reports and wait for ready message
|
|
272
285
|
const rejectedTimeout = () => reject('Connection timed out.');
|
|
@@ -732,10 +745,11 @@ class HeadTTS {
|
|
|
732
745
|
onerror: onerror,
|
|
733
746
|
started: performance.now(),
|
|
734
747
|
deferred: new utils.Deferred(),
|
|
735
|
-
|
|
748
|
+
metaData: {
|
|
736
749
|
part: i,
|
|
737
750
|
partsTotal: messages.length
|
|
738
|
-
}
|
|
751
|
+
},
|
|
752
|
+
userData: data.userData
|
|
739
753
|
};
|
|
740
754
|
deferredPromises.push( item.deferred.promise );
|
|
741
755
|
this.queueIn.push(item);
|
|
@@ -904,7 +918,7 @@ class HeadTTS {
|
|
|
904
918
|
console.error("HeadTTS: REST error, error=", error);
|
|
905
919
|
this.processData({
|
|
906
920
|
type: "error",
|
|
907
|
-
ref: item.id,
|
|
921
|
+
ref: item.message.id,
|
|
908
922
|
data: {
|
|
909
923
|
error: "HeadTTS: REST error, message=" + error.message
|
|
910
924
|
}
|
|
@@ -1009,7 +1023,8 @@ class HeadTTS {
|
|
|
1009
1023
|
this.items.delete( item.message.ref );
|
|
1010
1024
|
|
|
1011
1025
|
const message = item.message;
|
|
1012
|
-
|
|
1026
|
+
message.metaData = item.metaData;
|
|
1027
|
+
message.userData = item.userData;
|
|
1013
1028
|
const type = message.type;
|
|
1014
1029
|
|
|
1015
1030
|
if ( type === "audio" || type === "custom" ) {
|