Skip to main content

rightkit_asr/
lib.rs

1//! # rightkit-asr
2//!
3//! Rust bindings for NVIDIA's Parakeet speech recognition model using ONNX Runtime.
4//!
5//! Parakeet is a state-of-the-art automatic speech recognition (ASR) model developed by NVIDIA,
6//! based on the FastConformer-TDT architecture with 600 million parameters.
7//!
8//! ## Features
9//!
10//! - Easy-to-use API for speech-to-text transcription
11//! - Support for ONNX format models
12//! - 16kHz mono audio input
13//! - Punctuation and capitalization included in output
14//! - Fast inference using ONNX Runtime
15//!
16//! ## Quick Start
17//!
18//! ```no_run
19//! # #[cfg(feature = "whisper-tokenizers")]
20//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
21//! use rightkit_asr::{Parakeet, Transcriber, TimestampMode};
22//! # let audio = vec![0.0_f32; 16_000];
23//! # let sample_rate = 16_000;
24//! # let channels = 1;
25//!
26//! // Load the model
27//! let mut parakeet = Parakeet::from_pretrained(".", None)?;
28//!
29//! // Transcribe audio samples (see examples/raw.rs for audio loading)
30//! let result = parakeet.transcribe_samples(audio, sample_rate, channels, Some(TimestampMode::Words))?;
31//! println!("Transcription: {}", result.text);
32//! # Ok(())
33//! # }
34//! ```
35//!
36//! ## Model Requirements
37//!
38//! Your model directory should contain:
39//! - `model.onnx` - The ONNX model file
40//! - `model.onnx_data` - External model weights
41//! - `config.json` - Model configuration
42//! - `preprocessor_config.json` - Audio preprocessing configuration
43//! - `tokenizer.json` - Tokenizer vocabulary
44//! - `tokenizer_config.json` - Tokenizer configuration
45//!
46//! ## Audio Requirements
47//!
48//! - Format: WAV
49//! - Sample Rate: 16kHz
50//! - Channels: Mono (stereo will be converted automatically)
51//! - Bit Depth: 16-bit PCM or 32-bit float
52
53mod audio;
54mod config;
55mod decoder;
56mod decoder_tdt;
57mod error;
58mod execution;
59pub mod kws;
60mod model;
61mod model_eou;
62mod model_nemotron;
63mod model_tdt;
64mod model_transducer;
65mod onnx_beam;
66mod model_unified;
67mod nemotron;
68pub mod platform;
69// HF tokenizer users (CTC, EOU, Cohere, Whisper CoreML) are gated behind the
70// `whisper-tokenizers` feature so the Parakeet CoreML / ONNX TDT paths build
71// without the tokenizers C dependency.
72#[cfg(feature = "whisper-tokenizers")]
73mod decoder_ctc;
74#[cfg(feature = "whisper-tokenizers")]
75mod parakeet;
76#[cfg(feature = "whisper-tokenizers")]
77mod parakeet_eou;
78mod parakeet_tdt;
79mod parakeet_unified;
80mod transducer;
81#[cfg(feature = "sortformer")]
82pub mod sortformer;
83#[cfg(feature = "multitalker")]
84mod model_multitalker;
85#[cfg(feature = "multitalker")]
86pub mod multitalker;
87#[cfg(feature = "cohere")]
88mod model_cohere;
89#[cfg(feature = "cohere")]
90pub mod cohere;
91mod timestamps;
92mod transcriber;
93mod vocab;
94pub mod whisper;
95pub mod routing;
96pub mod chunked;
97pub mod conditioning;
98pub mod parakeet_core;
99#[cfg(feature = "onnx-tdt")]
100pub mod onnx_tdt;
101pub mod longform;
102#[cfg(target_os = "macos")]
103pub mod parakeet_coreml;
104
105pub use error::{Error, Result, UNSUPPORTED_PREFIX};
106pub use platform::EngineSupport;
107pub use execution::{ExecutionProvider, ModelConfig as ExecutionConfig};
108#[cfg(feature = "whisper-tokenizers")]
109pub use parakeet::Parakeet;
110pub use parakeet_tdt::ParakeetTDT;
111pub use transducer::{BeamOptions, StrictLayout, Transducer, TransducerOptions};
112pub use timestamps::{process_timestamps, TimestampMode};
113pub use transcriber::*;
114pub use whisper::{
115    audio_duration, is_unspaced_language, is_whisper_language, join_segment_text, load_wav_mono_16k,
116    recording_deadline, samples_to_ms, validate_language, CancelToken, DecodeMode, DecodeQuality,
117    InterruptReason, Language, LanguageDetection, ProgressCallback, ProgressProbe, Whisper,
118    WhisperCpp, WhisperInterrupted, WhisperModel, WhisperOptions, WhisperProgress, WhisperSegment,
119    WhisperTranscript, WhisperWord, RECORDING_DEADLINE_AUDIO_FACTOR, RECORDING_DEADLINE_BASE,
120    UNSPACED_LANGUAGES, WHISPER_LANGUAGES, WHISPER_SAMPLE_RATE,
121};
122pub use audio::{load_audio, load_wav_mono_16k_head, AudioSource, WavLoadError};
123pub use hound::WavSpec;
124#[cfg(target_os = "macos")]
125pub use whisper::ComputeUnits;
126#[cfg(all(target_os = "macos", feature = "whisper-tokenizers"))]
127pub use whisper::WhisperCoreMl;
128pub use routing::{select_engine, Availability, EngineKind, EngineSelection, RoutingPolicy};
129pub use chunked::{transcribe_spans, ChunkResult};
130#[cfg(target_os = "macos")]
131pub use parakeet_coreml::{CoreMlParakeet, CoreMlParakeetOptions, LongFormTranscript, PipelineMeta};
132pub use longform::{
133    pad_terminal_silence, samples_to_secs, LongFormOptions, LongFormProgress, PadPolicy, SeamPolicy,
134    TimedExports, TimedWord,
135};
136
137pub use config::{ModelConfig as ModelConfigJson, PreprocessorConfig};
138
139pub use decoder::{LanguageSource, LanguageTranscription, ReportedLanguage, TimedPiece, TimedToken, TranscriptionResult};
140pub use decoder_tdt::LAST_TOKEN_MIN_DURATION_MS;
141#[cfg(feature = "whisper-tokenizers")]
142pub use decoder_ctc::ParakeetDecoder;
143pub use model::ParakeetModel;
144pub use model_eou::ParakeetEOUModel;
145pub use model_nemotron::{NemotronEncoderCache, NemotronModel, NemotronModelConfig};
146pub use model_unified::{ParakeetUnifiedModel, UnifiedModelConfig};
147pub use nemotron::{Nemotron, NemotronHandle, SentencePieceVocab};
148#[cfg(feature = "whisper-tokenizers")]
149pub use parakeet_eou::{ParakeetEOU, ParakeetEOUHandle};
150pub use parakeet_unified::{ParakeetUnified, ParakeetUnifiedHandle, UnifiedStreamingConfig};
151
152#[cfg(feature = "multitalker")]
153pub use multitalker::{LatencyMode, MultitalkerASR, MultitalkerConfig, SpeakerTranscript, WordTimestamp};
154
155#[cfg(feature = "cohere")]
156pub use cohere::CohereASR;