# `WhisperCpp.Pcm`
[🔗](https://github.com/rubas/whisper_cpp/blob/v0.2.0/lib/whisper_cpp/pcm.ex#L1)

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.

# `duration_s`

```elixir
@spec duration_s(binary(), pos_integer()) :: float()
```

Returns the audio duration of an f32-PCM buffer in seconds.

# `slice`

```elixir
@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_s` is 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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
