|
|
|
|
|
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() |
|
|
|