Skip to content

Commit e6dd845

Browse files
committed
squash! whisper.wasm : fix unknown language issue
Make sure that we always free the language pointer for multilingual models.
1 parent f172926 commit e6dd845

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/whisper.wasm/emscripten.cpp

Lines changed: 4 additions & 3 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]) ? strdup(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,11 +103,11 @@ 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]);
109-
if (params.language != nullptr && strcmp(params.language, "en") != 0) {
110+
if (is_multilingual) {
110111
free((void*)params.language);
111112
}
112113
});

0 commit comments

Comments
 (0)