#[repr(C)]pub struct Microphone { /* private fields */ }
Expand description
This class provides access to the hardware’s microphone, and stores it in a Sound stream. Start and Stop recording, and check the Sound property for the results! Remember to ensure your application has microphone permissions enabled! https://stereokit.net/Pages/StereoKit/Microphone.html
see also: Sound
/// ### Examples
use stereokit_rust::{maths::{Vec3, Matrix}, mesh::Mesh, material::Material,
sound::Sound, system::Microphone, util::named_colors};
let sphere = Mesh::generate_cube(Vec3::ONE * 0.5, None);
let material = Material::pbr().tex_file_copy("textures/micro.jpeg", true, None)
.expect("sound.jpeg should be there");
let mut position = Vec3::new( 0.0, 0.0, 0.5);
let transform = Matrix::t(position);
let micros = Microphone::get_devices();
if micros.len() > 0 {
let first_in_list = micros[0].clone();
if Microphone::start(Some(first_in_list)) {
assert!(Microphone::is_recording());
} else {
assert!(!Microphone::is_recording());
}
}
filename_scr = "screenshots/microphone.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
sphere.draw(token, &material, transform, Some(named_colors::LIGHT_BLUE.into()), None );
if iter == 1990 && Microphone::is_recording() {
let micro_sound = Microphone::sound().expect("Microphone should be recording");
let mut read_samples: Vec<f32> = vec![0.0; 48000];
let recorded_data = micro_sound.read_samples(read_samples.as_mut_slice(), None);
Microphone::stop();
//assert_ne!(recorded_data, 0);
}
);

Implementations§
Source§impl Microphone
impl Microphone
Sourcepub fn sound() -> Result<Sound, StereoKitError>
pub fn sound() -> Result<Sound, StereoKitError>
This is the sound stream of the Microphone when it is recording. This Asset is created the first time it is accessed via this property, or during Start, and will persist. It is re-used for the Microphone stream if you start/stop/switch devices. https://stereokit.net/Pages/StereoKit/Microphone/Sound.html
see also mic_get_stream
Sourcepub fn is_recording() -> bool
pub fn is_recording() -> bool
Is the microphone currently recording? https://stereokit.net/Pages/StereoKit/Microphone/IsRecording.html
see also mic_is_recording
Sourcepub fn get_devices() -> Vec<String>
pub fn get_devices() -> Vec<String>
Constructs a list of valid Microphone devices attached to the system. These names can be passed into Start to select a specific device to record from. It’s recommended to cache this list if you’re using it frequently, as this list is constructed each time you call it.
It’s good to note that a user might occasionally plug or unplug microphone devices from their system, so this list may occasionally change. https://stereokit.net/Pages/StereoKit/Microphone/GetDevices.html
see also mic_device_count
mic_device_name
Sourcepub fn start(device_name: Option<String>) -> bool
pub fn start(device_name: Option<String>) -> bool
This begins recording audio from the Microphone! Audio is stored in Microphone.Sound as a stream of audio. If the Microphone is already recording with a different device, it will stop the previous recording and start again with the new device.
If null is provided as the device, then they system’s default input device will be used. Some systems may not provide access to devices other than the system’s default. https://stereokit.net/Pages/StereoKit/Microphone/Start.html
device_name
- The name of the microphone device to use, as seen in the GetDevices list. None will use the system’s default device preference.
Sourcepub fn stop()
pub fn stop()
Stops recording audio from the microphone. https://stereokit.net/Pages/StereoKit/Microphone/Stop.html
see also mic_stop
Trait Implementations§
Source§impl Debug for Microphone
impl Debug for Microphone
Source§impl PartialEq for Microphone
impl PartialEq for Microphone
impl StructuralPartialEq for Microphone
Auto Trait Implementations§
impl Freeze for Microphone
impl RefUnwindSafe for Microphone
impl Send for Microphone
impl Sync for Microphone
impl Unpin for Microphone
impl UnwindSafe for Microphone
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.