Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
efugier committed May 15, 2024
1 parent 3f19fe4 commit ecf8920
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/voice/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use device_query::{DeviceQuery, DeviceState, Keycode};
use std::process::{Child, Command};
use std::thread;
use std::time::Duration;

fn start_recording() -> Option<Child> {
if cfg!(target_os = "windows") {
Command::new("cmd")
.args(&["/C", "start", "rec", "output.wav"])
.spawn()
.ok()
} else if cfg!(target_os = "macos") {
Command::new("sh")
.arg("-c")
.arg("sox -d output.wav")
.spawn()
.ok()
} else {
Command::new("arecord").arg("output.wav").spawn().ok()
}
}

fn stop_recording(process: &mut Child) {
process.kill().expect("Failed to stop recording");
}

fn main() {
println!("Press any key. Press space to exit.");

let device_state = DeviceState::new();
let mut recording_process = start_recording().expect("Failed to start recording.");

loop {
let keys: Vec<Keycode> = device_state.get_keys();

if keys.contains(&Keycode::Space) {
stop_recording(&mut recording_process);
println!("Recording stopped.");
break;
}

thread::sleep(Duration::from_millis(100));
}

println!("Exiting program.");
}

0 comments on commit ecf8920

Please sign in to comment.