How to get the microphone streaming input file when using blocks?

this responds to your question


import gradio as gr
from transformers import pipeline
import time

pipe = pipeline("automatic-speech-recognition")

def transcribe(audio, state=""):
    print(audio)
    time.sleep(2)
    text = pipe(audio)["text"]
    state += text + " "
    return state, state


with gr.Blocks() as demo:
  state = gr.State(value="")
  with gr.Row():
      with gr.Column():
        audio = gr.Audio(source="microphone", type="filepath") 
      with gr.Column():
        textbox = gr.Textbox()
  audio.stream(fn=transcribe, inputs=[audio, state], outputs=[textbox, state])

demo.launch(debug=True)
1 Like