WhisperCt2.Pcm (whisper_ct2 v0.5.0)

Copy Markdown View Source

Helpers for slicing little-endian f32 PCM buffers without re-decoding the source audio.

A diarization-driven workflow typically decodes the master audio to f32 PCM once (upstream of this library) and then runs many short transcribe calls over per-turn slices. 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 f32-PCM bytes for [start_s, start_s + duration_s).

Functions

slice(samples, sample_rate, start_s, duration_s)

@spec slice(binary(), pos_integer(), number(), number()) ::
  {:ok, binary()} | {:error, WhisperCt2.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, %WhisperCt2.Error{reason: :invalid_request}} when:

  • start_s < 0;
  • duration_s is zero or negative, or rounds to zero samples;
  • the requested window is not fully contained in the buffer (start_sample + requested_samples > total_samples).

The range is not clamped — slicing past the end is a caller bug and we surface it loudly. Bound your duration before calling, or use min(duration_s, buffer_duration - start_s).