I need to cut an audio on the client-side and send the "cut" bytes to the NodeJS. It's possible? How can I implement?
I need to cut an audio on the client-side and send the "cut" bytes to the NodeJS. It's possible? How can I implement?
Well, I was able to solve my problem and came back here to share the solution for someone who might need it in the future. Even because I did not find anything similar on the net as incredible as it seems.
VanillaJS
window.onload = function (){
'use strict';
var xhr = new XMLHttpRequest();
xhr.open("GET",'path/da/musica', true);
xhr.responseType = "arraybuffer";
xhr.onload = function (e) {
var blob = new Blob([xhr.response], {type: "audio/mp3"});
var newBlob = new Blob([blob.slice(/*Início em bytes*/, /*Fim em bytes*/)], {type:"audio/mp3"});
var reader = new FileReader();
reader.onload = function(){
var dataURL = reader.result;
var output = document.getElementById('audio');
output.src = dataURL;
output.autoplay = true;
};
reader.readAsDataURL(newBlob);
}
xhr.send(null);
}
HTML
<audio id="audio"></audio>
Note: I did not use it in the most orthodox way, but it is functional