app.js 911 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. // Create an instance
  3. var wavesurfer;
  4. // Init & load
  5. document.addEventListener('DOMContentLoaded', function () {
  6. var micBtn = document.querySelector('#micBtn');
  7. // Init wavesurfer
  8. wavesurfer = WaveSurfer.create({
  9. container : '#waveform',
  10. waveColor : 'black',
  11. interact : false,
  12. cursorWidth : 0,
  13. plugins: [
  14. WaveSurfer.microphone.create()
  15. ]
  16. });
  17. wavesurfer.microphone.on('deviceReady', function() {
  18. console.info('Device ready!');
  19. });
  20. wavesurfer.microphone.on('deviceError', function(code) {
  21. console.warn('Device error: ' + code);
  22. });
  23. // start/stop mic on button click
  24. micBtn.onclick = function() {
  25. if (wavesurfer.microphone.active) {
  26. wavesurfer.microphone.stop();
  27. } else {
  28. wavesurfer.microphone.start();
  29. }
  30. };
  31. });