Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
# Function to record and save the audio
|
5 |
+
def record_sound(audio):
|
6 |
+
# Save the audio to a file
|
7 |
+
audio_path = "recorded_audio.wav"
|
8 |
+
audio['file'].save(audio_path)
|
9 |
+
return audio_path
|
10 |
+
|
11 |
+
# Function to play the audio back
|
12 |
+
def play_sound(audio_file):
|
13 |
+
# Return the path to the recorded audio file for playback
|
14 |
+
return audio_file
|
15 |
+
|
16 |
+
# Create Gradio interface with a microphone input and an audio output
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=record_sound, # Function that records audio
|
19 |
+
inputs=gr.Audio(source='microphone', type='filepath'), # Microphone input
|
20 |
+
outputs=gr.Audio(type='file'), # Output to play back recorded audio
|
21 |
+
title="Sound Recorder", # Title of the interface
|
22 |
+
description="Record audio from your microphone and play it back." # Description of the interface
|
23 |
+
)
|
24 |
+
|
25 |
+
# Launch the Gradio interface
|
26 |
+
iface.launch()
|