Spaces:
Sleeping
Sleeping
- main.py +4 -2
- templates/index.html +2 -2
main.py
CHANGED
@@ -79,8 +79,9 @@ def extract_features(audio):
|
|
79 |
|
80 |
async def process_audio_data(audio_data):
|
81 |
try:
|
82 |
-
|
83 |
-
|
|
|
84 |
except RuntimeError as e:
|
85 |
logger.error(f"Failed to read audio data: {e}")
|
86 |
return
|
@@ -97,6 +98,7 @@ async def process_audio_data(audio_data):
|
|
97 |
|
98 |
await manager.send_message(result)
|
99 |
|
|
|
100 |
@app.post("/start_detection")
|
101 |
async def start_detection():
|
102 |
global is_detecting
|
|
|
79 |
|
80 |
async def process_audio_data(audio_data):
|
81 |
try:
|
82 |
+
with io.BytesIO(audio_data) as audio_io:
|
83 |
+
audio_io.seek(0)
|
84 |
+
audio, sr = sf.read(audio_io, dtype='float32')
|
85 |
except RuntimeError as e:
|
86 |
logger.error(f"Failed to read audio data: {e}")
|
87 |
return
|
|
|
98 |
|
99 |
await manager.send_message(result)
|
100 |
|
101 |
+
|
102 |
@app.post("/start_detection")
|
103 |
async def start_detection():
|
104 |
global is_detecting
|
templates/index.html
CHANGED
@@ -63,7 +63,7 @@
|
|
63 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
64 |
logMessage('Microphone access granted', 'info');
|
65 |
|
66 |
-
mediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/
|
67 |
mediaRecorder.ondataavailable = function(event) {
|
68 |
if (websocket && websocket.readyState === WebSocket.OPEN) {
|
69 |
websocket.send(event.data);
|
@@ -81,7 +81,7 @@
|
|
81 |
const result = await response.json();
|
82 |
logMessage(`Detection started: ${result.status}`, 'info');
|
83 |
|
84 |
-
websocket = new WebSocket(`
|
85 |
websocket.onmessage = function(event) {
|
86 |
const data = event.data;
|
87 |
logMessage(`Detected ${data} audio`, data);
|
|
|
63 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
64 |
logMessage('Microphone access granted', 'info');
|
65 |
|
66 |
+
mediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/wav' });
|
67 |
mediaRecorder.ondataavailable = function(event) {
|
68 |
if (websocket && websocket.readyState === WebSocket.OPEN) {
|
69 |
websocket.send(event.data);
|
|
|
81 |
const result = await response.json();
|
82 |
logMessage(`Detection started: ${result.status}`, 'info');
|
83 |
|
84 |
+
websocket = new WebSocket(`ws://${window.location.host}/ws`);
|
85 |
websocket.onmessage = function(event) {
|
86 |
const data = event.data;
|
87 |
logMessage(`Detected ${data} audio`, data);
|