The one step that turns an AudioInput into PCM and its format, shared by every speech-to-text backend (#3143), and the RIFF/WAVE reader under it (#3144).
The rule, for every engine:
Bytes that start with a RIFF/WAVE header are a WAV file. Its chunks are walked (a LIST, fact or other chunk before data, an extensible fmt chunk, the pad byte after an odd-sized chunk), and the format is read from fmt, never assumed.
Other BytesAudio and StreamAudio bytes are raw 16-bit little-endian PCM at the declared sampleRate and numChannels: what every TTS client returns in GeneratedAudio.data.
A FileAudio must be a WAV file to be decoded; a cloud engine that takes other containers (MP3, FLAC ...) uploads such a file as it is, through uploadBytes.
Decoded PCM is always 16-bit signed little-endian: 8-bit (unsigned), 24- and 32-bit integer and 32-bit float WAV data is converted, so the preprocessing steps, which work on 16-bit samples, see the right amplitudes.
The PCM of a WAV file, or None when bytes is not one. A WAV whose fmt chunk is missing or truncated, has no data chunk, or holds a format other than integer PCM (8, 16, 24 or 32 bit) or 32-bit float is a Left naming what it found.
The PCM of a WAV file, or None when bytes is not one. A WAV whose fmt chunk is missing or truncated, has no data chunk, or holds a format other than integer PCM (8, 16, 24 or 32 bit) or 32-bit float is a Left naming what it found.
The bytes to upload to an engine that takes a container (a cloud API, the Whisper CLI): a FileAudio, or bytes that already are a WAV file, as they are; raw PCM wrapped in the WAV header it lacks, at its declared format.
The bytes to upload to an engine that takes a container (a cloud API, the Whisper CLI): a FileAudio, or bytes that already are a WAV file, as they are; raw PCM wrapped in the WAV header it lacks, at its declared format.