pub struct AudioRecorder {
pub sample_rate: u32,
/* private fields */
}Expand description
Accumulates inbound (caller) and outbound (bot) audio on a shared wall-clock timeline and mixes them down to a single mono WAV byte buffer.
Each leg records only its active chunks, but every chunk is stamped with its arrival time relative to call start, so render silence-pads the gaps and the two legs stay aligned — a caller turn at t=2s and a bot turn at t=5s land where they actually happened instead of both starting at sample 0 (which made the two voices play over each other in the recording).
Fields§
§sample_rate: u32Output WAV sample rate in Hz.
Implementations§
Source§impl AudioRecorder
impl AudioRecorder
Sourcepub fn new(sample_rate: u32) -> Self
pub fn new(sample_rate: u32) -> Self
Create a recorder that renders mixed audio at sample_rate Hz.
Sourcepub fn push_inbound(&mut self, chunk: &AudioChunk)
pub fn push_inbound(&mut self, chunk: &AudioChunk)
Append a chunk from the inbound (caller) leg, stamped at the live wall clock.
Stored at its own rate; resample + silence-pad happen in
render_wav. Empty chunks are dropped.
Sourcepub fn push_outbound(&mut self, chunk: &AudioChunk)
pub fn push_outbound(&mut self, chunk: &AudioChunk)
Append a chunk from the outbound (bot) leg, stamped at the live wall clock.
Sourcepub fn push_inbound_at(&mut self, offset: Duration, chunk: &AudioChunk)
pub fn push_inbound_at(&mut self, offset: Duration, chunk: &AudioChunk)
Append an inbound chunk at an explicit timeline offset from call start.
Deterministic entry point (no wall clock): the live taps go through
push_inbound; tests place chunks at known offsets.
Sourcepub fn push_outbound_at(&mut self, offset: Duration, chunk: &AudioChunk)
pub fn push_outbound_at(&mut self, offset: Duration, chunk: &AudioChunk)
Append an outbound chunk at an explicit timeline offset from call start.
Sourcepub fn duration_seconds(&self) -> f64
pub fn duration_seconds(&self) -> f64
Wall-clock call duration in seconds — the end of the later leg’s last audio.
Reported back to the control plane as usage_metrics.duration_seconds.
Sourcepub fn render_wav(&self) -> Result<Vec<u8>, FlowcatError>
pub fn render_wav(&self) -> Result<Vec<u8>, FlowcatError>
Mix both legs to mono and render a complete WAV file as bytes.
Each leg is resampled to self.sample_rate and laid out on the shared
timeline (silence-padding the gaps between turns); the two streams are
summed sample-by-sample (zero-padding the shorter leg to the longer), each
sum is clamped into i16, and the result is written as a mono 16-bit PCM
WAV via hound.