Audio Loader#
- bool trt_edgellm::rt::audio::loadAudioFile(
- std::filesystem::path const &path,
- int32_t targetSampleRate,
- AudioPCM &out
PCM container.
Always mono, float32 in [-1, 1]; the decoder mixes multi-channel input down.
sampleRateis the rate the samples are at: the decoder resamples ! to the rate it was asked for,audioUtils::wrapPcmrecords the rate the ! caller states.samplesstays readable for as long as this container ! holds it: a decoder attaches storage it allocated,wrapPcmattaches ! memory the caller keeps valid for the request. struct AudioPCM { std::shared_ptr<Tensor> samples; //!<[N]Float, host. int32_t sampleRate{16000}; int32_t numChannels{1};! Sample count in the single channel; zero when no samples are attached. int64_t numSamples() const noexcept; };
! 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. ! !
! 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:
bytes – Pointer to the encoded audio bytes. !
size – Length of
bytesin bytes. !targetSampleRate – Output sample rate (e.g. 16000 for Whisper). !
out – Populated on success; on failure
outis left in an ! unspecified state (do not consume its contents). !path – Local filesystem path. !
targetSampleRate – Output sample rate. !
out – Populated on success; on failure
outis left in an unspecified state (do not consume its contents).
- Returns:
true on success, false on decode failure. bool loadAudioBytes(uint8_t const* bytes, size_t size, int32_t targetSampleRate, AudioPCM& out);
- Returns:
true on success, false on open/decode failure.