msis commited on
Commit
805f7ee
1 Parent(s): 216357c

adds mic or file

Browse files
Files changed (1) hide show
  1. app.py +45 -15
app.py CHANGED
@@ -5,18 +5,48 @@ model = nemo_asr.models.ASRModel.restore_from("CnLgGm025_SpeUni1024_DI_EATL.nemo
5
  model.eval()
6
 
7
 
8
- def transcribe(audio_file):
9
- # import speech_recognition as sr
10
- # r = sr.Recognizer()
11
- # with sr.AudioFile(audio_file) as source:
12
- # audio = r.record(source)
13
- # return r.recognize_google(audio)
14
- t = model.transcribe([audio_file])
15
- return t[0]
16
-
17
-
18
- gr.Interface(
19
- transcribe,
20
- inputs=gr.inputs.Audio(source="microphone", type="filepath"),
21
- outputs="text",
22
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  model.eval()
6
 
7
 
8
+ def transcribe(audio_mic, audio_file, models_names):
9
+ # transcribe audio_mic and audio_file separately
10
+ # because transcribe() fails is path is empty
11
+ transcription_mic = "\n".join(
12
+ [
13
+ f"{model_name} => {model.transcribe([audio_mic])[0]}"
14
+ for model_name in models_names
15
+ ]
16
+ if audio_mic
17
+ else ""
18
+ )
19
+ transcription_file = "\n".join(
20
+ [
21
+ f"{model_name} => {model.transcribe([audio_file])[0]}"
22
+ for model_name in models_names
23
+ ]
24
+ if audio_file
25
+ else ""
26
+ )
27
+ return transcription_mic, transcription_file
28
+
29
+
30
+ selection = ["a", "b", "c"]
31
+
32
+ demo = gr.Blocks()
33
+
34
+ with demo:
35
+ models_names = gr.CheckboxGroup(selection)
36
+ with gr.Row():
37
+ audio_mic = gr.Audio(source="microphone", type="filepath", label="Microphone")
38
+ audio_file = gr.Audio(source="upload", type="filepath", label="File")
39
+
40
+ with gr.Row():
41
+ output_mic = gr.TextArea(label="Microphone Transcription")
42
+ output_file = gr.TextArea(label="Audio Transcription")
43
+
44
+ b1 = gr.Button("Transcribe")
45
+
46
+ b1.click(
47
+ transcribe,
48
+ inputs=[audio_mic, audio_file, models_names],
49
+ outputs=[output_mic, output_file],
50
+ )
51
+
52
+ demo.launch()