Helpers for slicing little-endian f32 PCM buffers without re-decoding the source audio.
slice/4 does the byte math (4 bytes per sample at sample_rate
samples/second) and bounds-checks against the buffer size.
Summary
Functions
Returns the audio duration of an f32-PCM buffer in seconds.
Returns the f32-PCM bytes for [start_s, start_s + duration_s).
Functions
@spec duration_s(binary(), pos_integer()) :: float()
Returns the audio duration of an f32-PCM buffer in seconds.
@spec slice(binary(), pos_integer(), number(), number()) :: {:ok, binary()} | {:error, WhisperCpp.Error.t()}
Returns the f32-PCM bytes for [start_s, start_s + duration_s).
samples is a binary of little-endian f32 samples at sample_rate
samples/second. Both start_s and duration_s are seconds; either
integer or float.
Returns {:error, %WhisperCpp.Error{reason: :invalid_request}} when:
start_s < 0;duration_sis zero or negative, or rounds to zero samples;- the requested window is not fully contained in the buffer.
The range is not clamped - slicing past the end is a caller bug.