I have been looking to cut a audio blob in Js, and return a cut blob.
The blob is registered using WebAudioRecorder.js and using the mic of your pc.
I already found this repo: mp3-cutter, but it is written in node.js, and require to have access to the filesystem.
I also found this one: audio-cutter, but it has a UI.
I have explored multiple solution and did not find any simple solution.
While analyzing the recording, i found out that the mp3 registered with the mic have a 1024 bit header. Using this, and based on this, i wrote little Js function:
/**
* params:
* params.src: Blob Object
* params.start: start time in sec
* params.end: end time in sec
* params.bitrate: in kbps
*/
function cutter(params) {
let cuttedBlob;
if (!params.src || params.start == null || params.end == null)
throw 'Invalid parameters! ';
if (params.start > params.end)
throw 'Start is bigger than end! ';
let kbps;
if (!params.bitrate)
{
console.log("Checks have been done");
console.log(params.src);
var kbit = params.src.size / 128;
console.log("bitrate: " + kbit);
kbps= Math.ceil(Math.round(kbit / 204) / 16) * 16;
console.log(kbps + "kbps");
}
else
kbps = params.bitrate;
cuttedBlob = params.src.slice(1024 + (params.start * kbps), params.end * kbps, "audio/mpeg3");
return cuttedBlob;
}
But it does not seems to work.
I am missing something ?
Thanks in advance !