nemo_stt_kz_quartznet15x5 / transcribe.py
transiteration's picture
Update transcribe.py
3eff449 verified
raw
history blame
730 Bytes
import os
from pathlib import Path
import nemo.collections.asr as nemo_asr
# def converter(audio_file):
# converted = audio_file.split(".")[0] + "converted_.wav"
# cmd_str = f"ffmpeg -y -i {audio_file} -ac 1 -ar 16000 {converted}"
# os.system(cmd_str)
# # os.remove(audio_file)
# return converted
def transcribe(audio_file):
# wav_file = converter(audio_file)
try:
text = model_kz.transcribe([audio_file])
return text[0]
except:
return 'Try another file format.'
language = "kz"
BASE_DIR = Path(__file__).resolve(strict=True).parent
model_kz = nemo_asr.models.EncDecCTCModel.restore_from(restore_path=f"{BASE_DIR}/stt_{language}_quartznet15x5.nemo")