wav.js

Yet another API for generating wav files in Javascript!

A simple API for generating uncompressed Waveform Audio File Format files in pure Javascript.

Fork me on GitHub

API Usage

Currently there is not a whole lot here but it will let you create .wav files in a pretty straightforward way. The only public function in the module is create, you call it like this:

var wave = wav.create(1, 44100, wav.SampleSize.EIGHT);
  • The first argument (1) is the number of channels (e.g. 2 for stereo, 1 for mono, etc)
  • The second argument (44100) is the sampling frequency in Hz.
  • The third argument (wav.SampleSize.EIGHT) is just an integer and is the number of bits per sample. I created a little enumeration since, in theory you could pass anything in here but in practice I am too lazy to figure out the calculations required to deal with anything. Have a look at the SampleSize enumeration for the allowed values.

Now that you have a wave object you can call the handy addSample function on it like so:

wave.addSample(123);

There are a few methods available:

  • addSampleToAllChannels - This adds the sample sample to all the output channel
  • getDataChunkSize - This gets the size of the data chunk
  • getTotalSampleCount - This gets the total number of samples
  • getSampleCountInOneChannel - This gets the sample count in a single channel
  • getFrequency - This returns the sampling frequency of the wav file.
  • getChannelCount - This returns the nmber of channels in the wav file
  • getSampleSize - The returns the number of bits per sample
building

So you want to help me out, brilliant…

  • Go ahead and fork the repository and clone it to your local machine.

  • Now you have the source get the dependencies using npm

      npm install
    
  • You have the dependencies, so now you can build it (and run the tests) using grunt.

      grunt
    
  • That’s it - code away and send me pull requests please!

The unit tests (written using nodeunit) are in th the test folder, the source is in src and the output goes in dist

Further Reading

You can find some auto-generated documentation here if you want to see any more details.