🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@ra2web/wavefile

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ra2web/wavefile

WAV file processing library from ra2web project

1.0.2
latest
Source
npm
Version published
Weekly downloads
7
-53.33%
Maintainers
1
Weekly downloads
 
Created
Source

@ra2web/wavefile

A WAV file processing library extracted from the ra2web project. This library provides comprehensive functionality for reading, writing, and manipulating WAV audio files.

Features

  • 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

Installation

npm install @ra2web/wavefile

Usage

Basic Usage

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();

Format Conversion

// 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();

Base64 and Data URI Support

// 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);

API Reference

WaveFile Class

Constructor

  • new WaveFile(buffer?) - Create a new WaveFile instance, optionally from a buffer

Methods

File I/O
  • 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
Format Conversion
  • toBitDepth(bitDepth, dithered?) - Convert bit depth
  • toSampleRate(sampleRate, options?) - Convert sample rate
  • toRIFF() - Convert to RIFF format
  • toRIFX() - Convert to RIFX format
Compression
  • 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
Audio Data
  • getSamples(interleaved?) - Get audio samples

Properties

  • fmt - Format chunk data
  • data - Audio data chunk
  • bitDepth - Current bit depth
  • container - Container format (RIFF/RIFX/RF64)

License

MIT

Contributing

This library was extracted from the ra2web project. For issues and contributions, please refer to the original project repository.

Keywords

wav

FAQs

Package last updated on 02 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts