//matchfile 是数据库里取出的,注册声音的输出结果(txt文件) //inputfile是测试时输入的声音,outputfile是输出文件 //这个函数算出来的是【单个】测试声音和数据库里保存声音【处理后的】文件的距离的平均值,然后算出的匹配度。 public static double matchingDegree(String[] matchfile, String inputfile, String outputfile) { //这个是getMfcc的重载函数,Register.cs里用的是字符串数组为参数,这里是单个字符串为参数。 MFCC.getMfcc(inputfile, outputfile); int len = matchfile.Length; double distance = Dtw.getDtw(matchfile[0], outputfile); for (int i = 1; i < len; i++) { distance = distance + Dtw.getDtw(matchfile[i], outputfile); } distance = distance / len / 1.0; var credit = ((50 - distance) / 50.0) * 100; if (credit < 80) { credit = 0; } else if (credit > 100) { credit = 100; } else { credit = Math.Sqrt((credit - 80) / 20); } credit *= 100; return(credit); }
protected double[,] dtwpath = new double[DTWMAXNUM, DTWMAXNUM]; /*保存路径*/ public static double getDtw(String file1, String file2) { //定义2个数组a_d double[] a_data = new double[] { 0.0, 0.2, 0.4, 0.3, 0.2, 0.4, 0.4, 0.2, 0.4, 0.5, 0.2, 0.4, 5.0, 5.2, 8.4, 6.0, 5.2, 7.4, 4.0, 5.2, 4.4, 10.3, 10.4, 10.5, 10.1, 10.6, 10.7, 11.3, 10.2, 10.9 }; double[] b_data = new double[] { 0.1, 0.2, 0.4, 0.3, 0.2, 0.4, 0.4, 0.2, 0.4, 0.5, 0.2, 0.4, 5.0, 5.2, 8.4, 6.0, 5.2, 7.4, 4.0, 5.2, 4.4, 10.3, 10.4, 10.5, 10.1, 10.6, 10.7, 11.3, 10.2, 10.9 }; Dtw dtw = new Dtw(); //读mfcc数据文件到数组 int i = 0, j = 0, r; double[] a = null; double[] b = null; a = dtw.read_file(file1, ref i); if (a == null) { //Console.Write("error!\n"); return(-1); } b = dtw.read_file(file2, ref j); if (b == null) { //Console.Write("error!\n"); return(-1); } //Console.Write("i = " + i + "\n"); //Console.Write("j = " + j + "\n"); double ret1, ret2; r = Math.Min(i, j) / 30; //ret=DTWDistanceFun(a_data, 10, b_data, 10, 2); ret1 = dtw.DTWDistanceFun(a, i, b, j, r); //Console.Write("DTW distance = " + ret1 + "\n"); // ret2 = dtw.DTWDistanceFun(b, j, a, i, r); //Console.Write("DTW distance = " + ret2 + "\n"); //mvector av, bv; //ret=VDTWDistanceFun(a_data, 10, b_data, 10, 2); //printf("VDTW distance :%f\n", ret); return(ret1); }