def getres(wp, m, d, save_path): res = predict(wp, m, d) # preds.append(res) if res in ["", " "]: wp = wp.replace("IOS", "Android") res = predict(wp, m, d) if res in ["", " "]: wp = wp.replace("Android", "Recorder") res = predict(wp, m, d) with open(save_path, "a+") as fw: fw.write(",".join([wp, res + "\r\n"])) return res
def masr_recognize(audio_path): audio_files=os.listdir(audio_path) list_texts={} for path in audio_files: audio_file=os.path.join(audio_path,path) # text = model.predict(audio_file) text=beamdecode.predict(audio_file) list_texts[path]=text return list_texts
def recognize(): try: f = request.files["audio"] file_name = f.filename.replace('"', '').strip() fpath = os.path.join('save_audio', file_name) f.save(fpath) text = beamdecode.predict(fpath) return jsonify({'recognize text': text, 'code': 200, 'message': '成功'}) except Exception: return jsonify({ 'recognize text': '', 'code': 600, 'message': '识别过程有误!' })
def recognize(): f = request.files["file"] f.save("test.wav") return beamdecode.predict("test.wav")
import _init_path from models.conv import GatedConv import beamdecode model = GatedConv.load("../pretrained/gated-conv.pth") while 1: text = beamdecode.predict("test/123.wav") print("") print("识别结果:") print(text)