audio_download.js
775 Bytes
// audio tag
const $tar = document.getElementById('audio_remote');
const mimeType = 'audio/webm';
const recorder = new MediaRecorder($tar.captureStream(), {
mimeType
});
recorder.onstart = function(e){
console.log('start', e);
};
recorder.ondataavailable = function(e){
console.log('ondata', e);
saveBlobData(e.data);
};
recorder.onstop = function(e){
console.log('stop', e);
};
recorder.start(1000);
function saveBlobData(data){
const blob = new Blob([data], {
type: mimeType
});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
document.body.appendChild(a);
a.style = 'display: none';
a.href = url;
a.download = document.title;
a.click();
window.URL.revokeObjectURL(url);
};