kowalsky commited on
Commit
43d9632
·
1 Parent(s): 81bbb17
Files changed (2) hide show
  1. main.py +6 -7
  2. templates/index.html +4 -2
main.py CHANGED
@@ -41,6 +41,10 @@ app.add_middleware(
41
  allow_headers=["*"],
42
  )
43
 
 
 
 
 
44
  is_detecting = False
45
 
46
  model = joblib.load('models/xgb_test.pkl')
@@ -61,8 +65,7 @@ class ConnectionManager:
61
 
62
  manager = ConnectionManager()
63
 
64
- def extract_features(audio):
65
- sr = 16000
66
  mfccs = librosa.feature.mfcc(y=audio, sr=sr, n_mfcc=13)
67
  mfccs = np.mean(mfccs, axis=1)
68
 
@@ -79,11 +82,7 @@ def extract_features(audio):
79
  return combined_features
80
 
81
  async def process_audio_data(audio_data):
82
- try:
83
- # Prepend header to the audio data
84
- with open("header.webm", 'rb') as source_file:
85
- header_data = source_file.read(1024)
86
-
87
  full_audio_data = header_data + audio_data
88
 
89
  # Convert audio data from webm to wav format using pydub
 
41
  allow_headers=["*"],
42
  )
43
 
44
+ # Prepend header to the audio data
45
+ with open("header.webm", 'rb') as source_file:
46
+ header_data = source_file.read(1024)
47
+
48
  is_detecting = False
49
 
50
  model = joblib.load('models/xgb_test.pkl')
 
65
 
66
  manager = ConnectionManager()
67
 
68
+ def extract_features(audio, sr = 16000):
 
69
  mfccs = librosa.feature.mfcc(y=audio, sr=sr, n_mfcc=13)
70
  mfccs = np.mean(mfccs, axis=1)
71
 
 
82
  return combined_features
83
 
84
  async def process_audio_data(audio_data):
85
+ try:
 
 
 
 
86
  full_audio_data = header_data + audio_data
87
 
88
  # Convert audio data from webm to wav format using pydub
templates/index.html CHANGED
@@ -111,6 +111,7 @@
111
  };
112
 
113
  const response = await fetch(`${window.location.origin}/start_detection`, {
 
114
  method: 'POST',
115
  });
116
 
@@ -119,9 +120,10 @@
119
  }
120
 
121
  const result = await response.json();
122
- logMessage(`Detection started: ${result.status}`, 'info');
123
 
124
  websocket = new WebSocket(`wss://${window.location.host}/ws`);
 
125
  websocket.onmessage = function(event) {
126
  const data = event.data;
127
  logMessage(`Detected ${data} audio`, data);
@@ -160,7 +162,7 @@
160
  }
161
 
162
  const result = await response.json();
163
- logMessage(`Detection stopped: ${result.status}`, 'info');
164
 
165
  if (websocket) {
166
  websocket.close();
 
111
  };
112
 
113
  const response = await fetch(`${window.location.origin}/start_detection`, {
114
+ // const response = await fetch(`http://localhost:7860/start_detection`, {
115
  method: 'POST',
116
  });
117
 
 
120
  }
121
 
122
  const result = await response.json();
123
+ logMessage(`Status: ${result.status}`, 'info');
124
 
125
  websocket = new WebSocket(`wss://${window.location.host}/ws`);
126
+ // websocket = new WebSocket(`ws://localhost:7860/ws`);
127
  websocket.onmessage = function(event) {
128
  const data = event.data;
129
  logMessage(`Detected ${data} audio`, data);
 
162
  }
163
 
164
  const result = await response.json();
165
+ logMessage(`Status: ${result.status}`, 'info');
166
 
167
  if (websocket) {
168
  websocket.close();