rutsam commited on
Commit
c91f24a
1 Parent(s): 71c3608
Files changed (1) hide show
  1. 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, 'rb') as out_file:
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
- if not file.name.endswith("wav"):
14
- sound = AudioSegment.from_mp3(out_file.name)
15
- sound.export(out_file.name, format="wav")
16
- files = [out_file.name]
17
- pac.convert_wav_to_16bit_mono(out_file.name,out_file.name)
18
  # print("file loaded is **************",file.file)
19
- for fname, transcription in zip(files, asr_model.transcribe(paths2audio_files=files)):
20
- print(f"Audio in {fname} was recognized as: {transcription}")
21
- print(transcription[0])
22
- return {"text": transcription[0], "filename": file.filename}
 
 
 
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}