whisper-online / app.py
Enric Perpinyà Pitarch
Offline check
34afb82
raw
history blame contribute delete
No virus
618 Bytes
from transformers import pipeline
import gradio as gr
import numpy as np
transcriber = pipeline("automatic-speech-recognition", model="ID2223/whisper-small-swedish")
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(
transcribe,
["state", gr.Audio(sources=["microphone"], streaming=True)],
["state", "text"],
live=True,
)
demo.launch()