Beispiel #1
0
        static void Main(string[] args)
        {
            string pathWave = @"C:\temp\google.wav";

            //google traductor
            var textospeech = new TextToSpeech("en");

            using (Task <Stream> audioStream = textospeech.DownloadAsStream("This is my tshirt"))
            {
                audioStream.Wait();
                if (audioStream.IsCompleted)
                {
                    using (audioStream.Result)
                    {
                        //stream from google to wav file
                        WaveConverter.ConvertMp3ToWav(audioStream.Result, pathWave);
                    }
                }
            }

            //audio movil
            string pathAudioMovilWave = @"C:\temp\Tshirt.wav";
            string pathAudioMovil     = @"C:\temp\Tshirt.m4a";

            WaveConverter.ConvertA4MToWav(pathAudioMovil, pathAudioMovilWave);

            var m_Wavefile = new WaveSound(pathWave); //wave from google

            m_Wavefile.ReadWaveFile();
            var waveFile2 = new WaveSound(pathAudioMovilWave); //wave from user

            waveFile2.ReadWaveFile();
            var result = m_Wavefile.Compare(waveFile2);

            Utils.CleanFiles(pathWave, pathAudioMovilWave);

            Console.WriteLine("Similar:" + result.ToString() + " %");
            Console.ReadLine();
        }
Beispiel #2
0
        /// <summary>Compare its wave sound to the given sound by applying FFT algorithm.</summary>
        /// <param name="wf">The wave sound that is used to compare with its own wave sound</param>
        /// <returns>percentage of similarity</returns>
        public float Compare(WaveSound wf)
        {
            int nbcorrect = 0;
            int i         = 0;

            bool endfile = false;
            int  a = 0, b = 0;

            float[] frames = new float[nbframe > wf.nbframe ? nbframe : wf.nbframe];
            comparedFrame = nbframe < wf.nbframe ? nbframe : wf.nbframe;
            short[] MissPlay = new short[comparedFrame];
            int     step     = 0;

            // Open FFT file
            using (BinaryReader f1 = new BinaryReader(File.Open(filename + ".fft.dat", FileMode.Open)))
                using (BinaryReader f2 = new BinaryReader(File.Open(wf.filename + ".fft.dat", FileMode.Open)))
                {
                    while (!endfile)
                    {
                        try
                        {
                            a = f1.ReadInt16();
                            b = f2.ReadInt16();
                            if (i == 49)
                            {
                            }
                            if (a == -9999 || b == -9999)
                            {
                                // Calculate the value for 1 frame
                                frames[i] = (float)nbcorrect / (fftPoint / 2);
                                i++;
                                nbcorrect = 0;
                            }
                            else
                            {
                                if (Math.Abs(a - b) <= 10)
                                {
                                    nbcorrect++;
                                }
                            }
                        }
                        catch
                        {
                            endfile = true;
                            f1.Close();
                            f2.Close();
                        }
                    }

                    nbcorrect = 0;
                    int idx = 0;
                    int len = comparedFrame;
                    comparedFrame = 0;

                    for (i = 0; i < len; i++)
                    {
                        nbcorrect += frames[i] >= 0.7 ? 1 : 0;
                        if (frames[i] < 0.7)
                        {
                            MissPlay[idx] = (short)i;
                            idx           = idx + 1;
                            comparedFrame++;
                        }
                    }

                    f1.Close();
                    f2.Close();
                    for (i = 0; i < comparedFrame; i++)
                    {
                        missData = missData + MissPlay[i] + ";";
                    }
                }


            return((float)(nbcorrect * 100 / frames.Length));
        }