Skip to content

Volume & EQ

All setter methods are synchronous SOAP calls that update the internal state cache on success.

MethodSignatureDescription
set_volumeset_volume(volume: u8)Absolute volume (0–100)
set_relative_volumeset_relative_volume(adjustment: i8)Relative adjustment, returns new level
set_muteset_mute(muted: bool)Mute or unmute
use sonos_sdk::prelude::*;
fn main() -> Result<(), SdkError> {
let sonos = SonosSystem::new()?;
let speaker = sonos.speaker("Kitchen").unwrap();
// Set absolute volume
speaker.set_volume(40)?;
// Adjust relative to current
let result = speaker.set_relative_volume(5)?;
println!("New volume: {}", result.new_volume);
// Mute
speaker.set_mute(true)?;
Ok(())
}
MethodSignatureRangeDescription
set_bassset_bass(level: i8)-10 to +10Bass EQ
set_trebleset_treble(level: i8)-10 to +10Treble EQ
set_loudnessset_loudness(enabled: bool)—Loudness compensation
speaker.set_bass(5)?;
speaker.set_treble(-3)?;
speaker.set_loudness(true)?;

Loudness boosts bass and treble at low volumes to compensate for human hearing characteristics.

let bass = speaker.bass.fetch()?;
let treble = speaker.treble.fetch()?;
let loudness = speaker.loudness.fetch()?;
println!(
"Bass: {}, Treble: {}, Loudness: {}",
bass.value(),
treble.value(),
loudness.is_enabled(),
);

A soundbar, or a speaker with a bonded sub, has settings of its own. Each one is a property on the main speaker, read with fetch(), written with set() and watchable like the EQ settings above:

PropertyValueRange
sub_enabledSubEnabled(bool)on / off
sub_levelSubLevel(i8)-15 to +15
surround_enabledSurroundEnabled(bool)on / off
surround_levelSurroundLevel(i8)-15 to +15, while playing TV
music_surround_levelMusicSurroundLevel(i8)-15 to +15, while playing music
surround_modeSurroundModeAmbient or Full, for music
night_modeNightMode(bool)on / off
speech_enhancementSpeechEnhancement(bool)on / off
audio_delayAudioDelay(u8)0 to 5 (lip sync)
use sonos_sdk::{MusicSurroundLevel, NightMode};
let basement = sonos.speaker("Basement").unwrap();
basement.night_mode.set(NightMode(true))?;
basement.music_surround_level.set(MusicSurroundLevel::new(3))?;
println!("TV surround level: {:?}", basement.surround_level.fetch()?);

A soundbar answers for every setting, sub settings included, even when no sub is bonded. Check speaker.satellites() before offering a sub or surround setting. Out-of-range values are rejected with SdkError::ValidationFailed before anything is sent.

Group volume adjusts all members proportionally. Controlled via the group handle, which addresses the group’s coordinator — sending GroupRenderingControl operations to a non-coordinator is a UPnP error 701, and Group routes around that for you:

MethodSignatureDescription
set_volumeset_volume(volume: u16)Absolute group volume (0–100)
set_relative_volumeset_relative_volume(adjustment: i16)Relative adjustment, returns new level
set_muteset_mute(muted: bool)Mute/unmute entire group
snapshot_volumesnapshot_volume()Save current levels for restore
let group = sonos.speaker("Living Room").unwrap().group().unwrap();
// Absolute
group.set_volume(40)?;
// Relative
let result = group.set_relative_volume(-5)?;
println!("New group volume: {}", result.new_volume);
// Mute all
group.set_mute(true)?;

snapshot_volume() sends SnapshotGroupVolume to the coordinator, which records the members’ current volumes as the ratios that subsequent group volume changes scale against. Call it after changing an individual member’s volume so the next group.set_volume() keeps the new balance:

let group = sonos.speaker("Living Room").unwrap().group().unwrap();
// Re-baseline the members' relative levels
group.snapshot_volume()?;
// Members now scale from that baseline
group.set_volume(20)?;

The SDK exposes no restore call. To put levels back, read each member’s volume first and set them again afterwards:

let group = sonos.speaker("Living Room").unwrap().group().unwrap();
let before: Vec<_> = group
.members()
.into_iter()
.map(|s| s.volume.fetch().map(|v| (s, v)))
.collect::<Result<_, _>>()?;
group.set_volume(20)?;
for (speaker, volume) in before {
speaker.set_volume(volume.value())?;
}

All volume and EQ properties support the reactive watch() pattern:

// Acquire every handle before the loop: iter() only emits events for
// properties that are already being watched.
let volume = speaker.volume.watch()?;
let mute = speaker.mute.watch()?;
let bass = speaker.bass.watch()?;
let treble = speaker.treble.watch()?;
let loudness = speaker.loudness.watch()?;
for _event in sonos.iter() {
println!("Vol: {:?}, Mute: {:?}, Bass: {:?}, Treble: {:?}, Loudness: {:?}",
volume.value(), mute.value(), bass.value(), treble.value(), loudness.value());
}

Group volume is also watchable:

let group = sonos.speaker("Living Room").unwrap().group().unwrap();
let vol = group.volume.watch()?;
let mute = group.mute.watch()?;
for _event in sonos.iter() {
println!("Group vol: {:?}, mute: {:?}", vol.value(), mute.value());
}