@met4citizen/headtts 1.1.1 → 1.2.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 +45 -41
- package/modules/headtts-node.mjs +2 -0
- package/modules/headtts.mjs +1 -1
- package/modules/language.mjs +2 -0
- package/modules/worker-tts.mjs +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,17 +12,22 @@ on a Node.js WebSocket/RESTful server (CPU-based).
|
|
|
12
12
|
WebGPU support. Uses neural voices with a StyleTTS 2 model.
|
|
13
13
|
Great for lip-sync use cases and fully compatible with the
|
|
14
14
|
[TalkingHead](https://github.com/met4citizen/TalkingHead).
|
|
15
|
-
MIT licensed, doesn't use eSpeak
|
|
15
|
+
MIT licensed, doesn't use eSpeak or any other GPL-licensed
|
|
16
16
|
module.
|
|
17
17
|
|
|
18
|
-
- **Cons**:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
- **Cons**: Only the latest desktop browsers have
|
|
19
|
+
[WebGPU support](https://caniuse.com/webgpu) enabled by default,
|
|
20
|
+
the WASM fallback is much slower.
|
|
21
|
+
Kokoro is a lightweight model, but it still takes time to
|
|
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
|
+
English is currently the only supported language.
|
|
23
26
|
|
|
24
|
-
**👉 If you're using a
|
|
25
|
-
[
|
|
27
|
+
**👉 If you're using a desktop browser, check out the
|
|
28
|
+
[IN-BROWSER DEMO](https://met4citizen.github.io/HeadTTS/)!**
|
|
29
|
+
If your browser doesn't have WebGPU support enabled,
|
|
30
|
+
the demo app uses WASM as a fallback.
|
|
26
31
|
|
|
27
32
|
The project uses [websockets/ws](https://github.com/websockets/ws) (MIT License),
|
|
28
33
|
[hugginface/transformers.js (with ONNX Runtime)](https://github.com/huggingface/transformers.js/)
|
|
@@ -60,12 +65,12 @@ set the `workerModule` and `dictionaryURL` options explicitly,
|
|
|
60
65
|
as the default relative paths will likely not work:
|
|
61
66
|
|
|
62
67
|
```javascript
|
|
63
|
-
import { HeadTTS } from "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.
|
|
68
|
+
import { HeadTTS } from "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.2/+esm";
|
|
64
69
|
|
|
65
70
|
const headtts = new HeadTTS({
|
|
66
71
|
/* ... */
|
|
67
|
-
workerModule: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.
|
|
68
|
-
dictionaryURL: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.
|
|
72
|
+
workerModule: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.2/modules/worker-tts.mjs",
|
|
73
|
+
dictionaryURL: "https://cdn.jsdelivr.net/npm/@met4citizen/headtts@1.2/dictionaries/"
|
|
69
74
|
});
|
|
70
75
|
```
|
|
71
76
|
|
|
@@ -86,7 +91,7 @@ Option | Description | Default value
|
|
|
86
91
|
`frameRate` | Frame rate in FPS for inference. | `40`
|
|
87
92
|
`languages` | Language modules to be pre-loaded. | [`"en-us"`]
|
|
88
93
|
`dictionaryURL` | URL to language dictionaries. Set to `null` to disable dictionaries. | `"../dictionaries"`
|
|
89
|
-
`voiceURL` | URL for loading voices. | `"https://huggingface.co/`<br>`onnx-community/`<br>`Kokoro-82M-v1.0-ONNX/`<br>`resolve/main/voices"`
|
|
94
|
+
`voiceURL` | URL for loading voices. If the given value is a relative URL, it should be relative to the worker file location. | `"https://huggingface.co/`<br>`onnx-community/`<br>`Kokoro-82M-v1.0-ONNX/`<br>`resolve/main/voices"`
|
|
90
95
|
`voices` | Voices to preload (e.g., `["af_bella", "am_fenrir"]`). | `[]`
|
|
91
96
|
`splitSentences` | Whether to split text into sentences. | `true`
|
|
92
97
|
`splitLength` | Maximum length (in characters) of each text chunk. | `500`
|
|
@@ -206,8 +211,6 @@ Type | Description | Example
|
|
|
206
211
|
`time` | Speak the time in `value` with corresponding `subtitles` (optional). The time is presented as milliseconds from epoch. | <pre>{<br> type: "time",<br> value: Date.now(),<br> subtitles: "6:45 PM"<br>}</pre>
|
|
207
212
|
`break` | The length of the break in milliseconds in `value` with corresponding `subtitles` (optional). | <pre>{<br> type: "break",<br> value: 2000,<br> subtitles: "..."<br>}</pre>
|
|
208
213
|
|
|
209
|
-
*TODO: Add support for `audio` type.*
|
|
210
|
-
|
|
211
214
|
An example using an array of input items:
|
|
212
215
|
|
|
213
216
|
```javascript
|
|
@@ -389,12 +392,13 @@ Returns an audio object metadata that can be passed on the TalkingHead
|
|
|
389
392
|
type: "audio",
|
|
390
393
|
ref: 13,
|
|
391
394
|
data: {
|
|
392
|
-
words: [
|
|
393
|
-
wtimes: [
|
|
394
|
-
wdurations: [
|
|
395
|
-
visemes: [
|
|
396
|
-
vtimes: [
|
|
397
|
-
vdurations: [
|
|
395
|
+
words: ['This ', 'is ', 'an ', 'example.'],
|
|
396
|
+
wtimes: [440, 656, 876, 1050],
|
|
397
|
+
wdurations: [236, 240, 194, 1035],
|
|
398
|
+
visemes: ['TH', 'I', 'SS', 'I', 'SS', 'aa', 'nn', 'I', 'kk', 'SS', 'aa', 'PP', 'PP', 'E', 'RR'],
|
|
399
|
+
vtimes: [440, 472, 562, 656, 753, 876, 993, 1050, 1097, 1149, 1200, 1322, 1372, 1423, 1499],
|
|
400
|
+
vdurations: [52, 110, 74, 117, 75, 137, 47, 67, 72, 71, 142, 70, 71, 96, 399],
|
|
401
|
+
phonemes: ['ð', 'ɪ', 's', 'ɪ', 'z', 'æ', 'n', 'ɪ', 'ɡ', 'z', 'æ', 'm', 'p', 'ə', 'l'],
|
|
398
402
|
audioEncoding: "wav"
|
|
399
403
|
}
|
|
400
404
|
}
|
|
@@ -430,13 +434,14 @@ OK response:
|
|
|
430
434
|
|
|
431
435
|
JSON|Description
|
|
432
436
|
---|---
|
|
433
|
-
`audio` |
|
|
437
|
+
`audio` | Base64 encoded WAV data for `"wav"` or raw PCM 16bit LE samples for `"pcm"` audio encoding.
|
|
434
438
|
`words` | Array of words.
|
|
435
439
|
`wtimes` | Array of word starting times for `words` in milliseconds.
|
|
436
440
|
`wdurations` | Array of word durations for `words` in milliseconds.
|
|
437
441
|
`visemes` | Array of Oculus viseme IDs: `'aa'`, `'E'`, `'I'`, `'O'`, `'U'`, `'PP'`, `'SS'`, `'TH'`, `'CH'`, `'FF'`, `'kk'`, `'nn'`, `'RR'`, `'DD'`, `'sil'`.
|
|
438
442
|
`vtimes` | Array of viseme starting times for `visemes` in milliseconds.
|
|
439
443
|
`vdurations` | Array of viseme durations for `visemes` in milliseconds.
|
|
444
|
+
`phonemes` | Array of phonemes corresponding to the array of visemes.
|
|
440
445
|
`audioEncoding` | Audio encoding: `"wav"` or `"pcm"`.
|
|
441
446
|
|
|
442
447
|
Error response:
|
|
@@ -474,9 +479,6 @@ and then to Misaki-compatible phonemes by applying the following mapping:
|
|
|
474
479
|
- `oʊ` → [ `O` ], `ˈoʊ` → [ `ˈO` ], `ˌoʊ` → [ `ˌO` ]
|
|
475
480
|
- `əʊ` → [ `Q` ], `ˈəʊ` → [ `ˈQ` ], `ˌəʊ` → [ `ˌQ` ]
|
|
476
481
|
|
|
477
|
-
Note: During the dataset conversion, some vowels were reduced to reflect
|
|
478
|
-
casual speech since HeadTTS is primarily designed for conversational use.
|
|
479
|
-
|
|
480
482
|
The final dictionary is a plain text file with around 125,000 lines (2,8MB).
|
|
481
483
|
Lines starting with `;;;` are comments. Each other line represents
|
|
482
484
|
one word and its pronunciations. The word and its different possible
|
|
@@ -535,21 +537,23 @@ memory consumption becomes a concern.
|
|
|
535
537
|
Unofficial latency results using my own
|
|
536
538
|
[latency test app](https://github.com/met4citizen/HeadTTS/blob/main/tests/latency.html):
|
|
537
539
|
|
|
538
|
-
TTS Engine
|
|
539
|
-
|
|
540
|
-
HeadTTS,
|
|
541
|
-
HeadTTS,
|
|
542
|
-
HeadTTS,
|
|
543
|
-
HeadTTS,
|
|
544
|
-
HeadTTS,
|
|
545
|
-
HeadTTS,
|
|
546
|
-
HeadTTS,
|
|
547
|
-
HeadTTS,
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
ElevenLabs
|
|
551
|
-
|
|
552
|
-
|
|
540
|
+
TTS Engine/Setup |`FIL`<sup>\[1]</sup>|`FBL`<sup>\[2]</sup>|`RTF`<sup>\[3]</sup>
|
|
541
|
+
---|---|---|---
|
|
542
|
+
HeadTTS, Chrome, WebGPU/fp32 | 8.6s | 852ms | 0.27
|
|
543
|
+
HeadTTS, Edge, WebGPU/fp32 | 8.8s | 858ms | 0.28
|
|
544
|
+
HeadTTS, Safari, WebGPU/fp32 | 25.8s | 2437ms | 0.82
|
|
545
|
+
HeadTTS, Chrome, WASM/q4 | 45.4s | 4404ms | 1.45
|
|
546
|
+
HeadTTS, Edge, WASM/q4 | 45.5s | 4392ms | 1.45
|
|
547
|
+
HeadTTS, Safari, WASM/q4 | 45.6s | 4447ms | 1.46
|
|
548
|
+
HeadTTS, WebSocket, CPU/fp32, 1 thread | 6.8s | 712ms | 0.22
|
|
549
|
+
HeadTTS, WebSocket, CPU/fp32, 4 threads | 6.0s | 2341ms | 0.20
|
|
550
|
+
HeadTTS, REST, CPU/fp32, 1 thread | 7.0s | 793ms | 0.23
|
|
551
|
+
HeadTTS, REST, CPU/fp32, 4 threads | 6.5s | 2638ms | 0.21
|
|
552
|
+
ElevenLabs, WebSocket | 4.8s | 977ms | 0.20
|
|
553
|
+
ElevenLabs, REST | 11.3s | 1097ms | 0.46
|
|
554
|
+
ElevenLabs, REST, Flash_v2_5 | 4.8s | 581ms | 0.22
|
|
555
|
+
Microsoft TTS, WebSocket (Speech SDK) | 1.1s | 274ms | 0.04
|
|
556
|
+
Google TTS, REST | 0.79s | 67ms | 0.03
|
|
553
557
|
|
|
554
558
|
|
|
555
559
|
<sup>\[1]</sup> *Finish latency*: Total time from sending text input to receiving
|
|
@@ -567,8 +571,8 @@ audio. If RTF < 1, synthesis is faster than real-time (i.e., good).
|
|
|
567
571
|
<summary>CLICK HERE here to see the TEST SETUP.</summary>
|
|
568
572
|
|
|
569
573
|
**Test setup**: Macbook Air M2 laptop, 8 cores, 16GB memory,
|
|
570
|
-
macOS
|
|
571
|
-
The latest Google Chrome
|
|
574
|
+
macOS Tahoe 26.0, Metal2 GPU 10 cores, 300/50 Mbit/s internet connection.
|
|
575
|
+
The latest Google Chrome, Edge, Safari desktop browsers.
|
|
572
576
|
|
|
573
577
|
All test cases use WAV or raw PCM 16bit LE format and the "List 1" of the
|
|
574
578
|
[Harvard Sentences](https://www.cs.columbia.edu/~hgs/audio/harvard.html):
|
package/modules/headtts-node.mjs
CHANGED
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@3.8.1/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/language.mjs
CHANGED
|
@@ -372,6 +372,7 @@ class LanguageBase {
|
|
|
372
372
|
// Output data
|
|
373
373
|
let phonemes = [];
|
|
374
374
|
const metadata = {
|
|
375
|
+
phonemes: [],
|
|
375
376
|
words: [], wtimes: [], wdurations: [],
|
|
376
377
|
visemes: [], vtimes: [], vdurations: []
|
|
377
378
|
};
|
|
@@ -433,6 +434,7 @@ class LanguageBase {
|
|
|
433
434
|
// Visemes
|
|
434
435
|
const viseme = part.visemes[j];
|
|
435
436
|
if ( viseme ) {
|
|
437
|
+
metadata.phonemes.push(ph);
|
|
436
438
|
metadata.visemes.push(viseme);
|
|
437
439
|
metadata.vtimes.push(i);
|
|
438
440
|
i = phonemes.length;
|
package/modules/worker-tts.mjs
CHANGED
|
@@ -225,7 +225,7 @@ async function loadVoice(s) {
|
|
|
225
225
|
buffer = response.buffer.slice(response.byteOffset, response.byteOffset + response.byteLength);
|
|
226
226
|
return buffer;
|
|
227
227
|
} else if ( !isNode && settings.voiceURL ) {
|
|
228
|
-
const url = new URL(settings.voiceURL);
|
|
228
|
+
const url = new URL(settings.voiceURL, self.location.href);
|
|
229
229
|
url.pathname += (url.pathname.endsWith("/") ? "" : "/") + s + ".bin";
|
|
230
230
|
if ( isTraceConnection ) {
|
|
231
231
|
utils.trace( 'Loading voice "' + url + '".' );
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@met4citizen/headtts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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,7 +12,7 @@
|
|
|
12
12
|
"dictionaries/"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@huggingface/transformers": "^3.
|
|
15
|
+
"@huggingface/transformers": "^3.8.1",
|
|
16
16
|
"ws": "^8.18.3"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/met4citizen/HeadTTS#readme",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"jest": "^
|
|
42
|
+
"jest": "^30.2.0"
|
|
43
43
|
}
|
|
44
44
|
}
|