A WAV file processing library extracted from the ra2web project. This library provides comprehensive functionality for reading, writing, and manipulating WAV audio files.
- Read and write WAV files
- Support for various bit depths (8, 16, 24, 32, 64-bit)
- Support for floating-point audio formats (32f, 64)
- Audio compression formats (IMA-ADPCM, A-Law, μ-Law)
- Sample rate conversion
- Bit depth conversion
- Audio format conversion
- Base64 encoding/decoding
- Data URI support
npm install @ra2web/wavefile
import { WaveFile } from '@ra2web/wavefile';
// Create a new WaveFile instance
const wav = new WaveFile();
// Load from buffer
const buffer = /* your audio buffer */;
wav.fromBuffer(buffer);
// Access audio properties
console.log('Sample Rate:', wav.fmt.sampleRate);
console.log('Channels:', wav.fmt.numChannels);
console.log('Bit Depth:', wav.bitDepth);
// Get samples
const samples = wav.getSamples();
// Convert to different formats
wav.toBitDepth('16');
wav.toSampleRate(44100);
// Export as buffer
const outputBuffer = wav.toBuffer();
// Convert to different compression formats
wav.toALaw(); // Convert to A-Law
wav.toMuLaw(); // Convert to μ-Law
wav.toIMAADPCM(); // Convert to IMA-ADPCM
// Convert from compressed formats
wav.fromALaw();
wav.fromMuLaw();
wav.fromIMAADPCM();
// Convert to Base64
const base64String = wav.toBase64();
// Load from Base64
wav.fromBase64(base64String);
// Convert to Data URI
const dataUri = wav.toDataURI();
// Load from Data URI
wav.fromDataURI(dataUri);
-
new WaveFile(buffer?)
- Create a new WaveFile instance, optionally from a buffer
-
fromBuffer(buffer)
- Load WAV data from a buffer -
toBuffer()
- Export WAV data as a buffer -
fromBase64(base64String)
- Load WAV data from Base64 string -
toBase64()
- Export WAV data as Base64 string -
fromDataURI(dataUri)
- Load WAV data from Data URI -
toDataURI()
- Export WAV data as Data URI
-
toBitDepth(bitDepth, dithered?)
- Convert bit depth -
toSampleRate(sampleRate, options?)
- Convert sample rate -
toRIFF()
- Convert to RIFF format -
toRIFX()
- Convert to RIFX format
-
toALaw()
- Convert to A-Law compression -
fromALaw(bitDepth?)
- Convert from A-Law compression -
toMuLaw()
- Convert to μ-Law compression -
fromMuLaw(bitDepth?)
- Convert from μ-Law compression -
toIMAADPCM()
- Convert to IMA-ADPCM compression -
fromIMAADPCM(bitDepth?)
- Convert from IMA-ADPCM compression
-
getSamples(interleaved?)
- Get audio samples
-
fmt
- Format chunk data -
data
- Audio data chunk -
bitDepth
- Current bit depth -
container
- Container format (RIFF/RIFX/RF64)
MIT
This library was extracted from the ra2web project. For issues and contributions, please refer to the original project repository.