Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/microphone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,19 @@ impl fmt::Display for Input {
}

/// Returns a list of available input devices on the system.
///
/// Note: this hides the 'null' device which generates zeros.
pub fn available_inputs() -> Result<Vec<Input>, ListError> {
let host = cpal::default_host();
let devices = host
Ok(cpal::default_host()
.input_devices()
.map_err(ListError)?
.map(|dev| Input { inner: dev });
Ok(devices.collect())
.filter(|dev| {
dev.description()
.map(|descr| descr.driver().is_none_or(|driver| driver != "null"))
.unwrap_or(false)
})
.map(|dev| Input { inner: dev })
.collect::<Vec<_>>())
}

/// A microphone input stream that can be used as `Source`.
Expand Down
7 changes: 6 additions & 1 deletion src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl DeviceSinkBuilder {
Self::from_default_device()
.and_then(|x| x.open_stream())
.or_else(|original_err| {
let mut devices = match cpal::default_host().output_devices() {
let devices = match cpal::default_host().output_devices() {
Ok(devices) => devices,
Err(err) => {
#[cfg(feature = "tracing")]
Expand All @@ -245,6 +245,11 @@ impl DeviceSinkBuilder {
}
};
devices
.filter(|dev| {
dev.description()
.map(|desc| desc.driver().is_some_and(|driver| driver != "null"))
.unwrap_or(false)
})
.find_map(|d| {
Self::from_device(d)
.and_then(|x| x.open_sink_or_fallback())
Expand Down