Skip to content

Commit

Permalink
Add clap flag translate (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: Miguel Piedrafita <[email protected]>
  • Loading branch information
jmfrank63 and m1guelpf authored Jan 24, 2023
1 parent 417e03f commit dd706bf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 84 deletions.
118 changes: 37 additions & 81 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ struct Args {

/// Path to the audio file to transcribe
audio: String,

/// Toggle translation
#[clap(short, long, default_value = "false")]
translate: bool,
}

#[tokio::main]
Expand All @@ -46,7 +50,7 @@ async fn main() {
);

let mut whisper = Whisper::new(Model::new(args.model), args.lang).await;
let transcript = whisper.transcribe(audio).unwrap();
let transcript = whisper.transcribe(audio, args.translate).unwrap();

write_to(
audio.with_file_name(format!("{file_name}.txt")),
Expand Down
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use futures_util::StreamExt;
use indicatif::{ProgressBar, ProgressStyle};
use num::integer::div_floor;
Expand Down
4 changes: 2 additions & 2 deletions src/whisper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ impl Whisper {
}
}

pub fn transcribe<P: AsRef<Path>>(&mut self, audio: P) -> Result<Transcript> {
pub fn transcribe<P: AsRef<Path>>(&mut self, audio: P, translate: bool) -> Result<Transcript> {
let mut params = FullParams::new(SamplingStrategy::Greedy { n_past: 0 });
params.set_translate(true);
params.set_translate(translate);
params.set_print_special(false);
params.set_print_progress(false);
params.set_print_realtime(false);
Expand Down

0 comments on commit dd706bf

Please sign in to comment.