-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use Ruspotter v2 * Use cpal for audio recording
- Loading branch information
Showing
13 changed files
with
1,343 additions
and
806 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
[package] | ||
name = "rustpotter-cli" | ||
version = "1.0.1" | ||
version = "2.0.0" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
description = "CLI for Rustpotter, an open source wake word spotter forged in rust." | ||
description = "CLI for Rustpotter, an open source wakeword spotter forged in rust." | ||
authors = ["Miguel Álvarez Díez <[email protected]>"] | ||
repository = "https://github.com/GiviMAD/rustpotter" | ||
|
||
exclude = ["tools/**",".github",".gitignore"] | ||
[dependencies] | ||
rustpotter = { version = "1.0.1", features = ["files", "build", "log", "vad"] } | ||
log = "0.4.6" | ||
pv_recorder = "1.0.2" | ||
rustpotter = { version = "2.0.0" } | ||
ctrlc = "3.2.2" | ||
clap = { version = "3.1.13", features = ["derive"] } | ||
clap = { version = "4.1.6", features = ["derive"] } | ||
hound = "3.4.0" | ||
include_dir = "0.7.2" | ||
tempfile = "3.3.0" | ||
simple_logger = "2.1.0" | ||
|
||
[features] | ||
default = [] | ||
# include recorder library into the binary for distribution outside cargo | ||
dist = [] | ||
cpal = "0.15.0" | ||
time = "0.3.20" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,49 @@ | ||
extern crate cpal; | ||
use clap::Args; | ||
use pv_recorder::RecorderBuilder; | ||
#[cfg(feature = "dist")] | ||
use crate::pv_recorder_utils::_get_pv_recorder_lib; | ||
#[derive(Args, Debug)] | ||
use cpal::traits::{DeviceTrait, HostTrait}; | ||
/// Record audio sample | ||
#[derive(Args, Debug)] | ||
#[clap()] | ||
pub struct DevicesCommand {} | ||
pub fn devices(_: DevicesCommand) -> Result<(), String> { | ||
#[cfg(feature = "dist")] | ||
let mut recorder_builder = RecorderBuilder::new(); | ||
#[cfg(not(feature = "dist"))] | ||
let recorder_builder = RecorderBuilder::new(); | ||
#[cfg(feature = "dist")] | ||
let lib_temp_path = _get_pv_recorder_lib(); | ||
#[cfg(feature = "dist")] | ||
recorder_builder.library_path(lib_temp_path.to_path_buf().as_path()); | ||
let recorder = recorder_builder.init() | ||
.expect("Failed to initialize recorder"); | ||
println!("Available record audio devices:"); | ||
let audio_devices = recorder.get_audio_devices(); | ||
match audio_devices { | ||
Ok(audio_devices) => { | ||
for (idx, device) in audio_devices.iter().enumerate() { | ||
println!("{}: {:?}", idx, device); | ||
println!("Supported hosts:\n {:?}", cpal::ALL_HOSTS); | ||
let default_host = cpal::default_host(); | ||
let host_id = default_host.id(); | ||
println!("Using hosts:\n {:?}", default_host.id()); | ||
println!("{}", host_id.name()); | ||
let host = cpal::host_from_id(host_id).map_err(|err| err.to_string())?; | ||
let default_in = host.default_input_device().map(|e| e.name().unwrap()); | ||
if let Some(def_in) = default_in { | ||
println!(" Default input device:\n {}", def_in); | ||
} else { | ||
println!(" No default input device"); | ||
} | ||
let devices = host.input_devices().map_err(|err| err.to_string())?; | ||
println!(" Devices: "); | ||
for (device_index, device) in devices.enumerate() { | ||
println!( | ||
" {} - \"{}\"", | ||
device_index, | ||
device.name().map_err(|err| err.to_string())? | ||
); | ||
|
||
// Input configs | ||
if let Ok(conf) = device.default_input_config() { | ||
println!(" Default input stream config:\n {:?}", conf); | ||
} | ||
let input_configs = match device.supported_input_configs() { | ||
Ok(f) => f.collect(), | ||
Err(e) => { | ||
println!(" Error getting supported input configs: {:?}", e); | ||
Vec::new() | ||
} | ||
}; | ||
if !input_configs.is_empty() { | ||
println!(" All supported input stream configs:"); | ||
for (config_index, config) in input_configs.into_iter().enumerate() { | ||
println!(" {} - {:?}", config_index, config); | ||
} | ||
} | ||
Err(err) => panic!("Failed to get audio devices: {}", err), | ||
}; | ||
#[cfg(all(feature = "dist", not(target_os = "windows")))] | ||
lib_temp_path.close().expect("Unable to remove temp file"); | ||
} | ||
Ok(()) | ||
} |
Oops, something went wrong.