File size: 709 Bytes
fc29d3f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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()
|