File size: 566 Bytes
18867c1
 
 
 
 
 
 
 
7e61478
 
 
 
 
18867c1
 
 
fdcf4ed
18867c1
 
 
7e61478
18867c1
 
 
 
 
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 numpy as np

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

def transcribe(audio):
    sr, y = audio
    
    # Convert to mono if stereo
    if y.ndim > 1:
        y = y.mean(axis=1)
        
    y = y.astype(np.float32)
    y /= np.max(np.abs(y))

    return transcriber({"sampling_rate": sr, "raw": y})["text"]  # type: ignore

demo = gr.Interface(
    transcribe,
    gr.Audio(sources="microphone"),
    "text",
)

if __name__ == "__main__":
    demo.launch()