Skip to content

Commit 77e0c86

Browse files
authored
whisper.wasm : fix unknown language issue (#3000)
* 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: #2998
1 parent eac1bc9 commit 77e0c86

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/whisper.wasm/emscripten.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ EMSCRIPTEN_BINDINGS(whisper) {
6565
}
6666

6767
struct whisper_full_params params = whisper_full_default_params(whisper_sampling_strategy::WHISPER_SAMPLING_GREEDY);
68+
bool is_multilingual = whisper_is_multilingual(g_contexts[index]);
6869

6970
params.print_realtime = true;
7071
params.print_progress = false;
7172
params.print_timestamps = true;
7273
params.print_special = false;
7374
params.translate = translate;
74-
params.language = whisper_is_multilingual(g_contexts[index]) ? lang.c_str() : "en";
75+
params.language = is_multilingual ? strdup(lang.c_str()) : "en";
7576
params.n_threads = std::min(nthreads, std::min(16, mpow2(std::thread::hardware_concurrency())));
7677
params.offset_ms = 0;
7778

@@ -102,10 +103,13 @@ EMSCRIPTEN_BINDINGS(whisper) {
102103

103104
// run the worker
104105
{
105-
g_worker = std::thread([index, params, pcmf32 = std::move(pcmf32)]() {
106+
g_worker = std::thread([index, params, pcmf32 = std::move(pcmf32), is_multilingual]() {
106107
whisper_reset_timings(g_contexts[index]);
107108
whisper_full(g_contexts[index], params, pcmf32.data(), pcmf32.size());
108109
whisper_print_timings(g_contexts[index]);
110+
if (is_multilingual) {
111+
free((void*)params.language);
112+
}
109113
});
110114
}
111115

0 commit comments

Comments
 (0)