This example uses a WebAssembly (WASM) port of the whisper.cpp
implementation of the transformer to run the inference inside a web page. The audio data does not leave your computer -
it is processed locally on your machine. The performance is not great but you should be able to achieve x2 or x3
real-time for the tiny and base models on a modern CPU and browser (i.e. transcribe a 60 seconds audio in about
~20-30 seconds).
The example is capable of running all models up to size small inclusive. Beyond that, the memory requirements and
performance are unsatisfactory. The implementation currently support only the Greedy sampling strategy. Both
transcription and translation are supported.
Since the model data is quite big (74MB for the tiny model) you need to manually load the model into the web-page.
The example supports both loading audio from a file and recording audio from the microphone. The maximum length of the
audio is limited to 120 seconds.
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/whisper.wasm/* /path/to/html/
cp bin/libmain.js /path/to/html/
cp bin/libmain.worker.js /path/to/html/
📝Note: By default this example is built with WHISPER_WASM_SINGLE_FILE=ON
which means that that a separate .wasm file will not be generated. Instead, the
WASM module is embedded in the main JS file as a base64 encoded string. To
generate a separate .wasm file, you need to disable this option by passing
-DWHISPER_WASM_SINGLE_FILE=OFF:
emcmake cmake .. -DWHISPER_WASM_SINGLE_FILE=OFF
This will generate a libmain.wasm file in the build/bin directory.
📝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 generated for versions later than 3.1.58.