File size: 1,166 Bytes
eb937e4
a05267c
eb937e4
f0b2cfd
eb937e4
a05267c
 
e50284d
a05267c
 
eb937e4
 
07fa407
eb937e4
 
 
9844004
f0b2cfd
76e0282
a05267c
f0b2cfd
 
 
 
 
eb937e4
f0b2cfd
 
 
 
 
 
 
 
 
 
 
 
 
 
a05267c
f0b2cfd
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import logging
import warnings

import gradio as gr
from transformers import pipeline
from transformers.utils.logging import disable_progress_bar

warnings.filterwarnings("ignore")

disable_progress_bar()

logging.basicConfig(
    format="%(asctime)s [%(levelname)s] [%(name)s] %(message)s",
    datefmt="%Y-%m-%dT%H:%M:%SZ",
)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

pipe = pipeline(model="bofenghuang/asr-wav2vec2-ctc-french")
logger.info("ASR pipeline has been initialized")


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(server_name="0.0.0.0", debug=True, share=True)
iface.launch()