smart-turn-rs

Crates.iosmart-turn-rs
lib.rssmart-turn-rs
version0.1.0
created_at2025-11-21 03:11:36.612369+00
updated_at2025-11-21 03:11:36.612369+00
descriptionA Rust library for livekit's smart turn detection v3 using ONNX Runtime.
homepage
repository
max_upload_size
id1943030
size43,565
jinti (shenjinti)

documentation

README

smart-turn-rs

Rust re-implementation of the pipecat-ai/smart-turn endpoint detector. It wraps ONNX Runtime via the ort crate and exposes a small API plus an example CLI for running predictions locally.

  • Example program (examples/basic.rs) demonstrates loading audio, computing features, and printing prediction results.

Audio Requirements

Smart Turn expects exactly 8 seconds of 16 kHz mono PCM audio per prediction. Provide audio in WAV format with:

  • Sample rate: 16_000 Hz
  • Channels: mono
  • Duration: at least 8 seconds (shorter inputs should be zero-padded to 8 seconds; longer clips should be truncated to the newest 8 seconds)

Feeding data that violates these constraints leads to preprocessing errors or unreliable predictions.

Getting Started

  1. Ensure Rust 1.81 or newer (matching the ort crate requirement).
  2. Fetch model weights, e.g. smart-turn-v3.0.onnx from the upstream repo.
  3. Clone this repository and run:
    cargo run --example basic -- --audio <path/to/8s_16k.wav> --model <path/to/smart-turn-v3.0.onnx>
    
    The example prints prediction, probability, real-time factor, and a JSON payload.

Using the Library

Add the crate to your project (currently via path/git dependency) and call the predictor:

use smart_turn_rs::{SmartTurnPredictor, features::log_mel_spectrogram};
use ndarray::Array3;
use std::path::Path;

fn run_smart_turn(model_path: &Path, features: Array3<f32>) -> anyhow::Result<()> {
    let mut predictor = SmartTurnPredictor::new(model_path)?;
    let result = predictor.predict(features)?;
    println!("prediction: {} (p={:.3})", result.prediction, result.probability);
    Ok(())
}

License

Follows the upstream project: BSD 2-Clause License. Refer to the original pipecat-ai/smart-turn for model provenance and additional documentation.

Commit count: 0

cargo fmt