From 3ba2906db06eebcd6572ede9887ce6f44d6e8dff Mon Sep 17 00:00:00 2001 From: nick huang Date: Fri, 20 Mar 2026 08:01:41 +0800 Subject: [PATCH] examples: add mic docs and limit mic example to unix --- README.md | 1 + build_mic.sh | 11 ----------- examples/CMakeLists.txt | 4 +++- examples/mic/README.md | 43 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 12 deletions(-) delete mode 100644 build_mic.sh create mode 100644 examples/mic/README.md diff --git a/README.md b/README.md index 474a1301d..ea59db59c 100644 --- a/README.md +++ b/README.md @@ -842,6 +842,7 @@ Some of the examples are even ported to run in the browser using WebAssembly. Ch | [whisper-cli](examples/cli) | [whisper.wasm](examples/whisper.wasm) | Tool for translating and transcribing audio using Whisper | | [whisper-bench](examples/bench) | [bench.wasm](examples/bench.wasm) | Benchmark the performance of Whisper on your machine | | [whisper-stream](examples/stream) | [stream.wasm](examples/stream.wasm) | Real-time transcription of raw microphone capture | +| [whisper-mic](examples/mic) | | Manual start/stop microphone transcription with interactive device selection | | [whisper-command](examples/command) | [command.wasm](examples/command.wasm) | Basic voice assistant example for receiving voice commands from the mic | | [whisper-server](examples/server) | | HTTP transcription server with OAI-like API | | [whisper-talk-llama](examples/talk-llama) | | Talk with a LLaMA bot | diff --git a/build_mic.sh b/build_mic.sh deleted file mode 100644 index 279e7271a..000000000 --- a/build_mic.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# Build script for examples/mic/whisper-mic.cpp -set -e - -cd "$(dirname "$0")" - -mkdir -p build_mic -cd build_mic - -cmake ../examples/mic -cmake --build . -j$(nproc) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b3fd7834c..4c62f711a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -118,7 +118,9 @@ else() endif (WHISPER_SDL2) add_subdirectory(deprecation-warning) - add_subdirectory(mic) + if (UNIX AND NOT WIN32) + add_subdirectory(mic) + endif() endif() if (WHISPER_SDL2) diff --git a/examples/mic/README.md b/examples/mic/README.md new file mode 100644 index 000000000..a8d0e5fe2 --- /dev/null +++ b/examples/mic/README.md @@ -0,0 +1,43 @@ +# whisper.cpp/examples/mic + +This example captures live microphone audio and performs manual start/stop transcription. +Unlike `whisper-stream`, it records a full segment first and then transcribes that segment. + +## Run + +```bash +./build/bin/whisper-mic -m ./models/ggml-base.bin +``` + +Press Enter to start recording, then press Enter again to stop and transcribe. + +## Options + +```text + -h, --help show help and exit + -m F, --model F model path + -t N, --timeout N max recording time in seconds + -c N, --capture N capture device ID + -l S, --language S language (for example: zh, en) + -ng, --no-gpu disable GPU inference +``` + +## Build + +```bash +cmake -B build +cmake --build build --config Release -j +``` + +## GPU build (optional) + +```bash +cmake -S . -B build_gpu -DGGML_CUDA=ON +cmake --build build_gpu --config Release -j +``` + +Then run: + +```bash +./build_gpu/bin/whisper-mic -m ./models/ggml-base.bin +```