speech-to-text / run_demo_streaming.py
bofenghuang's picture
add logger
eb937e4
raw
history blame
920 Bytes
import logging
import gradio as gr
from transformers import pipeline
logging.basicConfig(
format="%(asctime)s [%(levelname)s] [NLU] [Trainer] %(message)s",
datefmt="%Y-%m-%dT%H:%M:%SZ",
)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
pipe = pipeline(model="bhuang/wav2vec2-xls-r-1b-cv9-fr")
def transcribe(audio, state=""):
text = pipe(audio, chunk_length_s=5, stride_length_s=1)["text"]
state += text + " "
logger.info(f"Transcription for {audio}: {state}")
return state, state
# streaming mode
iface = gr.Interface(
fn=transcribe,
inputs=[gr.Audio(source="microphone", type="filepath", streaming=True, label="Record something..."), "state"],
outputs=["textbox", "state"],
title="Realtime Speech-to-Text in French",
description="Realtime demo for French automatic speech recognition.",
allow_flagging="never",
live=True,
)
iface.launch()