@@ -8,8 +8,12 @@ function freeConfig(config, Module) {
88 freeConfig ( config . config , Module )
99 }
1010
11- if ( 'config2' in config ) {
12- freeConfig ( config . config2 , Module )
11+ if ( 'matcha' in config ) {
12+ freeConfig ( config . matcha , Module )
13+ }
14+
15+ if ( 'kokoro' in config ) {
16+ freeConfig ( config . kokoro , Module )
1317 }
1418
1519 Module . _free ( config . ptr ) ;
@@ -132,6 +136,52 @@ function initSherpaOnnxOfflineTtsMatchaModelConfig(config, Module) {
132136 }
133137}
134138
139+ function initSherpaOnnxOfflineTtsKokoroModelConfig ( config , Module ) {
140+ const modelLen = Module . lengthBytesUTF8 ( config . model ) + 1 ;
141+ const voicesLen = Module . lengthBytesUTF8 ( config . voices ) + 1 ;
142+ const tokensLen = Module . lengthBytesUTF8 ( config . tokens || '' ) + 1 ;
143+ const dataDirLen = Module . lengthBytesUTF8 ( config . dataDir || '' ) + 1 ;
144+
145+ const n = modelLen + voicesLen + tokensLen + dataDirLen ;
146+
147+ const buffer = Module . _malloc ( n ) ;
148+
149+ const len = 5 * 4 ;
150+ const ptr = Module . _malloc ( len ) ;
151+
152+ let offset = 0 ;
153+ Module . stringToUTF8 ( config . model || '' , buffer + offset , modelLen ) ;
154+ offset += modelLen ;
155+
156+ Module . stringToUTF8 ( config . voices || '' , buffer + offset , voicesLen ) ;
157+ offset += voicesLen ;
158+
159+ Module . stringToUTF8 ( config . tokens || '' , buffer + offset , tokensLen ) ;
160+ offset += tokensLen ;
161+
162+ Module . stringToUTF8 ( config . dataDir || '' , buffer + offset , dataDirLen ) ;
163+ offset += dataDirLen ;
164+
165+ offset = 0 ;
166+ Module . setValue ( ptr , buffer + offset , 'i8*' ) ;
167+ offset += modelLen ;
168+
169+ Module . setValue ( ptr + 4 , buffer + offset , 'i8*' ) ;
170+ offset += voicesLen ;
171+
172+ Module . setValue ( ptr + 8 , buffer + offset , 'i8*' ) ;
173+ offset += tokensLen ;
174+
175+ Module . setValue ( ptr + 12 , buffer + offset , 'i8*' ) ;
176+ offset += dataDirLen ;
177+
178+ Module . setValue ( ptr + 16 , config . lengthScale || 1.0 , 'float' ) ;
179+
180+ return {
181+ buffer : buffer , ptr : ptr , len : len ,
182+ }
183+ }
184+
135185function initSherpaOnnxOfflineTtsModelConfig ( config , Module ) {
136186 if ( ! ( 'offlineTtsVitsModelConfig' in config ) ) {
137187 config . offlineTtsVitsModelConfig = {
@@ -159,14 +209,29 @@ function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
159209 } ;
160210 }
161211
212+ if ( ! ( 'offlineTtsKokoroModelConfig' in config ) ) {
213+ config . offlineTtsKokoroModelConfig = {
214+ model : '' ,
215+ voices : '' ,
216+ tokens : '' ,
217+ lengthScale : 1.0 ,
218+ dataDir : '' ,
219+ } ;
220+ }
221+
162222
163223 const vitsModelConfig = initSherpaOnnxOfflineTtsVitsModelConfig (
164224 config . offlineTtsVitsModelConfig , Module ) ;
165225
166226 const matchaModelConfig = initSherpaOnnxOfflineTtsMatchaModelConfig (
167227 config . offlineTtsMatchaModelConfig , Module ) ;
168228
169- const len = vitsModelConfig . len + matchaModelConfig . len + 3 * 4 ;
229+ const kokoroModelConfig = initSherpaOnnxOfflineTtsKokoroModelConfig (
230+ config . offlineTtsKokoroModelConfig , Module ) ;
231+
232+ const len = vitsModelConfig . len + matchaModelConfig . len +
233+ kokoroModelConfig . len + 3 * 4 ;
234+
170235 const ptr = Module . _malloc ( len ) ;
171236
172237 let offset = 0 ;
@@ -188,9 +253,12 @@ function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
188253 Module . _CopyHeap ( matchaModelConfig . ptr , matchaModelConfig . len , ptr + offset ) ;
189254 offset += matchaModelConfig . len ;
190255
256+ Module . _CopyHeap ( kokoroModelConfig . ptr , kokoroModelConfig . len , ptr + offset ) ;
257+ offset += kokoroModelConfig . len ;
258+
191259 return {
192260 buffer : buffer , ptr : ptr , len : len , config : vitsModelConfig ,
193- config2 : matchaModelConfig
261+ matcha : matchaModelConfig , kokoro : kokoroModelConfig ,
194262 }
195263}
196264
@@ -308,9 +376,18 @@ function createOfflineTts(Module, myConfig) {
308376 lengthScale : 1.0 ,
309377 } ;
310378
379+ const offlineTtsKokoroModelConfig = {
380+ model : '' ,
381+ voices : '' ,
382+ tokens : '' ,
383+ dataDir : '' ,
384+ lengthScale : 1.0 ,
385+ } ;
386+
311387 const offlineTtsModelConfig = {
312388 offlineTtsVitsModelConfig : offlineTtsVitsModelConfig ,
313389 offlineTtsMatchaModelConfig : offlineTtsMatchaModelConfig ,
390+ offlineTtsKokoroModelConfig : offlineTtsKokoroModelConfig ,
314391 numThreads : 1 ,
315392 debug : 1 ,
316393 provider : 'cpu' ,
0 commit comments