pgilles commited on
Commit
df2191f
1 Parent(s): ea94d6d

Create new file

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import librosa
2
+ import gradio as gr
3
+ #from transformers import Wav2Vec2Tokenizer, Wav2Vec2ForCTC
4
+ from transformers import pipeline
5
+
6
+ #Loading the model and the tokenizer
7
+ model_name = "unilux/wav2vec-xls-r-Luxembourgish20-with-LM"
8
+ pipe = pipeline("automatic-speech-recognition", model=model_name)
9
+
10
+ #tokenizer = Wav2Vec2Tokenizer.from_pretrained(model_name)
11
+ #model = Wav2Vec2ForCTC.from_pretrained(model_name)
12
+
13
+
14
+ def load_data(input_file):
15
+
16
+ """ Function for resampling to ensure that the speech input is sampled at 16KHz.
17
+ """
18
+ #read the file
19
+ speech, sample_rate = librosa.load(input_file)
20
+ #make it 1-D
21
+ if len(speech.shape) > 1:
22
+ speech = speech[:,0] + speech[:,1]
23
+ #Resampling at 16KHz since wav2vec2-base-960h is pretrained and fine-tuned on speech audio sampled at 16 KHz.
24
+ if sample_rate !=16000:
25
+ speech = librosa.resample(speech, sample_rate,16000)
26
+ return speech
27
+
28
+ def asr_pipe(input_file):
29
+ transcription = pipe(input_file, chunk_length_s=3, stride_length_s=(0.5, 0.5))
30
+ return transcription
31
+
32
+
33
+ gr.Interface(asr_pipe,
34
+ inputs = [
35
+ gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Hei kënnt Dir Är Sprooch iwwert de Mikro ophuelen"),
36
+ gr.inputs.Audio(source="upload", type='filepath', optional=True)
37
+ ],
38
+ outputs = gr.outputs.Textbox(label="Output Text"),
39
+ title="Sproocherkennung fir d'Lëtzebuergescht @uni.lu",
40
+ description = "Dës App convertéiert Är geschwate Sprooch an de (méi oder manner richegen ;-)) Text!",
41
+ examples = [["ChamberMeisch.wav"], ["Chamber_Fayot_2005.wav"]], theme="default").launch()
42
+