Files
VoelinClient/crates/tsc-audio/src/settings.rs
T
Claude 6fec2e3173 tsc-audio: echo cancellation, noise suppression, gain control, VAD, client volume, device hotplug
- process: Processor on sonora (pure Rust WebRTC APM: AEC3, NS, AGC2,
  high-pass) with serde ProcessingSettings; far end fed from what is played
- vad: level gate with hangover, optional RNN speech probability
- mixer: Mixer wraps the vendored AudioHandler with per-client volume/mute
- settings: AudioSettings bundles transmit mode, processing, VAD, devices
- device: stable device ids, default flags, loss detection through the
  error callback, Managed reopen/fallback policy
- tests: synthetic echo >= 10 dB, noise suppression keeps tone bursts,
  per-client gain, one-hour drift simulation at +-200 ppm
- dev profile optimises the sonora crates (real-time in debug builds)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
2026-09-25 19:48:23 +00:00

81 lines
2.4 KiB
Rust

//! All user audio settings in one serde struct, e.g. for
//! `tsc_store::Store::set_setting("audio", &settings)`. Missing fields take
//! their defaults, so stored settings survive new options.
use serde::{Deserialize, Serialize};
use crate::process::ProcessingSettings;
use crate::vad::VadSettings;
/// When the microphone is sent.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TransmitMode {
/// While the push-to-talk key or button is held.
#[default]
PushToTalk,
/// While the voice activity detector hears speech.
VoiceActivation,
/// Always (unless muted).
Continuous,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct AudioSettings {
pub transmit: TransmitMode,
pub processing: ProcessingSettings,
pub vad: VadSettings,
/// Microphone by device id (`device::DeviceInfo::id`); `None` follows
/// the system default.
pub input_device: Option<String>,
/// Speakers by device id; `None` follows the system default.
pub output_device: Option<String>,
/// Output volume for everyone, linear (1 = unchanged), applied before
/// the echo canceller sees the signal.
pub output_volume: f32,
/// Audio kept queued for the speakers. Lower is snappier, higher
/// survives scheduling hiccups.
pub playback_buffer_ms: u32,
}
impl Default for AudioSettings {
fn default() -> Self {
Self {
transmit: TransmitMode::PushToTalk,
processing: ProcessingSettings::default(),
vad: VadSettings::default(),
input_device: None,
output_device: None,
output_volume: 1.0,
playback_buffer_ms: 60,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn json_roundtrip_and_defaults() {
let mut s = AudioSettings {
transmit: TransmitMode::VoiceActivation,
input_device: Some("alsa:hw:1,0".into()),
..Default::default()
};
s.processing.echo_cancellation = false;
s.vad.threshold_db = -35.0;
let json = serde_json::to_string(&s).unwrap();
assert_eq!(serde_json::from_str::<AudioSettings>(&json).unwrap(), s);
// Older or partial settings fill in defaults.
let partial: AudioSettings =
serde_json::from_str(r#"{"transmit":"continuous","vad":{"hangover_ms":100}}"#).unwrap();
assert_eq!(partial.transmit, TransmitMode::Continuous);
assert_eq!(partial.vad.hangover_ms, 100);
assert_eq!(partial.vad.threshold_db, VadSettings::default().threshold_db);
assert_eq!(partial.processing, ProcessingSettings::default());
}
}