Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,29 +19,21 @@ def smooth_signal(signal, window_len=11):
|
|
19 |
smoothed = np.convolve(window/window.sum(), s, mode='valid')
|
20 |
return smoothed
|
21 |
|
22 |
-
def detect_beeps(audio_data, framerate, freq_zero, freq_one):
|
23 |
-
log_message("Starting beep detection.")
|
24 |
|
25 |
binary_data = bytearray()
|
26 |
-
|
27 |
-
# Calculate amplitude envelope to detect beep regions more clearly
|
28 |
-
envelope = np.abs(audio_data)
|
29 |
-
envelope = smooth_signal(envelope, window_len=100)
|
30 |
-
|
31 |
-
# Detect peaks in the smoothed amplitude envelope
|
32 |
-
peaks, _ = find_peaks(envelope, height=0.05, distance=framerate // 10)
|
33 |
-
|
34 |
previous_bit = None
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
window = audio_data[window_start:window_end]
|
40 |
|
41 |
-
# Perform FFT to detect the dominant frequency
|
42 |
yf = fft(window)
|
43 |
-
xf = fftfreq(
|
44 |
-
magnitude = np.abs(yf[:
|
45 |
dominant_freq = xf[np.argmax(magnitude)]
|
46 |
|
47 |
# Classify based on the dominant frequency
|
|
|
19 |
smoothed = np.convolve(window/window.sum(), s, mode='valid')
|
20 |
return smoothed
|
21 |
|
22 |
+
def detect_beeps(audio_data, framerate, freq_zero, freq_one, window_size=2048, step_size=512):
|
23 |
+
log_message("Starting beep detection with sliding window.")
|
24 |
|
25 |
binary_data = bytearray()
|
26 |
+
num_windows = len(audio_data) // step_size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
previous_bit = None
|
28 |
+
|
29 |
+
for i in range(0, len(audio_data) - window_size, step_size):
|
30 |
+
# Get the window of data
|
31 |
+
window = audio_data[i:i + window_size]
|
|
|
32 |
|
33 |
+
# Perform FFT to detect the dominant frequency in the window
|
34 |
yf = fft(window)
|
35 |
+
xf = fftfreq(window_size, 1 / framerate)
|
36 |
+
magnitude = np.abs(yf[:window_size // 2])
|
37 |
dominant_freq = xf[np.argmax(magnitude)]
|
38 |
|
39 |
# Classify based on the dominant frequency
|