### ExecutionConfig - Hardware Acceleration Source: https://context7.com/altunenes/parakeet-rs/llms.txt Explains how to configure hardware acceleration for the Parakeet model using `ExecutionConfig`. It shows examples for CPU, CUDA, WebGPU, and CoreML, including custom thread counts and cache directories. ```APIDOC ## `ExecutionConfig` — Hardware acceleration Builder for ONNX Runtime session configuration. Selects execution provider (CPU by default; GPU providers fall back to CPU if unavailable). Controls intra/inter-op thread counts and allows advanced session customization via a closure. ```rust use parakeet_rs::{Parakeet, ExecutionConfig, ExecutionProvider}; // CPU with custom thread count let config = ExecutionConfig::new().with_intra_threads(8); let mut model = Parakeet::from_pretrained(".", Some(config))?; // CUDA (requires --features cuda) #[cfg(feature = "cuda")] { let config = ExecutionConfig::new() .with_execution_provider(ExecutionProvider::Cuda); let mut model = Parakeet::from_pretrained(".", Some(config))?; } // WebGPU (Apple Silicon / browser-native Metal backend; requires --features webgpu) #[cfg(feature = "webgpu")] { let config = ExecutionConfig::new() .with_execution_provider(ExecutionProvider::WebGPU); let mut model = Parakeet::from_pretrained(".", Some(config))?; } // CoreML with compilation cache to avoid ~5 s recompile on each load #[cfg(feature = "coreml")] { let config = ExecutionConfig::new() .with_execution_provider(ExecutionProvider::CoreML) .with_coreml_cache_dir("./coreml_cache"); let mut model = Parakeet::from_pretrained(".", Some(config))?; } // Advanced: disable memory pattern optimization let config = ExecutionConfig::new() .with_custom_configure(|builder| builder.with_memory_pattern(false)); let mut model = Parakeet::from_pretrained(".", Some(config))?; # Ok::<(), Box>(()) ``` ``` -------------------------------- ### Hardware Acceleration Configuration with ExecutionConfig Source: https://context7.com/altunenes/parakeet-rs/llms.txt Configures ONNX Runtime session for hardware acceleration. Examples show CPU with custom threads, CUDA, WebGPU, and CoreML with cache support. Advanced options like disabling memory pattern optimization are also demonstrated. ```rust use parakeet_rs::{Parakeet, ExecutionConfig, ExecutionProvider}; // CPU with custom thread count let config = ExecutionConfig::new().with_intra_threads(8); let mut model = Parakeet::from_pretrained(".", Some(config))?; // CUDA (requires --features cuda) #[cfg(feature = "cuda")] { let config = ExecutionConfig::new() .with_execution_provider(ExecutionProvider::Cuda); let mut model = Parakeet::from_pretrained(".", Some(config))?; } // WebGPU (Apple Silicon / browser-native Metal backend; requires --features webgpu) #[cfg(feature = "webgpu")] { let config = ExecutionConfig::new() .with_execution_provider(ExecutionProvider::WebGPU); let mut model = Parakeet::from_pretrained(".", Some(config))?; } // CoreML with compilation cache to avoid ~5 s recompile on each load #[cfg(feature = "coreml")] { let config = ExecutionConfig::new() .with_execution_provider(ExecutionProvider::CoreML) .with_coreml_cache_dir("./coreml_cache"); let mut model = Parakeet::from_pretrained(".", Some(config))?; } // Advanced: disable memory pattern optimization let config = ExecutionConfig::new() .with_custom_configure(|builder| builder.with_memory_pattern(false)); let mut model = Parakeet::from_pretrained(".", Some(config))?; # Ok::<(), Box>(()) ``` -------------------------------- ### Offline and Streaming ASR with ParakeetUnified Source: https://context7.com/altunenes/parakeet-rs/llms.txt Demonstrates offline transcription of a file and buffered streaming transcription of audio chunks. Includes examples for getting timed transcripts and configuring custom streaming parameters. A shared handle can be used for concurrent streams. ```rust use parakeet_rs::{ParakeetUnified, ParakeetUnifiedHandle, Transcriber, TimestampMode, UnifiedStreamingConfig}; use std::io::Write; // -- Offline mode (uses Transcriber trait) -- let mut model = ParakeetUnified::from_pretrained("./unified", None)?; let result = model.transcribe_file("speech.wav", Some(TimestampMode::Words))?; println!("{}", result.text); for w in result.tokens.iter().take(10) { println!("[{:.2}s - {:.2}s] {}", w.start, w.end, w.text); } // -- Streaming mode -- let mut model = ParakeetUnified::from_pretrained("./unified", None)?; let config = model.streaming_config(); let chunk_size = config.chunk_samples(); // e.g. 8960 samples = 560 ms let mut reader = hound::WavReader::open("speech.wav")?; let audio: Vec = reader.samples::() .map(|s| s.map(|v| v as f32 / 32768.0)) .collect::>()?; for chunk in audio.chunks(chunk_size) { let text = model.transcribe_chunk(chunk)?; if !text.is_empty() { print!("{}", text); std::io::stdout().flush()? ;} } let tail = model.flush()?; if !tail.is_empty() { print!("{}", tail); } let result = model.get_timed_transcript(TimestampMode::Sentences); println!("\nSentences:"); for s in &result.tokens { println!("[{:.2}s - {:.2}s] {}", s.start, s.end, s.text); } // -- Custom streaming config (must be divisible by subsampling factor 8) -- let custom = UnifiedStreamingConfig { left_context_secs: 5.6, chunk_secs: 0.56, right_context_secs: 0.56, }; let mut model = ParakeetUnified::from_pretrained_with_streaming_config( "./unified", None, custom )?; // -- Shared handle for concurrent streams -- let handle = ParakeetUnifiedHandle::load("./unified", None)?; let mut a = ParakeetUnified::from_shared(&handle); let mut b = ParakeetUnified::from_shared(&handle); # Ok::<(), Box>(()) ``` -------------------------------- ### Configure Parakeet with Custom Session Settings Source: https://github.com/altunenes/parakeet-rs/blob/master/README.md Utilize the advanced session configuration via ort SessionBuilder to customize Parakeet's behavior. This example disables memory pattern optimization. ```rust let config = ExecutionConfig::new() .with_custom_configure(|builder| builder.with_memory_pattern(false)); ``` -------------------------------- ### Enable Apple WebGPU Backend Source: https://context7.com/altunenes/parakeet-rs/llms.txt Use this feature for WebGPU acceleration on Apple devices, recommended over CoreML for Parakeet models. ```toml parakeet-rs = { version = "0.3", features = ["webgpu"] } ``` -------------------------------- ### Enable CoreML Backend Source: https://context7.com/altunenes/parakeet-rs/llms.txt Use this feature for CoreML acceleration. Note that it may be slower for dynamic-shape Parakeet graphs compared to WebGPU on Apple. ```toml parakeet-rs = { version = "0.3", features = ["coreml"] } ``` -------------------------------- ### Enable Dynamic ONNX Runtime Library Loading Source: https://context7.com/altunenes/parakeet-rs/llms.txt Use this feature to dynamically load the ONNX Runtime library, allowing you to ship your own `libonnxruntime.so`. ```toml parakeet-rs = { version = "0.3", features = ["load-dynamic"] } ``` -------------------------------- ### Nemotron::from_pretrained and transcribe_chunk Source: https://context7.com/altunenes/parakeet-rs/llms.txt Loads the Nemotron streaming ASR model and demonstrates how to process audio in chunks for real-time transcription. It includes methods for transcribing chunks, retrieving the full transcript, and resetting the model's state. ```APIDOC ## `Nemotron` — Cache-aware streaming ASR (Nemotron 0.6B) Streaming RNNT model with punctuation and capitalization. Process audio in 560 ms chunks (`chunk_size = 8960` samples at 16 kHz). Maintains a multi-layer encoder cache (left context = 70, conv context = 8) and LSTM decoder state across chunks. `transcribe_chunk` returns incremental text; `get_transcript` returns the full accumulated text. `reset` clears all state for a new utterance. ```rust use parakeet_rs::Nemotron; use std::io::Write; // Load from directory: encoder.onnx, encoder.onnx.data, decoder_joint.onnx, tokenizer.model let mut model = Nemotron::from_pretrained("./nemotron", None)?; let mut reader = hound::WavReader::open("speech.wav")?; let spec = reader.spec(); assert_eq!(spec.sample_rate, 16000, "must be 16 kHz"); let mut audio: Vec = reader.samples::() .map(|s| s.map(|v| v as f32 / 32768.0)) .collect::>()?; // Downmix stereo if spec.channels > 1 { audio = audio.chunks(spec.channels as usize) .map(|c| c.iter().sum::() / spec.channels as f32) .collect(); } const CHUNK: usize = 8960; // 560 ms for chunk in audio.chunks(CHUNK) { let mut buf = chunk.to_vec(); buf.resize(CHUNK, 0.0); // zero-pad last chunk let text = model.transcribe_chunk(&buf)?; if !text.is_empty() { print!("{{}}", text); std::io::stdout().flush()?; } } // Flush encoder pipeline with 3 silence chunks for _ in 0..3 { let text = model.transcribe_chunk(&vec![0.0f32; CHUNK])?; if !text.is_empty() { print!("{{}}", text); } } println!("\nFull: {{}}", model.get_transcript()); // Output (streaming, token by token): Hello, this is a test of the Nemotron model. # Ok::<(), Box>(()) ``` ``` -------------------------------- ### DiarizationConfig Presets and Customization Source: https://context7.com/altunenes/parakeet-rs/llms.txt Shows how to use pre-defined `DiarizationConfig` presets like `callhome` and `dihard3`, or create a custom configuration for fine-tuning diarization thresholds and smoothing parameters. ```rust use parakeet_rs::sortformer::{DiarizationConfig, Sortformer}; // Pre-tuned dataset configs let callhome = DiarizationConfig::callhome(); // onset=0.641, offset=0.561, pad_onset=0.229s, pad_offset=0.079s // min_duration_on=0.511s, min_duration_off=0.296s, median_window=11 let dihard3 = DiarizationConfig::dihard3(); // onset=0.56, offset=1.0, min_duration_on=0.007s (very permissive) // Custom config for a quieter environment let mut config = DiarizationConfig::custom(0.5, 0.4); config.min_duration_on = 0.2; // allow 200 ms segments config.min_duration_off = 0.15; // merge gaps shorter than 150 ms config.median_window = 9; // lighter smoothing let sf = Sortformer::with_config("model.onnx", None, config)?; # Ok::<(), Box>(()) ``` -------------------------------- ### Initialize Parakeet with CUDA Execution Provider Source: https://github.com/altunenes/parakeet-rs/blob/master/README.md Instantiate Parakeet with a custom ExecutionConfig that specifies the CUDA execution provider. The library automatically falls back to CPU if GPU initialization fails. Ensure all necessary ONNX models are in the specified directory. ```rust use parakeet_rs::{Parakeet, ExecutionConfig, ExecutionProvider}; let config = ExecutionConfig::new().with_execution_provider(ExecutionProvider::Cuda); let mut parakeet = Parakeet::from_pretrained(".", Some(config))?; ``` -------------------------------- ### Parakeet::from_pretrained Source: https://context7.com/altunenes/parakeet-rs/llms.txt Loads the Parakeet CTC 0.6B English model from a directory or a direct path to an ONNX file. It supports CPU and GPU execution, with GPU acceleration being opt-in via Cargo feature flags. ```APIDOC ## `Parakeet::from_pretrained` — Load CTC (English) model Loads the Parakeet CTC 0.6B English model from a directory (auto-selects `model.onnx`, `model_fp16.onnx`, `model_int8.onnx`, or `model_q4.onnx` in priority order) or a direct path to an ONNX file. Requires `tokenizer.json` in the same directory. Returns `Result`. ```rust use parakeet_rs::{Parakeet, ExecutionConfig, ExecutionProvider, Transcriber, TimestampMode}; // --- CPU (default) --- let mut model = Parakeet::from_pretrained(".", None)?; // --- CUDA GPU --- #[cfg(feature = "cuda")] { let config = ExecutionConfig::new() .with_execution_provider(ExecutionProvider::Cuda) .with_intra_threads(4); let mut model = Parakeet::from_pretrained(".", Some(config))?; } // --- Point directly to a quantized file --- let mut model = Parakeet::from_pretrained("model_int8.onnx", None)?; // Transcribe a WAV file; CTC has no punctuation -> use Words mode let result = model.transcribe_file("audio.wav", Some(TimestampMode::Words))?; println!("{}", result.text); // Word-level timestamps for word in &result.tokens { println!("[{:.3}s - {:.3}s] {}", word.start, word.end, word.text); } // Expected output: // hello world how are you today // [0.000s - 0.240s] hello // [0.240s - 0.480s] world // ... # Ok::<(), Box>(()) ``` ``` -------------------------------- ### Transcribe Audio with Different Timestamp Modes Source: https://context7.com/altunenes/parakeet-rs/llms.txt Demonstrates transcribing an audio file using `ParakeetTDT` with `TimestampMode::Tokens`, `TimestampMode::Words`, and `TimestampMode::Sentences`. Ensure the model directory contains the necessary ONNX and vocabulary files. ```rust use parakeet_rs::{ParakeetTDT, Transcriber, TimestampMode}; let mut model = ParakeetTDT::from_pretrained("./tdt", None)?; // Token-level (raw BPE output) let r = model.transcribe_file("speech.wav", Some(TimestampMode::Tokens))?; for t in &r.tokens { println!("[{:.3}s] {{}}", t.start, t.text); } // Word-level let r = model.transcribe_file("speech.wav", Some(TimestampMode::Words))?; for w in &r.tokens { println!("[{:.2}s - {:.2}s] {{}}", w.start, w.end, w.text); } // Sentence-level (TDT predicts punctuation -> natural boundaries) let r = model.transcribe_file("speech.wav", Some(TimestampMode::Sentences))?; for s in &r.tokens { println!("[{:.2}s - {:.2}s] {{}}", s.start, s.end, s.text); } // Expected: // [0.00s - 3.12s] Hello, how are you today? // [3.12s - 6.45s] I'm doing well, thank you. # Ok::<(), Box>(()) ``` -------------------------------- ### Sortformer Full-File and Streaming Diarization Source: https://context7.com/altunenes/parakeet-rs/llms.txt Demonstrates full-file diarization using default or custom configurations, stateful streaming with `diarize_chunk`, and buffered streaming with `feed`/`flush`. Requires the `sortformer` feature. Ensure audio is 16kHz mono. ```rust use parakeet_rs::sortformer::{Sortformer, DiarizationConfig, SpeakerSegment}; // -- Full-file diarization (callhome config, default) -- let mut sf = Sortformer::with_config( "diar_streaming_sortformer_4spk-v2.onnx", None, DiarizationConfig::callhome(), // onset=0.641, offset=0.561, min_on=0.511s )?; println!("Latency: {:.1}s", sf.latency()); // 10.0 s with default chunk_len=124 let (audio, sample_rate, channels) = load_16k_wav("meeting.wav")?; let segments = sf.diarize(audio, sample_rate, channels)?; for seg in &segments { println!( "[{:.2}s - {:.2}s] Speaker {}", seg.start as f64 / 16_000.0, seg.end as f64 / 16_000.0, seg.speaker_id, ); } // -- Streaming (stateful, preserves speaker identity across chunks) -- sf.reset_state(); let audio_chunks: Vec> = /* real-time mic chunks */ vec![]; for chunk in &audio_chunks { let segs = sf.diarize_chunk(chunk)?; for s in segs { println!("[ {:.2}s] Speaker {}", s.start as f64 / 16_000.0, s.speaker_id); } } // -- Buffered streaming with absolute timestamps -- let mut sf2 = Sortformer::new("diar_streaming_sortformer_4spk-v2.onnx")?; let audio_stream = vec![0.0f32; 16000 * 30]; // 30 s audio for chunk in audio_stream.chunks(16000) { // 1 s at a time let segs = sf2.feed(chunk)?; for s in segs { println!("abs [{:.2}s] Speaker {}", s.start as f64/16000.0, s.speaker_id); } } let final_segs = sf2.flush()?; // -- Custom detection thresholds -- let mut cfg = DiarizationConfig::custom(0.5, 0.4); // more sensitive cfg.min_duration_on = 0.3; cfg.median_window = 15; let sf3 = Sortformer::with_config("model.onnx", None, cfg)?; fn load_16k_wav(p: &str) -> Result<(Vec, u32, u16), Box> { let mut r = hound::WavReader::open(p)?; let s = r.spec(); let a: Vec = r.samples::().map(|x| x.map(|v| v as f32/32768.0)).collect::>()?; Ok((a, s.sample_rate, s.channels)) } # Ok::<(), Box>(()) ``` -------------------------------- ### Load CTC (English) model with Parakeet::from_pretrained Source: https://context7.com/altunenes/parakeet-rs/llms.txt Loads the Parakeet CTC 0.6B English model from a directory or a specific ONNX file. Requires tokenizer.json. Supports CPU and CUDA GPU execution with configurable thread counts. Transcribes a WAV file and outputs text and word-level timestamps. ```rust use parakeet_rs::{Parakeet, ExecutionConfig, ExecutionProvider, Transcriber, TimestampMode}; // --- CPU (default) --- let mut model = Parakeet::from_pretrained(".", None)?; // --- CUDA GPU --- #[cfg(feature = "cuda")] { let config = ExecutionConfig::new() .with_execution_provider(ExecutionProvider::Cuda) .with_intra_threads(4); let mut model = Parakeet::from_pretrained(".", Some(config))?; } // --- Point directly to a quantized file --- let mut model = Parakeet::from_pretrained("model_int8.onnx", None)?; // Transcribe a WAV file; CTC has no punctuation -> use Words mode let result = model.transcribe_file("audio.wav", Some(TimestampMode::Words))?; println!("{}", result.text); // Word-level timestamps for word in &result.tokens { println!("[{:.3}s - {:.3}s] {}", word.start, word.end, word.text); } // Expected output: // hello world how are you today // [0.000s - 0.240s] hello // [0.240s - 0.480s] world // ... ``` -------------------------------- ### Enable TensorRT Backend Source: https://context7.com/altunenes/parakeet-rs/llms.txt Enable the TensorRT execution provider for GPU acceleration. Other supported backends include DirectML, OpenVINO, MIGraphX, and NNAPI. ```toml parakeet-rs = { version = "0.3", features = ["tensorrt"] } ``` ```toml parakeet-rs = { version = "0.3", features = ["directml"] } ``` -------------------------------- ### Load ParakeetTDT Model and Transcribe Source: https://context7.com/altunenes/parakeet-rs/llms.txt Loads the Parakeet TDT multilingual model from a specified directory. This model supports 25 languages and automatic language detection. Audio files longer than 8-10 minutes should be split manually. ```rust use parakeet_rs::{ParakeetTDT, Transcriber, TimestampMode}; let mut model = ParakeetTDT::from_pretrained("./tdt", None)?; // Sentence-level timestamps with punctuation let result = model.transcribe_file("interview.wav", Some(TimestampMode::Sentences))?; println!("{{}}", result.text); for segment in &result.tokens { println!( "[{:.2}s - {:.2}s] {{}}", segment.start, segment.end, segment.text ); } // Expected: // Hello, my name is Alice and I work at NVIDIA. // [0.00s - 2.40s] Hello, my name is Alice and I work at NVIDIA. // Word-level let result = model.transcribe_file("interview.wav", Some(TimestampMode::Words))?; for word in result.tokens.iter().take(5) { println!("[{:.3}s - {:.3}s] {{}}", word.start, word.end, word.text); } # Ok::<(), Box>(()) ``` -------------------------------- ### ParakeetUnified - Offline and Streaming ASR Source: https://context7.com/altunenes/parakeet-rs/llms.txt Demonstrates how to use the ParakeetUnified model for both offline file transcription and buffered streaming audio processing. It covers basic usage, streaming configuration, and handling of results with timestamps. ```APIDOC ## `ParakeetUnified` — Offline + buffered streaming RNNT ASR 600M-parameter model supporting both offline (full-file) and buffered-streaming modes. Streaming uses a sliding window with configurable left context (5.6 s), chunk size (0.56 s), and right context (0.56 s). `transcribe_chunk` feeds audio incrementally; `flush` processes any remaining buffered audio at stream end; `get_timed_transcript` returns accumulated timestamps at any granularity. ```rust use parakeet_rs::{ParakeetUnified, ParakeetUnifiedHandle, Transcriber, TimestampMode, UnifiedStreamingConfig}; use std::io::Write; // -- Offline mode (uses Transcriber trait) -- let mut model = ParakeetUnified::from_pretrained("./unified", None)?; let result = model.transcribe_file("speech.wav", Some(TimestampMode::Words))?; println!("{}", result.text); for w in result.tokens.iter().take(10) { println!("[{:.2}s - {:.2}s] {}", w.start, w.end, w.text); } // -- Streaming mode -- let mut model = ParakeetUnified::from_pretrained("./unified", None)?; let config = model.streaming_config(); let chunk_size = config.chunk_samples(); // e.g. 8960 samples = 560 ms let mut reader = hound::WavReader::open("speech.wav")?; let audio: Vec = reader.samples::() .map(|s| s.map(|v| v as f32 / 32768.0)) .collect::>()?; for chunk in audio.chunks(chunk_size) { let text = model.transcribe_chunk(chunk)?; if !text.is_empty() { print!("{}", text); std::io::stdout().flush()?; } } let tail = model.flush()?; if !tail.is_empty() { print!("{}", tail); } let result = model.get_timed_transcript(TimestampMode::Sentences); println!("\nSentences:"); for s in &result.tokens { println!("[{:.2}s - {:.2}s] {}", s.start, s.end, s.text); } // -- Custom streaming config (must be divisible by subsampling factor 8) -- let custom = UnifiedStreamingConfig { left_context_secs: 5.6, chunk_secs: 0.56, right_context_secs: 0.56, }; let mut model = ParakeetUnified::from_pretrained_with_streaming_config( "./unified", None, custom )?; // -- Shared handle for concurrent streams -- let handle = ParakeetUnifiedHandle::load("./unified", None)?; let mut a = ParakeetUnified::from_shared(&handle); let mut b = ParakeetUnified::from_shared(&handle); # Ok::<(), Box>(()) ``` ``` -------------------------------- ### Enable Multiple Features Source: https://context7.com/altunenes/parakeet-rs/llms.txt Combine multiple features such as CUDA, Sortformer, and Cohere for advanced speech processing capabilities. ```toml parakeet-rs = { version = "0.3", features = ["cuda", "sortformer", "cohere"] } ``` -------------------------------- ### Streaming Transcription with Nemotron Model Source: https://github.com/altunenes/parakeet-rs/blob/master/README.md Perform cache-aware streaming ASR with punctuation using the Nemotron model. Process audio in specified chunk sizes for real-time transcription. ```rust use parakeet_rs::Nemotron; let mut model = Nemotron::from_pretrained("./nemotron", None)?; // Process in 560ms chunks for streaming const CHUNK_SIZE: usize = 8960; // 560ms at 16kHz for chunk in audio.chunks(CHUNK_SIZE) { let text = model.transcribe_chunk(chunk)?; print!("{}", text); } ``` -------------------------------- ### ParakeetTDT::from_pretrained Source: https://context7.com/altunenes/parakeet-rs/llms.txt Loads the Parakeet TDT (Token-and-Duration Transducer) multilingual model from a specified directory. This model supports automatic language detection and is suitable for sentence-level timestamping. ```APIDOC ## `ParakeetTDT::from_pretrained` — Load TDT multilingual model Loads the Parakeet TDT (Token-and-Duration Transducer) multilingual model. Requires a directory containing `encoder-model.onnx`, `encoder-model.onnx.data`, `decoder_joint-model.onnx`, and `vocab.txt`. Supports 25 languages with automatic language detection. Uses 128 mel features (vs 80 for CTC) and a RNNT decoder. Audio length limit is approximately 8-10 minutes; split longer files manually. ```rust use parakeet_rs::{ParakeetTDT, Transcriber, TimestampMode}; let mut model = ParakeetTDT::from_pretrained("./tdt", None)?; // Sentence-level timestamps with punctuation let result = model.transcribe_file("interview.wav", Some(TimestampMode::Sentences))?; println!("{{}}", result.text); for segment in &result.tokens { println!( "[{:.2}s - {:.2}s] {{}}", segment.start, segment.end, segment.text ); } // Expected: // Hello, my name is Alice and I work at NVIDIA. // [0.00s - 2.40s] Hello, my name is Alice and I work at NVIDIA. // Word-level let result = model.transcribe_file("interview.wav", Some(TimestampMode::Words))?; for word in result.tokens.iter().take(5) { println!("[{:.3}s - {:.3}s] {{}}", word.start, word.end, word.text); } # Ok::<(), Box>(()) ``` ``` -------------------------------- ### Load and Transcribe Audio with TDT Model Source: https://github.com/altunenes/parakeet-rs/blob/master/README.md Utilize the TDT model for multilingual speech recognition with auto-detection across 25 languages. Transcribe audio samples and retrieve sentence-level or token-level timestamps. ```rust use parakeet_rs::{ParakeetTDT, Transcriber, TimestampMode}; let mut parakeet = ParakeetTDT::from_pretrained("./tdt", None)?; let result = parakeet.transcribe_samples(audio, 16000, 1, Some(TimestampMode::Sentences))?; println!("{}", result.text); // Token-level timestamps for token in result.tokens { println!("[{:.3}s - {:.3}s] {}", token.start, token.end, token.text); } ``` -------------------------------- ### Load and Transcribe Audio with CTC Model Source: https://github.com/altunenes/parakeet-rs/blob/master/README.md Use the CTC model for English-only speech recognition. Load the model from a specified path and transcribe audio samples, with options for word-level timestamps. ```rust use parakeet_rs::{Parakeet, Transcriber, TimestampMode}; let mut parakeet = Parakeet::from_pretrained(".", None)?; // Load and transcribe audio (see examples/raw.rs for full example) let result = parakeet.transcribe_samples(audio, 1600, 1, Some(TimestampMode::Words))?; println!("{}", result.text); // Token-level timestamps for token in result.tokens { println!("[{:.3}s - {:.3}s] {}", token.start, token.end, token.text); } ``` -------------------------------- ### NemotronHandle / Nemotron::from_shared Source: https://context7.com/altunenes/parakeet-rs/llms.txt Load the ONNX session once into a NemotronHandle, then spawn multiple independent Nemotron instances each with their own encoder cache and decoder state but sharing the expensive ONNX session. The model lock is held only during inference. ```APIDOC ## `NemotronHandle` / `Nemotron::from_shared` — Shared model for concurrent streams Load the ONNX session once into a `NemotronHandle`, then spawn multiple independent `Nemotron` instances each with their own encoder cache and decoder state but sharing the expensive ONNX session. The model lock is held only during inference (~20-50 ms per 560 ms chunk). ```rust use parakeet_rs::{NemotronHandle, Nemotron}; // Load once let handle = NemotronHandle::load("./nemotron", None)?; // Spawn independent streams (e.g., microphone + system audio simultaneously) let mut stream_a = Nemotron::from_shared(&handle); let mut stream_b = Nemotron::from_shared(&handle); const CHUNK: usize = 8960; let audio_a = vec![0.0f32; CHUNK * 10]; // replace with real audio let audio_b = vec![0.0f32; CHUNK * 10]; for (chunk_a, chunk_b) in audio_a.chunks(CHUNK).zip(audio_b.chunks(CHUNK)) { let mut a = chunk_a.to_vec(); a.resize(CHUNK, 0.0); let mut b = chunk_b.to_vec(); b.resize(CHUNK, 0.0); stream_a.transcribe_chunk(&a)?; stream_b.transcribe_chunk(&b)?; } println!("Stream A: {}", stream_a.get_transcript()); println!("Stream B: {}", stream_b.get_transcript()); // Both streams produce independent transcripts from the shared session # Ok::<(), Box>(()) ``` ``` -------------------------------- ### Load NemotronHandle for Shared Model Source: https://context7.com/altunenes/parakeet-rs/llms.txt Load the ONNX session once into a NemotronHandle to enable multiple Nemotron instances to share the model for concurrent transcription streams. The model lock is held only during inference. ```rust use parakeet_rs::{NemotronHandle, Nemotron}; // Load once let handle = NemotronHandle::load("./nemotron", None)?; // Spawn independent streams (e.g., microphone + system audio simultaneously) let mut stream_a = Nemotron::from_shared(&handle); let mut stream_b = Nemotron::from_shared(&handle); const CHUNK: usize = 8960; let audio_a = vec![0.0f32; CHUNK * 10]; // replace with real audio let audio_b = vec![0.0f32; CHUNK * 10]; for (chunk_a, chunk_b) in audio_a.chunks(CHUNK).zip(audio_b.chunks(CHUNK)) { let mut a = chunk_a.to_vec(); a.resize(CHUNK, 0.0); let mut b = chunk_b.to_vec(); b.resize(CHUNK, 0.0); stream_a.transcribe_chunk(&a)?; stream_b.transcribe_chunk(&b)?; } println!("Stream A: {}", stream_a.get_transcript()); println!("Stream B: {}", stream_b.get_transcript()); // Both streams produce independent transcripts from the shared session # Ok::<(), Box>(()) ``` -------------------------------- ### Configure GPU Support for Parakeet-RS Source: https://github.com/altunenes/parakeet-rs/blob/master/README.md Add the 'cuda' feature to your parakeet-rs dependency in Cargo.toml to enable GPU support. Other supported execution providers (EPs) like tensorrt, webgpu, directml, migraphx, or other ort supported EPs can also be specified. ```toml parakeet-rs = { version = "0.3", features = ["cuda"] } ``` -------------------------------- ### Nemotron (Streaming) Transcription Source: https://github.com/altunenes/parakeet-rs/blob/master/README.md Cache-aware streaming ASR with punctuation using the Nemotron model. Processes audio in chunks. ```APIDOC ## Nemotron (Streaming) Transcription ### Description Cache-aware streaming ASR with punctuation using the Nemotron model. Processes audio in chunks. ### Method ```rust use parakeet_rs::Nemotron; let mut model = Nemotron::from_pretrained("./nemotron", None)?; // Process in 560ms chunks for streaming const CHUNK_SIZE: usize = 8960; // 560ms at 16kHz for chunk in audio.chunks(CHUNK_SIZE) { let text = model.transcribe_chunk(chunk)?; print!("{}", text); } ``` ### Parameters - `chunk`: A slice of audio samples. ``` -------------------------------- ### DiarizationConfig — Post-processing thresholds for diarization Source: https://context7.com/altunenes/parakeet-rs/llms.txt Allows customization of diarization post-processing, including onset/offset detection, padding, minimum duration filtering, and median smoothing. Provides presets and a custom configuration option. ```APIDOC ## `DiarizationConfig` — Post-processing thresholds for diarization Controls how raw per-frame sigmoid predictions are converted into speaker segments: onset/offset hysteresis thresholds, padding, minimum duration filtering, and median smoothing. Three presets match NVIDIA's published YAML configs; `custom` allows arbitrary tuning. ```rust use parakeet_rs::sortformer::{DiarizationConfig, Sortformer}; // Pre-tuned dataset configs let callhome = DiarizationConfig::callhome(); // onset=0.641, offset=0.561, pad_onset=0.229s, pad_offset=0.079s // min_duration_on=0.511s, min_duration_off=0.296s, median_window=11 let dihard3 = DiarizationConfig::dihard3(); // onset=0.56, offset=1.0, min_duration_on=0.007s (very permissive) // Custom config for a quieter environment let mut config = DiarizationConfig::custom(0.5, 0.4); config.min_duration_on = 0.2; // allow 200 ms segments config.min_duration_off = 0.15; // merge gaps shorter than 150 ms config.median_window = 9; // lighter smoothing let sf = Sortformer::with_config("model.onnx", None, config)?; # Ok::<(), Box>(()) ``` ``` -------------------------------- ### Parakeet-RS Cargo Features Source: https://context7.com/altunenes/parakeet-rs/llms.txt Configure Parakeet-RS dependencies using Cargo features for specific model families (sortformer, multitalker, cohere) and hardware acceleration (cuda). The default feature uses CPU-only inference. ```toml # Cargo.toml # CPU only (default) [dependencies] parakeet-rs = "0.3" # Sortformer diarization parakeet-rs = { version = "0.3", features = ["sortformer"] } # Multitalker (implies sortformer) parakeet-rs = { version = "0.3", features = ["multitalker"] } # Cohere multilingual ASR parakeet-rs = { version = "0.3", features = ["cohere"] } # CUDA GPU acceleration parakeet-rs = { version = "0.3", features = ["cuda"] } ``` -------------------------------- ### Streaming ASR with Nemotron Model Source: https://context7.com/altunenes/parakeet-rs/llms.txt Utilizes the `Nemotron` model for cache-aware streaming Automatic Speech Recognition. Audio is processed in chunks, and the model maintains encoder cache and decoder state across chunks for continuous transcription. Ensure the model directory contains the necessary ONNX and tokenizer files. ```rust use parakeet_rs::Nemotron; use std::io::Write; // Load from directory: encoder.onnx, encoder.onnx.data, decoder_joint.onnx, tokenizer.model let mut model = Nemotron::from_pretrained("./nemotron", None)?; let mut reader = hound::WavReader::open("speech.wav")?; let spec = reader.spec(); assert_eq!(spec.sample_rate, 16000, "must be 16 kHz"); let mut audio: Vec = reader.samples::() .map(|s| s.map(|v| v as f32 / 32768.0)) .collect::>()?; // Downmix stereo if spec.channels > 1 { audio = audio.chunks(spec.channels as usize) .map(|c| c.iter().sum::() / spec.channels as f32) .collect(); } const CHUNK: usize = 8960; // 560 ms for chunk in audio.chunks(CHUNK) { let mut buf = chunk.to_vec(); buf.resize(CHUNK, 0.0); // zero-pad last chunk let text = model.transcribe_chunk(&buf)?; if !text.is_empty() { print!("{{}}", text); std::io::stdout().flush()?; } } // Flush encoder pipeline with 3 silence chunks for _ in 0..3 { let text = model.transcribe_chunk(&vec![0.0f32; CHUNK])?; if !text.is_empty() { print!("{{}}", text); } } println!("\nFull: {{}}", model.get_transcript()); // Output (streaming, token by token): Hello, this is a test of the Nemotron model. # Ok::<(), Box>(()) ``` -------------------------------- ### Speaker Diarization with Sortformer v2 Source: https://github.com/altunenes/parakeet-rs/blob/master/README.md Add the 'sortformer' feature for streaming speaker diarization. Configure with different diarization presets like Callhome, DiHard3, or custom settings. Use `diarize` for full audio or `diarize_chunk` for real-time processing. ```toml parakeet-rs = { version = "0.3", features = ["sortformer"] } ``` ```rust use parakeet_rs::sortformer::{Sortformer, DiarizationConfig}; let mut sortformer = Sortformer::with_config( "diar_streaming_sortformer_4spk-v2.onnx", // or v2.1.onnx None, DiarizationConfig::callhome(), // or dihard3(),custom() )?; let segments = sortformer.diarize(audio, 16000, 1)?; for seg in segments { println!("Speaker {} [{:.2}s - {:.2}s]", seg.speaker_id, seg.start as f64 / 16_000.0, seg.end as f64 / 16_000.0); } // For streaming/real-time use, diarize_chunk() preserves state across calls: let segments = sortformer.diarize_chunk(&audio_chunk_16k_mono)?; ``` -------------------------------- ### TimestampMode Enum and Usage Source: https://context7.com/altunenes/parakeet-rs/llms.txt Demonstrates the usage of the TimestampMode enum to control the granularity of transcription output, from individual tokens to full sentences. ```APIDOC ## `TimestampMode` — Token / Word / Sentence grouping Enum controlling how raw model output timestamps are post-processed. `Tokens` returns one `TimedToken` per BPE/SentencePiece token (most granular). `Words` merges subword tokens into words, handling SentencePiece `\u2581` boundaries, contractions, and hyphenated compounds. `Sentences` further groups words by `.`, `?`, and `!` into full sentences (requires punctuation-aware models: TDT, Nemotron, Unified). For CTC use `Words`; CTC outputs lowercase alphabet without punctuation. ```rust use parakeet_rs::{ParakeetTDT, Transcriber, TimestampMode}; let mut model = ParakeetTDT::from_pretrained("./tdt", None)?; // Token-level (raw BPE output) let r = model.transcribe_file("speech.wav", Some(TimestampMode::Tokens))?; for t in &r.tokens { println!("[{:.3}s] {{}}", t.start, t.text); } // Word-level let r = model.transcribe_file("speech.wav", Some(TimestampMode::Words))?; for w in &r.tokens { println!("[{:.2}s - {:.2}s] {{}}", w.start, w.end, w.text); } // Sentence-level (TDT predicts punctuation -> natural boundaries) let r = model.transcribe_file("speech.wav", Some(TimestampMode::Sentences))?; for s in &r.tokens { println!("[{:.2}s - {:.2}s] {{}}", s.start, s.end, s.text); } // Expected: // [0.00s - 3.12s] Hello, how are you today? // [3.12s - 6.45s] I'm doing well, thank you. # Ok::<(), Box>(()) ``` ``` -------------------------------- ### ParakeetEOU Source: https://context7.com/altunenes/parakeet-rs/llms.txt Streaming ASR with end-of-utterance detection. Lighter 120M-parameter streaming model with EOU token detection. Uses 160 ms chunks. Maintains a 4-second rolling audio buffer for mel context. `transcribe` returns incremental text; when `reset_on_eou = true` it appends " [EOU]" and soft-resets decoder state while preserving encoder context. ```APIDOC ## `ParakeetEOU` — Streaming ASR with end-of-utterance detection Lighter 120M-parameter streaming model with EOU (end-of-utterance) token detection. Uses 160 ms chunks (`chunk_size = 2560` samples). Maintains a 4-second rolling audio buffer for mel context. `transcribe` returns incremental text; when `reset_on_eou = true` it appends `" [EOU]"` and soft-resets decoder state while preserving encoder context. ```rust use parakeet_rs::ParakeetEOU; use std::io::Write; // Load: encoder.onnx, decoder_joint.onnx, tokenizer.json let mut model = ParakeetEOU::from_pretrained("./fullstr", None)?; let mut reader = hound::WavReader::open("speech.wav")?; let spec = reader.spec(); let audio: Vec = reader.samples::() .map(|s| s.map(|v| v as f32 / 32768.0)) .collect::>()?; const CHUNK: usize = 2560; // 160 ms let mut full_text = String::new(); for chunk in audio.chunks(CHUNK) { let mut buf = chunk.to_vec(); buf.resize(CHUNK, 0.0); // reset_on_eou = false keeps state flowing for continuous transcription let text = model.transcribe(&buf, false)?; if !text.is_empty() { print!("{}", text); std::io::stdout().flush()?; full_text.push_str(&text); } } // Flush with 3 silence chunks for _ in 0..3 { let text = model.transcribe(&vec![0.0f32; CHUNK], false)?; if !text.is_empty() { print!("{}", text); full_text.push_str(&text); } } println!("\nFull: {}", full_text.trim()); // --- Shared model for concurrent streams --- use parakeet_rs::ParakeetEOUHandle; let handle = ParakeetEOUHandle::load("./fullstr", None)?; let mut a = ParakeetEOU::from_shared(&handle); let mut b = ParakeetEOU::from_shared(&handle); # Ok::<(), Box>(()) ``` ``` -------------------------------- ### Streaming ASR with ParakeetEOU Source: https://context7.com/altunenes/parakeet-rs/llms.txt Utilize ParakeetEOU for streaming ASR with end-of-utterance detection. It maintains a rolling audio buffer and can append '[EOU]' and soft-reset the decoder state while preserving encoder context when `reset_on_eou` is true. ```rust use parakeet_rs::ParakeetEOU; use std::io::Write; // Load: encoder.onnx, decoder_joint.onnx, tokenizer.json let mut model = ParakeetEOU::from_pretrained("./fullstr", None)?; let mut reader = hound::WavReader::open("speech.wav")?; let spec = reader.spec(); let audio: Vec = reader.samples::() .map(|s| s.map(|v| v as f32 / 32768.0)) .collect::>()?; const CHUNK: usize = 2560; // 160 ms let mut full_text = String::new(); for chunk in audio.chunks(CHUNK) { let mut buf = chunk.to_vec(); buf.resize(CHUNK, 0.0); // reset_on_eou = false keeps state flowing for continuous transcription let text = model.transcribe(&buf, false)?; if !text.is_empty() { print!("{}", text); std::io::stdout().flush()?; full_text.push_str(&text); } } // Flush with 3 silence chunks for _ in 0..3 { let text = model.transcribe(&vec![0.0f32; CHUNK], false)?; if !text.is_empty() { print!("{}", text); full_text.push_str(&text); } } println!("\nFull: {}", full_text.trim()); // --- Shared model for concurrent streams --- use parakeet_rs::ParakeetEOUHandle; let handle = ParakeetEOUHandle::load("./fullstr", None)?; let mut a = ParakeetEOU::from_shared(&handle); let mut b = ParakeetEOU::from_shared(&handle); # Ok::<(), Box>(()) ```