bunsen-tool 0.43.0

bunsen's models on the command line: speech to text (Parakeet, Qwen3-ASR, Voxtral Realtime, Whisper) and who spoke when (Sortformer), text to speech (ZONOS3, Qwen3-TTS), chat (Qwen3, Qwen3.5, Gemma, nanochat) and typed decisions (Laya). The chat driver is also a library, `bunsen_tool::chat`.
Documentation
//! Transcribing with Parakeet: the construct through a stream driver.
use std::sync::Arc;

use bunsen::{
    errors::{
        BunsenResult,
        ResultContext,
    },
    kits::speech::asr::{
        driver::TranscriptSegment,
        parakeet::{
            ParakeetConstruct,
            ParakeetEngine,
            ParakeetStreamDriver,
        },
    },
};

use crate::asr::{
    Emission,
    Transcript,
    Word,
    millis,
    segment_speaker,
    speaker_turns,
    stream,
};

/// Parakeet's own transcription flags: none. The policy is the model's, its
/// presets and patch resolved (`--model '<name>{window_seconds: 20}'`).
#[derive(clap::Args, Debug, Default)]
pub struct ParakeetFlags {}

/// The driver for `bundle` under its policy and `emission`.
///
/// # Errors
/// [`Policy`](bunsen::errors::BunsenErrorKind::Policy) if the policy's
/// `window_seconds` is under one encoder frame; as the driver and the VAD.
pub fn driver(
    bundle: Arc<ParakeetConstruct>,
    emission: Emission,
) -> BunsenResult<ParakeetStreamDriver> {
    let engine = ParakeetEngine::new(bundle)
        .context("the model policy's window_seconds")
        .as_policy()?;
    let driver = ParakeetStreamDriver::new(engine, emission.into())?;
    Ok(driver)
}

/// Transcribes one recording through `driver`: each committed segment is a
/// word.
pub fn transcribe(
    driver: &ParakeetStreamDriver,
    samples: &[f32],
    chunk: usize,
) -> BunsenResult<(Transcript, Vec<TranscriptSegment>)> {
    let (segments, _) = stream::stream(driver, samples, chunk)?;
    let words = segments
        .iter()
        .filter_map(|s| {
            let text = s.text.as_deref()?.trim();
            (!text.is_empty()).then(|| Word {
                word: text.to_string(),
                start: millis(s.start),
                end: millis(s.end),
                tokens: s.tokens.clone(),
                speaker: segment_speaker(s),
            })
        })
        .collect();
    let transcript = Transcript {
        text: stream::join_text(&segments),
        turns: driver.speakers().map(|_| speaker_turns(&segments)),
        language: None,
        words: Some(words),
        segments: None,
    };
    Ok((transcript, segments))
}