aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-10-08 06:49:33 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-10-08 07:21:37 +0200
commita5af9c3d351085f4005a949f8c382a3aad4e0b29 (patch)
tree0ad133d931553e68a68588e983976a66b3309083 /README.md
downloadsvad-a5af9c3d351085f4005a949f8c382a3aad4e0b29.tar.gz
svad-a5af9c3d351085f4005a949f8c382a3aad4e0b29.zip
initv0.1.0
Diffstat (limited to 'README.md')
-rw-r--r--README.md74
1 files changed, 74 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..88f135e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,74 @@
+# svad
+
+Voice activity detection library using [Silero VAD](https://github.com/snakers4/silero-vad) v6.2 weights. Supports mono 16 kHz and 8 kHz audio, speech probabilities, and speech segmentation.
+
+## Build
+
+To build the library, you need Make, a C11 compiler (GCC or Clang), and `ar`.
+
+### Get the weights
+
+This step needs `curl`, Python 3, and [uv](https://docs.astral.sh/uv/getting-started/installation/). The `uv` command below installs NumPy and ONNX for the script. Python is not needed to compile or run the C library.
+
+Run these commands from the project folder. They download the Silero VAD v6.2 models and create `weights_16k.h` and `weights_8k.h`. Both headers must be in this folder before you run `make`:
+
+```sh
+mkdir -p build/models
+base=https://raw.githubusercontent.com/snakers4/silero-vad/v6.2/src/silero_vad/data
+curl -fL "$base/silero_vad_16k_op15.onnx" -o build/models/silero_vad_16k_op15.onnx
+curl -fL "$base/silero_vad.onnx" -o build/models/silero_vad.onnx
+
+uv run --no-project --with numpy --with onnx python scripts/export_weights.py \
+ build/models/silero_vad_16k_op15.onnx \
+ build/models/silero_vad.onnx \
+ build/generated
+
+cp build/generated/src/weights_16k.h build/generated/src/weights_8k.h .
+```
+
+The script also creates `build/generated/svad_weights.bin`. You only need that file if you use `svad_create_from_file` to load weights at run time.
+
+### Build the library
+
+```sh
+make # builds libsvad.a
+make debug # optional debug build
+make clean # removes build outputs
+```
+
+Link your application with `libsvad.a` and `-lm`.
+
+## Usage
+
+Save this example as `example.c`. It reads raw mono signed 16-bit PCM in native byte order from standard input at 16 kHz and prints one speech probability per 32 ms chunk. Input must already be decoded and resampled; WAV headers are not accepted.
+
+```c
+#include "svad.h"
+#include <stdio.h>
+
+int main(void)
+{
+ svad_t *vad = svad_create(16000);
+ if (!vad) return 1;
+
+ const size_t chunk_size = (size_t)svad_chunk_samples(vad);
+ int16_t chunk[512];
+ size_t n;
+ while ((n = fread(chunk, sizeof(*chunk), chunk_size, stdin)) > 0) {
+ for (size_t i = n; i < chunk_size; ++i) chunk[i] = 0;
+ printf("%.6f\n", svad_process_s16(vad, chunk));
+ }
+
+ svad_destroy(vad);
+ return ferror(stdin) ? 1 : 0;
+}
+```
+
+```sh
+cc -std=c11 -I. example.c libsvad.a -lm -o example
+./example < audio.pcm
+```
+
+Use `svad_create(8000)` for 8 kHz audio. Each call consumes exactly 512 samples at 16 kHz or 256 at 8 kHz, without overlap. `svad_process_f32` accepts float samples in `[-1, 1]`. Call `svad_reset` before starting a new audio stream and use a separate instance for each concurrent stream.
+
+For speech boundaries, feed probabilities to `svad_segmenter_update` after `svad_segmenter_init`, or use `svad_speech_timestamps` for a complete recording. See [svad.h](./svad.h) for the API and segmentation parameters.