@met4citizen/headtts 1.3.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 +25 -21
- package/headtts-node.json +41 -0
- package/modules/build-en-us.mjs +178 -0
- package/modules/headtts-node.mjs +7 -7
- package/modules/headtts.mjs +1 -1
- package/modules/worker-tts.mjs +16 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -63,12 +63,12 @@ set the `workerModule` and `dictionaryURL` options explicitly,
|
|
|
63
63
|
as the default relative paths will likely not work:
|
|
64
64
|
|
|
65
65
|
```javascript
|
|
66
|
-
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";
|
|
67
67
|
|
|
68
68
|
const headtts = new HeadTTS({
|
|
69
69
|
/* ... */
|
|
70
|
-
workerModule: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.
|
|
71
|
-
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/"
|
|
72
72
|
});
|
|
73
73
|
```
|
|
74
74
|
|
|
@@ -268,6 +268,8 @@ cd HeadTTS
|
|
|
268
268
|
npm install
|
|
269
269
|
```
|
|
270
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
|
+
|
|
271
273
|
Start the server:
|
|
272
274
|
|
|
273
275
|
```bash
|
|
@@ -524,8 +526,8 @@ ALUMIINI FOLI KATT OKSI PAPE SEOS VENE VUOK
|
|
|
524
526
|
|
|
525
527
|
# Appendix C: Latency
|
|
526
528
|
|
|
527
|
-
In-browser TTS using WebGPU runs approximately
|
|
528
|
-
and about
|
|
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
|
|
529
531
|
performs surprisingly well. However, increasing the thread pool size
|
|
530
532
|
degrades performance. WebGPU inference on a Node.js server is slightly
|
|
531
533
|
faster than CPU inference, but it supports only a single dedicated WebGPU
|
|
@@ -540,20 +542,20 @@ Unofficial latency results using my own
|
|
|
540
542
|
|
|
541
543
|
TTS Engine/Setup |`FIL`<sup>\[1]</sup>|`FBL`<sup>\[2]</sup>|`RTF`<sup>\[3]</sup>
|
|
542
544
|
---|---|---|---
|
|
543
|
-
HeadTTS, Chrome, WebGPU/fp32 |
|
|
544
|
-
HeadTTS, Edge, WebGPU/fp32 |
|
|
545
|
-
HeadTTS, Safari, WebGPU/fp32 |
|
|
546
|
-
HeadTTS, Chrome, WASM/q4 | 45.4s |
|
|
547
|
-
HeadTTS, Edge, WASM/q4 | 45.
|
|
548
|
-
HeadTTS, Safari, WASM/q4 | 45.
|
|
549
|
-
HeadTTS,
|
|
550
|
-
HeadTTS,
|
|
551
|
-
HeadTTS,
|
|
552
|
-
HeadTTS,
|
|
553
|
-
HeadTTS, REST, WebGPU/fp32, 1 thread |
|
|
554
|
-
HeadTTS, REST, WebGPU/fp32, 2 threads | 3.6s |
|
|
555
|
-
HeadTTS, REST, CPU/fp32, 1 thread |
|
|
556
|
-
HeadTTS, REST, CPU/fp32, 4 threads |
|
|
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
|
|
557
559
|
ElevenLabs, WebSocket | 4.8s | 977ms | 0.20
|
|
558
560
|
ElevenLabs, REST | 11.3s | 1097ms | 0.46
|
|
559
561
|
ElevenLabs, REST, Flash_v2_5 | 4.8s | 581ms | 0.22
|
|
@@ -573,8 +575,10 @@ solutions use streaming, some not.
|
|
|
573
575
|
audio. If RTF < 1, synthesis is faster than real-time (i.e., good).
|
|
574
576
|
|
|
575
577
|
**Test setup**: Macbook Air M2 laptop, 8 cores, 16GB memory,
|
|
576
|
-
macOS
|
|
577
|
-
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.
|
|
578
582
|
|
|
579
583
|
All test cases use WAV or raw PCM 16bit LE format and the "List 1" of the
|
|
580
584
|
[Harvard Sentences](https://www.cs.columbia.edu/~hgs/audio/harvard.html):
|
|
@@ -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
|
@@ -385,15 +385,13 @@ if ( wss ) {
|
|
|
385
385
|
if ( message.type === "setup" ) {
|
|
386
386
|
// TODO: Check setup values
|
|
387
387
|
Object.assign(ttsSetup, message.data);
|
|
388
|
-
} else {
|
|
388
|
+
} else if ( message.type === "synthesize" ) {
|
|
389
389
|
|
|
390
390
|
// Set values
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
message.data.audioEncoding = ttsSetup.audioEncoding.slice();
|
|
396
|
-
}
|
|
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();
|
|
397
395
|
|
|
398
396
|
queue.push(message);
|
|
399
397
|
for( let i=0; i<config.tts.threads; i++ ) {
|
|
@@ -405,6 +403,8 @@ if ( wss ) {
|
|
|
405
403
|
break;
|
|
406
404
|
}
|
|
407
405
|
}
|
|
406
|
+
} else {
|
|
407
|
+
console.error('HeadTTS Server: Rejected disallowed message type "' + message.type + '" from WebSocket client (' + id + ').');
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
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@4.
|
|
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
|
@@ -23,6 +23,16 @@ const voices = new Map(); // Voices
|
|
|
23
23
|
let settings = {}; // Settings
|
|
24
24
|
const queue = []; // Text-to-speech work queue
|
|
25
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
|
+
|
|
26
36
|
// Different event handler for Node.js and browsers
|
|
27
37
|
let eventHandler;
|
|
28
38
|
let fileReader;
|
|
@@ -139,6 +149,12 @@ async function connect() {
|
|
|
139
149
|
StyleTextToSpeech2Model.from_pretrained( settings.model, {
|
|
140
150
|
dtype: settings.dtype,
|
|
141
151
|
device: settings.device,
|
|
152
|
+
session_options: settings.device === "webgpu" ? {
|
|
153
|
+
executionProviders: [{
|
|
154
|
+
name: "webgpu",
|
|
155
|
+
forceCpuNodeNames,
|
|
156
|
+
}]
|
|
157
|
+
} : undefined,
|
|
142
158
|
progress_callback: progress
|
|
143
159
|
}),
|
|
144
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": "^4.
|
|
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
|
}
|