Update app.py
Browse files
app.py
CHANGED
@@ -16,13 +16,15 @@ import math
|
|
16 |
from scipy.signal import butter, sosfiltfilt
|
17 |
|
18 |
|
19 |
-
def apply_low_pass_filter(audio_segment, cutoff_freq, order=6):
|
20 |
"""
|
21 |
Applies a low-pass filter to an AudioSegment.
|
|
|
22 |
Args:
|
23 |
audio_segment: The AudioSegment to filter.
|
24 |
cutoff_freq: The cutoff frequency in Hz.
|
25 |
order: The order of the Butterworth filter.
|
|
|
26 |
Returns:
|
27 |
A new AudioSegment with the filtered audio.
|
28 |
"""
|
@@ -32,7 +34,23 @@ def apply_low_pass_filter(audio_segment, cutoff_freq, order=6): ##added
|
|
32 |
normalized_cutoff = cutoff_freq / nyquist_freq
|
33 |
sos = butter(order, normalized_cutoff, btype='low', output='sos')
|
34 |
filtered_array = sosfiltfilt(sos, segment_array)
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
|
38 |
def get_silence(duration_ms=1000):
|
|
|
16 |
from scipy.signal import butter, sosfiltfilt
|
17 |
|
18 |
|
19 |
+
def apply_low_pass_filter(audio_segment, cutoff_freq, order=6):
|
20 |
"""
|
21 |
Applies a low-pass filter to an AudioSegment.
|
22 |
+
|
23 |
Args:
|
24 |
audio_segment: The AudioSegment to filter.
|
25 |
cutoff_freq: The cutoff frequency in Hz.
|
26 |
order: The order of the Butterworth filter.
|
27 |
+
|
28 |
Returns:
|
29 |
A new AudioSegment with the filtered audio.
|
30 |
"""
|
|
|
34 |
normalized_cutoff = cutoff_freq / nyquist_freq
|
35 |
sos = butter(order, normalized_cutoff, btype='low', output='sos')
|
36 |
filtered_array = sosfiltfilt(sos, segment_array)
|
37 |
+
|
38 |
+
sample_width = audio_segment.sample_width
|
39 |
+
dtype = None
|
40 |
+
if sample_width == 1:
|
41 |
+
dtype = np.int8
|
42 |
+
elif sample_width == 2:
|
43 |
+
dtype = np.int16
|
44 |
+
elif sample_width == 3:
|
45 |
+
dtype = np.int32 # Or potentially a custom type depending on the library
|
46 |
+
elif sample_width == 4:
|
47 |
+
dtype = np.int32
|
48 |
+
|
49 |
+
if dtype is not None:
|
50 |
+
return audio_segment._spawn(filtered_array.astype(dtype))
|
51 |
+
else:
|
52 |
+
raise ValueError(f"Unsupported sample width: {sample_width}")
|
53 |
+
|
54 |
|
55 |
|
56 |
def get_silence(duration_ms=1000):
|