Spaces:
Runtime error
Runtime error
Add nemo inference code
Browse files
app.py
CHANGED
|
@@ -25,20 +25,20 @@ def process_audio_file(file):
|
|
| 25 |
return data
|
| 26 |
|
| 27 |
|
| 28 |
-
def transcribe(
|
| 29 |
warn_output = ""
|
| 30 |
-
if (
|
| 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 =
|
| 34 |
|
| 35 |
-
elif (
|
| 36 |
return "ERROR: You have to either use the microphone or upload an audio file"
|
| 37 |
|
| 38 |
-
elif
|
| 39 |
-
file =
|
| 40 |
else:
|
| 41 |
-
file =
|
| 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
|
| 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 |
)
|