File size: 1,277 Bytes
e4406a3 3d1d87d e4406a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import sys
import time
from pathlib import Path
import csv
sys.path.append('/Users/jeqin/work/code/funasr_wrapper/build') # 添加编译生成的模块路径
sys.path.append('/Users/jeqin/work/code/funasr_wrapper/build/src') # 添加编译生成的模块路径
import funasr_py
def save_csv(file_path, rows):
with open(file_path, "w", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerows(rows)
print(f"write csv to {file_path}")
def main():
t0 = time.time()
config_file = "/Users/jeqin/work/code/funasr_wrapper/testpy/config.json"
asr = funasr_py.FunasrEasy(config_file)
# 初始化模型
asr.init()
t1 = time.time()
print("Initializing model: ", t1-t0)
audios = Path("/test_data/audio_clips/")
rows = [["file_name", "inference_time", "inference_result"]]
for audio in sorted(audios.glob("*s-ac1/Chinese*")):
print(audio)
t1 = time.time()
result = asr.infer(str(audio))
text = asr.get_text(result)
asr.free_result(result)
t = time.time() - t1
print("inference time:", t)
print(text)
rows.append([f"{audio.parent.name}/{audio.name}", t, text])
save_csv("csv/funasr_c.csv", rows)
if __name__ == '__main__':
main()
|