createAudioBlob
Creates a WAV audio Blob from raw 16-bit PCM data.
function createAudioBlob(
pcmData,
sampleRate,
numChannels?): Blob;
Defined in: src/utils/audio.ts:360
Creates a WAV audio Blob from raw 16-bit PCM data.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
pcmData | Int16Array | undefined | The raw 16-bit PCM audio samples. |
sampleRate | number | undefined | The audio sample rate in Hz. |
numChannels | number | 1 | The number of audio channels. |
Returns
Blob
A Blob containing a valid WAV file.
Remarks
Combines a WAV header (via createWavHeader) with the provided PCM data to produce a complete, playable WAV file as a Blob. The resulting blob has MIME type 'audio/wav' and can be used with <audio> elements or the Web Audio API.
Default Value
numChannels: 1
Example
const pcmSamples = floatTo16BitPCM(floatSamples);
const wavBlob = createAudioBlob(pcmSamples, 16000);
// Play via an audio element
const url = URL.createObjectURL(wavBlob);
const audio = new Audio(url);
audio.play();