Skip to content

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

ParameterTypeDefault valueDescription
pcmDataInt16ArrayundefinedThe raw 16-bit PCM audio samples.
sampleRatenumberundefinedThe audio sample rate in Hz.
numChannelsnumber1The 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();

See

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency