Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scope.startRecord = function() {
- var stopRecord = document.getElementById('stopRecord');
- var startRecord = document.getElementById('stopRecord');
- if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
- $scope.voiceRecordingDiv=true;
- canvas = document.querySelector('.visualizer');
- canvasCtx = canvas.getContext("2d");
- startRecord.disabled = true;
- $('#startRecord').css('opacity','0.5');
- stopRecord.disabled=false;
- $('#stopRecord').css('opacity','1');
- $('#sendNote').hide();
- sendNote.disabled=true;
- // This will prompt for permission if not allowed earlier
- navigator.mediaDevices.getUserMedia({audio:true})
- .then(function(stream) {
- audioChunks = [];
- window.streamReference = stream;
- rec = new MediaRecorder(stream);
- visualize(stream);
- rec.ondataavailable = e => {
- audioChunks.push(e.data);
- if (rec.state == "inactive"){
- let blob = new Blob(audioChunks,{type:'audio/mp3; codecs=opus'});
- recordedAudio.src = URL.createObjectURL(blob);
- audioNote = URL.createObjectURL(blob);
- recordedAudio.controls=true;
- recordedAudio.autoplay=true;
- /* audioDownload.href = recordedAudio.src;
- audioDownload.download = 'mp3';
- audioDownload.innerHTML = 'download'; */
- }
- }
- rec.start();
- })
- .catch(function(err){console.log(err)});
- } else {
- alert('This feature not supported on your browser!');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement