AudioDevice

Struct AudioDevice 

Source
pub struct AudioDevice { /* private fields */ }
Expand description

Audio device like microphone It will automatically stop recording and will be destroyed

Implementations§

Source§

impl AudioDevice

Source

pub fn default() -> Result<AudioDevice>

Open default audio device(microphone) with SPS(samples per second) = 16000

Source

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);
}
Source

pub fn with_name_and_sps( name: &str, samples_per_second: usize, ) -> Result<AudioDevice>

Open specified audio device with given SPS

Source

pub fn start_recording(&mut self) -> Result<()>

Start recording

Source

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()?;
Source

pub fn read<'a>(&self, buffer: &'a mut [i16]) -> Result<Option<&'a [i16]>>

Read sound to buffer, and return slide of read samples(length of slice may be not equal to buffer length). Return None if nothing to read

Trait Implementations§

Source§

impl Drop for AudioDevice

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.