Skip to content

Commit

Permalink
refactor!
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Oct 19, 2024
1 parent 4b4d347 commit e10c6d0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/vad_whisper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use sherpa_rs::{
fn main() -> Result<()> {
// Read audio data from the file
let path = std::env::args().nth(1).expect("Missing file path argument");
let (sample_rate, mut samples) = read_audio_file(&path)?;
let (mut samples, sample_rate) = read_audio_file(&path)?;

// Pad with 3 seconds of slience so vad will able to detect stop
for _ in 0..3 * sample_rate {
Expand Down
2 changes: 1 addition & 1 deletion examples/whisper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::time::Instant;
fn main() -> Result<()> {
let path = std::env::args().nth(1).expect("Missing file path argument");
let provider = std::env::args().nth(2).unwrap_or("cpu".into());
let (sample_rate, samples) = read_audio_file(&path)?;
let (samples, sample_rate) = read_audio_file(&path)?;

// Check if the sample rate is 16000
if sample_rate != 16000 {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn get_default_provider() -> String {
.into()
}

pub fn read_audio_file(path: &str) -> Result<(u32, Vec<f32>)> {
pub fn read_audio_file(path: &str) -> Result<(Vec<f32>, u32)> {
let mut reader = hound::WavReader::open(path)?;
let sample_rate = reader.spec().sample_rate;

Expand All @@ -42,5 +42,5 @@ pub fn read_audio_file(path: &str) -> Result<(u32, Vec<f32>)> {
.map(|s| s.unwrap() as f32 / i16::MAX as f32)
.collect();

Ok((sample_rate, samples))
Ok((samples, sample_rate))
}
2 changes: 1 addition & 1 deletion src/whisper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ mod tests {
#[test]
fn test_whisper_transcribe() {
let path = "motivation.wav";
let (sample_rate, samples) = read_audio_file(&path).expect("file not found");
let (samples, sample_rate) = read_audio_file(&path).unwrap();

// Check if the sample rate is 16000
if sample_rate != 16000 {
Expand Down

0 comments on commit e10c6d0

Please sign in to comment.