File size: 870 Bytes
f350579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
import os

# Function to record and save the audio
def record_sound(audio):
    # Save the audio to a file
    audio_path = "recorded_audio.wav"
    audio['file'].save(audio_path)
    return audio_path

# Function to play the audio back
def play_sound(audio_file):
    # Return the path to the recorded audio file for playback
    return audio_file

# Create Gradio interface with a microphone input and an audio output
iface = gr.Interface(
    fn=record_sound,  # Function that records audio
    inputs=gr.Audio(source='microphone', type='filepath'),  # Microphone input
    outputs=gr.Audio(type='file'),  # Output to play back recorded audio
    title="Sound Recorder",  # Title of the interface
    description="Record audio from your microphone and play it back."  # Description of the interface
)

# Launch the Gradio interface
iface.launch()