forked from thewh1teagle/sherpa-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhisper.rs
38 lines (32 loc) · 1.43 KB
/
whisper.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Transcribe wav file using OpenAI Whisper
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-whisper-tiny.tar.bz2
tar xvf sherpa-onnx-whisper-tiny.tar.bz2
wget https://github.com/thewh1teagle/sherpa-rs/releases/download/v0.1.0/motivation.wav -O motivation.wav
cargo run --example whisper motivation.wav
*/
use sherpa_rs::{
read_audio_file,
whisper::{WhisperConfig, WhisperRecognizer},
};
fn main() {
let path = std::env::args().nth(1).expect("Missing file path argument");
let provider = std::env::args().nth(2).unwrap_or("cpu".into());
let (samples, sample_rate) = read_audio_file(&path).unwrap();
assert_eq!(sample_rate, 16000, "The sample rate must be 16000.");
let config = WhisperConfig {
decoder: "sherpa-onnx-whisper-tiny/tiny-decoder.onnx".into(),
encoder: "sherpa-onnx-whisper-tiny/tiny-encoder.onnx".into(),
tokens: "sherpa-onnx-whisper-tiny/tiny-tokens.txt".into(),
language: "en".into(),
provider: Some(provider),
num_threads: None,
bpe_vocab: None,
..Default::default() // fill in any missing fields with defaults
};
let mut recognizer = WhisperRecognizer::new(config).unwrap();
let start_t = std::time::Instant::now();
let result = recognizer.transcribe(sample_rate, &samples);
println!("✅ Text: {}", result.text);
println!("⏱️ Time taken for transcription: {:?}", start_t.elapsed());
}