danbev commited on
Commit
d53c30c
·
unverified ·
1 Parent(s): 2a8a6b4

whisper.wasm : fix unknown language issue (#3000)

Browse files

* 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 CHANGED
@@ -65,13 +65,14 @@ EMSCRIPTEN_BINDINGS(whisper) {
65
  }
66
 
67
  struct whisper_full_params params = whisper_full_default_params(whisper_sampling_strategy::WHISPER_SAMPLING_GREEDY);
 
68
 
69
  params.print_realtime = true;
70
  params.print_progress = false;
71
  params.print_timestamps = true;
72
  params.print_special = false;
73
  params.translate = translate;
74
- params.language = whisper_is_multilingual(g_contexts[index]) ? lang.c_str() : "en";
75
  params.n_threads = std::min(nthreads, std::min(16, mpow2(std::thread::hardware_concurrency())));
76
  params.offset_ms = 0;
77
 
@@ -102,10 +103,13 @@ EMSCRIPTEN_BINDINGS(whisper) {
102
 
103
  // run the worker
104
  {
105
- g_worker = std::thread([index, params, pcmf32 = std::move(pcmf32)]() {
106
  whisper_reset_timings(g_contexts[index]);
107
  whisper_full(g_contexts[index], params, pcmf32.data(), pcmf32.size());
108
  whisper_print_timings(g_contexts[index]);
 
 
 
109
  });
110
  }
111
 
 
65
  }
66
 
67
  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]);
69
 
70
  params.print_realtime = true;
71
  params.print_progress = false;
72
  params.print_timestamps = true;
73
  params.print_special = false;
74
  params.translate = translate;
75
+ params.language = is_multilingual ? strdup(lang.c_str()) : "en";
76
  params.n_threads = std::min(nthreads, std::min(16, mpow2(std::thread::hardware_concurrency())));
77
  params.offset_ms = 0;
78
 
 
103
 
104
  // run the worker
105
  {
106
+ g_worker = std::thread([index, params, pcmf32 = std::move(pcmf32), is_multilingual]() {
107
  whisper_reset_timings(g_contexts[index]);
108
  whisper_full(g_contexts[index], params, pcmf32.data(), pcmf32.size());
109
  whisper_print_timings(g_contexts[index]);
110
+ if (is_multilingual) {
111
+ free((void*)params.language);
112
+ }
113
  });
114
  }
115