【语音AI】识别结果格式转换
TXT转换为MLF脚本
- src2mlf.py
#-*- coding:utf-8 -*- import os,sys def to_mlf(xi): dx={ "0":"零", "1":"一", "2":"二", "3":"三", "4":"四", "5":"五", "6":"六", "7":"七", "8":"八", "9":"九" }; d=[] eng=[] tx=[",",".","!","(",")",",","。","!",';','、',':','?','“','”']; for x in xi: u=x.encode("utf-8") if u in tx: continue; if len(u)==1: if u in dx: u=dx[u] eng.append(str(u, encoding='utf-8')) else: if len(eng)>0: d.append("".join(eng).upper()) eng=[] d.append(str(u, encoding='utf-8')) if len(eng)>0: d.append("".join(eng).upper()) return d def fn_to_lab(s): x=s.split() for i in x: d=to_mlf(i.strip()) if len(d)>0: print("\n".join(d)) print('.') fn=sys.argv[1] print('#!MLF!#') for l in open(fn): l=l.strip() x=l.split() k=x[0].strip() v=" ".join(x[1:]) t=".".join(k) print('"*No%s.lab" ' % t) fn_to_lab(v)
将源文件src.txt和测试结果testResult.txt通过此文件转成mlf格式的文件
Note:
1.此脚本是将测试用例转为src.mlf
2.如需将测试结果testResult.txt 转testResult.mlf,则拷贝一份如 rec2mlf.py,改第53行的关键字lab为rec即可。
- 脚本使用
1 python src2mlf.py src.txt >src.mlf 2 python rec2mlf.py testResult.txt >testResult.mlf
----保持谦虚保持清醒