中文语音评测之thchs30+gop_speechocean762实现

一 、thchs30中文模型训练

参见https://blog.csdn.net/wyw0000/article/details/125456902?spm=1001.2014.3001.5502
这里不详细叙述

二、拷贝一份gop_speechocean762

拷贝一份gop_speechocean762,命名为gop_chinese

三、拷贝lang、extractor和tdnn_sp到gop_chinese下

从thchs30目录下拷贝lang、extractor和tdnn_sp到gop_chinese下

cd gop_chinese
mkdir thchs30
cp -rf thchs30/data/lang thchs30
cp -rf thchs30/exp/nnet3/extractor thchs30
cp -rf thchs30/exp/nnet3/tdnn1a_sp thchs30/tdnn_sp 

修改run.sh

librispeech_eg=../thchs30
model=$librispeech_eg/tdnn_sp
ivector_extractor=$librispeech_eg/extractor
lang=$librispeech_eg/lang

三 、生成dict_nosp和lang_nosp

1 、从thchs30拷贝data/dict 到gop_chinese 的data/dict_nosp下 ,同时修改run.sh

 if [ $stage -le 6 ]; then
  # Prepare lang
  #local/prepare_dict.sh data/local/lexicon.txt data/local/dict_nosp

  utils/prepare_lang.sh --phone-symbol-table $lang/phones.txt \
    data/local/dict_nosp "<UNK>" data/local/lang_tmp_nosp data/lang_nosp
fi

2、 修改utils/prepare_lang.sh中的position_dependent_phones 为false

因为thchs30中文音素不像英文音素那样带有位置标识,如:_B、_I、_S、_E,故position_dependent_phones 设置成false

3、 修改run.sh 中的data/local/dict_nosp ""为data/local/dict_nosp “<SPOKEN_NOISE>”

四、准备评测数据

评测数据集仍然可以使用thch30,对于评测数据中的score.json可以借助于其他家成熟的评测接口跑thch30的数据,将评测结果转化的score.json的格式,再用score.json生成对应的text-phone,text-phone是按照词组进行切分的,一定要保证其音素与score.json是一致的,否则在训练gop模型的时候会报Unmatch错

五、修改run.sh脚本

由于thchs30的phones.txt序号0和1不是有效的音素,而2是a,是有效音素,故–skip-phones-string为0:1

#修改前
compute-gop --phone-map=data/lang_nosp/phone-to-pure-phone.int \
        --skip-phones-string=0:1:2 
#修改后
compute-gop --phone-map=data/lang_nosp/phone-to-pure-phone.int \
        --skip-phones-string=0:1 \

六、评测脚本c++改造

