I am working on a small app that takes user audio and sends it over the back-end service. For this, I am using Angular.
So far I have created an app that takes user audio and sends it, I can also download the file and hear my self (for testing purposes).
Now, when user audio is too big let's say more than 10 sec, I would want to slice it up into chunks. I have the implemented code for it. I can get the chunks, pass them into the array and download them all. But when I try to play them I am only able to play the first audio chunk, for the rest I cannot even open them.
This is where I am slicing my blob into sub-blobs.
if (this.duration > this.audioLimitBeforeChunking) {
let numChunks = this.duration/this.audioLimitBeforeChunking;
Math.floor(numChunks/1000);
console.log('numChunks is: ', numChunks);
for (let index = 0; index <= numChunks; index++) {
var byteEnd = Math.ceil((size/numChunks) * (index + 1));
this.blobArray.push(blob.slice(this.byteIndex, byteEnd));
this.byteIndex += (byteEnd - this.byteIndex);
}
}
This is where I am downloading all the sub-blobs.
for (let i = 0; i <= this.blobArray.length; i++) {
this.url = URL.createObjectURL(this.blobArray[i]);
this.audioFile = new File([this.blobArray[i]], "I_like_apples" + i + ".wav");
let postBody = {
'file': this.audioFile,
'user_token': '*******',
'reference_text': '******',
'model_id': '******'
}
console.log("inside sendData() component");
this.httpService.getStatus(postBody).subscribe(
(response:any) => {
console.log(response)
}
)
const a = document.createElement('a');
a.style.display = 'none';
a.href = this.url;
a.download = 'test.wav';
document.body.appendChild(a);
a.click();
}
}
As I mentioned above, I can only play the first sub-blob for the rest I cannot even open the audio file. Any idea what is going on here? Am I missing something?