Skip to main content

ProcessedChunk

Struct ProcessedChunk 

Source
pub struct ProcessedChunk {
    pub samples: Vec<f32>,
    pub start_boundary: ChunkBoundary,
    pub end_boundary: ChunkBoundary,
    pub start_time: AudioTimestamp,
    pub end_time: AudioTimestamp,
    pub speech_ratio: f32,
    pub energy: f32,
    pub snr_db: Option<f32>,
    pub has_clipping: bool,
    pub overlap_prev: Option<Vec<f32>>,
    pub overlap_next: Option<Vec<f32>>,
    pub overlap_ms: u32,
}
Expand description

A processed audio chunk with temporal and quality metadata.

Represents a segment of audio aligned to speech boundaries.

Fields§

§samples: Vec<f32>

Audio samples in the chunk (normalized f32, range [-1.0, 1.0]).

§start_boundary: ChunkBoundary

Type of boundary at chunk start.

§end_boundary: ChunkBoundary

Type of boundary at chunk end.

§start_time: AudioTimestamp

Absolute start time of chunk in audio stream.

§end_time: AudioTimestamp

Absolute end time of chunk in audio stream.

§speech_ratio: f32

Ratio of speech frames in chunk (0.0 = all silence, 1.0 = all speech).

Derived from VAD analysis.

§energy: f32

RMS energy of the chunk (computed during generation).

Useful for quality assessment and thresholding.

§snr_db: Option<f32>

Signal-to-noise ratio in decibels (dB).

Computed as 20 * log10(signal_rms / noise_rms), where noise_rms is estimated from silence regions. None if no noise baseline is available (e.g., first chunk with no silence).

Higher SNR values indicate cleaner audio:

  • 30 dB: Excellent quality

  • 20-30 dB: Good quality
  • 10-20 dB: Acceptable quality
  • <10 dB: Poor quality (high noise)
§has_clipping: bool

Indicates whether the chunk contains clipping artifacts.

Clipping occurs when sample values exceed the normalized range [-1.0, 1.0], typically manifesting as |sample| >= 0.999. Clipped audio may cause audible distortion.

true if any sample in the chunk is clipped, false otherwise.

§overlap_prev: Option<Vec<f32>>

Overlap samples from the previous chunk (for context).

Contains the trailing overlap_duration samples from the previous chunk, preserving acoustic context across the boundary. None for the first chunk in the stream.

§overlap_next: Option<Vec<f32>>

Overlap samples for the next chunk (for context).

Contains the trailing overlap_duration samples from this chunk, to be prepended to the next chunk for context. None for the last chunk in the stream.

§overlap_ms: u32

Actual overlap duration in milliseconds.

The duration of samples in overlap_prev and overlap_next. Typically matches ChunkerConfig::overlap_duration (default 50ms), but may be shorter for chunks at stream boundaries.

Implementations§

Source§

impl ProcessedChunk

Source

pub fn duration(&self) -> Result<AudioDuration>

Get the duration of this chunk.

§Errors

Returns Error::Processing if end_time < start_time (indicates invalid chunk).

Source

pub fn is_speech(&self) -> bool

Check if this chunk contains primarily speech.

Source

pub fn is_silence(&self) -> bool

Check if this chunk is silence.

Source

pub fn samples_without_overlap(&self) -> &[f32]

Get samples without overlap (deduplicated core content).

Returns the chunk’s primary samples, excluding any overlap regions that would be duplicated when processing sequential chunks. Useful for callers that want to avoid processing overlap regions twice.

Source

pub fn total_samples_with_overlap(&self) -> usize

Returns total sample count including overlap regions.

Useful for buffer allocation when reconstructing the full audio data with prepended/appended overlaps.

Trait Implementations§

Source§

impl Clone for ProcessedChunk

Source§

fn clone(&self) -> ProcessedChunk

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProcessedChunk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<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