pgilles's picture
Update app.py
bff0c13
raw
history blame
1.57 kB
from transformers import pipeline
import gradio as gr
import librosa
#Loading the model and the tokenizer
model_name = "pgilles/wav2vec-xls-r-Luxembourgish20-with-LM"
p = pipeline("automatic-speech-recognition", model=model_name)
#tokenizer = Wav2Vec2Tokenizer.from_pretrained(model_name)
#model = Wav2Vec2ForCTC.from_pretrained(model_name)
def load_data(input_file):
""" Function for resampling to ensure that the speech input is sampled at 16KHz.
"""
#read the file
speech, sample_rate = librosa.load(input_file)
#make it 1-D
if len(speech.shape) > 1:
speech = speech[:,0] + speech[:,1]
#Resampling at 16KHz since wav2vec2-base-960h is pretrained and fine-tuned on speech audio sampled at 16 KHz.
if sample_rate !=16000:
speech = librosa.resample(speech, sample_rate,16000)
return speech
def asr_pipe(input_file):
transcription = p(input_file, chunk_length_s=3, stride_length_s=(1, 1))["text"]
return transcription
gr.Interface(asr_pipe,
inputs = gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Hei kënnt Dir Är Sprooch iwwert de Mikro ophuelen"),
outputs = gr.outputs.Textbox(label="Erkannten Text"),
title="Sproocherkennung fir d'Lëtzebuergescht @uni.lu",
description = "Dës App convertéiert Är geschwate Sprooch an de (méi oder manner richtegen ;-)) Text!",
examples = [["ChamberMeisch.wav"], ["Chamber_Fayot_2005.wav"], ["Erlieft-a-Verzielt.wav"], ["Schnessen_Beispill.wav"]], theme="default").launch()