Audio Loader#

struct AudioPCM#

PCM container.

Always mono, float32 in [-1, 1]; the decoder mixes multi-channel input down. sampleRate is the rate the samples are at: the decoder resamples to the rate it was asked for, audioUtils::wrapPcm records the rate the caller states. samples stays readable for as long as this container holds it: a decoder attaches storage it allocated, wrapPcm attaches memory the caller keeps valid for the request.

Public Functions

int64_t numSamples() const noexcept#

Sample count in the single channel; zero when no samples are attached.

Public Members

std::shared_ptr<Tensor> samples#

[N] Float, host.

int32_t sampleRate = {16000}#
int32_t numChannels = {1}#
bool trt_edgellm::rt::audio::loadAudioBytes(
uint8_t const *bytes,
size_t size,
int32_t targetSampleRate,
AudioPCM &out
)#

Load raw audio bytes (wav / mp3 / flac) into mono float32 PCM resampled to targetSampleRate. Internally decodes the container via vendored miniaudio (auto-detects format from magic bytes) and mixes multi-channel to mono.

http(s):// URLs are not handled here — bytes are expected to be a complete container blob already.

Parameters:
  • bytes – Pointer to the encoded audio bytes.

  • size – Length of bytes in bytes.

  • targetSampleRate – Output sample rate (e.g. 16000 for Whisper).

  • out – Populated on success; on failure out is left in an unspecified state (do not consume its contents).

Returns:

true on success, false on decode failure.

bool trt_edgellm::rt::audio::loadAudioFile(
std::filesystem::path const &path,
int32_t targetSampleRate,
AudioPCM &out
)#

Load a local audio file (wav / mp3 / flac) into mono float32 PCM resampled to targetSampleRate.

Used by the CLI / offline path. The HTTP server uses loadAudioBytes.

Parameters:
  • path – Local filesystem path.

  • targetSampleRate – Output sample rate.

  • out – Populated on success; on failure out is left in an unspecified state (do not consume its contents).

Returns:

true on success, false on open/decode failure.