2022-10-25 17:25:23 +00:00
|
|
|
# stream
|
|
|
|
|
|
|
|
This is a naive example of performing real-time inference on audio from your microphone.
|
|
|
|
The `stream` tool samples the audio every half a second and runs the transcription continously.
|
|
|
|
More info is available in [issue #10](https://github.com/ggerganov/whisper.cpp/issues/10).
|
|
|
|
|
2024-01-26 15:39:54 +00:00
|
|
|
```bash
|
2024-12-15 19:55:36 +00:00
|
|
|
./build/bin/stream -m ./models/ggml-base.en.bin -t 8 --step 500 --length 5000
|
2022-10-25 17:25:23 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
https://user-images.githubusercontent.com/1991296/194935793-76afede7-cfa8-48d8-a80f-28ba83be7d09.mp4
|
|
|
|
|
2022-12-16 16:04:19 +00:00
|
|
|
## Sliding window mode with VAD
|
2022-12-15 18:38:08 +00:00
|
|
|
|
|
|
|
Setting the `--step` argument to `0` enables the sliding window mode:
|
|
|
|
|
2024-01-26 15:39:54 +00:00
|
|
|
```bash
|
2024-12-18 06:43:48 +00:00
|
|
|
./build/bin/stream -m ./models/ggml-base.en.bin -t 6 --step 0 --length 30000 -vth 0.6
|
2022-12-15 18:38:08 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
In this mode, the tool will transcribe only after some speech activity is detected. A very
|
|
|
|
basic VAD detector is used, but in theory a more sophisticated approach can be added. The
|
|
|
|
`-vth` argument determines the VAD threshold - higher values will make it detect silence more often.
|
|
|
|
It's best to tune it to the specific use case, but a value around `0.6` should be OK in general.
|
|
|
|
When silence is detected, it will transcribe the last `--length` milliseconds of audio and output
|
|
|
|
a transcription block that is suitable for parsing.
|
|
|
|
|
|
|
|
## Building
|
|
|
|
|
2022-10-25 17:25:23 +00:00
|
|
|
The `stream` tool depends on SDL2 library to capture audio from the microphone. You can build it like this:
|
|
|
|
|
|
|
|
```bash
|
2024-03-20 16:42:11 +00:00
|
|
|
# Install SDL2
|
|
|
|
# On Debian based linux distributions:
|
2022-10-25 17:25:23 +00:00
|
|
|
sudo apt-get install libsdl2-dev
|
|
|
|
|
2024-03-20 16:42:11 +00:00
|
|
|
# On Fedora Linux:
|
|
|
|
sudo dnf install SDL2 SDL2-devel
|
|
|
|
|
2022-10-25 17:25:23 +00:00
|
|
|
# Install SDL2 on Mac OS
|
|
|
|
brew install sdl2
|
|
|
|
|
2024-12-15 19:55:36 +00:00
|
|
|
cmake -B build -DWHISPER_SDL2=ON
|
|
|
|
cmake --build build --config Release
|
2023-10-29 17:11:13 +00:00
|
|
|
|
2024-12-15 19:55:36 +00:00
|
|
|
./build/bin/stream
|
2023-10-29 17:11:13 +00:00
|
|
|
```
|
|
|
|
|
2022-11-25 21:57:46 +00:00
|
|
|
## Web version
|
|
|
|
|
|
|
|
This tool can also run in the browser: [examples/stream.wasm](/examples/stream.wasm)
|