From 77e0c86ab62eda9392a8567f4c29ab8d140cb0ba Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 3 Apr 2025 19:50:47 +0200 Subject: [PATCH] whisper.wasm : fix unknown language issue (#3000) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- examples/whisper.wasm/emscripten.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/whisper.wasm/emscripten.cpp b/examples/whisper.wasm/emscripten.cpp index b84893de..03bf4132 100644 --- a/examples/whisper.wasm/emscripten.cpp +++ b/examples/whisper.wasm/emscripten.cpp @@ -65,13 +65,14 @@ EMSCRIPTEN_BINDINGS(whisper) { } struct whisper_full_params params = whisper_full_default_params(whisper_sampling_strategy::WHISPER_SAMPLING_GREEDY); + bool is_multilingual = whisper_is_multilingual(g_contexts[index]); params.print_realtime = true; params.print_progress = false; 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 = is_multilingual ? strdup(lang.c_str()) : "en"; params.n_threads = std::min(nthreads, std::min(16, mpow2(std::thread::hardware_concurrency()))); params.offset_ms = 0; @@ -102,10 +103,13 @@ EMSCRIPTEN_BINDINGS(whisper) { // run the worker { - g_worker = std::thread([index, params, pcmf32 = std::move(pcmf32)]() { + g_worker = std::thread([index, params, pcmf32 = std::move(pcmf32), is_multilingual]() { whisper_reset_timings(g_contexts[index]); whisper_full(g_contexts[index], params, pcmf32.data(), pcmf32.size()); whisper_print_timings(g_contexts[index]); + if (is_multilingual) { + free((void*)params.language); + } }); }