Skip to main content

AudioRecorder

Struct AudioRecorder 

Source
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: u32

Output WAV sample rate in Hz.

Implementations§

Source§

impl AudioRecorder

Source

pub fn new(sample_rate: u32) -> Self

Create a recorder that renders mixed audio at sample_rate Hz.

Source

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.

Source

pub fn push_outbound(&mut self, chunk: &AudioChunk)

Append a chunk from the outbound (bot) leg, stamped at the live wall clock.

Source

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.

Source

pub fn push_outbound_at(&mut self, offset: Duration, chunk: &AudioChunk)

Append an outbound chunk at an explicit timeline offset from call start.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more