Skip to content

Commit 5200612

Browse files
committed
whisper.wasm : copy lang string
1 parent 5705c82 commit 5200612

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

examples/whisper.wasm/emscripten.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,17 @@ EMSCRIPTEN_BINDINGS(whisper) {
5050
}));
5151

5252
emscripten::function("full_default", emscripten::optional_override([](size_t index, const emscripten::val & audio, const std::string &lang, int nthreads, bool translate) {
53-
printf("[danbev] lang from emscripten: %s\n", lang.c_str());
5453
if (g_worker.joinable()) {
5554
g_worker.join();
5655
}
5756

5857
--index;
5958

6059
if (index >= g_contexts.size()) {
61-
printf("[danbev] index out of range: %zu\n", index);
6260
return -1;
6361
}
6462

6563
if (g_contexts[index] == nullptr) {
66-
printf("[danbev] context is null: %zu\n", index);
6764
return -2;
6865
}
6966

@@ -74,10 +71,7 @@ EMSCRIPTEN_BINDINGS(whisper) {
7471
params.print_timestamps = true;
7572
params.print_special = false;
7673
params.translate = translate;
77-
78-
79-
params.language = whisper_is_multilingual(g_contexts[index]) ? lang.c_str() : "en";
80-
printf("[danbev] lang from emscripten setting params.language: %s\n", params.language);
74+
params.language = whisper_is_multilingual(g_contexts[index]) ? strdup(lang.c_str()) : "en";
8175
params.n_threads = std::min(nthreads, std::min(16, mpow2(std::thread::hardware_concurrency())));
8276
params.offset_ms = 0;
8377

@@ -112,6 +106,10 @@ EMSCRIPTEN_BINDINGS(whisper) {
112106
whisper_reset_timings(g_contexts[index]);
113107
whisper_full(g_contexts[index], params, pcmf32.data(), pcmf32.size());
114108
whisper_print_timings(g_contexts[index]);
109+
110+
if (params.language != nullptr && strcmp(params.language, "en") != 0) {
111+
free((void*)params.language);
112+
}
115113
});
116114
}
117115

0 commit comments

Comments
 (0)