Capture Gardio input audio and save to a file

i would like to capture the audio from the microphone do the necessary conversion and save as wav or mp3 file locally but I haven’t been able to figure this out. Here’s the high level pseudo code.
I have been able to capture the audio and save it without the Gradio interface but just can’t seem to figure out with gradio.
Also tried to see if ChatGPT4 and didn’t have much luck.
I have not been able to to save the audio. I know the microphone is capturing since I can play that on the US. any help or hints appreciated. Thanks in advance!


import gradio as gr

def save_audio(audio):
    # capture the audio and save it to a file as wav or mp3
      file_name = save (audioinput.wav)
     return "file saved as "+file_name

gr.Interface(
    fn=save_audio, 
    inputs=gr.Audio(source="microphone", type="filepath"), 
    outputs="text").launch()
4 Likes