Awell00 commited on
Commit
275c3ae
·
1 Parent(s): 30c6426

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
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, sample_rate=44100):
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(lowcut, highcut, fs, order=5):
133
- nyquist = 0.5 * fs
134
- low = lowcut / nyquist
135
- high = highcut / 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, lowcut, highcut, fs, order=5):
143
- b, a = butter_bandpass(lowcut, highcut, fs, order=order)
144
  y = lfilter(b, a, data)
145
  return y
146
 
147
 
148
  def main():
149
- input_file = 'output_text.wav'
150
- output_file = 'output_filtered_sender.wav'
151
- lowcut = 18000
152
- highcut = 19000
153
-
154
  try:
155
- fs, data = read(input_file)
156
 
157
- filtered_data = butter_bandpass_filter(data, lowcut, highcut, fs)
158
- write(output_file, fs, np.int16(filtered_data))
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)}"