diff --git a/src/talk/cmdline.rs b/src/talk/cmdline.rs index 807d677..bd16704 100644 --- a/src/talk/cmdline.rs +++ b/src/talk/cmdline.rs @@ -17,10 +17,18 @@ pub struct Opt { /// The path to the audio file. #[structopt(short, long, parse(from_os_str), conflicts_with = "microphone")] pub file_path: Option, - /// Use the microphone as the source. Which microphone depends + /// Use the microphone as the source. Defaults to autoaudiosrc - Which microphone depends /// on [gstraemer](https://gstreamer.freedesktop.org/documentation/autodetect/autoaudiosrc.html?gi-language=c#autoaudiosrc-page) #[structopt(short, long, conflicts_with = "file_path")] pub microphone: bool, + /// Use a specific microphone like "alsasrc device=hw:1" + #[structopt( + short, + long, + default_value = "autoaudiosrc", + conflicts_with = "file_path" + )] + pub input_src: String, /// Use to change the volume of the input #[structopt(short, long, default_value = "1.0")] pub volume: f32, diff --git a/src/talk/gst.rs b/src/talk/gst.rs index a469295..b0e44b7 100644 --- a/src/talk/gst.rs +++ b/src/talk/gst.rs @@ -8,27 +8,13 @@ use std::sync::mpsc::{sync_channel, Receiver, SyncSender}; use super::errors::Error; use byte_slice_cast::*; -pub(super) fn file_input( - filename: &str, +pub(super) fn from_input( + input_src: &str, volume: f32, block_align: u16, sample_rate: u16, ) -> Result>, Error> { - let pipeline = create_pipeline( - &format!("filesrc location={}", filename), - volume, - block_align, - sample_rate, - )?; - input(pipeline) -} - -pub(super) fn mic_input( - volume: f32, - block_align: u16, - sample_rate: u16, -) -> Result>, Error> { - let pipeline = create_pipeline("autoaudiosrc", volume, block_align, sample_rate)?; + let pipeline = create_pipeline(input_src, volume, block_align, sample_rate)?; input(pipeline) } diff --git a/src/talk/mod.rs b/src/talk/mod.rs index ef1131e..c99461b 100644 --- a/src/talk/mod.rs +++ b/src/talk/mod.rs @@ -79,13 +79,18 @@ pub fn main(opt: Opt) -> Result<(), Error> { } let rx = match (&opt.file_path, &opt.microphone) { - (Some(path), false) => gst::file_input( - path.to_str().expect("File path not UTF8 complient"), + (Some(path), false) => gst::from_input( + &format!( + "filesrc location={}", + path.to_str().expect("File path not UTF8 complient") + ), opt.volume, block_size, sample_rate, )?, - (None, true) => gst::mic_input(opt.volume, block_size, sample_rate)?, + (None, true) => { + gst::from_input(&opt.input_src, opt.volume, block_size, sample_rate)? + } _ => unreachable!(), };