Skip to content

Commit 491ecd7

Browse files
committed
wip : polishing WASM example
1 parent db460b7 commit 491ecd7

4 files changed

Lines changed: 397 additions & 85 deletions

File tree

bindings/javascript/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ if (WHISPER_WASM_SINGLE_FILE)
2121
)
2222
endif()
2323

24-
#-s TOTAL_MEMORY=536870912 \
2524
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \
2625
--bind \
27-
-s MODULARIZE=1 \
28-
-s ASSERTIONS=1 \
2926
-s USE_PTHREADS=1 \
30-
-s PTHREAD_POOL_SIZE=9 \
31-
-s ALLOW_MEMORY_GROWTH=1 \
27+
-s PTHREAD_POOL_SIZE=8 \
28+
-s INITIAL_MEMORY=1610612736 \
29+
-s TOTAL_MEMORY=1610612736 \
3230
-s FORCE_FILESYSTEM=1 \
33-
-s EXPORT_NAME=\"'whisper_factory'\" \
31+
-s EXPORTED_RUNTIME_METHODS=\"['print', 'printErr', 'ccall', 'cwrap']\" \
3432
${EXTRA_FLAGS} \
3533
")

bindings/javascript/emscripten.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ EMSCRIPTEN_BINDINGS(whisper) {
1313
for (size_t i = 0; i < g_contexts.size(); ++i) {
1414
if (g_contexts[i] == nullptr) {
1515
g_contexts[i] = whisper_init(path_model.c_str());
16-
return i + 1;
16+
if (g_contexts[i] != nullptr) {
17+
return i + 1;
18+
} else {
19+
return (size_t) 0;
20+
}
1721
}
1822
}
1923

@@ -29,7 +33,7 @@ EMSCRIPTEN_BINDINGS(whisper) {
2933
}
3034
}));
3135

32-
emscripten::function("full_default", emscripten::optional_override([](size_t index, const emscripten::val & audio) {
36+
emscripten::function("full_default", emscripten::optional_override([](size_t index, const emscripten::val & audio, const std::string & lang, bool translate) {
3337
--index;
3438

3539
if (index >= g_contexts.size()) {
@@ -42,15 +46,20 @@ EMSCRIPTEN_BINDINGS(whisper) {
4246

4347
struct whisper_full_params params = whisper_full_default_params(whisper_sampling_strategy::WHISPER_SAMPLING_GREEDY);
4448

49+
printf("full_default: available threads %d\n", std::thread::hardware_concurrency());
50+
4551
params.print_realtime = true;
4652
params.print_progress = false;
4753
params.print_timestamps = true;
4854
params.print_special_tokens = false;
49-
params.translate = false;
50-
params.language = "en";
55+
params.translate = translate;
56+
params.language = whisper_is_multilingual(g_contexts[index]) ? lang.c_str() : "en";
5157
params.n_threads = std::min(8, (int) std::thread::hardware_concurrency());
5258
params.offset_ms = 0;
5359

60+
printf("full_default: using %d threads\n", params.n_threads);
61+
printf("full_default: language '%s'\n", params.language);
62+
5463
std::vector<float> pcmf32;
5564
const int n = audio["length"].as<int>();
5665

bindings/javascript/whisper.js

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)