Skip to content

Commit

Permalink
perf: improve logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ckaznable committed May 25, 2023
1 parent f5521fc commit 926596f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ clap = { version = "4.2.7", features = ["derive"] }
ringbuf = "0.3.3"
tract-onnx = "0.17.9"
rubato = "0.12.0"
owo-colors = "3.5.0"

[profile.release]
opt-level = 'z' # Optimize for size
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use audio::{resample_to_16k, YOUTUBE_TS_SAMPLE_RATE};
use clap::Parser;
use owo_colors::OwoColorize;
use ringbuf::{Consumer, HeapRb, LocalRb, Producer, Rb, SharedRb};
use speech::{SpeechConfig, WhisperPayload};
use std::{
Expand Down Expand Up @@ -241,7 +242,7 @@ fn evoke_whisper_thread(
speech::process(&mut state, &mut payload, &mut |segment, start| {
println!(
"[{}] {}",
util::format_timestamp_to_time(segment_time + start),
util::format_timestamp_to_time(segment_time + start).bright_yellow(),
segment
);
});
Expand Down
6 changes: 4 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use owo_colors::OwoColorize;

#[derive(Clone, Default)]
pub struct Log {
enable: bool,
Expand All @@ -10,13 +12,13 @@ impl Log {

pub fn verbose<S: AsRef<str>>(&self, msg: S) {
if self.enable {
println!("[verbose] {}", msg.as_ref());
println!("{} {}", "[verbose]".green(), msg.as_ref().green());
}
}

pub fn error<S: AsRef<str>>(&self, msg: S) {
if self.enable {
println!("[error] {}", msg.as_ref());
println!("{} {}", "[error]".red(), msg.as_ref().red().bold());
}
}
}
Expand Down

0 comments on commit 926596f

Please sign in to comment.