File size: 3,148 Bytes
0ad74ed |
1 |
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: audio_component_events"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " input_audio = gr.Audio(type=\"filepath\", label=\"Input Audio\", sources=[\"upload\", \"microphone\"])\n", " with gr.Column():\n", " output_audio = gr.Audio(label=\"Output Audio\", sources=[\"upload\", \"microphone\"])\n", "\n", " with gr.Row():\n", " with gr.Column():\n", " input_num_change = gr.Number(label=\"# Input Change Events\", value=0)\n", " input_num_input = gr.Number(label=\"# Input Input Events\", value=0)\n", " input_num_load = gr.Number(label=\"# Input Upload Events\", value=0)\n", " input_num_play = gr.Number(label=\"# Input Play Events\", value=0)\n", " input_num_pause = gr.Number(label=\"# Input Pause Events\", value=0)\n", "\n", " with gr.Column():\n", " input_record = gr.Number(label=\"# Input Start Recording Events\", value=0)\n", " input_pause = gr.Number(label=\"# Input Pause Recording Events\", value=0)\n", " input_stop = gr.Number(label=\"# Input Stop Recording Events\", value=0)\n", "\n", " with gr.Column():\n", " output_num_play = gr.Number(label=\"# Output Play Events\", value=0)\n", " output_num_pause = gr.Number(label=\"# Output Pause Events\", value=0)\n", " output_num_stop = gr.Number(label=\"# Output Stop Events\", value=0)\n", "\n", " input_audio.upload(lambda s, n: (s, n + 1), [input_audio, input_num_load], [output_audio, input_num_load])\n", " input_audio.change(lambda n: n + 1, input_num_change, input_num_change)\n", " input_audio.play(lambda n: n + 1, input_num_play, input_num_play)\n", " input_audio.pause(lambda n: n + 1, input_num_pause, input_num_pause)\n", " input_audio.change(lambda n: n + 1, input_num_change, input_num_change)\n", " input_audio.input(lambda n: n + 1, input_num_input, input_num_input)\n", "\n", " input_audio.start_recording(lambda n: n + 1, input_record, input_record)\n", " input_audio.pause_recording(lambda n: n + 1, input_pause, input_pause)\n", " input_audio.stop_recording(lambda n: n + 1, input_stop, input_stop)\n", "\n", " output_audio.play(lambda n: n + 1, output_num_play, output_num_play)\n", " output_audio.pause(lambda n: n + 1, output_num_pause, output_num_pause)\n", " output_audio.stop(lambda n: n + 1, output_num_stop, output_num_stop)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |