Skip to content

Commit 44bfb04

Browse files
authored
Merge pull request #14 from alexpinel/dev
forgot some tts stuff
2 parents 2e5cc8d + 17ce859 commit 44bfb04

File tree

5 files changed

+255
-1
lines changed

5 files changed

+255
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ dist
99
.DS_Store
1010
mpnet/
1111
baai/
12-
vits-piper-en_US-glados
1312
whisper
13+
espeak-ng-data

llm/vits-piper-en_US-glados/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Introduction
2+
3+
This model is converted from
4+
https://github.com/dnhkng/GlaDOS/raw/main/models/glados.onnx
5+
6+
See https://colab.research.google.com/drive/1m3Zr8H1RJaoZu4Y7hpQlav5vhtw3A513?usp=sharing
7+
for how the model is convered to sherpa-onnx
60.6 MB
Binary file not shown.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
3
2+
! 4
3+
" 150
4+
# 149
5+
$ 2
6+
' 5
7+
( 6
8+
) 7
9+
, 8
10+
- 9
11+
. 10
12+
0 130
13+
1 131
14+
2 132
15+
3 133
16+
4 134
17+
5 135
18+
6 136
19+
7 137
20+
8 138
21+
9 139
22+
: 11
23+
; 12
24+
? 13
25+
X 156
26+
^ 1
27+
_ 0
28+
a 14
29+
b 15
30+
c 16
31+
d 17
32+
e 18
33+
f 19
34+
g 154
35+
h 20
36+
i 21
37+
j 22
38+
k 23
39+
l 24
40+
m 25
41+
n 26
42+
o 27
43+
p 28
44+
q 29
45+
r 30
46+
s 31
47+
t 32
48+
u 33
49+
v 34
50+
w 35
51+
x 36
52+
y 37
53+
z 38
54+
æ 39
55+
ç 40
56+
ð 41
57+
ø 42
58+
ħ 43
59+
ŋ 44
60+
œ 45
61+
ǀ 46
62+
ǁ 47
63+
ǂ 48
64+
ǃ 49
65+
ɐ 50
66+
ɑ 51
67+
ɒ 52
68+
ɓ 53
69+
ɔ 54
70+
ɕ 55
71+
ɖ 56
72+
ɗ 57
73+
ɘ 58
74+
ə 59
75+
ɚ 60
76+
ɛ 61
77+
ɜ 62
78+
ɞ 63
79+
ɟ 64
80+
ɠ 65
81+
ɡ 66
82+
ɢ 67
83+
ɣ 68
84+
ɤ 69
85+
ɥ 70
86+
ɦ 71
87+
ɧ 72
88+
ɨ 73
89+
ɪ 74
90+
ɫ 75
91+
ɬ 76
92+
ɭ 77
93+
ɮ 78
94+
ɯ 79
95+
ɰ 80
96+
ɱ 81
97+
ɲ 82
98+
ɳ 83
99+
ɴ 84
100+
ɵ 85
101+
ɶ 86
102+
ɸ 87
103+
ɹ 88
104+
ɺ 89
105+
ɻ 90
106+
ɽ 91
107+
ɾ 92
108+
ʀ 93
109+
ʁ 94
110+
ʂ 95
111+
ʃ 96
112+
ʄ 97
113+
ʈ 98
114+
ʉ 99
115+
ʊ 100
116+
ʋ 101
117+
ʌ 102
118+
ʍ 103
119+
ʎ 104
120+
ʏ 105
121+
ʐ 106
122+
ʑ 107
123+
ʒ 108
124+
ʔ 109
125+
ʕ 110
126+
ʘ 111
127+
ʙ 112
128+
ʛ 113
129+
ʜ 114
130+
ʝ 115
131+
ʟ 116
132+
ʡ 117
133+
ʢ 118
134+
ʦ 155
135+
ʰ 145
136+
ʲ 119
137+
ˈ 120
138+
ˌ 121
139+
ː 122
140+
ˑ 123
141+
˞ 124
142+
ˤ 146
143+
̃ 141
144+
̧ 140
145+
̩ 144
146+
̪ 142
147+
̯ 143
148+
̺ 152
149+
̻ 153
150+
β 125
151+
ε 147
152+
θ 126
153+
χ 127
154+
ᵻ 128
155+
↑ 151
156+
↓ 148
157+
ⱱ 129
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const path = require('path');
2+
3+
// Function to dynamically resolve the module paths from the local node_modules
4+
function requireLocalModule(moduleName) {
5+
try {
6+
// Attempt to require the module from the local node_modules directory
7+
const modulePath = path.resolve(__dirname, 'node_modules', moduleName);
8+
return require(modulePath);
9+
} catch (error) {
10+
console.error(`Error requiring module ${moduleName} from local node_modules directory:`, error);
11+
throw error;
12+
}
13+
}
14+
15+
// Require the modules from the local node_modules directory
16+
const tar = requireLocalModule('tar');
17+
const sherpa_onnx = requireLocalModule('sherpa-onnx');
18+
19+
function createOfflineTts() {
20+
try {
21+
console.log("Creating offline TTS...");
22+
23+
const currentDirectory = __dirname;
24+
25+
let offlineTtsVitsModelConfig = {
26+
model: path.join(currentDirectory, 'en_US-glados.onnx'),
27+
tokens: path.join(currentDirectory, 'tokens.txt'),
28+
dataDir: path.join(currentDirectory, 'espeak-ng-data'),
29+
lexicon: '',
30+
dictDir: '',
31+
noiseScale: 0.667,
32+
noiseScaleW: 0.9,
33+
lengthScale: 1.0,
34+
};
35+
36+
let offlineTtsModelConfig = {
37+
offlineTtsVitsModelConfig: offlineTtsVitsModelConfig,
38+
numThreads: 1,
39+
debug: 1,
40+
provider: 'gpu',
41+
};
42+
43+
let offlineTtsConfig = {
44+
offlineTtsModelConfig: offlineTtsModelConfig,
45+
ruleFsts: '',
46+
ruleFars: '',
47+
maxNumSentences: 2,
48+
};
49+
50+
return sherpa_onnx.createOfflineTts(offlineTtsConfig);
51+
} catch (error) {
52+
console.error('Failed to create TTS:', error, error.stack);
53+
process.exit(1);
54+
}
55+
}
56+
57+
process.on('message', async (data) => {
58+
try {
59+
console.log(`Received message to process: ${data.cmd}`);
60+
const userDataPath = data.userDataPath;
61+
const filePath = path.join(userDataPath, 'output.wav');
62+
63+
const tts = createOfflineTts();
64+
console.log("TTS engine created, generating audio...");
65+
const audio = tts.generate({
66+
text: data.message,
67+
sid: 0,
68+
speed: 1.0
69+
});
70+
console.log(`Audio generated, saving to ${filePath}...`);
71+
tts.save(filePath, audio);
72+
tts.free();
73+
74+
console.log(`Posting back filePath: ${filePath}`);
75+
process.send({ filePath: filePath });
76+
} catch (error) {
77+
console.error('Error processing TTS request:', error);
78+
process.send({ error: error.message });
79+
}
80+
});
81+
82+
process.on('uncaughtException', error => {
83+
console.error('Unhandled Exception:', error);
84+
process.exit(1);
85+
});
86+
87+
process.on('unhandledRejection', reason => {
88+
console.error('Unhandled Rejection:', reason);
89+
process.exit(1);
90+
});

0 commit comments

Comments
 (0)