Spaces:
Running
Running
File size: 973 Bytes
8d6648d 7ba16e7 8d6648d 7ba16e7 8d6648d 7ba16e7 8d6648d 7ba16e7 8d6648d 7ba16e7 8d6648d 7ba16e7 8d6648d 7ba16e7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
const recordButton = document.getElementById("recordButton");
const stopButton = document.getElementById("stopButton");
const audioChunks = [];
let mediaRecorder;
navigator.mediaDevices.getUserMedia({ audio: true })
.then(function(stream) {
mediaRecorder = new MediaRecorder(stream);
recordButton.onclick = function() {
mediaRecorder.start();
console.log("Recording started...");
};
stopButton.onclick = function() {
mediaRecorder.stop();
console.log("Recording stopped...");
};
mediaRecorder.ondataavailable = function(e) {
audioChunks.push(e.data);
};
mediaRecorder.onstop = function(e) {
const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
const reader = new FileReader();
reader.readAsDataURL(audioBlob);
reader.onloadend = function() {
const base64data = reader.result.split(',')[1];
Streamlit.setComponentValue(base64data);
};
};
}); |