from env to flags

master v0.1.0
Bel LaPointe 2023-11-28 22:31:16 -07:00
parent 72a1420638
commit 1dd631872c
3 changed files with 138 additions and 19 deletions

View File

@ -63,6 +63,54 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "anstream"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
[[package]]
name = "anstyle-parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -213,6 +261,46 @@ dependencies = [
"libloading", "libloading",
] ]
[[package]]
name = "clap"
version = "4.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.39",
]
[[package]]
name = "clap_lex"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]] [[package]]
name = "cmake" name = "cmake"
version = "0.1.50" version = "0.1.50"
@ -222,6 +310,12 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]] [[package]]
name = "combine" name = "combine"
version = "4.6.6" version = "4.6.6"
@ -335,6 +429,12 @@ version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "home" name = "home"
version = "0.5.5" version = "0.5.5"
@ -773,6 +873,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"chrono", "chrono",
"clap",
"cpal", "cpal",
"signal-hook", "signal-hook",
"tokio", "tokio",
@ -851,6 +952,12 @@ version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.109" version = "1.0.109"
@ -926,6 +1033,12 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "walkdir" name = "walkdir"
version = "2.4.0" version = "2.4.0"

View File

@ -13,3 +13,4 @@ cpal = "0.15.2"
signal-hook = "0.3.17" signal-hook = "0.3.17"
byteorder = "1.5.0" byteorder = "1.5.0"
chrono = "0.4.31" chrono = "0.4.31"
clap = { version = "4.4.10", features = ["derive"] }

View File

@ -3,27 +3,32 @@ use cpal::traits::{HostTrait, DeviceTrait, StreamTrait};
use signal_hook::{iterator::Signals, consts::signal::SIGINT}; use signal_hook::{iterator::Signals, consts::signal::SIGINT};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use chrono; use chrono;
use clap::Parser;
#[derive(Parser, Debug)]
struct Flags {
#[arg(long, default_value = "../models/ggml-tiny.en.bin")]
model: String,
#[arg(long, default_value = "8")]
threads: i32,
#[arg(long, default_value = "0.8")]
stream_churn: f32,
#[arg(long, default_value = "5")]
stream_step: u64,
wav: Option<String>,
}
fn main() { fn main() {
let w = new_whisper( let flags = Flags::parse();
std::env::var("MODEL")
.unwrap_or(String::from("../models/ggml-tiny.en.bin")),
std::env::var("P")
.unwrap_or(String::from("8"))
.parse::<i32>().expect("$P must be a number"),
).unwrap();
let stream_churn = std::env::var("STREAM_CHURN")
.unwrap_or(String::from("0.8"))
.parse::<f32>().expect("$STREAM_CHURN must be a number");
let stream_step = Duration::new(
std::env::var("STREAM_STEP")
.unwrap_or(String::from("5"))
.parse::<u64>().expect("$STREAM_STEP must be a number"),
0,
);
match std::env::var("WAV") { let w = new_whisper(flags.model, flags.threads).unwrap();
Ok(wav) => { let stream_churn = flags.stream_churn;
let stream_step = Duration::new(flags.stream_step, 0);
match flags.wav {
Some(wav) => {
let (header, data) = wav::read( let (header, data) = wav::read(
&mut std::fs::File::open(wav).expect("failed to open $WAV"), &mut std::fs::File::open(wav).expect("failed to open $WAV"),
).expect("failed to decode $WAV"); ).expect("failed to decode $WAV");
@ -35,7 +40,7 @@ fn main() {
let result = w.transcribe(&audio_data).unwrap(); let result = w.transcribe(&audio_data).unwrap();
println!("{}", result); println!("{}", result);
}, },
Err(_) => { None => {
let host = cpal::default_host(); let host = cpal::default_host();
let device = host.default_input_device().unwrap(); let device = host.default_input_device().unwrap();
let cfg = device.supported_input_configs() let cfg = device.supported_input_configs()