Visualizes audio input from a microphone in wavesurfer.js instances.
WaveSurfer
instanceMicrophone
instancestart
, stopDevice
, play
, pause
, stop
and togglePlay
methods
var wavesurfer = Object.create(WaveSurfer);
wavesurfer.init({
container : '#waveform',
waveColor : 'black',
interact : false,
cursorWidth : 0
});
var microphone = Object.create(WaveSurfer.Microphone);
microphone.init({
wavesurfer: wavesurfer
});
microphone.on('deviceReady', function(stream) {
console.log('Device ready!', stream);
});
microphone.on('deviceError', function(code) {
console.warn('Device error: ' + code);
});
// start the microphone
microphone.start();
// pause rendering
//microphone.pause();
// resume rendering
//microphone.play();
// stop visualization and disconnect microphone
//microphone.stopDevice();
// same as stopDevice() but also clears the wavesurfer canvas
//microphone.stop();
// destroy the plugin
//microphone.destroy();
Name | Required | Default | Description |
---|---|---|---|
wavesurfer |
yes | A WaveSurfer instance. | |
bufferSize |
no | 4096 | The buffer size in units of sample-frames. If specified, the bufferSize must be one of the following values: 256, 512, 1024, 2048, 4096, 8192, 16384. |
numberOfInputChannels |
no | 1 | Integer specifying the number of channels for this node's input. Values of up to 32 are supported. |
numberOfOutputChannels |
no | 1 | Integer specifying the number of channels for this node's output. Values of up to 32 are supported. |
Name | Description |
---|---|
deviceReady |
Invoked when the device is ready to use. Callback will receive a LocalMediaStream object that contains the microphone stream. |
deviceError |
Invoked when the user doesn't allow the browser to access the microphone. Callback will receive a (string) error code. |