smajumdar commited on
Commit
3ab0ef0
1 Parent(s): 75e1446

Add nemo inference code

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -25,20 +25,20 @@ def process_audio_file(file):
25
  return data
26
 
27
 
28
- def transcribe(file_mic, file_upload):
29
  warn_output = ""
30
- if (file_mic is not None) and (file_upload is not None):
31
  warn_output = "WARNING: You've uploaded an audio file and used the microphone. " \
32
  "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
33
- file = file_mic
34
 
35
- elif (file_mic is None) and (file_upload is None):
36
  return "ERROR: You have to either use the microphone or upload an audio file"
37
 
38
- elif file_mic is not None:
39
- file = file_mic
40
  else:
41
- file = file_upload
42
 
43
  audio_data = process_audio_file(file)
44
 
@@ -47,6 +47,7 @@ def transcribe(file_mic, file_upload):
47
  soundfile.write(audio_path, audio_data, SAMPLE_RATE)
48
 
49
  transcriptions = model.transcribe([audio_path])
 
50
  # if transcriptions form a tuple (from RNNT), extract just "best" hypothesis
51
  if type(transcriptions) == tuple and len(transcriptions) == 2:
52
  transcriptions = transcriptions[0]
@@ -63,8 +64,8 @@ iface = gr.Interface(
63
  outputs="text",
64
  layout="horizontal",
65
  theme="huggingface",
66
- title="NeMo Conformer Transducer Large",
67
- description="Demo for speech recognition using Conformers",
68
  enable_queue=True,
69
  allow_flagging=False,
70
  )
 
25
  return data
26
 
27
 
28
+ def transcribe(Microphone, File_Upload):
29
  warn_output = ""
30
+ if (Microphone is not None) and (File_Upload is not None):
31
  warn_output = "WARNING: You've uploaded an audio file and used the microphone. " \
32
  "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
33
+ file = Microphone
34
 
35
+ elif (Microphone is None) and (File_Upload is None):
36
  return "ERROR: You have to either use the microphone or upload an audio file"
37
 
38
+ elif Microphone is not None:
39
+ file = Microphone
40
  else:
41
+ file = File_Upload
42
 
43
  audio_data = process_audio_file(file)
44
 
 
47
  soundfile.write(audio_path, audio_data, SAMPLE_RATE)
48
 
49
  transcriptions = model.transcribe([audio_path])
50
+
51
  # if transcriptions form a tuple (from RNNT), extract just "best" hypothesis
52
  if type(transcriptions) == tuple and len(transcriptions) == 2:
53
  transcriptions = transcriptions[0]
 
64
  outputs="text",
65
  layout="horizontal",
66
  theme="huggingface",
67
+ title="NeMo Conformer Transducer Large - English",
68
+ description="Demo for English speech recognition using Conformer Transducers",
69
  enable_queue=True,
70
  allow_flagging=False,
71
  )