Visualizes audio input from a microphone in wavesurfer.js instances.
WaveSurfer
instanceMicrophone
instancestart
, 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.togglePlay();
// stop and disconnect microphone
//microphone.stop();
Name | Required | Description |
---|---|---|
wavesurfer |
yes | A WaveSurfer instance. |
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. |