gradio/demo/audio_component_events/run.ipynb
aliabid94 9b42ba8f10
Update guides esp plots (#8907)
* changes

* changes

* revert changes

* changes

* add changeset

* notebooks script

* changes

* changes

---------

Co-authored-by: Ali Abid <aliabid94@gmail.com>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
2024-07-29 22:08:51 -07:00

3.1 KiB

Gradio Demo: audio_component_events

In [ ]:
!pip install -q gradio 
In [ ]:
import gradio as gr

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            input_audio = gr.Audio(type="filepath", label="Input Audio", sources=["upload", "microphone"])
        with gr.Column():
            output_audio = gr.Audio(label="Output Audio", sources=["upload", "microphone"])

    with gr.Row():
        with gr.Column():
            input_num_change = gr.Number(label="# Input Change Events", value=0)
            input_num_input = gr.Number(label="# Input Input Events", value=0)
            input_num_load = gr.Number(label="# Input Upload Events", value=0)
            input_num_play = gr.Number(label="# Input Play Events", value=0)
            input_num_pause = gr.Number(label="# Input Pause Events", value=0)

        with gr.Column():
            input_record = gr.Number(label="# Input Start Recording Events", value=0)
            input_pause = gr.Number(label="# Input Pause Recording Events", value=0)
            input_stop = gr.Number(label="# Input Stop Recording Events", value=0)

        with gr.Column():
            output_num_play = gr.Number(label="# Output Play Events", value=0)
            output_num_pause = gr.Number(label="# Output Pause Events", value=0)
            output_num_stop = gr.Number(label="# Output Stop Events", value=0)

            input_audio.upload(lambda s, n: (s, n + 1), [input_audio, input_num_load], [output_audio, input_num_load])
            input_audio.change(lambda n: n + 1, input_num_change, input_num_change)
            input_audio.play(lambda n: n + 1, input_num_play, input_num_play)
            input_audio.pause(lambda n: n + 1, input_num_pause, input_num_pause)
            input_audio.change(lambda n: n + 1, input_num_change, input_num_change)
            input_audio.input(lambda n: n + 1, input_num_input, input_num_input)

            input_audio.start_recording(lambda n: n + 1, input_record, input_record)
            input_audio.pause_recording(lambda n: n + 1, input_pause, input_pause)
            input_audio.stop_recording(lambda n: n + 1, input_stop, input_stop)

            output_audio.play(lambda n: n + 1, output_num_play, output_num_play)
            output_audio.pause(lambda n: n + 1, output_num_pause, output_num_pause)
            output_audio.stop(lambda n: n + 1, output_num_stop, output_num_stop)

if __name__ == "__main__":
    demo.launch()