@met4citizen/headtts 1.2.0 → 1.4.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 +39 -48
- package/headtts-node.json +41 -0
- package/modules/build-en-us.mjs +178 -0
- package/modules/headtts-node.mjs +13 -7
- package/modules/headtts.mjs +1 -1
- package/modules/worker-tts.mjs +23 -1
- package/package.json +5 -5
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.4/+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.4/modules/worker-tts.mjs",
|
|
71
|
+
dictionaryURL: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.4/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"`
|
|
@@ -270,6 +268,8 @@ cd HeadTTS
|
|
|
270
268
|
npm install
|
|
271
269
|
```
|
|
272
270
|
|
|
271
|
+
Note: Microsoft has stopped publishing macOS x86_64 binaries for ONNX Runtime. If you are using an Intel Mac, you can try pinning "onnxruntime-node" to the older version "1.23.2" in the transformers dependencies. Workaround via [@piousbox](https://github.com/piousbox) (see [#12](https://github.com/met4citizen/HeadTTS/pull/12)).
|
|
272
|
+
|
|
273
273
|
Start the server:
|
|
274
274
|
|
|
275
275
|
```bash
|
|
@@ -310,7 +310,7 @@ Property|Description|Default
|
|
|
310
310
|
`tts.transformersModule` | Name of the transformers.js module to use. | `"@huggingface/transformers"`
|
|
311
311
|
`tts.model` | The timestamped Kokoro TTS ONNX model. | `"onnx-community/`<br>`Kokoro-82M-v1.0-ONNX-timestamped"`
|
|
312
312
|
`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.
|
|
313
|
+
`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
314
|
`tts.styleDim` | The embedding dimension for style. | `256`
|
|
315
315
|
`tts.audioSampleRate` | Audio sample rate in Hertz (Hz). | `24000`
|
|
316
316
|
`tts.frameRate` | Frame rate in frames per second (FPS). | `40`
|
|
@@ -526,29 +526,36 @@ ALUMIINI FOLI KATT OKSI PAPE SEOS VENE VUOK
|
|
|
526
526
|
|
|
527
527
|
# Appendix C: Latency
|
|
528
528
|
|
|
529
|
-
In-browser TTS
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
529
|
+
In-browser TTS using WebGPU runs approximately 5x faster than real time
|
|
530
|
+
and about 7x faster than WASM. CPU-based inference on a Node.js server
|
|
531
|
+
performs surprisingly well. However, increasing the thread pool size
|
|
532
|
+
degrades performance. WebGPU inference on a Node.js server is slightly
|
|
533
|
+
faster than CPU inference, but it supports only a single dedicated WebGPU
|
|
534
|
+
thread. On Metal, the fastest HeadTTS configuration is WebGPU with two
|
|
535
|
+
threads where the second thread automatically falls back to CPU execution.
|
|
536
|
+
|
|
537
|
+
I recommend using 32-bit floating point precision (fp32) for the best
|
|
538
|
+
audio quality unless memory consumption becomes a concern.
|
|
536
539
|
|
|
537
540
|
Unofficial latency results using my own
|
|
538
541
|
[latency test app](https://github.com/met4citizen/HeadTTS/blob/main/tests/latency.html):
|
|
539
542
|
|
|
540
543
|
TTS Engine/Setup |`FIL`<sup>\[1]</sup>|`FBL`<sup>\[2]</sup>|`RTF`<sup>\[3]</sup>
|
|
541
544
|
---|---|---|---
|
|
542
|
-
HeadTTS, Chrome, WebGPU/fp32 |
|
|
543
|
-
HeadTTS, Edge, WebGPU/fp32 |
|
|
544
|
-
HeadTTS, Safari, WebGPU/fp32 |
|
|
545
|
-
HeadTTS, Chrome, WASM/q4 | 45.4s |
|
|
546
|
-
HeadTTS, Edge, WASM/q4 | 45.
|
|
547
|
-
HeadTTS, Safari, WASM/q4 | 45.
|
|
548
|
-
HeadTTS,
|
|
549
|
-
HeadTTS,
|
|
550
|
-
HeadTTS,
|
|
551
|
-
HeadTTS,
|
|
545
|
+
HeadTTS, Chrome, WebGPU/fp32 | 6.7s | 678ms | **0.21**
|
|
546
|
+
HeadTTS, Edge, WebGPU/fp32 | 6.2s | 601ms | **0.20**
|
|
547
|
+
HeadTTS, Safari, WebGPU/fp32 | 11.1s | 1082ms | 0.35
|
|
548
|
+
HeadTTS, Chrome, WASM/q4 | 45.4s | 4401ms | 1.46
|
|
549
|
+
HeadTTS, Edge, WASM/q4 | 45.4s | 4392ms | 1.45
|
|
550
|
+
HeadTTS, Safari, WASM/q4 | 45.2s | 4390ms | 1.45
|
|
551
|
+
HeadTTS, Node/WS, WebGPU/fp32, 1 thread | 5.7s | 578ms | **0.18**
|
|
552
|
+
HeadTTS, Node/WS, WebGPU/fp32, 2 threads | 3.6s | 678ms | **0.11**
|
|
553
|
+
HeadTTS, Node/WS, CPU/fp32, 1 thread | 6.8s | 674ms | 0.21
|
|
554
|
+
HeadTTS, Node/WS, CPU/fp32, 4 threads | 7.3s | 2837ms | 0.23
|
|
555
|
+
HeadTTS, Node/REST, WebGPU/fp32, 1 thread | 5.7s | 1228ms | **0.18**
|
|
556
|
+
HeadTTS, Node/REST, WebGPU/fp32, 2 threads | 3.6s | 707ms | **0.11**
|
|
557
|
+
HeadTTS, Node/REST, CPU/fp32, 1 thread | 6.8s | 677ms | 0.21
|
|
558
|
+
HeadTTS, Node/REST, CPU/fp32, 4 threads | 7.2s | 2736ms | 0.23
|
|
552
559
|
ElevenLabs, WebSocket | 4.8s | 977ms | 0.20
|
|
553
560
|
ElevenLabs, REST | 11.3s | 1097ms | 0.46
|
|
554
561
|
ElevenLabs, REST, Flash_v2_5 | 4.8s | 581ms | 0.22
|
|
@@ -567,27 +574,11 @@ solutions use streaming, some not.
|
|
|
567
574
|
<sup>\[3]</sup> *Real-time factor* = Time to generate full audio / Duration of the full
|
|
568
575
|
audio. If RTF < 1, synthesis is faster than real-time (i.e., good).
|
|
569
576
|
|
|
570
|
-
<details>
|
|
571
|
-
<summary>CLICK HERE here to see the TEST SETUP.</summary>
|
|
572
|
-
|
|
573
577
|
**Test setup**: Macbook Air M2 laptop, 8 cores, 16GB memory,
|
|
574
|
-
macOS
|
|
575
|
-
The latest Google Chrome
|
|
578
|
+
macOS 27.2.1, Metal2 GPU 10 cores, 300/50 Mbit/s internet connection.
|
|
579
|
+
The latest Google Chrome (158.0.8127.88),
|
|
580
|
+
Edge (158.0.4370.45),
|
|
581
|
+
Safari (27.2) desktop browsers.
|
|
576
582
|
|
|
577
583
|
All test cases use WAV or raw PCM 16bit LE format and the "List 1" of the
|
|
578
584
|
[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>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"server": {
|
|
3
|
+
"port": 8882,
|
|
4
|
+
"certFile": null,
|
|
5
|
+
"keyFile": null,
|
|
6
|
+
"websocket": true,
|
|
7
|
+
"rest": true,
|
|
8
|
+
"connectionTimeout": 20000,
|
|
9
|
+
"corsOrigin": "*"
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
"tts": {
|
|
13
|
+
"threads": 1,
|
|
14
|
+
|
|
15
|
+
"transformersModule": "@huggingface/transformers",
|
|
16
|
+
|
|
17
|
+
"model": "onnx-community/Kokoro-82M-v1.0-ONNX-timestamped",
|
|
18
|
+
"dtype": "fp32",
|
|
19
|
+
"device": "webgpu",
|
|
20
|
+
"styleDim": 256,
|
|
21
|
+
"frameRate": 40,
|
|
22
|
+
"audioSampleRate": 24000,
|
|
23
|
+
|
|
24
|
+
"languages": ["en-us"],
|
|
25
|
+
"dictionaryPath": "./dictionaries",
|
|
26
|
+
"voicePath": "./voices",
|
|
27
|
+
"voices": ["af_bella","am_fenrir"],
|
|
28
|
+
|
|
29
|
+
"deltaStart": -10,
|
|
30
|
+
"deltaEnd": 10,
|
|
31
|
+
|
|
32
|
+
"defaults": {
|
|
33
|
+
"voice": "af_bella",
|
|
34
|
+
"language": "en-us",
|
|
35
|
+
"speed": 1,
|
|
36
|
+
"audioEncoding": "wav"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
"trace": 0
|
|
41
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Import core modules
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import readline from "readline";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import process from 'node:process';
|
|
7
|
+
|
|
8
|
+
// Setup __dirname in ES module scope
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
|
|
12
|
+
// CMU to IPA phoneme map (with stress)
|
|
13
|
+
const cmuToIPA = {
|
|
14
|
+
"AA0": "ɑ", "AA1": "ˈɑ", "AA2": "ˌɑ",
|
|
15
|
+
"AE0": "æ", "AE1": "ˈæ", "AE2": "ˌæ",
|
|
16
|
+
"AH0": "ə", "AH1": "ˈʌ", "AH2": "ˌə",
|
|
17
|
+
"AO0": "ɔ", "AO1": "ˈɔ", "AO2": "ˌɔ",
|
|
18
|
+
"AW0": "aʊ", "AW1": "ˈaʊ", "AW2": "ˌaʊ",
|
|
19
|
+
"AY0": "aɪ", "AY1": "ˈaɪ", "AY2": "ˌaɪ",
|
|
20
|
+
"EH0": "ɛ", "EH1": "ˈɛ", "EH2": "ˌɛ",
|
|
21
|
+
"ER0": "ɚ", "ER1": "ˈɝ", "ER2": "ˌɝ",
|
|
22
|
+
"EY0": "eɪ", "EY1": "ˈeɪ", "EY2": "ˌeɪ",
|
|
23
|
+
"IH0": "ɪ", "IH1": "ˈɪ", "IH2": "ˌɪ",
|
|
24
|
+
"IY0": "i", "IY1": "ˈi", "IY2": "ˌi",
|
|
25
|
+
"OW0": "oʊ", "OW1": "ˈoʊ", "OW2": "ˌoʊ",
|
|
26
|
+
"OY0": "ɔɪ", "OY1": "ˈɔɪ", "OY2": "ˌɔɪ",
|
|
27
|
+
"UH0": "ʊ", "UH1": "ˈʊ", "UH2": "ˌʊ",
|
|
28
|
+
"UW0": "u", "UW1": "ˈu", "UW2": "ˌu",
|
|
29
|
+
"B": "b", "CH": "tʃ", "D": "d", "DH": "ð", "F": "f", "G": "ɡ",
|
|
30
|
+
"HH": "h", "JH": "dʒ", "K": "k", "L": "l", "M": "m", "N": "n",
|
|
31
|
+
"NG": "ŋ", "P": "p", "R": "ɹ", "S": "s", "SH": "ʃ", "T": "t",
|
|
32
|
+
"TH": "θ", "V": "v", "W": "w", "Y": "j", "Z": "z", "ZH": "ʒ"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const IPAToMisaki = {
|
|
36
|
+
"ɚ": ["ɜ","ɹ"], "ˈɝ": ["ˈɜ","ɹ"], "ˌɝ": ["ˌɜ","ɹ"],
|
|
37
|
+
"tʃ": ["ʧ"], "dʒ": ["ʤ"],
|
|
38
|
+
"eɪ": ["A"], "ˈeɪ": ["ˈA"], "ˌeɪ": ["ˌA"],
|
|
39
|
+
"aɪ": ["I"], "ˈaɪ": ["ˈI"], "ˌaɪ": ["ˌI"],
|
|
40
|
+
"aʊ": ["W"], "ˈaʊ": ["ˈW"], "ˌaʊ": ["ˌW"],
|
|
41
|
+
"ɔɪ": ["Y"], "ˈɔɪ": ["ˈY"], "ˌɔɪ": ["ˌY"],
|
|
42
|
+
"oʊ": ["O"], "ˈoʊ": ["ˈO"], "ˌoʊ": ["ˌO"],
|
|
43
|
+
"əʊ": ["Q"], "ˈəʊ": ["ˈQ"], "ˈəʊ": ["ˌQ"]
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const reducedPronunciations = {
|
|
47
|
+
I: ["AY1"]
|
|
48
|
+
|
|
49
|
+
// NOTE: Skipping reduced vowels, because Kokoro was not taught with them
|
|
50
|
+
|
|
51
|
+
/* A: ["AH0"], ABOUT: ["AH0", "B", "AW1", "T"], AN: ["AH0", "N"],
|
|
52
|
+
AND: ["AH0", "N"], ARE: ["ER0"], AS: ["AH0", "Z"], AT: ["AH0", "T"],
|
|
53
|
+
BE: ["B", "IY0"], BEEN: ["B", "IH0", "N"], CAN: ["K", "AH0", "N"],
|
|
54
|
+
COULD: ["K", "UH0", "D"], DID: ["D", "IH0", "D"], DO: ["D", "OW0"],
|
|
55
|
+
DOES: ["D", "AH0", "Z"], FOR: ["F", "ER0"], FROM: ["F", "R", "AH0", "M"],
|
|
56
|
+
HAD: ["HH", "AH0", "D"], HAS: ["HH", "AH0", "Z"], HAVE: ["HH", "AH0", "V"],
|
|
57
|
+
HE: ["HH", "IY0"], HER: ["HH", "ER0"], HIM: ["HH", "IH0", "M"],
|
|
58
|
+
HIS: ["HH", "IH0", "Z"], I: ["AY0"], IF: ["IH0", "F"], IN: ["IH0", "N"],
|
|
59
|
+
IS: ["IH0", "Z"], IT: ["IH0", "T"], ME: ["M", "IY0"],
|
|
60
|
+
MIGHT: ["M", "AY0", "T"], MUST: ["M", "AH0", "S", "T"],
|
|
61
|
+
NOT: ["N", "AH0", "T"], OF: ["AH0", "V"], ON: ["AH0", "N"], OR: ["ER0"],
|
|
62
|
+
OUR: ["AW0", "ER0"], OUT: ["AW0", "T"], SHALL: ["SH", "AH0", "L"],
|
|
63
|
+
SHOULD: ["SH", "UH0", "D"], SO: ["S", "OW0"], THAN: ["DH", "AH0", "N"],
|
|
64
|
+
THAT: ["DH", "AH0", "T"], THE: ["DH", "AH0"], THEM: ["DH", "AH0", "M"],
|
|
65
|
+
THERE: ["DH", "EH1", "R"], THEY: ["DH", "EY0"], THIS: ["DH", "IH0", "S"],
|
|
66
|
+
TO: ["T", "AH0"], UP: ["AH0", "P"], US: ["AH0", "S"], WAS: ["W", "AH0", "Z"],
|
|
67
|
+
WE: ["W", "IY0"], WERE: ["W", "ER0"], WHAT: ["W", "AH0", "T"],
|
|
68
|
+
WHO: ["HH", "UW0"], WILL: ["W", "IH0", "L"], WOULD: ["W", "UH0", "D"],
|
|
69
|
+
YOU: ["Y", "UW0"], YOUR: ["Y", "ER0"], "I'M": ["AY0", "M"],
|
|
70
|
+
"YOU'RE": ["Y", "ER0"], "HE'S": ["HH", "IY0", "Z"], "SHE'S": ["SH", "IY0", "Z"],
|
|
71
|
+
"IT'S": ["IH0", "T", "S"], "WE'RE": ["W", "ER0"], "THEY'RE": ["DH", "ER0"],
|
|
72
|
+
"I'VE": ["AY0", "V"], "YOU'VE": ["Y", "UW0", "V"], "WE'VE": ["W", "IY0", "V"],
|
|
73
|
+
"THEY'VE": ["DH", "EY0", "V"], "I'D": ["AY0", "D"], "YOU'D": ["Y", "UW0", "D"],
|
|
74
|
+
"HE'D": ["HH", "IY0", "D"], "SHE'D": ["SH", "IY0", "D"],
|
|
75
|
+
"WE'D": ["W", "IY0", "D"], "THEY'D": ["DH", "EY0", "D"],
|
|
76
|
+
"I'LL": ["AY0", "L"], "YOU'LL": ["Y", "UW0", "L"], "HE'LL": ["HH", "IY0", "L"],
|
|
77
|
+
"SHE'LL": ["SH", "IY0", "L"], "WE'LL": ["W", "IY0", "L"],
|
|
78
|
+
"THEY'LL": ["DH", "EY0", "L"], "DON'T": ["D", "OW0", "N", "T"],
|
|
79
|
+
"DOESN'T": ["D", "AH0", "Z", "N", "T"], "DIDN'T": ["D", "IH0", "D", "N", "T"],
|
|
80
|
+
"HASN'T": ["HH", "AE0", "Z", "N", "T"], "HAVEN'T": ["HH", "AE0", "V", "N", "T"],
|
|
81
|
+
"HADN'T": ["HH", "AE0", "D", "N", "T"], "ISN'T": ["IH0", "Z", "N", "T"],
|
|
82
|
+
"AREN'T": ["AA0", "R", "N", "T"], "WASN'T": ["W", "AH0", "Z", "N", "T"],
|
|
83
|
+
"WEREN'T": ["W", "ER0", "N", "T"], "WOULDN'T": ["W", "UH0", "D", "N", "T"],
|
|
84
|
+
"SHOULDN'T": ["SH", "UH0", "D", "N", "T"], "COULDN'T": ["K", "UH0", "D", "N", "T"],
|
|
85
|
+
"MUSTN'T": ["M", "AH0", "S", "N", "T"], "LET'S": ["L", "EH0", "T", "S"],
|
|
86
|
+
"THAT'S": ["DH", "AE0", "T", "S"], "WHO'S": ["HH", "UW0", "Z"],
|
|
87
|
+
"WHAT'S": ["W", "AH0", "T", "S"], "WHERE'S": ["W", "EH0", "R", "Z"],
|
|
88
|
+
"WHEN'S": ["W", "EH0", "N", "Z"], "WHY'S": ["W", "AY0", "Z"],
|
|
89
|
+
"HOW'S": ["HH", "AW0", "Z"], "AIN'T": ["EY0", "N", "T"], "Y'ALL": ["Y", "AO0", "L"] */
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// File paths
|
|
93
|
+
const inputFile = path.join(__dirname, "cmudict-0.7b");
|
|
94
|
+
const outputFile = path.join(__dirname, "en-us.txt");
|
|
95
|
+
|
|
96
|
+
// Create read and write streams
|
|
97
|
+
const rl = readline.createInterface({
|
|
98
|
+
input: fs.createReadStream(inputFile),
|
|
99
|
+
crlfDelay: Infinity
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const outStream = fs.createWriteStream(outputFile, { encoding: "utf8" });
|
|
103
|
+
|
|
104
|
+
// Add comment
|
|
105
|
+
outStream.write(";;; Generated by script for the https://github.com/met4citizen/HeadTTS project\n");
|
|
106
|
+
outStream.write(";;; See the copyright notice for the original source data below:\n");
|
|
107
|
+
outStream.write(";;; \n");
|
|
108
|
+
|
|
109
|
+
let currentBase = null;
|
|
110
|
+
let currentPronunciations = [];
|
|
111
|
+
|
|
112
|
+
// Helper: write current base word and all its pronunciations
|
|
113
|
+
function flushWord() {
|
|
114
|
+
if (!currentBase || currentPronunciations.length === 0) return;
|
|
115
|
+
|
|
116
|
+
outStream.write(`${currentBase}`);
|
|
117
|
+
for (const phonemes of currentPronunciations) {
|
|
118
|
+
const ipaStr = phonemes.join("");
|
|
119
|
+
outStream.write(`\t${ipaStr}`);
|
|
120
|
+
}
|
|
121
|
+
outStream.write("\n");
|
|
122
|
+
|
|
123
|
+
currentPronunciations = [];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function addPronounciation(wordRaw,...phonemes) {
|
|
127
|
+
const baseWord = wordRaw.replace(/\(\d+\)$/, "");
|
|
128
|
+
const misaki = [];
|
|
129
|
+
phonemes.forEach(ph => {
|
|
130
|
+
if ( !cmuToIPA.hasOwnProperty(ph) ) {
|
|
131
|
+
console.error("Found unknown phoneme: " + ph);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
const ipa = cmuToIPA[ph];
|
|
135
|
+
if ( IPAToMisaki.hasOwnProperty(ipa) ) {
|
|
136
|
+
misaki.push(...IPAToMisaki[ipa]);
|
|
137
|
+
} else {
|
|
138
|
+
misaki.push(ipa);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
if (baseWord !== currentBase) {
|
|
143
|
+
flushWord(); // write previous word group
|
|
144
|
+
currentBase = baseWord;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
currentPronunciations.push(misaki);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
rl.on("line", (line) => {
|
|
151
|
+
if (!line ) return;
|
|
152
|
+
if (line.startsWith(";;;")) {
|
|
153
|
+
outStream.write(line + "\n");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const [wordRaw, ...phonemes] = line.trim().split(/\s+/);
|
|
158
|
+
if ( reducedPronunciations.hasOwnProperty(wordRaw) ) {
|
|
159
|
+
addPronounciation( wordRaw, ...reducedPronunciations[wordRaw] );
|
|
160
|
+
delete reducedPronunciations[wordRaw];
|
|
161
|
+
} else {
|
|
162
|
+
addPronounciation( wordRaw, ...phonemes );
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
rl.on("close", () => {
|
|
168
|
+
flushWord(); // write last word group
|
|
169
|
+
|
|
170
|
+
// Write the rest
|
|
171
|
+
Object.keys(reducedPronunciations).forEach( x => {
|
|
172
|
+
addPronounciation( x, ...reducedPronunciations[x] );
|
|
173
|
+
flushWord();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
outStream.end();
|
|
177
|
+
console.log(`✅ Finished writing data to ${outputFile}`);
|
|
178
|
+
});
|
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
|
|
@@ -379,15 +385,13 @@ if ( wss ) {
|
|
|
379
385
|
if ( message.type === "setup" ) {
|
|
380
386
|
// TODO: Check setup values
|
|
381
387
|
Object.assign(ttsSetup, message.data);
|
|
382
|
-
} else {
|
|
388
|
+
} else if ( message.type === "synthesize" ) {
|
|
383
389
|
|
|
384
390
|
// Set values
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
message.data.audioEncoding = ttsSetup.audioEncoding.slice();
|
|
390
|
-
}
|
|
391
|
+
message.data.voice = ttsSetup.voice.slice();
|
|
392
|
+
message.data.language = ttsSetup.language.slice();
|
|
393
|
+
message.data.speed = ttsSetup.speed;
|
|
394
|
+
message.data.audioEncoding = ttsSetup.audioEncoding.slice();
|
|
391
395
|
|
|
392
396
|
queue.push(message);
|
|
393
397
|
for( let i=0; i<config.tts.threads; i++ ) {
|
|
@@ -399,6 +403,8 @@ if ( wss ) {
|
|
|
399
403
|
break;
|
|
400
404
|
}
|
|
401
405
|
}
|
|
406
|
+
} else {
|
|
407
|
+
console.error('HeadTTS Server: Rejected disallowed message type "' + message.type + '" from WebSocket client (' + id + ').');
|
|
402
408
|
}
|
|
403
409
|
}
|
|
404
410
|
} catch(error) {
|
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@3
|
|
40
|
+
transformersModule: "https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3/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;
|
|
@@ -21,6 +23,16 @@ const voices = new Map(); // Voices
|
|
|
21
23
|
let settings = {}; // Settings
|
|
22
24
|
const queue = []; // Text-to-speech work queue
|
|
23
25
|
|
|
26
|
+
// Force Kokoro's LSTM nodes onto CPU
|
|
27
|
+
const forceCpuNodeNames = [
|
|
28
|
+
"/encoder/text_encoder/lstm/LSTM",
|
|
29
|
+
"/encoder/predictor/text_encoder/lstms.0/LSTM",
|
|
30
|
+
"/encoder/predictor/text_encoder/lstms.2/LSTM",
|
|
31
|
+
"/encoder/predictor/text_encoder/lstms.4/LSTM",
|
|
32
|
+
"/encoder/predictor/lstm/LSTM",
|
|
33
|
+
"/encoder/shared/LSTM",
|
|
34
|
+
];
|
|
35
|
+
|
|
24
36
|
// Different event handler for Node.js and browsers
|
|
25
37
|
let eventHandler;
|
|
26
38
|
let fileReader;
|
|
@@ -113,7 +125,11 @@ async function connect() {
|
|
|
113
125
|
|
|
114
126
|
// Load modules dynamically
|
|
115
127
|
try {
|
|
116
|
-
({ StyleTextToSpeech2Model, AutoTokenizer, Tensor } = await import(settings.transformersModule));
|
|
128
|
+
({ StyleTextToSpeech2Model, AutoTokenizer, Tensor, env, LogLevel } = await import(settings.transformersModule));
|
|
129
|
+
|
|
130
|
+
// Set log level to ERROR
|
|
131
|
+
env.logLevel = LogLevel.ERROR;
|
|
132
|
+
|
|
117
133
|
} catch(error) {
|
|
118
134
|
console.error("HeadTTS Worker: Importing modules failed, error=", error);
|
|
119
135
|
throw new Error("Importing modules failed.");
|
|
@@ -133,6 +149,12 @@ async function connect() {
|
|
|
133
149
|
StyleTextToSpeech2Model.from_pretrained( settings.model, {
|
|
134
150
|
dtype: settings.dtype,
|
|
135
151
|
device: settings.device,
|
|
152
|
+
session_options: settings.device === "webgpu" ? {
|
|
153
|
+
executionProviders: [{
|
|
154
|
+
name: "webgpu",
|
|
155
|
+
forceCpuNodeNames,
|
|
156
|
+
}]
|
|
157
|
+
} : undefined,
|
|
136
158
|
progress_callback: progress
|
|
137
159
|
}),
|
|
138
160
|
AutoTokenizer.from_pretrained( settings.model, {
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@met4citizen/headtts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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",
|
|
7
7
|
"files": [
|
|
8
8
|
"README.md",
|
|
9
9
|
"LICENSE",
|
|
10
|
-
"
|
|
10
|
+
"headtts-node.json",
|
|
11
11
|
"modules/",
|
|
12
12
|
"dictionaries/"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@huggingface/transformers": "^3.
|
|
16
|
-
"ws": "^8.
|
|
15
|
+
"@huggingface/transformers": "^4.3.2",
|
|
16
|
+
"ws": "^8.22.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"start": "node ./modules/headtts-node.mjs",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/met4citizen/HeadTTS#readme",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"jest": "^30.2
|
|
42
|
+
"jest": "^30.5.2"
|
|
43
43
|
}
|
|
44
44
|
}
|