Spaces:
Sleeping
Sleeping
- templates/index.html +17 -0
templates/index.html
CHANGED
@@ -39,6 +39,7 @@
|
|
39 |
const stopButton = document.getElementById('stopButton');
|
40 |
const consoleDiv = document.getElementById('console');
|
41 |
let websocket = null;
|
|
|
42 |
|
43 |
function logMessage(message, type) {
|
44 |
const log = document.createElement('p');
|
@@ -59,6 +60,16 @@
|
|
59 |
stopButton.disabled = false;
|
60 |
|
61 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
const response = await fetch(`${window.location.origin}/start_detection`, {
|
63 |
method: 'POST',
|
64 |
});
|
@@ -78,6 +89,8 @@
|
|
78 |
websocket.onclose = function() {
|
79 |
logMessage('WebSocket connection closed', 'info');
|
80 |
};
|
|
|
|
|
81 |
} catch (error) {
|
82 |
logMessage(`Error: ${error.message}`, 'error');
|
83 |
}
|
@@ -94,6 +107,10 @@
|
|
94 |
stopButton.disabled = true;
|
95 |
|
96 |
try {
|
|
|
|
|
|
|
|
|
97 |
const response = await fetch(`${window.location.origin}/stop_detection`, {
|
98 |
method: 'POST',
|
99 |
});
|
|
|
39 |
const stopButton = document.getElementById('stopButton');
|
40 |
const consoleDiv = document.getElementById('console');
|
41 |
let websocket = null;
|
42 |
+
let mediaRecorder = null;
|
43 |
|
44 |
function logMessage(message, type) {
|
45 |
const log = document.createElement('p');
|
|
|
60 |
stopButton.disabled = false;
|
61 |
|
62 |
try {
|
63 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
64 |
+
logMessage('Microphone access granted', 'info');
|
65 |
+
|
66 |
+
mediaRecorder = new MediaRecorder(stream);
|
67 |
+
mediaRecorder.ondataavailable = function(event) {
|
68 |
+
if (websocket && websocket.readyState === WebSocket.OPEN) {
|
69 |
+
websocket.send(event.data);
|
70 |
+
}
|
71 |
+
};
|
72 |
+
|
73 |
const response = await fetch(`${window.location.origin}/start_detection`, {
|
74 |
method: 'POST',
|
75 |
});
|
|
|
89 |
websocket.onclose = function() {
|
90 |
logMessage('WebSocket connection closed', 'info');
|
91 |
};
|
92 |
+
|
93 |
+
mediaRecorder.start(3000); // Start recording with 3-second intervals
|
94 |
} catch (error) {
|
95 |
logMessage(`Error: ${error.message}`, 'error');
|
96 |
}
|
|
|
107 |
stopButton.disabled = true;
|
108 |
|
109 |
try {
|
110 |
+
if (mediaRecorder && mediaRecorder.state === 'recording') {
|
111 |
+
mediaRecorder.stop();
|
112 |
+
}
|
113 |
+
|
114 |
const response = await fetch(`${window.location.origin}/stop_detection`, {
|
115 |
method: 'POST',
|
116 |
});
|