Merge branch 'talk'

This commit is contained in:
QuantumEntangledAndy committed 2021-08-07 16:13:04 +07:00
commit cc4e0dadbd
3 files changed
+20 -21

No files matched your search

+9 -1
View File
@@ -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<PathBuf>,
/// 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,
+3 -17
View File
@@ -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<Receiver<Vec<u8>>, 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<Receiver<Vec<u8>>, Error> {
let pipeline = create_pipeline("autoaudiosrc", volume, block_align, sample_rate)?;
let pipeline = create_pipeline(input_src, volume, block_align, sample_rate)?;
input(pipeline)
}
+8 -3
View File
@@ -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!(),
};