File size: 648 Bytes
a95b4f8
 
 
 
91376db
a95b4f8
 
 
 
 
 
 
 
 
 
 
 
 
 
4290093
 
 
a95b4f8
 
 
91376db
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
import gradio as gr
from transformers import pipeline
import numpy as np

transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-tiny.en")

def transcribe(stream, new_chunk):
    sr, y = new_chunk
    y = y.astype(np.float32)
    y /= np.max(np.abs(y))

    if stream is not None:
        stream = np.concatenate([stream, y])
    else:
        stream = y
    return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]


demo = gr.Interface(
    fn=transcribe,
    inputs = gr.Audio(sources=["microphone"], streaming=True),
    outputs = gr.outputs.Textbox(),
    live=True,
)

demo.launch(debug=True, share=True)