File size: 1,572 Bytes
df2191f
022f864
 
df2191f
 
c872bc8
022f864
df2191f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bff0c13
df2191f
022f864
bff0c13
0d69e89
 
df2191f
c900926
0bb7d2e
ebcd408
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
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()