File size: 1,569 Bytes
183ee92 |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
let ws;
let isRecording = false;
function toggleRecording() {
if (!isRecording) {
ws = new WebSocket("ws://localhost:8000/ws");
ws.onopen = () => ws.send("start");
ws.onmessage = (event) => {
const serverMessage = event.data;
if (serverMessage.startsWith("chunk:")) {
const chunkText = serverMessage.substring(6); // Remove "chunk:" prefix
document.getElementById('audio-chunks').innerText = chunkText;
} else if (serverMessage === "Restarting system...") {
isRecording = false;
updateButton();
} else {
document.getElementById('results').innerText = serverMessage;
}
};
isRecording = true;
} else {
ws.send("stop");
isRecording = false;
}
updateButton();
}
function updateButton() {
const startButton = document.getElementById('startBtn');
if (isRecording) {
startButton.innerText = "Stop";
startButton.className = "stop-button";
} else {
startButton.innerText = "Start";
startButton.className = "start-button";
}
}
document.getElementById('startBtn').addEventListener('click', toggleRecording);
document.getElementById('toggleClassListBtn').addEventListener('click', function() {
var classList = document.getElementById('class-list');
if (classList.style.display === "none") {
classList.style.display = "block";
} else {
classList.style.display = "none";
}
}); |