大佬,流式的是怎么个思路啊
wyt1234 opened this issue · 1 comments
wyt1234 commented
大佬,流式的是怎么个思路啊
yeyupiaoling commented
Lines 64 to 85 in 6adb6a9
def real_time_predict_demo(): | |
state = None | |
result = [] | |
# 识别间隔时间 | |
interval_time = 1 | |
CHUNK = 16000 * interval_time | |
all_data = [] | |
# 读取数据 | |
wf = wave.open(args.wav_path, 'rb') | |
data = wf.readframes(CHUNK) | |
# 播放 | |
while data != b'': | |
all_data.append(data) | |
start = time.time() | |
score, text, state = predictor.predict_stream(audio_bytes=data, to_an=args.to_an, init_state_h_box=state) | |
result.append(text) | |
print("分段结果:消耗时间:%dms, 识别结果: %s, 得分: %d" % ((time.time() - start) * 1000, ''.join(result), score)) | |
data = wf.readframes(CHUNK) | |
all_data = b''.join(all_data) | |
start = time.time() | |
score, text, state = predictor.predict_stream(audio_bytes=all_data, to_an=args.to_an, is_end=True) | |
print("整一句结果:消耗时间:%dms, 识别结果: %s, 得分: %d" % ((time.time() - start) * 1000, text, score)) |