﻿# decodeAudioData: decoded audio is resampled to the AudioContext rate

decodeAudioData: decoded audio is resampled to the AudioContext rate. A focused voice-infrastructure guide with the documented mechanism, a reproducible validation scenario, evidence and operational limits.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/voice-decodeaudiodata-context-resampling/
Language: en

BaseAudioContext.decodeAudioData returns decoded audio at the context's sample rate. That can differ from the original file rate. A browser voice loader that assumes decoding only removes compression may consequently label or resample the waveform incorrectly before passing it to a speech model. Inspect the returned AudioBuffer rather than carrying the source-file rate forward by assumption.

## The audio contract

The API's decode operation includes resampling to the AudioContext rate and expects complete file data, not arbitrary fragments of an encoded file. The returned buffer has its own sampleRate, length and channel properties. Those describe the actual waveform now available to the application. Original container metadata remains useful provenance, but it is not a substitute for the returned representation. Relabeling this output with the old rate changes interpreted duration and pitch without performing the inverse conversion.

## Implementation details

Record the context rate and inspect the successful AudioBuffer before choosing any additional resampler. Pass the actual rate and valid sample region into model preparation, and retain the source rate separately as provenance. If a model needs another rate, perform and document that conversion from the returned rate rather than from an assumed original one. Keep file decoding errors distinct from unsupported fragment handling. Do not use this whole-file interface as a streaming decoder merely because network delivery happens to produce ArrayBuffer objects.

## A constructed validation case

Decode a known complete file whose original rate differs from the selected context rate. Verify returned metadata, duration derived from valid samples and a known temporal marker. Compare a correct downstream conversion with a deliberately mislabeled-rate path. Add a file fragment as a separate unsupported-input case rather than expecting successful streaming decode. Acceptance requires truthful representation metadata and preserved timing within the selected conversion protocol, not sample-for-sample identity with the compressed file's unavailable original waveform.

## Operational limits

Correct rate accounting does not certify recognition quality or the quality of every browser resampler. It establishes the waveform contract for those later comparisons. Keep implicit decode resampling visible so duplicate conversions or wrong duration labels are not reported as model or GPU differences.

## Primary references

[Webaudio Spec](https://www.w3.org/TR/webaudio-1.1/); [Mdn Audio Decode](https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/decodeAudioData).

This is a proposed voice-system validation, not an executed Retrivium benchmark. Preserve the implementation version and unresolved outcomes; interface documentation does not establish the quality or timing of a deployed voice service.

## Related reading

[Audio resampling for datasets: keep timestamps aligned when sample counts change](/journal/data-guide-audio-resample-time-labels/); [RNNoise floating-point input: PCM amplitude scale is part of the interface](/journal/fg2-rnnoise-float-pcm-amplitude-format/).
