You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/audio/src/bin/test_speaker.rs
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,19 @@
1
1
use audio::AudioInput;
2
2
3
+
/// Runs a simple binary test that creates an `AudioInput` from the default speaker, obtains its stream, and prints which `AudioStream` variant was returned.
4
+
///
5
+
/// This program exercises creation of a speaker `AudioInput`, requests its stream, and reports whether the stream is a `RealtimeSpeaker` variant. It does not poll or consume audio samples.
6
+
///
7
+
/// # Examples
8
+
///
9
+
/// ```
10
+
/// // Call the test binary's main to perform the creation and type check.
11
+
/// // The example demonstrates the intended usage; output is printed to stdout.
Copy file name to clipboardExpand all lines: crates/audio/src/lib.rs
+56-1Lines changed: 56 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,18 @@ pub struct AudioInput {
69
69
}
70
70
71
71
implAudioInput{
72
+
/// Get the name of the system's default input (microphone) device.
73
+
///
74
+
/// # Returns
75
+
///
76
+
/// A `String` with the device name, `"Unknown Microphone"` if the device exists but has no name, or `"No Microphone Available"` if there is no default input device.
77
+
///
78
+
/// # Examples
79
+
///
80
+
/// ```
81
+
/// let name = get_default_mic_device_name();
82
+
/// assert!(!name.is_empty());
83
+
/// ```
72
84
pubfnget_default_mic_device_name() -> String{
73
85
let host = cpal::default_host();
74
86
ifletSome(device) = host.default_input_device(){
@@ -78,6 +90,19 @@ impl AudioInput {
78
90
}
79
91
}
80
92
93
+
/// Returns a list of available input (microphone) device names.
94
+
///
95
+
/// The returned list contains the names of enumerated input devices. It filters out the
96
+
/// "hypr-audio-tap" device and will append the virtual "echo-cancel-source" device if
97
+
/// `pactl list sources short` reports it and it is not already present.
98
+
///
99
+
/// # Examples
100
+
///
101
+
/// ```
102
+
/// let devices = crate::audio::list_mic_devices();
103
+
/// // devices is a Vec<String> of device names (may be empty)
/// Creates an AudioInput configured to stream from a microphone.
162
+
///
163
+
/// If `device_name` is `Some(name)`, attempts to open the input device with that name; if `None`, uses the default input device. On success returns an `AudioInput` with `source` set to `RealtimeMic` and `mic` initialized.
164
+
///
165
+
/// # Errors
166
+
///
167
+
/// Returns a `crate::Error` if microphone initialization fails.
168
+
///
169
+
/// # Examples
170
+
///
171
+
/// ```
172
+
/// let ai = AudioInput::from_mic(None).expect("failed to open default microphone");
0 commit comments