8 releases

0.3.5 Nov 26, 2024
0.3.4 Aug 28, 2024
0.2.1 Feb 28, 2024
0.1.0 Dec 16, 2023

#324 in Audio

Download history 32/week @ 2024-08-17 312/week @ 2024-08-24 33/week @ 2024-08-31 15/week @ 2024-09-07 159/week @ 2024-09-14 114/week @ 2024-09-21 106/week @ 2024-09-28 52/week @ 2024-10-05 68/week @ 2024-10-12 37/week @ 2024-10-19 43/week @ 2024-10-26 35/week @ 2024-11-02 21/week @ 2024-11-09 38/week @ 2024-11-16 198/week @ 2024-11-23 54/week @ 2024-11-30

316 downloads per month
Used in 3 crates (via kalosm)

MIT/Apache

730KB
2.5K SLoC

Kalosm Sound

Kalosm Sound is a collection of audio models and utilities for the Kalosm framework. It supports several voice activity detection models, and provides utilities for transcribing audio into text.

Sound Streams

Models in kalosm sound work with any AsyncSource. You can use MicInput::stream to stream audio from the microphone, or any synchronous audio source that implements rodio::Source like a mp3 or wav file.

You can transform the audio streams with:

Voice Activity Detection

VAD models are used to detect when a speaker is speaking in a given audio stream. The simplest way to use a VAD model is to create an audio stream and call VoiceActivityDetectorExt::voice_activity_stream to stream audio chunks that are actively being spoken:

use kalosm::sound::*;
#[tokio::main]
async fn main() {
    // Get the default microphone input
    let mic = MicInput::default();
    // Stream the audio from the microphone
    let stream = mic.stream().unwrap();
    // Detect voice activity in the audio stream
    let mut vad = stream.voice_activity_stream();
    while let Some(input) = vad.next().await {
        println!("Probability: {}", input.probability);
    }
}

Kalosm also provides VoiceActivityStreamExt::rechunk_voice_activity to collect chunks of consecutive audio samples with a high vad probability. This can be useful for applications like speech recognition where context between consecutive audio samples is important.

use kalosm::sound::*;
use rodio::Source;
#[tokio::main]
async fn main() {
    // Get the default microphone input
    let mic = MicInput::default();
    // Stream the audio from the microphone
    let stream = mic.stream().unwrap();
    // Chunk the audio into chunks of speech
    let vad = stream.voice_activity_stream();
    let mut audio_chunks = vad.rechunk_voice_activity();
    // Print the chunks as they are streamed in
    while let Some(input) = audio_chunks.next().await {
        println!("New voice activity chunk with duration {:?}", input.total_duration());
    }
}

Transcription

You can use the Whisper model to transcribe audio into text. Kalosm can transcribe any AsyncSource into a transcription stream with the AsyncSourceTranscribeExt::transcribe method:

use kalosm::sound::*;
#[tokio::main]
async fn main() {
    // Get the default microphone input
    let mic = MicInput::default();
    // Stream the audio from the microphone
    let stream = mic.stream().unwrap();
    // Transcribe the audio into text with the default Whisper model
    let mut transcribe = stream.transcribe(Whisper::new().await.unwrap());
    // Print the text as it is streamed in
    transcribe.to_std_out().await.unwrap();
}

Dependencies

~36–79MB
~1.5M SLoC