pub struct AudioMicrophone { /* private fields */ }Expand description
Rust wrapper for Android microphone service
Implementations§
Source§impl AudioMicrophone
impl AudioMicrophone
Sourcepub fn new(
env: JNIEnv<'_>,
context: &GlobalRef,
sample_rate: i32,
channel_config: i32,
audio_format: i32,
) -> Result<Self, MicError>
pub fn new( env: JNIEnv<'_>, context: &GlobalRef, sample_rate: i32, channel_config: i32, audio_format: i32, ) -> Result<Self, MicError>
Create a new AudioMicrophone instance
§Arguments
env- JNI environmentcontext- GlobalRef to context object (used to get the correct ClassLoader)sample_rate- Sample rate (e.g., 16000, 44100, 48000)channel_config- Channel configuration (use ChannelInConfig constants)audio_format- Audio encoding format (use AudioEncoding constants)
§Returns
Returns initialized AudioMicrophone instance
§Examples
See the README.md for complete usage examples.
Sourcepub async fn read(&self, duration_ms: i32) -> Result<Vec<u8>, MicError>
pub async fn read(&self, duration_ms: i32) -> Result<Vec<u8>, MicError>
Read audio data asynchronously
§Arguments
duration_ms- Duration of audio to read in milliseconds
§Returns
Result<Vec<u8>, MicError>- Audio data (raw PCM data)
§Buffer Design
To prevent stuttering, the internal buffer size is automatically calculated as 2x the requested duration. For example, if you want to read 1 second (1000ms) of data, the internal buffer will prepare at least 2 seconds of data.
§Examples
See README.md for complete usage examples.
Sourcepub fn get_sample_rate(&self) -> i32
pub fn get_sample_rate(&self) -> i32
Get sample rate
Sourcepub fn get_channel_count(&self) -> i32
pub fn get_channel_count(&self) -> i32
Get channel count
Sourcepub fn get_audio_format(&self) -> i32
pub fn get_audio_format(&self) -> i32
Get audio format
Sourcepub fn get_buffer_size(&self) -> Result<i32, MicError>
pub fn get_buffer_size(&self) -> Result<i32, MicError>
Get buffer size
Sourcepub fn calculate_bytes_for_duration(&self, duration_ms: i32) -> i32
pub fn calculate_bytes_for_duration(&self, duration_ms: i32) -> i32
Calculate number of bytes for a specified duration
Trait Implementations§
Source§impl Drop for AudioMicrophone
impl Drop for AudioMicrophone
impl Send for AudioMicrophone
impl Sync for AudioMicrophone
Auto Trait Implementations§
impl Freeze for AudioMicrophone
impl RefUnwindSafe for AudioMicrophone
impl Unpin for AudioMicrophone
impl UnwindSafe for AudioMicrophone
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