Microphone capture device and session helpers.
Dependencies
///|
fn main {
let devices = @proton_microphone.MicrophoneDevice::list()
for device in devices {
println(device.session_label())
}
}///|
fn example_label {
let device = @proton_microphone.MicrophoneDevice::{
id: "mic-1",
name: "Built-in Mic",
state: Idle,
default_config: @proton_microphone.CaptureConfig::new(
echo_cancellation=true,
noise_suppression=true,
),
monitor_supported: true,
}
println(device.session_label())
}pub(all) struct CaptureConfig {
channels : Int
sample_rate_hz : Int
sample_format : SampleFormat
echo_cancellation : Bool
noise_suppression : Bool
} derive(Eq, Debug)impl Show for CaptureConfigfn CaptureConfig::new(channels? : Int, sample_rate_hz? : Int, sample_format? : SampleFormat, echo_cancellation? : Bool, noise_suppression? : Bool) -> CaptureConfigtest "CaptureConfig::new applies conservative defaults" {
let config = CaptureConfig::new(sample_rate_hz=44_100)
assert_eq(config.channels, 1)
assert_eq(config.sample_rate_hz, 44_100)
}test "normalized clamps channels and sample rate to safe bounds" {
let config = CaptureConfig::new(channels=0, sample_rate_hz=4_000).normalized()
assert_eq(config.channels, 1)
assert_eq(config.sample_rate_hz, 8_000)
}test "recommended_chunk_frames is ten milliseconds of audio" {
assert_eq(
CaptureConfig::new(sample_rate_hz=48_000).recommended_chunk_frames(),
480,
)
}test "uses_voice_processing reflects requested flags" {
assert_false(CaptureConfig::new().uses_voice_processing())
assert_true(
CaptureConfig::new(noise_suppression=true).uses_voice_processing(),
)
}impl Show for CaptureStatetest "label returns a stable lowercase string" {
assert_eq(CaptureState::Recording.label(), "recording")
}pub(all) struct MicrophoneDevice {
id : String
name : String
state : CaptureState
default_config : CaptureConfig
monitor_supported : Bool
} derive(Eq, Debug)impl Show for MicrophoneDevicefor device in @proton_microphone.MicrophoneDevice::list() {
println(device.session_label())
}test "parse_listing assigns dense ids and drops monitors" {
let devices = MicrophoneDevice::parse_listing(
"Built-in Mic\nMonitor of Output\nUSB Mic\n",
)
assert_eq(devices.length(), 2)
assert_eq(devices[0].id, "mic-0")
assert_eq(devices[1].name, "USB Mic")
}impl Show for SampleFormattest "bytes_per_sample reflects the format width" {
assert_eq(SampleFormat::I16.bytes_per_sample(), 2)
assert_eq(SampleFormat::F32.bytes_per_sample(), 4)
}Microphone capture device and session helpers.
Dependencies