Reputation: 1
console.log("Starting recording ...")
audioChunks = []
recorder.addEventListener('dataavailable', evt => {
if(evt.data.size > 0 && close_record === 1) {
audioChunks.push(evt.data);
// Giữ lại chỉ 10 audio chunk mới nhất
// if (audioChunks.length > 10) {
// audioChunks = audioChunks.slice(-10);
// }
blob = new Blob(audioChunks, { type: 'video/webm' });
async function makepredict(){
let response = await fetch(`http://127.0.0.1:8000/api/audio/`, {
method: 'POST',
mode: 'cors',
body: blob
});
let result = response.json();
return result;
};
makepredict().then( function(result) {
if (result['translate'] !== "oke"){
console.log(result)
}else{
console.log(audioChunks.length)
}
});
}
})
recorder.start(300)
When I not use "audioChunks = audioChunks.slice(-10)" with unlimited data audio then the audio that the server receives via API can be opened in webm format, but when I use code "audioChunks = audioChunks.slice(-10);" limit it to only taking the last 10 data chunks, an error occurs. I cannot open the audio file received by the server in webm format
if (audioChunks.length > 10) {
audioChunks = audioChunks.slice(-10);
}
I have tried many ways but still cannot fix the error. Please support me. Thank you very much
Upvotes: 0
Views: 20