Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,7 +38,7 @@ def signal_function(frequency, time):
|
|
38 |
return np.sin(2 * np.pi * frequency * time)
|
39 |
|
40 |
|
41 |
-
def generate_silence(duration
|
42 |
return np.zeros(int(sample_rate * duration))
|
43 |
|
44 |
|
@@ -129,33 +129,29 @@ def encode_and_generate_audio(text):
|
|
129 |
|
130 |
# -----------------Filter----------------- #
|
131 |
|
132 |
-
def butter_bandpass(
|
133 |
-
nyquist = 0.5 *
|
134 |
-
low =
|
135 |
-
high =
|
136 |
coef = butter(order, [low, high], btype='band')
|
137 |
b = coef[0]
|
138 |
a = coef[1]
|
139 |
return b, a
|
140 |
|
141 |
|
142 |
-
def butter_bandpass_filter(data,
|
143 |
-
b, a = butter_bandpass(
|
144 |
y = lfilter(b, a, data)
|
145 |
return y
|
146 |
|
147 |
|
148 |
def main():
|
149 |
-
|
150 |
-
output_file = 'output_filtered_sender.wav'
|
151 |
-
lowcut = 18000
|
152 |
-
highcut = 19000
|
153 |
-
|
154 |
try:
|
155 |
-
|
156 |
|
157 |
-
filtered_data = butter_bandpass_filter(data,
|
158 |
-
write(output_file,
|
159 |
return "Filtered Audio Generated"
|
160 |
except Exception as e:
|
161 |
return f"Error: {str(e)}"
|
|
|
38 |
return np.sin(2 * np.pi * frequency * time)
|
39 |
|
40 |
|
41 |
+
def generate_silence(duration):
|
42 |
return np.zeros(int(sample_rate * duration))
|
43 |
|
44 |
|
|
|
129 |
|
130 |
# -----------------Filter----------------- #
|
131 |
|
132 |
+
def butter_bandpass(sr, order=5):
|
133 |
+
nyquist = 0.5 * sr
|
134 |
+
low = low_frequency / nyquist
|
135 |
+
high = high_frequency / nyquist
|
136 |
coef = butter(order, [low, high], btype='band')
|
137 |
b = coef[0]
|
138 |
a = coef[1]
|
139 |
return b, a
|
140 |
|
141 |
|
142 |
+
def butter_bandpass_filter(data, sr, order=5):
|
143 |
+
b, a = butter_bandpass(low_frequency, high_frequency, sr, order=order)
|
144 |
y = lfilter(b, a, data)
|
145 |
return y
|
146 |
|
147 |
|
148 |
def main():
|
149 |
+
|
|
|
|
|
|
|
|
|
150 |
try:
|
151 |
+
sr, data = read(input_file)
|
152 |
|
153 |
+
filtered_data = butter_bandpass_filter(data, low_frequency, high_frequency, sr)
|
154 |
+
write(output_file, sr, np.int16(filtered_data))
|
155 |
return "Filtered Audio Generated"
|
156 |
except Exception as e:
|
157 |
return f"Error: {str(e)}"
|