@met4citizen/headtts 1.2.0 → 1.3.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 +24 -37
- package/modules/headtts-node.mjs +6 -0
- package/modules/headtts.mjs +1 -1
- package/modules/worker-tts.mjs +7 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,8 +5,8 @@ provides phoneme-level timestamps and Oculus visemes for lip-sync, in addition
|
|
|
5
5
|
to audio output (WAV/PCM). It uses
|
|
6
6
|
[Kokoro](https://huggingface.co/onnx-community/Kokoro-82M-v1.0-ONNX-timestamped)
|
|
7
7
|
neural model and voices, and inference can run entirely in
|
|
8
|
-
the browser (
|
|
9
|
-
on a Node.js WebSocket/RESTful server (CPU
|
|
8
|
+
the browser (WebGPU or WASM), or alternatively
|
|
9
|
+
on a Node.js WebSocket/RESTful server (WebGPU or CPU).
|
|
10
10
|
|
|
11
11
|
- **Pros**: Free. Doesn't require a server in in-browser mode.
|
|
12
12
|
WebGPU support. Uses neural voices with a StyleTTS 2 model.
|
|
@@ -20,13 +20,11 @@ module.
|
|
|
20
20
|
the WASM fallback is much slower.
|
|
21
21
|
Kokoro is a lightweight model, but it still takes time to
|
|
22
22
|
load the first time and consumes a lot of memory.
|
|
23
|
-
WebGPU support in onnx-runtime-node is still experimental
|
|
24
|
-
and not released, so server-side inference is relatively slow.
|
|
25
23
|
English is currently the only supported language.
|
|
26
24
|
|
|
27
25
|
**👉 If you're using a desktop browser, check out the
|
|
28
|
-
[IN-BROWSER DEMO](https://met4citizen.github.io/HeadTTS/)!**
|
|
29
|
-
|
|
26
|
+
[IN-BROWSER DEMO](https://met4citizen.github.io/HeadTTS/)!** - If
|
|
27
|
+
your browser doesn't have WebGPU support enabled,
|
|
30
28
|
the demo app uses WASM as a fallback.
|
|
31
29
|
|
|
32
30
|
The project uses [websockets/ws](https://github.com/websockets/ws) (MIT License),
|
|
@@ -65,12 +63,12 @@ set the `workerModule` and `dictionaryURL` options explicitly,
|
|
|
65
63
|
as the default relative paths will likely not work:
|
|
66
64
|
|
|
67
65
|
```javascript
|
|
68
|
-
import { HeadTTS } from "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.
|
|
66
|
+
import { HeadTTS } from "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.3/+esm";
|
|
69
67
|
|
|
70
68
|
const headtts = new HeadTTS({
|
|
71
69
|
/* ... */
|
|
72
|
-
workerModule: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.
|
|
73
|
-
dictionaryURL: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.
|
|
70
|
+
workerModule: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.3/modules/worker-tts.mjs",
|
|
71
|
+
dictionaryURL: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.3/dictionaries/"
|
|
74
72
|
});
|
|
75
73
|
```
|
|
76
74
|
|
|
@@ -82,7 +80,7 @@ Option | Description | Default value
|
|
|
82
80
|
`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"]`
|
|
83
81
|
`audioCtx` | Audio context for creating audio buffers. If `null`, a new one is created. | `null`
|
|
84
82
|
`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`
|
|
85
|
-
`transformersModule` | URL of the `transformers.js` module to load. | `"https://cdn.jsdelivr.net/npm/`<br>`@huggingface/transformers@
|
|
83
|
+
`transformersModule` | URL of the `transformers.js` module to load. | `"https://cdn.jsdelivr.net/npm/`<br>`@huggingface/transformers@4.0.0`<br>`/dist/transformers.min.js"`
|
|
86
84
|
`model` | Kokoro text-to-speech ONNX model (timestamped) used for in-browser inference. | `"onnx-community/`<br>`Kokoro-82M-v1.0-ONNX-timestamped"`
|
|
87
85
|
`dtypeWebgpu` | Data type precision for WebGPU inference: `"fp32"` (recommended), `"fp16"`, `"q8"`, `"q4"`, or `"q4f16"`. | `"fp32"`
|
|
88
86
|
`dtypeWasm` | Data type precision for WASM inference: `"fp32"`, `"fp16"`, `"q8"`, `"q4"`, or `"q4f16"`. | `"q4"`
|
|
@@ -310,7 +308,7 @@ Property|Description|Default
|
|
|
310
308
|
`tts.transformersModule` | Name of the transformers.js module to use. | `"@huggingface/transformers"`
|
|
311
309
|
`tts.model` | The timestamped Kokoro TTS ONNX model. | `"onnx-community/`<br>`Kokoro-82M-v1.0-ONNX-timestamped"`
|
|
312
310
|
`tts.dtype` | The data type precision used for inference. Available options: `"fp32"`, `"fp16"`, `"q8"`, `"q4"`, or `"q4f16"`. | `"fp32"`
|
|
313
|
-
`tts.device` | Computation backend to use.
|
|
311
|
+
`tts.device` | Computation backend to use: `"webgpu"` or `"cpu"`. NOTE: Node.js WebGPU implementation in Transformers.js is not thread safe, so we can only have one thread for WebGPU. Others will be automatically started as `"cpu"`. | `"webgpu"`
|
|
314
312
|
`tts.styleDim` | The embedding dimension for style. | `256`
|
|
315
313
|
`tts.audioSampleRate` | Audio sample rate in Hertz (Hz). | `24000`
|
|
316
314
|
`tts.frameRate` | Frame rate in frames per second (FPS). | `40`
|
|
@@ -526,27 +524,34 @@ ALUMIINI FOLI KATT OKSI PAPE SEOS VENE VUOK
|
|
|
526
524
|
|
|
527
525
|
# Appendix C: Latency
|
|
528
526
|
|
|
529
|
-
In-browser TTS
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
527
|
+
In-browser TTS using WebGPU runs approximately 3x faster than real time
|
|
528
|
+
and about 10x faster than WASM. CPU-based inference on a Node.js server
|
|
529
|
+
performs surprisingly well. However, increasing the thread pool size
|
|
530
|
+
degrades performance. WebGPU inference on a Node.js server is slightly
|
|
531
|
+
faster than CPU inference, but it supports only a single dedicated WebGPU
|
|
532
|
+
thread. On Metal, the fastest HeadTTS configuration is WebGPU with two
|
|
533
|
+
threads where the second thread automatically falls back to CPU execution.
|
|
534
|
+
|
|
535
|
+
I recommend using 32-bit floating point precision (fp32) for the best
|
|
536
|
+
audio quality unless memory consumption becomes a concern.
|
|
536
537
|
|
|
537
538
|
Unofficial latency results using my own
|
|
538
539
|
[latency test app](https://github.com/met4citizen/HeadTTS/blob/main/tests/latency.html):
|
|
539
540
|
|
|
540
541
|
TTS Engine/Setup |`FIL`<sup>\[1]</sup>|`FBL`<sup>\[2]</sup>|`RTF`<sup>\[3]</sup>
|
|
541
542
|
---|---|---|---
|
|
542
|
-
HeadTTS, Chrome, WebGPU/fp32 | 8.6s | 852ms | 0.27
|
|
543
|
+
HeadTTS, Chrome, WebGPU/fp32 | 8.6s | 852ms | **0.27**
|
|
543
544
|
HeadTTS, Edge, WebGPU/fp32 | 8.8s | 858ms | 0.28
|
|
544
545
|
HeadTTS, Safari, WebGPU/fp32 | 25.8s | 2437ms | 0.82
|
|
545
546
|
HeadTTS, Chrome, WASM/q4 | 45.4s | 4404ms | 1.45
|
|
546
547
|
HeadTTS, Edge, WASM/q4 | 45.5s | 4392ms | 1.45
|
|
547
548
|
HeadTTS, Safari, WASM/q4 | 45.6s | 4447ms | 1.46
|
|
549
|
+
HeadTTS, WebSocket, WebGPU/fp32, 1 thread | 6.6s | 719ms | 0.21
|
|
550
|
+
HeadTTS, WebSocket, WebGPU/fp32, 2 threads | 3.8s | 742ms | **0.12**
|
|
548
551
|
HeadTTS, WebSocket, CPU/fp32, 1 thread | 6.8s | 712ms | 0.22
|
|
549
552
|
HeadTTS, WebSocket, CPU/fp32, 4 threads | 6.0s | 2341ms | 0.20
|
|
553
|
+
HeadTTS, REST, WebGPU/fp32, 1 thread | 6.7s | 713ms | 0.21
|
|
554
|
+
HeadTTS, REST, WebGPU/fp32, 2 threads | 3.6s | 717ms | **0.11**
|
|
550
555
|
HeadTTS, REST, CPU/fp32, 1 thread | 7.0s | 793ms | 0.23
|
|
551
556
|
HeadTTS, REST, CPU/fp32, 4 threads | 6.5s | 2638ms | 0.21
|
|
552
557
|
ElevenLabs, WebSocket | 4.8s | 977ms | 0.20
|
|
@@ -567,27 +572,9 @@ solutions use streaming, some not.
|
|
|
567
572
|
<sup>\[3]</sup> *Real-time factor* = Time to generate full audio / Duration of the full
|
|
568
573
|
audio. If RTF < 1, synthesis is faster than real-time (i.e., good).
|
|
569
574
|
|
|
570
|
-
<details>
|
|
571
|
-
<summary>CLICK HERE here to see the TEST SETUP.</summary>
|
|
572
|
-
|
|
573
575
|
**Test setup**: Macbook Air M2 laptop, 8 cores, 16GB memory,
|
|
574
576
|
macOS Tahoe 26.0, Metal2 GPU 10 cores, 300/50 Mbit/s internet connection.
|
|
575
577
|
The latest Google Chrome, Edge, Safari desktop browsers.
|
|
576
578
|
|
|
577
579
|
All test cases use WAV or raw PCM 16bit LE format and the "List 1" of the
|
|
578
580
|
[Harvard Sentences](https://www.cs.columbia.edu/~hgs/audio/harvard.html):
|
|
579
|
-
|
|
580
|
-
```text
|
|
581
|
-
The birch canoe slid on the smooth planks.
|
|
582
|
-
Glue the sheet to the dark blue background.
|
|
583
|
-
It's easy to tell the depth of a well.
|
|
584
|
-
These days a chicken leg is a rare dish.
|
|
585
|
-
Rice is often served in round bowls.
|
|
586
|
-
The juice of lemons makes fine punch.
|
|
587
|
-
The box was thrown beside the parked truck.
|
|
588
|
-
The hogs were fed chopped corn and garbage.
|
|
589
|
-
Four hours of steady work faced us.
|
|
590
|
-
A large size in stockings is hard to sell.
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
</details>
|
package/modules/headtts-node.mjs
CHANGED
|
@@ -196,6 +196,12 @@ for( let i=0; i<config.tts.threads; i++ ) {
|
|
|
196
196
|
[ "transformersModule", "model", "dtype", "device", "styleDim", "frameRate",
|
|
197
197
|
"languages", "dictionaryPath", "voicePath", "voices", "audioSampleRate",
|
|
198
198
|
"deltaStart", "deltaEnd", "trace" ].forEach( x => data[x] = config.tts[x] );
|
|
199
|
+
|
|
200
|
+
// Node.js WebGPU is not thread safe, so we can only have one thread for WebGPU
|
|
201
|
+
if ( data.device === "webgpu" && i > 0 ) {
|
|
202
|
+
data.device = "cpu";
|
|
203
|
+
}
|
|
204
|
+
|
|
199
205
|
const message = {
|
|
200
206
|
type: "connect",
|
|
201
207
|
data: data
|
package/modules/headtts.mjs
CHANGED
|
@@ -37,7 +37,7 @@ class HeadTTS {
|
|
|
37
37
|
audioCtx: null,
|
|
38
38
|
|
|
39
39
|
workerModule: null,
|
|
40
|
-
transformersModule: "https://cdn.jsdelivr.net/npm/@huggingface/transformers@
|
|
40
|
+
transformersModule: "https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.0.0/dist/transformers.min.js",
|
|
41
41
|
|
|
42
42
|
model: "onnx-community/Kokoro-82M-v1.0-ONNX-timestamped",
|
|
43
43
|
dtypeWebgpu: "fp32", // "fp32" | "fp16" | "q8" | "q4" | "q4f16"
|
package/modules/worker-tts.mjs
CHANGED
|
@@ -4,6 +4,8 @@ import * as utils from "./utils.mjs";
|
|
|
4
4
|
let StyleTextToSpeech2Model;
|
|
5
5
|
let AutoTokenizer;
|
|
6
6
|
let Tensor;
|
|
7
|
+
let env;
|
|
8
|
+
let LogLevel;
|
|
7
9
|
|
|
8
10
|
// Status flags
|
|
9
11
|
let filesProgress;
|
|
@@ -113,7 +115,11 @@ async function connect() {
|
|
|
113
115
|
|
|
114
116
|
// Load modules dynamically
|
|
115
117
|
try {
|
|
116
|
-
({ StyleTextToSpeech2Model, AutoTokenizer, Tensor } = await import(settings.transformersModule));
|
|
118
|
+
({ StyleTextToSpeech2Model, AutoTokenizer, Tensor, env, LogLevel } = await import(settings.transformersModule));
|
|
119
|
+
|
|
120
|
+
// Set log level to ERROR
|
|
121
|
+
env.logLevel = LogLevel.ERROR;
|
|
122
|
+
|
|
117
123
|
} catch(error) {
|
|
118
124
|
console.error("HeadTTS Worker: Importing modules failed, error=", error);
|
|
119
125
|
throw new Error("Importing modules failed.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@met4citizen/headtts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "HeadTTS: A free Javascript text-to-speech with timestamps and visemes.",
|
|
5
5
|
"main": "modules/headtts.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"dictionaries/"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@huggingface/transformers": "^
|
|
16
|
-
"ws": "^8.
|
|
15
|
+
"@huggingface/transformers": "^4.0.0",
|
|
16
|
+
"ws": "^8.20.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"start": "node ./modules/headtts-node.mjs",
|