File size: 1,010 Bytes
4bad891
 
 
5cbdb9e
 
 
 
e95ce5b
5cbdb9e
d84fe22
 
5cbdb9e
95ce231
 
7ea1125
 
 
 
 
95ce231
 
 
 
 
 
 
 
 
7ea1125
95ce231
 
 
 
 
b023db4
5cbdb9e
d84fe22
5cbdb9e
d84fe22
95ce231
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
import os

import numpy as np
import gradio as gr
from transformers import pipeline


transcriber = pipeline(task="automatic-speech-recognition", model="geokanaan/Whisper_Base_Lebanese_Arabizi")

HF_TOKEN = os.getenv('WRITE')
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "flagged_Audio_Lebanese")

def transcribe(stream, new_chunk):
    sr, y = new_chunk
    
    # 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))

    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,
    title="UNDER MAINTENANCE",
    description="Realtime demo for Lebanese Arabizi speech recognition",
    allow_flagging='manual',  # Enable manual flagging
)

demo.launch()