I need help with a problem. I want to add a button in my Gradio app to start/stop audio recording. Basically, what I am trying to do is place a button on the UI. When a user clicks on the this button(let's say "Speak"), then audio recoding starts and the button text changes to "Stop". When user clicks on the button again(which now says "Stop") then audio recording stops.
I was looking at this code: Cannot record with a Gradio audio input using dynamic layout
The behaviour of the button is similar to what I need but I am unable to trigger audio player recoding.
Thank you for spending time to go through my query!
import gradio
with gradio.Blocks() as interface:
recorder = gradio.Audio(source='microphone', type='filepath', visible=False)
action_btn = gradio.Button('Speak')
def next_line(action, _):
if action == 'Speak':
return {action_btn: 'Next', recorder: recorder.start_recording}
else:
return {action_btn: 'Done', recorder: gradio.update(visible=False)}
action_btn.click(next_line, inputs=[action_btn, recorder], outputs=[action_btn, recorder])
interface.launch(share=False)