Silero VAD (Voice Activity Detector) for Kotlin Multiplatform, powered by onnxruntime-kmp. The ONNX model is embedded into the library with the cn.rtast.kembeddable Gradle plugin.
| Platform | Backend |
|---|---|
| JVM (desktop) | com.microsoft.onnxruntime:onnxruntime via onnxruntime-kmp |
| Android | com.microsoft.onnxruntime:onnxruntime-android via onnxruntime-kmp |
| macOS arm64 / x64 | prebuilt libonnxruntime via onnxruntime-kmp cinterop |
| Linux x64 | prebuilt libonnxruntime via onnxruntime-kmp cinterop |
| Windows x64 | prebuilt onnxruntime.dll via onnxruntime-kmp cinterop |
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
mavenCentral()
// kembeddable runtime artifacts
maven("https://repo.maven.rtast.cn/releases")
}
}
// module build.gradle.kts
kotlin {
sourceSets {
commonMain.dependencies {
implementation("cn.enaium:silero-vad-kmp:1.0.0")
}
}
}dependencies {
implementation("cn.enaium:silero-vad-kmp-jvm:1.0.0")
}dependencies {
implementation("cn.enaium:silero-vad-kmp-android:1.0.0")
}The model is embedded via the kembeddable plugin (no extra configuration needed).
The libonnxruntime shared library must be shipped next to the final binary (see
onnxruntime-kmp for the artifact/table):
| Platform | Runtime file to ship |
|---|---|
| macOS arm64 | libonnxruntime.1.dylib |
| macOS x64 | libonnxruntime.1.23.2.dylib |
| Linux x64 | libonnxruntime.so.1 |
| Windows x64 | onnxruntime.dll |
import cn.enaium.silero.vad.SileroVad
import cn.enaium.silero.vad.config.SampleRate
val vad = SileroVad(
sampleRate = SampleRate.SAMPLE_RATE_16K, // 8K or 16K
minSpeechDurationMs = 100,
minSilenceDurationMs = 100,
)
// 16 kHz -> 512 samples (32 ms) per frame, 8 kHz -> 256 samples.
val speech = vad.isSpeech(shortSamples) // ShortArray / FloatArray / ByteArray (16-bit LE PCM)
vad.close()isSpeech(ShortArray)/isSpeech(FloatArray)/isSpeech(ByteArray)(little-endian 16-bit PCM).- The constructor feeds one frame at a time; the model keeps its internal state.
reset()clears the internal state (call before a new utterance/stream).
The example module shares a Compose Multiplatform UI;
only the microphone reader differs per platform:
- JVM desktop —
javax.soundTargetDataLine: run with./gradlew :example:run. - Android —
AudioRecord: host theexampleAAR in an app (contains theMainActivity). - macOS native —
AVFAudioAVAudioEngine: run with./gradlew :example:runDebugExecutableMacosArm64(console output; the shared Compose UI is JVM-only, so the native example is a CLI app).
./gradlew publishToMavenLocal # requires onnxruntime-kmp 1.0.0 in ~/.m2
./gradlew jvmTest # JVM tests (embedded model over a 60 s test WAV)
./gradlew macosArm64Test # native test (copies libonnxruntime next to the binary)
./gradlew :example:run # JVM desktop example
./gradlew :example:runDebugExecutableMacosArm64 # macOS native example (AVAudioEngine)MIT, see LICENSE. The embedded silero_vad.onnx model is from the
snakers4/silero-vad project (MIT).