Beispiel #1
0
        public static AudioFeature FromBytesCompressed(byte[] byteArray)
        {
            using (Stream stream = new MemoryStream(byteArray)) {
                Matrix mean           = Matrix.LoadBinary(stream);
                Matrix covarMatrix    = Matrix.LoadBinary(stream);
                Matrix covarMatrixInv = Matrix.LoadBinary(stream);
                stream.Flush();

                MandelEllis.GmmMe gmmme = new MandelEllis.GmmMe(mean, covarMatrix, covarMatrixInv);
                var mandelEllis         = new MandelEllis(gmmme);
                return(mandelEllis);
            }
        }
		public AudioFeature Calculate(double[] input)
		{
			//pack the mfccs into a pointlist
			double[][] mfccCoefficients = mfcc.Process(input);

			//check if element 0 exists
			if(mfccCoefficients.Length == 0)
				throw new ArgumentException("The input stream is to short to process;");

			//create mfcc matrix
			Matrix mfccs = new Matrix(mfccCoefficients);
			#if DEBUG
			mfccs.WriteText("mfccdata-mandelellis.txt");
			mfccs.DrawMatrixGraph("mfccdata-mandelellis.png");
			#endif

			// compute mean
			//Matrix mean = mfccs.Mean(1).Transpose();
			Matrix mean = mfccs.Mean(2);
			#if DEBUG
			mean.WriteText("mean-mandelellis.txt");
			mean.DrawMatrixGraph("mean-mandelellis.png");
			#endif
			
			// create covariance matrix
			Matrix covarMatrix = mfccs.Cov();
			#if DEBUG
			covarMatrix.WriteText("covariance-mandelellis.txt");
			covarMatrix.DrawMatrixGraph("covariance-mandelellis.png");
			#endif
			
			// Inverse Covariance
			Matrix covarMatrixInv;
			try {
				//covarMatrixInv = covarMatrix.Inverse();
				covarMatrixInv = covarMatrix.InverseGausJordan();
			} catch (Exception) {
				Console.Error.WriteLine("Mandel Ellis Extraction Failed!");
				return null;
			}
			#if DEBUG
			covarMatrixInv.WriteText("inverse_covariance-mandelellis.txt");
			covarMatrixInv.DrawMatrixGraph("inverse_covariance-mandelellis.png");
			#endif

			MandelEllis.GmmMe gmmMe = new MandelEllis.GmmMe(mean, covarMatrix, covarMatrixInv);
			MandelEllis mandelEllis = new MandelEllis(gmmMe);
			return mandelEllis;
		}
		public static AudioFeature FromBytesCompressed(byte[] byteArray)
		{
			using (Stream stream = new MemoryStream(byteArray)) {
				Matrix mean = Matrix.LoadBinary(stream);
				Matrix covarMatrix = Matrix.LoadBinary(stream);
				Matrix covarMatrixInv = Matrix.LoadBinary(stream);
				stream.Flush();
				
				MandelEllis.GmmMe gmmme = new MandelEllis.GmmMe(mean, covarMatrix, covarMatrixInv);
				var mandelEllis = new MandelEllis(gmmme);
				return mandelEllis;
			}
		}