| import gradio as gr |
| from helper import process_audio |
| import numpy as np |
|
|
| |
| SAMPLE_SPEECH = "anushka.wav" |
| SAMPLE_NOISE = "traffic.wav" |
|
|
|
|
| def process_audio_files(speech_file, noise_file, alpha, beta): |
| """ |
| Process the audio files and return the mixed output |
| |
| Args: |
| speech_file (tuple): Speech audio (sample_rate, data) |
| noise_file (tuple): Noise audio (sample_rate, data) |
| alpha (float): First slider value (-30 to +30) |
| beta (float): Second slider value (-30 to +30) |
| |
| Returns: |
| tuple: (sample_rate, processed_audio_data) |
| """ |
| speech_sr, speech_data = speech_file |
| noise_sr, noise_data = noise_file |
|
|
| |
| output_audio = process_audio(speech_data, noise_data, speech_sr, noise_sr, |
| alpha, beta) |
|
|
| |
| samples = np.array(output_audio.get_array_of_samples()) |
|
|
| return (output_audio.frame_rate, samples) |
|
|
|
|
| |
|
|
|
|
| with gr.Blocks() as app: |
| gr.Markdown("# Audio Mixing Application") |
|
|
| with gr.Row(): |
| with gr.Column(): |
| |
| speech_input = gr.Audio( |
| label="Speech Audio", |
| type="numpy" |
| ) |
| noise_input = gr.Audio( |
| label="Noise Audio", |
| type="numpy" |
| ) |
|
|
| |
| gr.Examples( |
| examples=[[SAMPLE_SPEECH, SAMPLE_NOISE]], |
| inputs=[speech_input, noise_input], |
| label="Sample Audio Files" |
| ) |
|
|
| |
| alpha_slider = gr.Slider( |
| minimum=-30, |
| maximum=30, |
| value=0, |
| step=1, |
| label="Alpha (Speech Control)", |
| info="Controls speech loudness: Left (-30) reduces volume, Right (+30) increases volume" |
| ) |
| beta_slider = gr.Slider( |
| minimum=-30, |
| maximum=30, |
| value=0, |
| step=1, |
| label="Beta (Noise Control)", |
| info="Controls noise loudness: Left (-30) reduces volume, Right (+30) increases volume" |
| ) |
|
|
| |
| submit_btn = gr.Button("Process Audio") |
|
|
| with gr.Column(): |
| |
| output_audio = gr.Audio( |
| label="Mixed Audio", |
| type="numpy" |
| ) |
|
|
| |
| submit_btn.click( |
| fn=process_audio_files, |
| inputs=[speech_input, noise_input, alpha_slider, beta_slider], |
| outputs=output_audio |
| ) |
|
|
| if __name__ == "__main__": |
| app.launch() |
|
|