File size: 704 Bytes
0fb9949
 
 
1278823
0fb9949
1278823
 
 
0fb9949
 
7cb4a5f
12c52b2
0fb9949
 
 
 
 
 
 
 
 
e744c08
0fb9949
 
 
 
 
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
from transformers import pipeline
import time
import torch

device = "cuda:0" if torch.cuda.is_available() else "cpu"

pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base.en", device=device)

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(sources="microphone", type="filepath") 
      with gr.Column():
        textbox = gr.Textbox()
  audio.stream(fn=transcribe, inputs=[audio, state], outputs=[textbox, state])

demo.launch(debug=True)