Giter Club home page Giter Club logo

wav-audio-encoder-js's Introduction

WavAudioEncoder.js

What is it?

WavAudioEncoder.js is a small JavaScript library that encodes audio data to Waveform Audio (.wav) on web browsers.

Acknowledgement

Basic idea is taken from Recorderjs (https://github.com/mattdiamond/Recorderjs). API has been totally re-designed and simplified. Now it has been a lower layer part of WebAudioRecorder.js.

Demo

https://higuma.github.io/wav-audio-encoder-js/

Library files

lib/ contains library files.

  • WavAudioEncoder.js: JavaScript library (uncompressed)
  • WavAudioEncoder.min.js: JavaScript library (minified)

Using library

You can use it from both HTML and Web Worker.

  • from HTML: <script src="javascripts/WavAudioEncoder.js"></script>
  • from Worker: importScripts("javascripts/WavAudioEncoder.js");

API

encoder = new WavAudioEncoder(sampleRate, numChannels)

Create an encoder object.

  • Parameters
    • samleRate: sampling rate [Hz]
    • numChannels: number of audio channels
  • Returns
    • encoder object

In current implementation, bit width is fixed to 16 (2 bytes).

encoder.encode(buffers)

Encode audio buffers.

  • Parameters
    • buffers: array of sample buffers ([Float32Array, Float32Array ...])
  • Returns
    • (none)

buffers must be an array of Float32Array audio data (range = [-1, 1]). Array length must be same as number of channels. It supports stream (incremental) processing. Sample buffers are processed to .wav fragment and appended to internal data.

blob = encoder.finish([mimeType])

Finish encoding and get Waveform Audio as a Blob.

  • Parameters
    • mimeType(optional): MIME type (default = "audio/wav")
  • Returns
    • Blob object

After calling .finish(), all internal data is cleared. You must create a new encoder object to encode another audio data.

encoder.cancel()
  • Parameters
    • (none)
  • Returns
    • (none)

Cancel encoding and clear all internal data.

License

MIT (see LICENSE.txt).

wav-audio-encoder-js's People

Contributors

higuma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wav-audio-encoder-js's Issues

Encoded WAV file slow playback

Hey higuma,

I really appreciate the work you've done on this and the related libraries. These abstractions really help. I was hoping you might have greater insight into a misunderstanding of mine on how to properly encode the file, namely the fact that the .wav files I produce appear to be in slow motion (the weird clipping is also probably a side effect).

Here is an example output file of mine:
onefive.wav.zip

For the buffer, I use Float32Array arrays derived from this Web Audio API function: analyser.getFloatTimeDomainData(array_float_time_domain), here in my particular code. And here in the Mozilla docs.

In my experimentation, I've noticed that varying the bufferLength = analyser.fftSize that initializes the Float32Array either slows down or speeds up the playback of the recording: lower powers of 2 play back proportionally faster. Since these are powers of 2 up to 2048, there are only so many I could reasonably try.

The only other setting that seemed to drastically change the recording is the sampleRate, but this of course is set by the system itself. Here is where I actually start encoding the .wav.

I may be doing something heinously wrong, and I understand that my problem may be out of the purview of maintaining the library itself. However, perhaps you can see an obvious logical mistake I have made. What am I messing up?

-jgujgu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.