Spaces:
Runtime error
Runtime error
save file
Browse files- nemo_asr.py +16 -12
nemo_asr.py
CHANGED
|
@@ -4,19 +4,23 @@ import nemo.collections.asr as nemo_asr
|
|
| 4 |
|
| 5 |
|
| 6 |
def transcribe(file, modelName="stt_rw_conformer_transducer_large"):
|
| 7 |
-
with open(file.name, '
|
| 8 |
-
out_file = file.read() # async read
|
|
|
|
|
|
|
| 9 |
#out_file.write(content) # async write
|
| 10 |
-
print(out_file.name)
|
| 11 |
asr_model = nemo_asr.models.EncDecRNNTBPEModel.from_pretrained(
|
| 12 |
model_name=modelName)
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
# print("file loaded is **************",file.file)
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def transcribe(file, modelName="stt_rw_conformer_transducer_large"):
|
| 7 |
+
with open(file.name, 'wb') as out_file:
|
| 8 |
+
#out_file = file.read() # async read
|
| 9 |
+
content = file.read()
|
| 10 |
+
out_file.write(content)
|
| 11 |
#out_file.write(content) # async write
|
| 12 |
+
#print(out_file.name)
|
| 13 |
asr_model = nemo_asr.models.EncDecRNNTBPEModel.from_pretrained(
|
| 14 |
model_name=modelName)
|
| 15 |
+
# if not file.name.endswith("wav"):
|
| 16 |
+
# sound = AudioSegment.from_mp3(out_file.name)
|
| 17 |
+
# sound.export(out_file.name, format="wav")
|
| 18 |
+
# files = [out_file.name]
|
| 19 |
+
# pac.convert_wav_to_16bit_mono(out_file.name,out_file.name)
|
| 20 |
# print("file loaded is **************",file.file)
|
| 21 |
+
# for fname, transcription in zip(files, asr_model.transcribe(paths2audio_files=files)):
|
| 22 |
+
# print(f"Audio in {fname} was recognized as: {transcription}")
|
| 23 |
+
# print(transcription[0])
|
| 24 |
+
transcription= asr_model.transcribe([out_file.name])
|
| 25 |
+
print(transcription)
|
| 26 |
+
return {"text": transcription, "filename": out_file.name}
|