Skip to main content

whisper_apr/
lib.rs

1//! # Whisper.apr
2//!
3//! WASM-first automatic speech recognition engine implementing OpenAI's Whisper architecture.
4//!
5//! ## Overview
6//!
7//! Whisper.apr is designed from inception for WASM deployment via `wasm32-unknown-unknown`,
8//! leveraging Rust's superior WASM toolchain for:
9//! - 30-40% smaller binary sizes through tree-shaking
10//! - Native WASM SIMD 128-bit intrinsics without Emscripten overhead
11//! - Zero-copy audio buffer handling via shared memory
12//!
13//! ## Quick Start
14//!
15//! ```rust,ignore
16//! use whisper_apr::{WhisperApr, TranscribeOptions};
17//!
18//! let whisper = WhisperApr::load("base.apr")?;
19//! let result = whisper.transcribe(&audio_samples, TranscribeOptions::default())?;
20//! println!("{}", result.text);
21//! ```
22//!
23//! ## Features
24//!
25//! - `std` (default): Standard library support
26//! - `wasm`: WASM bindings via wasm-bindgen
27//! - `simd`: SIMD acceleration via trueno
28//! - `tracing`: Performance tracing via renacer
29
30#![cfg_attr(not(feature = "std"), no_std)]
31#![warn(missing_docs)]
32#![deny(clippy::unwrap_used)]
33
34#[cfg(not(feature = "std"))]
35extern crate alloc;
36
37#[cfg(feature = "dhat-profiler")]
38#[doc(hidden)]
39pub use dhat;
40
41pub mod audio;
42pub mod detection;
43pub mod error;
44pub mod format;
45pub mod inference;
46pub mod memory;
47pub mod model;
48/// Unified parallelism abstraction for CLI and WASM (ยง11.3.2)
49pub mod parallel;
50pub mod progress;
51pub mod simd;
52pub mod timestamps;
53pub mod tokenizer;
54#[macro_use]
55pub mod trace;
56pub mod vad;
57
58/// Speaker diarization module (who spoke when)
59pub mod diarization;
60
61/// WebGPU compute backend for accelerated inference
62pub mod gpu;
63
64/// Backend abstraction and automatic selection
65pub mod backend;
66
67/// Vocabulary and hotword customization
68pub mod vocabulary;
69
70/// Activation probing for forward-pass debugging (WAPR-MOONSHINE-013)
71pub mod probe;
72
73/// HuggingFace Hub publishing (WAPR-PUB-001)
74pub mod publish;
75
76/// Pre-publish verification (WAPR-PUB-001)
77pub mod verify;
78
79/// Benchmark infrastructure for multi-backend comparison
80#[allow(clippy::all)]
81pub mod benchmark_generated;
82
83/// CUDA GPU acceleration via trueno-gpu/realizar
84#[cfg(feature = "realizar-gpu")]
85pub mod cuda;
86
87/// Re-exports world-class production inference primitives from realizar.
88///
89/// Provides: Flash Attention, Sliding Window Attention,
90/// FusedLayerNormLinear, KVCache, PagedKvCache,
91/// Q4_K, Q5_K, Q6_K quantization with fused ops.
92#[cfg(feature = "realizar-inference")]
93pub mod realizar_inference {
94    pub use realizar::layers::{
95        Attention, FeedForward, FusedLayerNormLinear, KVCache, LayerNorm, Linear,
96        MultiHeadAttention, SlidingWindowAttention,
97    };
98
99    pub use realizar::paged_kv::{PagedCacheError, PagedKvCache, SeqId};
100
101    pub use realizar::quantize::{
102        dequantize_q4_k, dequantize_q5_k, dequantize_q6_k, dequantize_q8_0, fused_q4k_dot_simd,
103        fused_q4k_parallel_matvec, fused_q5k_dot_simd, fused_q5k_parallel_matvec,
104        fused_q6k_dot_simd, fused_q6k_parallel_matvec, Q4_KBlock, Q5_KBlock, Q6_KBlock, Q8_0Block,
105    };
106
107    pub use realizar::tensor::Tensor;
108
109    // Speculative decoding (Points 66-80)
110    pub use realizar::speculative::{
111        SpeculativeConfig, SpeculativeError, SpeculativeModel, SpeculativeResult, SpeculativeStats,
112        TokenProb,
113    };
114
115    // GPU backend detection (Points 26-50)
116    #[cfg(feature = "realizar-gpu")]
117    pub use realizar::cuda::CudaExecutor;
118
119    /// Check if CUDA GPU is available at runtime
120    #[cfg(feature = "realizar-gpu")]
121    pub fn gpu_available() -> bool {
122        CudaExecutor::is_available()
123    }
124}
125
126#[cfg(feature = "wasm")]
127pub mod wasm;
128
129/// CLI module for native command-line interface
130#[cfg(feature = "cli")]
131pub mod cli;
132
133/// TUI module for pipeline visualization dashboard
134#[cfg(feature = "tui")]
135pub mod tui;
136
137pub use error::{WhisperError, WhisperResult};
138
139/// Core types and implementations
140#[allow(clippy::all)]
141mod core_generated;
142pub use core_generated::*;