pgilles commited on
Commit
022f864
1 Parent(s): c900926

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -1,11 +1,10 @@
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 = "pgilles/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)
@@ -26,13 +25,24 @@ def load_data(input_file):
26
  return speech
27
 
28
  def asr_pipe(input_file):
29
- transcription = pipe(input_file, chunk_length_s=3, stride_length_s=(1, 1))
30
  return transcription
31
 
32
-
33
- gr.Interface(asr_pipe,
34
- inputs = gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Hei kënnt Dir Är Sprooch iwwert de Mikro ophuelen"),
35
- outputs = gr.outputs.Textbox(label="Output Text"),
 
 
 
 
 
 
 
 
 
 
 
36
  title="Sproocherkennung fir d'Lëtzebuergescht @uni.lu",
37
  description = "Dës App convertéiert Är geschwate Sprooch an de (méi oder manner richtegen ;-)) Text!",
38
  examples = [["ChamberMeisch.wav"], ["Chamber_Fayot_2005.wav"], ["Erlieft-a-Verzielt.wav"], ["Schnessen_Beispill.wav"]], theme="default").launch()
 
 
 
 
1
  from transformers import pipeline
2
+ import gradio as gr
3
+ import librosa
4
 
5
  #Loading the model and the tokenizer
6
  model_name = "pgilles/wav2vec-xls-r-Luxembourgish20-with-LM"
7
+ p = pipeline("automatic-speech-recognition", model=model_name)
8
 
9
  #tokenizer = Wav2Vec2Tokenizer.from_pretrained(model_name)
10
  #model = Wav2Vec2ForCTC.from_pretrained(model_name)
 
25
  return speech
26
 
27
  def asr_pipe(input_file):
28
+ transcription = p(input_file, chunk_length_s=3, stride_length_s=(1, 1))
29
  return transcription
30
 
31
+ def transcribe(audio, state=""):
32
+ #time.sleep(2)
33
+ text = p(audio)["text"]
34
+ state += text + " "
35
+ return state, state
36
+
37
+ gr.Interface(transcribe,
38
+ inputs = [
39
+ gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Hei kënnt Dir Är Sprooch iwwert de Mikro ophuelen"),
40
+ "state"
41
+ ],
42
+ outputs = [
43
+ gr.outputs.Textbox(label="Erkannten Text"),
44
+ "state"
45
+ ],
46
  title="Sproocherkennung fir d'Lëtzebuergescht @uni.lu",
47
  description = "Dës App convertéiert Är geschwate Sprooch an de (méi oder manner richtegen ;-)) Text!",
48
  examples = [["ChamberMeisch.wav"], ["Chamber_Fayot_2005.wav"], ["Erlieft-a-Verzielt.wav"], ["Schnessen_Beispill.wav"]], theme="default").launch()