whisper.cpp/examples/bench.wasm
Enes Grahovac 5d4390d281
examples : add HEAPU8 to all of the exported runtime methods (#3134)
This commit adds HEAPU8 to the list of exported methods.

The motivation for this commit is that currently this is causing an error on Window systems where HEAPU8 in undefined, which results in the following error message in the web console:

main.js:1 Uncaught TypeError:
Cannot read properties of undefined (reading 'buffer') at __emval_get_property
(main.js:1:1363125) at 003a453a:0xc4a47 at 003a453a:0xc51cd at
Object.full_default (eval at craftInvokerFunction (main.js:1:1347011),
<anonymous>:9:10) at whisper.cpp/:647:42

danbev originally fixed this for whisper.wasm, stream.wasm, and command.stream, but the issue still exists on the other examples which I patch in this code.

Resolves: #3059
2025-05-10 06:44:13 +02:00
..
CMakeLists.txt examples : add HEAPU8 to all of the exported runtime methods (#3134) 2025-05-10 06:44:13 +02:00
emscripten.cpp whisper : add support for large v3 (#1444) 2023-11-07 15:30:18 +02:00
index-tmpl.html ci : add github pages workflow for wasm examples (#2969) 2025-03-31 11:34:40 +02:00
README.md wasm : add note about worker.js file generation [no ci] (#3133) 2025-05-09 15:42:45 +02:00

bench.wasm

Benchmark the performance of whisper.cpp in the browser using WebAssembly

Link: https://ggerganov.github.io/whisper.cpp/bench.wasm

Terminal version: examples/bench

Build instructions

# build using Emscripten (v3.1.2)
git clone https://github.com/ggerganov/whisper.cpp
cd whisper.cpp
mkdir build-em && cd build-em
emcmake cmake ..
make -j

The example can then be started by running a local HTTP server:

python3 examples/server.py

And then opening a browser to the following URL: http://localhost:8000/bench.wasm

To run the example in a different server, you need to copy the following files to the server's HTTP path:

# copy the produced page to your HTTP path
cp bin/bench.wasm/*       /path/to/html/
cp bin/libbench.js        /path/to/html/
cp bin/libbench.worker.js /path/to/html/

📝 Note: As of Emscripten 3.1.58 (April 2024), separate worker.js files are no longer generated and the worker is embedded in the main JS file. So the worker file will not be geneated for versions later than 3.1.58.