Support extra languages in multi-lang kokoro tts (#2303)

This commit is contained in:
Fangjun Kuang
2025-06-20 11:22:52 +08:00
committed by GitHub
parent a6095f5f64
commit 6982b86c66
28 changed files with 187 additions and 49 deletions

View File

@@ -143,13 +143,14 @@ function initSherpaOnnxOfflineTtsKokoroModelConfig(config, Module) {
const dataDirLen = Module.lengthBytesUTF8(config.dataDir || '') + 1;
const dictDirLen = Module.lengthBytesUTF8(config.dictDir || '') + 1;
const lexiconLen = Module.lengthBytesUTF8(config.lexicon || '') + 1;
const langLen = Module.lengthBytesUTF8(config.lang || '') + 1;
const n =
modelLen + voicesLen + tokensLen + dataDirLen + dictDirLen + lexiconLen;
const n = modelLen + voicesLen + tokensLen + dataDirLen + dictDirLen +
lexiconLen + langLen;
const buffer = Module._malloc(n);
const len = 7 * 4;
const len = 8 * 4;
const ptr = Module._malloc(len);
let offset = 0;
@@ -171,6 +172,9 @@ function initSherpaOnnxOfflineTtsKokoroModelConfig(config, Module) {
Module.stringToUTF8(config.lexicon || '', buffer + offset, lexiconLen);
offset += lexiconLen;
Module.stringToUTF8(config.lang || '', buffer + offset, langLen);
offset += langLen;
offset = 0;
Module.setValue(ptr, buffer + offset, 'i8*');
offset += modelLen;
@@ -192,6 +196,9 @@ function initSherpaOnnxOfflineTtsKokoroModelConfig(config, Module) {
Module.setValue(ptr + 24, buffer + offset, 'i8*');
offset += lexiconLen;
Module.setValue(ptr + 28, buffer + offset, 'i8*');
offset += langLen;
return {
buffer: buffer, ptr: ptr, len: len,
}
@@ -233,6 +240,7 @@ function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
dataDir: '',
dictDir: '',
lexicon: '',
lang: '',
};
}

View File

@@ -15,7 +15,7 @@ extern "C" {
static_assert(sizeof(SherpaOnnxOfflineTtsVitsModelConfig) == 8 * 4, "");
static_assert(sizeof(SherpaOnnxOfflineTtsMatchaModelConfig) == 8 * 4, "");
static_assert(sizeof(SherpaOnnxOfflineTtsKokoroModelConfig) == 7 * 4, "");
static_assert(sizeof(SherpaOnnxOfflineTtsKokoroModelConfig) == 8 * 4, "");
static_assert(sizeof(SherpaOnnxOfflineTtsModelConfig) ==
sizeof(SherpaOnnxOfflineTtsVitsModelConfig) +
sizeof(SherpaOnnxOfflineTtsMatchaModelConfig) +