import gradio as gr import soundfile as sf import numpy as np def save_audio(audio): # audio is a tuple with (file_path, sample_rate) file_path, sample_rate = audio # Read the audio file data, samplerate = sf.read(file_path) # Save the audio file output_path = "recorded_audio.wav" sf.write(output_path, data, samplerate) return "Audio recorded and saved as 'recorded_audio.wav'." with gr.Blocks() as demo: gr.Markdown("# Audio Recorder") audio_input = gr.Audio(source="microphone", type="filepath") record_button = gr.Button("Record") output_text = gr.Textbox() record_button.click(fn=save_audio, inputs=audio_input, outputs=output_text) demo.launch()