pub struct AudioDevice { /* private fields */ }Expand description
Audio device like microphone It will automatically stop recording and will be destroyed
Implementations§
Source§impl AudioDevice
impl AudioDevice
Sourcepub fn default() -> Result<AudioDevice>
pub fn default() -> Result<AudioDevice>
Open default audio device(microphone) with SPS(samples per second) = 16000
Sourcepub fn default_with_sps(samples_per_second: usize) -> Result<AudioDevice>
pub fn default_with_sps(samples_per_second: usize) -> Result<AudioDevice>
Open default audio device(microphone) with given SPS
§Example
use std::thread;
let mut device=AudioDevice::default_with_sps(44100)?;
device.start_recording()?;
loop{ //recording loop
match device.read(&mut buffer[..])? {
Some( buffer ) => {
for i in 0..buffer.len() {
...
}
},
None => break,
}
thread::sleep_ms(100);
}Sourcepub fn with_name_and_sps(
name: &str,
samples_per_second: usize,
) -> Result<AudioDevice>
pub fn with_name_and_sps( name: &str, samples_per_second: usize, ) -> Result<AudioDevice>
Open specified audio device with given SPS
Sourcepub fn start_recording(&mut self) -> Result<()>
pub fn start_recording(&mut self) -> Result<()>
Start recording
Sourcepub fn stop_recording(&mut self) -> Result<()>
pub fn stop_recording(&mut self) -> Result<()>
Stop recording
§Example
let mut device=AudioDevice::default_with_sps(44100)?;
device.start_recording()?;
loop{ //recording loop
...
}
device.stop_recording()?;
thread::sleep_ms(1000);
device.start_recording()?;
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AudioDevice
impl RefUnwindSafe for AudioDevice
impl !Send for AudioDevice
impl !Sync for AudioDevice
impl Unpin for AudioDevice
impl UnwindSafe for AudioDevice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more