Advertisement
sankarmahadevan

Untitled

May 12th, 2021
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $scope.startRecord = function() {
  2.         var stopRecord = document.getElementById('stopRecord');
  3.         var startRecord = document.getElementById('stopRecord');
  4.         if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  5.           $scope.voiceRecordingDiv=true;
  6.           canvas = document.querySelector('.visualizer');  
  7.           canvasCtx = canvas.getContext("2d");
  8.           startRecord.disabled = true;
  9.           $('#startRecord').css('opacity','0.5');
  10.           stopRecord.disabled=false;
  11.           $('#stopRecord').css('opacity','1');
  12.           $('#sendNote').hide();
  13.           sendNote.disabled=true;
  14.           // This will prompt for permission if not allowed earlier
  15.           navigator.mediaDevices.getUserMedia({audio:true})
  16.             .then(function(stream) {
  17.               audioChunks = [];
  18.               window.streamReference = stream;
  19.               rec = new MediaRecorder(stream);
  20.               visualize(stream);             
  21.               rec.ondataavailable = e => {
  22.                 audioChunks.push(e.data);              
  23.                 if (rec.state == "inactive"){
  24.                   let blob = new Blob(audioChunks,{type:'audio/mp3; codecs=opus'});
  25.                   recordedAudio.src = URL.createObjectURL(blob);
  26.                   audioNote = URL.createObjectURL(blob);
  27.                   recordedAudio.controls=true;
  28.                   recordedAudio.autoplay=true;
  29.                   /* audioDownload.href = recordedAudio.src;
  30.                   audioDownload.download = 'mp3';
  31.                   audioDownload.innerHTML = 'download'; */
  32.                }
  33.               }
  34.             rec.start();
  35.             })
  36.             .catch(function(err){console.log(err)});
  37.         } else {
  38.             alert('This feature not supported on your browser!');
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement