This repository has been archived by the owner on Jul 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
transcribe.rs
57 lines (55 loc) · 1.85 KB
/
transcribe.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::{env::set_var, path::Path};
fn main() -> Result<(), anyhow::Error> {
let scorer_file;
let (model_path, scorer_path) = initialise_app();
let mut model = ds_transcriber::model::instance_model(
model_path.as_ref(),
match scorer_path {
Some(scorer) => {
scorer_file = scorer;
Some(scorer_file.as_ref())
}
None => None,
},
)?;
let i_said = ds_transcriber::transcribe(ds_transcriber::StreamSettings::default(), &mut model)?;
println!("I said: {}", i_said);
Ok(())
}
fn initialise_app() -> (impl AsRef<Path>, Option<impl AsRef<Path>>) {
let m = clap::command!()
.arg(
clap::Arg::new("model_path")
.takes_value(true)
.short('m')
.long("model")
.help("Path to your DeepSpeech [.pb/.pbmm] model"),
)
.arg(
clap::Arg::new("scorer_path")
.takes_value(true)
.short('s')
.long("scorer")
.help("An optional path pointing to your DeepSpeech [.scorer] scorer"),
)
.arg(
clap::Arg::new("native_client")
.takes_value(true)
.short('c')
.long("client")
.help("Path to the DeepSpeech [native_client]"),
)
.get_matches();
let model_path = match m.value_of("model_path") {
Some(val) => val,
None => panic!("no model specified"),
};
let scorer_path = m.value_of("scorer_path").map(String::from);
let native_client = match m.value_of("native_client") {
Some(val) => val,
None => panic!("no native client specified"),
};
set_var("LD_LIBRARY_PATH", native_client);
set_var("LIBRARY_PATH", native_client);
(model_path.to_owned(), scorer_path)
}