import librosa import gradio as gr #from transformers import Wav2Vec2Tokenizer, Wav2Vec2ForCTC from transformers import pipeline #Loading the model and the tokenizer model_name = "unilux/wav2vec-xls-r-Luxembourgish20-with-LM" pipe = 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 = pipe(input_file, chunk_length_s=3, stride_length_s=(0.5, 0.5)) 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="Output Text"), title="Sproocherkennung fir d'Lëtzebuergescht @uni.lu", description = "Dës App convertéiert Är geschwate Sprooch an de (méi oder manner richegen ;-)) Text!", examples = [["ChamberMeisch.wav"], ["Chamber_Fayot_2005.wav"], ["Erlieft-a-Verzielt.wav"], ["Schnëssen-Beispill"]], theme="default").launch()