Commit
·
d0cffdb
1
Parent(s):
dd2a81f
update model
Browse files- sherpa-onnx-tts.js +116 -1
- sherpa-onnx-wasm-main-tts.js +0 -0
- sherpa-onnx-wasm-main-tts.wasm +2 -2
sherpa-onnx-tts.js
CHANGED
@@ -8,6 +8,10 @@ function freeConfig(config, Module) {
|
|
8 |
freeConfig(config.config, Module)
|
9 |
}
|
10 |
|
|
|
|
|
|
|
|
|
11 |
Module._free(config.ptr);
|
12 |
}
|
13 |
|
@@ -66,11 +70,103 @@ function initSherpaOnnxOfflineTtsVitsModelConfig(config, Module) {
|
|
66 |
}
|
67 |
}
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
const vitsModelConfig = initSherpaOnnxOfflineTtsVitsModelConfig(
|
71 |
config.offlineTtsVitsModelConfig, Module);
|
72 |
|
73 |
-
const
|
|
|
|
|
|
|
74 |
const ptr = Module._malloc(len);
|
75 |
|
76 |
let offset = 0;
|
@@ -87,9 +183,14 @@ function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
|
87 |
const buffer = Module._malloc(providerLen);
|
88 |
Module.stringToUTF8(config.provider, buffer, providerLen);
|
89 |
Module.setValue(ptr + offset, buffer, 'i8*');
|
|
|
|
|
|
|
|
|
90 |
|
91 |
return {
|
92 |
buffer: buffer, ptr: ptr, len: len, config: vitsModelConfig,
|
|
|
93 |
}
|
94 |
}
|
95 |
|
@@ -195,12 +296,26 @@ function createOfflineTts(Module, myConfig) {
|
|
195 |
noiseScaleW: 0.8,
|
196 |
lengthScale: 1.0,
|
197 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
const offlineTtsModelConfig = {
|
199 |
offlineTtsVitsModelConfig: offlineTtsVitsModelConfig,
|
|
|
200 |
numThreads: 1,
|
201 |
debug: 1,
|
202 |
provider: 'cpu',
|
203 |
};
|
|
|
204 |
let offlineTtsConfig = {
|
205 |
offlineTtsModelConfig: offlineTtsModelConfig,
|
206 |
ruleFsts: '',
|
|
|
8 |
freeConfig(config.config, Module)
|
9 |
}
|
10 |
|
11 |
+
if ('config2' in config) {
|
12 |
+
freeConfig(config.config2, Module)
|
13 |
+
}
|
14 |
+
|
15 |
Module._free(config.ptr);
|
16 |
}
|
17 |
|
|
|
70 |
}
|
71 |
}
|
72 |
|
73 |
+
function initSherpaOnnxOfflineTtsMatchaModelConfig(config, Module) {
|
74 |
+
const acousticModelLen = Module.lengthBytesUTF8(config.acousticModel) + 1;
|
75 |
+
const vocoderLen = Module.lengthBytesUTF8(config.vocoder) + 1;
|
76 |
+
const lexiconLen = Module.lengthBytesUTF8(config.lexicon || '') + 1;
|
77 |
+
const tokensLen = Module.lengthBytesUTF8(config.tokens || '') + 1;
|
78 |
+
const dataDirLen = Module.lengthBytesUTF8(config.dataDir || '') + 1;
|
79 |
+
const dictDirLen = Module.lengthBytesUTF8(config.dictDir || '') + 1;
|
80 |
+
|
81 |
+
const n = acousticModelLen + vocoderLen + lexiconLen + tokensLen +
|
82 |
+
dataDirLen + dictDirLen;
|
83 |
+
|
84 |
+
const buffer = Module._malloc(n);
|
85 |
+
|
86 |
+
const len = 8 * 4;
|
87 |
+
const ptr = Module._malloc(len);
|
88 |
+
|
89 |
+
let offset = 0;
|
90 |
+
Module.stringToUTF8(
|
91 |
+
config.acousticModel || '', buffer + offset, acousticModelLen);
|
92 |
+
offset += acousticModelLen;
|
93 |
+
|
94 |
+
Module.stringToUTF8(config.vocoder || '', buffer + offset, vocoderLen);
|
95 |
+
offset += vocoderLen;
|
96 |
+
|
97 |
+
Module.stringToUTF8(config.lexicon || '', buffer + offset, lexiconLen);
|
98 |
+
offset += lexiconLen;
|
99 |
+
|
100 |
+
Module.stringToUTF8(config.tokens || '', buffer + offset, tokensLen);
|
101 |
+
offset += tokensLen;
|
102 |
+
|
103 |
+
Module.stringToUTF8(config.dataDir || '', buffer + offset, dataDirLen);
|
104 |
+
offset += dataDirLen;
|
105 |
+
|
106 |
+
Module.stringToUTF8(config.dictDir || '', buffer + offset, dictDirLen);
|
107 |
+
offset += dictDirLen;
|
108 |
+
|
109 |
+
offset = 0;
|
110 |
+
Module.setValue(ptr, buffer + offset, 'i8*');
|
111 |
+
offset += acousticModelLen;
|
112 |
+
|
113 |
+
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
114 |
+
offset += vocoderLen;
|
115 |
+
|
116 |
+
Module.setValue(ptr + 8, buffer + offset, 'i8*');
|
117 |
+
offset += lexiconLen;
|
118 |
+
|
119 |
+
Module.setValue(ptr + 12, buffer + offset, 'i8*');
|
120 |
+
offset += tokensLen;
|
121 |
+
|
122 |
+
Module.setValue(ptr + 16, buffer + offset, 'i8*');
|
123 |
+
offset += dataDirLen;
|
124 |
+
|
125 |
+
Module.setValue(ptr + 20, config.noiseScale || 0.667, 'float');
|
126 |
+
Module.setValue(ptr + 24, config.lengthScale || 1.0, 'float');
|
127 |
+
Module.setValue(ptr + 28, buffer + offset, 'i8*');
|
128 |
+
offset += dictDirLen;
|
129 |
+
|
130 |
+
return {
|
131 |
+
buffer: buffer, ptr: ptr, len: len,
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
136 |
+
if (!('offlineTtsVitsModelConfig' in config)) {
|
137 |
+
config.offlineTtsVitsModelConfig = {
|
138 |
+
model: '',
|
139 |
+
lexicon: '',
|
140 |
+
tokens: '',
|
141 |
+
noiseScale: 0.667,
|
142 |
+
noiseScaleW: 0.8,
|
143 |
+
lengthScale: 1.0,
|
144 |
+
dataDir: '',
|
145 |
+
dictDir: '',
|
146 |
+
};
|
147 |
+
}
|
148 |
+
|
149 |
+
if (!('offlineTtsMatchaModelConfig' in config)) {
|
150 |
+
config.offlineTtsMatchaModelConfig = {
|
151 |
+
acousticModel: '',
|
152 |
+
vocoder: '',
|
153 |
+
lexicon: '',
|
154 |
+
tokens: '',
|
155 |
+
noiseScale: 0.667,
|
156 |
+
lengthScale: 1.0,
|
157 |
+
dataDir: '',
|
158 |
+
dictDir: '',
|
159 |
+
};
|
160 |
+
}
|
161 |
+
|
162 |
+
|
163 |
const vitsModelConfig = initSherpaOnnxOfflineTtsVitsModelConfig(
|
164 |
config.offlineTtsVitsModelConfig, Module);
|
165 |
|
166 |
+
const matchaModelConfig = initSherpaOnnxOfflineTtsMatchaModelConfig(
|
167 |
+
config.offlineTtsMatchaModelConfig, Module);
|
168 |
+
|
169 |
+
const len = vitsModelConfig.len + matchaModelConfig.len + 3 * 4;
|
170 |
const ptr = Module._malloc(len);
|
171 |
|
172 |
let offset = 0;
|
|
|
183 |
const buffer = Module._malloc(providerLen);
|
184 |
Module.stringToUTF8(config.provider, buffer, providerLen);
|
185 |
Module.setValue(ptr + offset, buffer, 'i8*');
|
186 |
+
offset += 4;
|
187 |
+
|
188 |
+
Module._CopyHeap(matchaModelConfig.ptr, matchaModelConfig.len, ptr + offset);
|
189 |
+
offset += matchaModelConfig.len;
|
190 |
|
191 |
return {
|
192 |
buffer: buffer, ptr: ptr, len: len, config: vitsModelConfig,
|
193 |
+
config2: matchaModelConfig
|
194 |
}
|
195 |
}
|
196 |
|
|
|
296 |
noiseScaleW: 0.8,
|
297 |
lengthScale: 1.0,
|
298 |
};
|
299 |
+
|
300 |
+
const offlineTtsMatchaModelConfig = {
|
301 |
+
acousticModel: '',
|
302 |
+
vocoder: '',
|
303 |
+
lexicon: '',
|
304 |
+
tokens: '',
|
305 |
+
dataDir: '',
|
306 |
+
dictDir: '',
|
307 |
+
noiseScale: 0.667,
|
308 |
+
lengthScale: 1.0,
|
309 |
+
};
|
310 |
+
|
311 |
const offlineTtsModelConfig = {
|
312 |
offlineTtsVitsModelConfig: offlineTtsVitsModelConfig,
|
313 |
+
offlineTtsMatchaModelConfig: offlineTtsMatchaModelConfig,
|
314 |
numThreads: 1,
|
315 |
debug: 1,
|
316 |
provider: 'cpu',
|
317 |
};
|
318 |
+
|
319 |
let offlineTtsConfig = {
|
320 |
offlineTtsModelConfig: offlineTtsModelConfig,
|
321 |
ruleFsts: '',
|
sherpa-onnx-wasm-main-tts.js
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
sherpa-onnx-wasm-main-tts.wasm
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:31fb55950ac85f48710698bc17a74496254ce35598bb413b9932b2aac28b957b
|
3 |
+
size 11610917
|