Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import soundfile as sf
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def save_audio(audio):
|
| 6 |
+
# audio is a tuple with (file_path, sample_rate)
|
| 7 |
+
file_path, sample_rate = audio
|
| 8 |
+
# Read the audio file
|
| 9 |
+
data, samplerate = sf.read(file_path)
|
| 10 |
+
# Save the audio file
|
| 11 |
+
output_path = "recorded_audio.wav"
|
| 12 |
+
sf.write(output_path, data, samplerate)
|
| 13 |
+
return "Audio recorded and saved as 'recorded_audio.wav'."
|
| 14 |
+
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("# Audio Recorder")
|
| 17 |
+
audio_input = gr.Audio(source="microphone", type="filepath")
|
| 18 |
+
record_button = gr.Button("Record")
|
| 19 |
+
output_text = gr.Textbox()
|
| 20 |
+
|
| 21 |
+
record_button.click(fn=save_audio, inputs=audio_input, outputs=output_text)
|
| 22 |
+
|
| 23 |
+
demo.launch()
|