whisper.wasm : fix unknown language issue

This commit addresses an issue with whisper.wasm where the following
error was being displayed when running the application in github pages:
```
whisper_lang_id: unknown language 'д=␙c'
```

This turned out to be a memory corruption issue and further details
can be found in the reference issue below.

Refs: https://github.com/ggerganov/whisper.cpp/issues/2998
This commit is contained in:
Daniel Bevenius 2025-04-03 14:03:01 +02:00
parent eac1bc9c47
commit f1729267c9

View File

@ -71,7 +71,7 @@ EMSCRIPTEN_BINDINGS(whisper) {
params.print_timestamps = true;
params.print_special = false;
params.translate = translate;
params.language = whisper_is_multilingual(g_contexts[index]) ? lang.c_str() : "en";
params.language = whisper_is_multilingual(g_contexts[index]) ? strdup(lang.c_str()) : "en";
params.n_threads = std::min(nthreads, std::min(16, mpow2(std::thread::hardware_concurrency())));
params.offset_ms = 0;
@ -106,6 +106,9 @@ EMSCRIPTEN_BINDINGS(whisper) {
whisper_reset_timings(g_contexts[index]);
whisper_full(g_contexts[index], params, pcmf32.data(), pcmf32.size());
whisper_print_timings(g_contexts[index]);
if (params.language != nullptr && strcmp(params.language, "en") != 0) {
free((void*)params.language);
}
});
}