writeWavHeader
@siteed/expo-audio-stream • Docs
@siteed/expo-audio-stream / writeWavHeader
Function: writeWavHeader()
writeWavHeader(
options
):ArrayBuffer
Writes or updates a WAV (RIFF) header based on the provided options.
This function can be used in three ways:
- To create a standalone WAV header (when no buffer is provided).
- To create a WAV header and combine it with existing audio data (when a buffer without a header is provided).
- To update an existing WAV header in the provided buffer.
For streaming audio where the final size is unknown, this function sets the size fields
to the maximum 32-bit value (0xFFFFFFFF). These can be updated later using the
updateWavHeaderSize
function once the final size is known.
Parameters
• options: WavHeaderOptions
The options for creating or updating the WAV header.
Returns
ArrayBuffer
An ArrayBuffer containing the WAV header, or the header combined with the provided audio data.
Throws
Throws an error if the provided options are invalid or if the buffer is too small.
Examples
// Create a standalone WAV header
const header = writeWavHeader({
sampleRate: 44100,
numChannels: 2,
bitDepth: 16
});
// Create a WAV header and combine it with audio data
const completeWav = writeWavHeader({
buffer: audioData,
sampleRate: 44100,
numChannels: 2,
bitDepth: 16
});