Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -75,32 +75,7 @@ def add_background_noise(audio_path, noise_level):
|
|
75 |
noisy_audio = audio.overlay(noise)
|
76 |
return save_audio(noisy_audio, "output_noisy.wav")
|
77 |
|
78 |
-
# 9.
|
79 |
-
def change_balance(audio_path, balance):
|
80 |
-
audio = load_audio(audio_path)
|
81 |
-
|
82 |
-
# Разделяем аудио на левый и правый каналы
|
83 |
-
left_channel = audio.split_to_mono()[0]
|
84 |
-
right_channel = audio.split_to_mono()[1]
|
85 |
-
|
86 |
-
# Регулируем громкость каналов в зависимости от баланса
|
87 |
-
if balance < 0.5:
|
88 |
-
# Уменьшаем громкость правого канала
|
89 |
-
right_channel = right_channel - (20 * (0.5 - balance))
|
90 |
-
elif balance > 0.5:
|
91 |
-
# Уменьшаем громкость левого канала
|
92 |
-
left_channel = left_channel - (20 * (balance - 0.5))
|
93 |
-
|
94 |
-
# Собираем аудио из двух каналов
|
95 |
-
balanced_audio = AudioSegment.from_mono_arrays(
|
96 |
-
left_channel.get_array_of_samples(),
|
97 |
-
right_channel.get_array_of_samples(),
|
98 |
-
frame_rate=audio.frame_rate
|
99 |
-
)
|
100 |
-
|
101 |
-
return save_audio(balanced_audio, "output_balanced.wav")
|
102 |
-
|
103 |
-
# 10. Фильтр низких частот
|
104 |
def low_pass_filter(audio_path, cutoff_freq):
|
105 |
y, sr = librosa.load(audio_path, sr=None)
|
106 |
y = librosa.effects.preemphasis(y, coef=cutoff_freq / sr)
|
@@ -210,24 +185,14 @@ with gr.Blocks() as interface:
|
|
210 |
gr.Button("Применить").click(add_background_noise, inputs=[audio_input_8, noise_level], outputs=output_8)
|
211 |
gr.Button("Очистить результаты").click(clear_output, inputs=None, outputs=output_8)
|
212 |
|
213 |
-
# Вкладка 9:
|
214 |
-
with gr.Tab("
|
215 |
with gr.Column():
|
216 |
audio_input_9 = gr.Audio(type="filepath", label="Входное аудио")
|
217 |
-
|
218 |
output_9 = gr.Audio(type="filepath", label="Выходное аудио")
|
219 |
with gr.Row():
|
220 |
-
gr.Button("Применить").click(
|
221 |
gr.Button("Очистить результаты").click(clear_output, inputs=None, outputs=output_9)
|
222 |
|
223 |
-
# Вкладка 10: Фильтр низких частот
|
224 |
-
with gr.Tab("Фильтр низких частот"):
|
225 |
-
with gr.Column():
|
226 |
-
audio_input_10 = gr.Audio(type="filepath", label="Входное аудио")
|
227 |
-
cutoff_freq = gr.Slider(minimum=100, maximum=1000, step=50, label="Частота среза (Гц)")
|
228 |
-
output_10 = gr.Audio(type="filepath", label="Выходное аудио")
|
229 |
-
with gr.Row():
|
230 |
-
gr.Button("Применить").click(low_pass_filter, inputs=[audio_input_10, cutoff_freq], outputs=output_10)
|
231 |
-
gr.Button("Очистить результаты").click(clear_output, inputs=None, outputs=output_10)
|
232 |
-
|
233 |
interface.launch()
|
|
|
75 |
noisy_audio = audio.overlay(noise)
|
76 |
return save_audio(noisy_audio, "output_noisy.wav")
|
77 |
|
78 |
+
# 9. Фильтр низких частот
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
def low_pass_filter(audio_path, cutoff_freq):
|
80 |
y, sr = librosa.load(audio_path, sr=None)
|
81 |
y = librosa.effects.preemphasis(y, coef=cutoff_freq / sr)
|
|
|
185 |
gr.Button("Применить").click(add_background_noise, inputs=[audio_input_8, noise_level], outputs=output_8)
|
186 |
gr.Button("Очистить результаты").click(clear_output, inputs=None, outputs=output_8)
|
187 |
|
188 |
+
# Вкладка 9: Фильтр низких частот
|
189 |
+
with gr.Tab("Фильтр низких частот"):
|
190 |
with gr.Column():
|
191 |
audio_input_9 = gr.Audio(type="filepath", label="Входное аудио")
|
192 |
+
cutoff_freq = gr.Slider(minimum=100, maximum=1000, step=50, label="Частота среза (Гц)")
|
193 |
output_9 = gr.Audio(type="filepath", label="Выходное аудио")
|
194 |
with gr.Row():
|
195 |
+
gr.Button("Применить").click(low_pass_filter, inputs=[audio_input_9, cutoff_freq], outputs=output_9)
|
196 |
gr.Button("Очистить результаты").click(clear_output, inputs=None, outputs=output_9)
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
interface.launch()
|