mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
* changes * changes * revert changes * changes * add changeset * notebooks script * changes * changes --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
27 lines
659 B
Python
27 lines
659 B
Python
import gradio as gr
|
|
from transformers import pipeline
|
|
import numpy as np
|
|
|
|
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.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"] # type: ignore
|
|
|
|
demo = gr.Interface(
|
|
transcribe,
|
|
["state", gr.Audio(sources=["microphone"], streaming=True)],
|
|
["state", "text"],
|
|
live=True,
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|