Expand description
Pure-Rust dominant speaker identification for WebRTC applications.
This crate implements the three-time-scale subband comparison algorithm
described in Volfin & Cohen, “Dominant Speaker Identification for
Multipoint Videoconferencing”, IEEE 2012. The implementation follows
mediasoup’s C++ ActiveSpeakerObserver for constants and Jitsi’s Java
DominantSpeakerIdentification for the overall structure.
Feed it RFC 6464 audio-level observations and it tells you who is talking. No FFI, no WebRTC stack dependency, no unsafe code.
§Quick start
Timestamps are caller-supplied u64 milliseconds — use any epoch you like
(e.g. Instant::now().elapsed().as_millis() as u64 in std environments,
or performance.now() as u64 in a WASM AudioWorklet).
use dominant_speaker::ActiveSpeakerDetector;
let mut detector = ActiveSpeakerDetector::new();
// Register two participants (timestamp = 0 ms).
detector.add_peer(1u64, 0);
detector.add_peer(2u64, 0);
// Feed audio levels (0 = loud, 127 = silent, per RFC 6464).
// Simulate peer 1 speaking for 2 seconds at 20 ms cadence.
let mut t_ms: u64 = 0;
while t_ms < 2000 {
detector.record_level(1, 5, t_ms); // peer 1: active
detector.record_level(2, 127, t_ms); // peer 2: silent
t_ms += 20;
}
// Call tick() on a 300 ms timer — returns Some(SpeakerChange) only on change.
if let Some(change) = detector.tick(300) {
println!("Dominant speaker: peer {}", change.peer_id);
}See the README for algorithm details, constants reference, and prior art.
Structs§
- Active
Speaker Detector - Per-room dominant-speaker detector.
- Detector
Config - Tunable constants for the dominant-speaker election.
- Speaker
Change - Emitted by
ActiveSpeakerDetector::tickwhen the dominant speaker changes.
Constants§
- TICK_
INTERVAL - Recommended tick interval matching mediasoup’s production tuning.
Type Aliases§
- Default
Detector - Convenience alias using
u64peer IDs — backward-compatible with v0.1.x.