Add JavaScript API (WebAssembly) for Kokoro TTS 1.0 (#1809)
This commit is contained in:
@@ -141,12 +141,15 @@ function initSherpaOnnxOfflineTtsKokoroModelConfig(config, Module) {
|
||||
const voicesLen = Module.lengthBytesUTF8(config.voices) + 1;
|
||||
const tokensLen = Module.lengthBytesUTF8(config.tokens || '') + 1;
|
||||
const dataDirLen = Module.lengthBytesUTF8(config.dataDir || '') + 1;
|
||||
const dictDirLen = Module.lengthBytesUTF8(config.dictDir || '') + 1;
|
||||
const lexiconLen = Module.lengthBytesUTF8(config.lexicon || '') + 1;
|
||||
|
||||
const n = modelLen + voicesLen + tokensLen + dataDirLen;
|
||||
const n =
|
||||
modelLen + voicesLen + tokensLen + dataDirLen + dictDirLen + lexiconLen;
|
||||
|
||||
const buffer = Module._malloc(n);
|
||||
|
||||
const len = 5 * 4;
|
||||
const len = 7 * 4;
|
||||
const ptr = Module._malloc(len);
|
||||
|
||||
let offset = 0;
|
||||
@@ -162,6 +165,12 @@ function initSherpaOnnxOfflineTtsKokoroModelConfig(config, Module) {
|
||||
Module.stringToUTF8(config.dataDir || '', buffer + offset, dataDirLen);
|
||||
offset += dataDirLen;
|
||||
|
||||
Module.stringToUTF8(config.dictDir || '', buffer + offset, dictDirLen);
|
||||
offset += dictDirLen;
|
||||
|
||||
Module.stringToUTF8(config.lexicon || '', buffer + offset, lexiconLen);
|
||||
offset += lexiconLen;
|
||||
|
||||
offset = 0;
|
||||
Module.setValue(ptr, buffer + offset, 'i8*');
|
||||
offset += modelLen;
|
||||
@@ -177,6 +186,12 @@ function initSherpaOnnxOfflineTtsKokoroModelConfig(config, Module) {
|
||||
|
||||
Module.setValue(ptr + 16, config.lengthScale || 1.0, 'float');
|
||||
|
||||
Module.setValue(ptr + 20, buffer + offset, 'i8*');
|
||||
offset += dictDirLen;
|
||||
|
||||
Module.setValue(ptr + 24, buffer + offset, 'i8*');
|
||||
offset += lexiconLen;
|
||||
|
||||
return {
|
||||
buffer: buffer, ptr: ptr, len: len,
|
||||
}
|
||||
@@ -216,6 +231,8 @@ function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
||||
tokens: '',
|
||||
lengthScale: 1.0,
|
||||
dataDir: '',
|
||||
dictDir: '',
|
||||
lexicon: '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -382,6 +399,8 @@ function createOfflineTts(Module, myConfig) {
|
||||
tokens: '',
|
||||
dataDir: '',
|
||||
lengthScale: 1.0,
|
||||
dictDir: '',
|
||||
lexicon: '',
|
||||
};
|
||||
|
||||
const offlineTtsModelConfig = {
|
||||
|
||||
@@ -15,7 +15,7 @@ extern "C" {
|
||||
|
||||
static_assert(sizeof(SherpaOnnxOfflineTtsVitsModelConfig) == 8 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOfflineTtsMatchaModelConfig) == 8 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOfflineTtsKokoroModelConfig) == 5 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOfflineTtsKokoroModelConfig) == 7 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOfflineTtsModelConfig) ==
|
||||
sizeof(SherpaOnnxOfflineTtsVitsModelConfig) +
|
||||
sizeof(SherpaOnnxOfflineTtsMatchaModelConfig) +
|
||||
@@ -56,6 +56,8 @@ void MyPrint(SherpaOnnxOfflineTtsConfig *tts_config) {
|
||||
fprintf(stdout, "tokens: %s\n", kokoro->tokens);
|
||||
fprintf(stdout, "data_dir: %s\n", kokoro->data_dir);
|
||||
fprintf(stdout, "length scale: %.3f\n", kokoro->length_scale);
|
||||
fprintf(stdout, "dict_dir: %s\n", kokoro->dict_dir);
|
||||
fprintf(stdout, "lexicon: %s\n", kokoro->lexicon);
|
||||
|
||||
fprintf(stdout, "----------tts model config----------\n");
|
||||
fprintf(stdout, "num threads: %d\n", tts_model_config->num_threads);
|
||||
|
||||
Reference in New Issue
Block a user