static float RecognizeAudio(string path, string svmModel) { SVMAudio mySVM = new SVMAudio(); mySVM.LoadSVMFromFile(svmModel); double[] y = AudioFeatures.load2(path); double[,] mfcc_mass = MFCC_calculating.MFCC_20_calculation(y); double[] features_vector = FeaturesFromMFCC(mfcc_mass); int features_size = 100; Image <Gray, float> features = new Image <Gray, float>(features_size, 1); Image <Gray, float> results = new Image <Gray, float>(1, 1); AudioFeatures.NormalizeFromFile(@"C:\Projeto\autoleitura\paulorenato\AudioCSharp\Modelo\scaleSVMTrain.txt", features_vector); for (int i = 0; i < features_size; i++) { features.Data[0, i, 0] = (float)features_vector[i]; } mySVM.Predict(features, results); return(results.Data[0, 0, 0]); }
public static double[][] getDataFromBase(String path, string fileName) { DirectoryInfo dir = new DirectoryInfo(path); DirectoryInfo[] subDirs = dir.GetDirectories(); double[][] data = new double[4125][]; int audioIndex = 0; //Salvar Características string file_full_path = Path.Combine(@"C:\Projeto\autoleitura\paulorenato\AudioCSharp\Caracteristicas", fileName); StreamWriter fileStream = new StreamWriter(file_full_path); foreach (DirectoryInfo sub in subDirs) { FileInfo[] files = sub.GetFiles("*.wav"); Console.WriteLine("Current working directory: " + sub.Name); foreach (FileInfo file in files) { data[audioIndex] = new double[101]; int featureIndex = 0; double[] y = load2(file.FullName); double[,] mfcc_mass = MFCC_calculating.MFCC_20_calculation(y); int count_frames = mfcc_mass.Length / 20; for (int i = 0; i < 20; i++) { double media = 0.0; double max = Double.MinValue; double min = Double.MaxValue; double[] values = new double[count_frames]; for (int k = 0; k < count_frames; k++) { if (mfcc_mass[k, i] < min) { min = mfcc_mass[k, i]; } if (mfcc_mass[k, i] > max) { max = mfcc_mass[k, i]; } media += mfcc_mass[k, i]; values[k] = mfcc_mass[k, i]; } media = media / count_frames; double variance = Variance(values, media); double mediana = GetMedian(values); data[audioIndex][featureIndex++] = mediana; data[audioIndex][featureIndex++] = media; data[audioIndex][featureIndex++] = variance; data[audioIndex][featureIndex++] = min; data[audioIndex][featureIndex++] = max; fileStream.Write(mediana.ToString("0.000000000", System.Globalization.CultureInfo.InvariantCulture) + ","); fileStream.Write(media.ToString("0.000000000", System.Globalization.CultureInfo.InvariantCulture) + ","); fileStream.Write(variance.ToString("0.00000000000", System.Globalization.CultureInfo.InvariantCulture) + ","); fileStream.Write(min.ToString("0.000000000", System.Globalization.CultureInfo.InvariantCulture) + ","); fileStream.Write(max.ToString("0.000000000", System.Globalization.CultureInfo.InvariantCulture) + ","); } data[audioIndex][featureIndex] = (double)int.Parse(sub.Name); fileStream.WriteLine(int.Parse(sub.Name)); fileStream.Flush(); audioIndex++; } } fileStream.Flush(); return(data); }