对于实际应用的语音评测场景来说,使用shell脚本肯定是不现实的,因为不能支持高并发。因此需要将脚本用c++重新实现一遍,实际上这个脚本干活的步骤也是c++实现的,只要找到每步对应的c++实现,组织到一起就可以完成c++的改造。我之前就是以这样的思路完成的,最近发现gop_speechocean762的作者张俊博大神已经实现了c++的版本,链接地址:https://github.com/jimbozhang/kaldi-gop

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
for Itr=1:Max_Itr for i=1:nop % Determin RSs and Search by LTs %-------------------------------------------------------- Rf=((i-1)/(nop-1))(RM-Rm)+Rm; Rd=norm(GOP-GTs(:,RKs(i))); Rs=Rf(Rf>=Rd)+Rd*(Rd>Rf); LTs_C=Create_LTs(No_LTs,Rs,Dim); LTs=repmat(GTs(:,RKs(i)),1,No_LTs)+LTs_C; LTs=SS(LTs,Par_Interval); %---------------- if Graphic_on==1 subplot(2,2,1) hold off pause(0.000001); plot(LTs(1,:),LTs(2,:),'x'); hold on ezplot(['(x-' num2str(GTs(1,RKs(i))) ')^2 + (y-' num2str(GTs(2,RKs(i))) ')^2 -' num2str(Rs^2)],[0 10],[0 10]); hold off xlim([Par_Interval(1,1) Par_Interval(1,2)]); ylim([Par_Interval(2,1) Par_Interval(2,2)]); pbaspect([1 1 1]) title('Local Search') xlabel('x_1') ylabel('x_2') end %---------------- LTs_Cost=Ev_Fcn(LTs,Fcn_Name); [L_min,L_inx]= min(LTs_Cost); if L_min<=LP_Cost(RKs(i)) LP(:,RKs(i))=LTs(:,L_inx); LP_Cost(RKs(i))=L_min; end if L_min<=GOP_Cost GOP_Cost=L_min; GOP=LTs(:,L_inx); end end % Search by GTs %-------------------------------------------------------- for i=1:nop GTs(:,i)=New_GT(GTs(:,i),LP(:,i),GOP,Lambda,Theta,Beta); GTs(:,i)=SS(GTs(:,i),Par_Interval); GTs_Cost(i)=Ev_Fcn(GTs(:,i),Fcn_Name); end % Ranking %-------------------------------------------------------- [Gts_Sorted,RKs]=sort(GTs_Cost); GOP_B=GTs(:,RKs(1)); GOP_Cost_B=Gts_Sorted(1); if GOP_Cost_B<=GOP_Cost GOP_Cost=GOP_Cost_B; GOP=GOP_B; end OP_Cost(Itr+1)=GOP_Cost; %---------------- if Graphic_on==1 subplot(2,2,2) hold off pause(.000001) plot(GTs(1,:),GTs(2,:),'*') hold on plot(GOP(1,:),GOP(2,:),'X','color','red') xlim([Par_Interval(1,1) Par_Interval(1,2)]); ylim([Par_Interval(2,1) Par_Interval(2,2)]); hold off pbaspect([1 1 1]*3) title('Global Search') xlabel('x_1') ylabel('x_2') end %---------------- %---------------- if Graphic_on==1 subplot(2,2,3) hold off pause(.000001) plot(OP_Cost(1:Itr+1)) pbaspect([2 1 1]) xlim([1 Max_Itr+1]) title(['Cost=' num2str(GOP_Cost,'%4.10f')]) xlabel('Iteration') ylabel('Cost') else hold off pause(.000001) plot(0:Itr,OP_Cost(1:Itr+1),'.','MarkerSize',15,'LineStyle','-','Color',[214 30 0]/255,'MarkerEdgeColor',[3 93 118]/255) pbaspect([2 1 1]) title(['Itr=' num2str(Itr) ', Cost=' num2str(GOP_Cost,'%4.10f')]) xlim([0 Max_Itr]) xlabel('Iteration') ylabel('Cost') end %---------------- end 把这段MATLAB代码转换为python代码
06-01
以下是将给定的MATLAB代码转换为Python代码的结果: ```python for Itr in range(1, Max_Itr + 1): for i in range(1, nop + 1): # Determine RSs and search by LTs # -------------------------------------------------------- Rf = ((i - 1) / (nop - 1)) * (RM - Rm) + Rm Rd = np.linalg.norm(GOP - GTs[:, RKs[i - 1]]) Rs = Rf[Rf >= Rd] + Rd * (Rd > Rf) LTs_C = Create_LTs(No_LTs, Rs, Dim) LTs = np.tile(GTs[:, RKs[i - 1]], (1, No_LTs)) + LTs_C LTs = SS(LTs, Par_Interval) # ---------------- if Graphic_on == 1: plt.subplot(2, 2, 1) plt.cla() plt.plot(LTs[0, :], LTs[1, :], 'x') plt.hold(True) ezplot('(x - %f)^2 + (y - %f)^2 - %f' % (GTs[0, RKs[i - 1]], GTs[1, RKs[i - 1]], Rs ** 2), [0, 10], [0, 10]) plt.hold(False) plt.xlim([Par_Interval[0, 0], Par_Interval[0, 1]]) plt.ylim([Par_Interval[1, 0], Par_Interval[1, 1]]) plt.gca().set_aspect('equal', adjustable='box') plt.title('Local Search') plt.xlabel('x_1') plt.ylabel('x_2') # ---------------- LTs_Cost = Ev_Fcn(LTs, Fcn_Name) L_min, L_inx = np.min(LTs_Cost), np.argmin(LTs_Cost) if L_min <= LP_Cost[RKs[i - 1]]: LP[:, RKs[i - 1]] = LTs[:, L_inx] LP_Cost[RKs[i - 1]] = L_min if L_min <= GOP_Cost: GOP_Cost = L_min GOP = LTs[:, L_inx] # Search by GTs # -------------------------------------------------------- for j in range(1, nop + 1): GTs[:, j - 1] = New_GT(GTs[:, j - 1], LP[:, j - 1], GOP, Lambda, Theta, Beta) GTs[:, j - 1] = SS(GTs[:, j - 1], Par_Interval) GTs_Cost[j - 1] = Ev_Fcn(GTs[:, j - 1], Fcn_Name) # Ranking # -------------------------------------------------------- Gts_Sorted = np.sort(GTs_Cost) RKs = np.argsort(GTs_Cost) GOP_B = GTs[:, RKs[0]] GOP_Cost_B = Gts_Sorted[0] if GOP_Cost_B <= GOP_Cost: GOP_Cost = GOP_Cost_B GOP = GOP_B OP_Cost[Itr] = GOP_Cost # ---------------- if Graphic_on == 1: plt.subplot(2, 2, 2) plt.cla() plt.plot(GTs[0, :], GTs[1, :], '*') plt.hold(True) plt.plot(GOP[0, :], GOP[1, :], 'X', color='red') plt.xlim([Par_Interval[0, 0], Par_Interval[0, 1]]) plt.ylim([Par_Interval[1, 0], Par_Interval[1, 1]]) plt.hold(False) plt.gca().set_aspect('equal', adjustable='box') plt.title('Global Search') plt.xlabel('x_1') plt.ylabel('x_2') # ---------------- if Graphic_on == 1: plt.subplot(2, 2, 3) plt.cla() plt.plot(OP_Cost[0:Itr + 1]) plt.gca().set_aspect('equal', adjustable='box') plt.xlim([1, Max_Itr + 1]) plt.title('Cost = %f' % GOP_Cost) plt.xlabel('Iteration') plt.ylabel('Cost') else: plt.cla() plt.plot(range(Itr + 1), OP_Cost[0:Itr + 1], '.', MarkerSize=15, LineStyle='-', Color=[214, 30, 0] / 255, MarkerEdgeColor=[3, 93, 118] / 255) plt.gca().set_aspect('equal', adjustable='box') plt.xlim([0, Max_Itr]) plt.title('Itr = %d, Cost = %f' % (Itr, GOP_Cost)) plt.xlabel('Iteration') plt.ylabel('Cost') # ---------------- plt.pause(0.0001) # -------------- # ---------------- ``` 需要注意的是,这里的代码仅为转换结果,因此无法保证代码正确性。您需要根据原始MATLAB代码和转换结果进行逐行比较,以确保转换结果的正确性。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值