Example #1
0
        private void UpdateRow(TrainFilesCarrier.TrainFileRow row)
        {
            string file = VCDir.Instance.TrainDirAudio + row.Path;

            if (File.Exists(file))
            {
                _yourChanged = true;
                _yourPath    = file;
                _yourWav     = new WavFileWrapper(_yourPath);

                if (_yourWav.Load())
                {
                    _yourWav.NormalizeWave(1.0);
                    LogUtil.Info("Load Wave: {0}   -- OK\n", _yourPath);
                    option = VCContext.Instance.MFCCOptions;
                    if (option.ShiftSampleToZero)
                    {
                        LogUtil.Info("Shift Sample To Zero: --   -- OK\n");
                        _yourWav.ShifToZero();
                    }
                    waveViewer.WaveData = _yourWav.FullData;
                    waveViewer.FitToScreen();
                    _label = row.Word;
                    int size = _yourWav.FullData.Count;
                    _startSelected         = (float)row.Start / size;
                    _endSelected           = (float)row.End / size;
                    waveViewer.LeftSlider  = _startSelected;
                    waveViewer.RightSlider = _endSelected;
                }
            }
        }
        private void vadVoice(string path)
        {
            WavFileWrapper wav = new WavFileWrapper(path);

            if (wav.Load())
            {
                VadWrapper vad = new VadWrapper(wav);
                vad.UseEnergy(0.015f, 0.01f, true, 3, false);
                if (vad.Process(option.EnergyThreshold))
                {
                    float begin = 0;
                    float end   = 0;
                    uint  deta  = 0;
                    for (uint i = 0; i < vad.GetSizeOfSegment(); i++)
                    {
                        if (vad.GetEndSegment(i) - vad.GetStartSegment(i) > deta)
                        {
                            deta  = vad.GetEndSegment(i) - vad.GetStartSegment(i);
                            begin = (float)vad.GetStartSegment(i);
                            end   = (float)vad.GetEndSegment(i);
                        }
                    }
                    if (deta > 0)
                    {
                        int size = wav.FullData.Count;
                        _startSelected            = begin / size;
                        _endSelected              = end / size;
                        waveViewer.LeftSlider     = _startSelected;
                        waveViewer.RightSlider    = _endSelected;
                        waveViewer.ThresholdChart = (float)vad.ThresholdEnergy;
                        waveViewer.Chart          = vad.SmoothEnergies;
                    }
                }
            }
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            // WavFileWrapper wav = new WavFileWrapper(@"C:\Users\hungc\Desktop\Project\Binary\Voice Comparasion\Debug\Data\Test\sin100.wav"/*"C:\\Users\\hungc\\Desktop\\Project\\Binary\\TestExtractionLib\\Debug\\what_movies_have_you_seen_recently.wav"*/);
            WavFileWrapper wav    = new WavFileWrapper(@"C:\Users\hungc\Desktop\Project\Binary\TestExtraction\Debug\what_movies_have_you_seen_recently.wav");
            bool           result = wav.Load();

            wav.SelectedWave(11999, 12512);
            MFCCWrapper mfcc = new MFCCWrapper(wav, 512u, 0u, 20u, 0.0f, 8000.0f, 12u, 2);

            mfcc.Process();
            WaveViewerForm wavView = new WaveViewerForm();

            wavView.Data = wav.SelectedData;
            wavView.Show();
            LineChartForm chart = new LineChartForm(Object.Enum.FormTag.NONE);

            chart.MaxValue = (int)mfcc.Mfcc[0].Max() + 1;
            chart.MinValue = (int)mfcc.Mfcc[0].Min() - 1;
            chart.Data     = mfcc.Mfcc[0];
            chart.Show();
        }
Example #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            OptionWrapper.SetLog(false);
            WavFileWrapper wav    = new WavFileWrapper(@"C:\Users\hungc\Desktop\Project\Binary\Voice Comparasion\Debug\Data\Test\sin100.wav");
            bool           result = wav.Load();

            wav.SelectedWave(0, 20000);
            MFCCWrapper mfcc = new MFCCWrapper(wav, 0.015f, 0.005f, 18, 0.0f, 4000, 12, 2);

            mfcc.Process();

            MfccChartForm chart = new MfccChartForm(Object.Enum.FormTag.NONE);

            chart.Text = "MFCC";
            chart.Data = mfcc.Mfcc;
            chart.Show();

            /*
             * MfccChartForm chart2 = new MfccChartForm(Object.Enum.FormTag.NONE);
             * chart2.Text = "Bank Log";
             * chart2.Data = mfcc.BandFilter;
             * chart2.Show();
             *
             * MfccChartForm chart3 = new MfccChartForm(Object.Enum.FormTag.NONE);
             * chart3.Text = "FREQ";
             * chart3.Data = mfcc.Freq;
             * chart3.Show();
             *
             * MfccChartForm chart4 = new MfccChartForm(Object.Enum.FormTag.NONE);
             * chart4.Text = "Delta";
             * chart4.Data = mfcc.DetalMfcc;
             * chart4.Show();
             *
             * MfccChartForm chart5 = new MfccChartForm(Object.Enum.FormTag.NONE);
             * chart5.Text = "Double";
             * chart5.Data = mfcc.DoubleDetalMfcc;
             * chart5.Show();*/
        }
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            bool refpeak = false;

            if (rightChanged)
            {
                _refWav = new WavFileWrapper(refPath);
                //_refWav = new WavFileWrapper(@"C:\Users\Jimmy\Desktop\Human Voice Detector\HumanVoiceDetector\bin\Debug\Echo IVRresult_id=21774831&t=audio&r=1434196481.wav"); ;
                if (_refWav.Load())
                {
                    if (option.NormalizeAudio)
                    {
                        peakRef = _refWav.Peak();
                        refpeak = option.NormalizeAudio;
                    }
                    refmfcc = new MFCCWrapper(_refWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    refmfcc.Process();

                    refpitch = new PitchWrapper(_refWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        refpitch.SetMedianWindowSize(option.MedianWindow);
                    }

                    refpitch.Process();
                    rightChanged = false;
                    // Debug.WriteLine("Process Ref file completed Time {0}", DateTime.Now);
                }
            }
            if (refmfcc != null && refmfcc.ProcessDone)
            {
                SetDataChart(FormTag.REF_WAVE);
                //Debug.WriteLine("Process Ref: Draw Wave Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_FREQ);
                //Debug.WriteLine("Process Ref: Draw Freq Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_MFCC);
                //Debug.WriteLine("Process Ref: Draw MFCC Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DOUBLE);
                //Debug.WriteLine("Process Ref: Draw Double Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DETAL);
                //Debug.WriteLine("Process Ref: Draw Detal Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_PITCH);
                //Debug.WriteLine("Process Ref: Draw Pitch Done {0}", DateTime.Now);
            }

            //Debug.WriteLine("Set data chart Ref Ref Done {0}", DateTime.Now);


            if (leftChanged)
            {
                _yourWav = new WavFileWrapper(yourPath);

                if (_yourWav.Load())
                {
                    yourmfcc = new MFCCWrapper(_yourWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    if (refpeak)
                    {
                        _yourWav.NormalizeWave(peakRef);
                    }
                    yourmfcc.Process();

                    yourpitch = new PitchWrapper(_yourWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        yourpitch.SetMedianWindowSize(option.MedianWindow);
                    }
                    yourpitch.Process();
                    leftChanged = false;
                }
            }
            if (yourmfcc != null && yourmfcc.ProcessDone)
            {
                // TO DO: Process Bar
                SetDataChart(FormTag.YOUR_WAVE);
                SetDataChart(FormTag.YOUR_MFCC);
                SetDataChart(FormTag.YOUR_FREQ);
                SetDataChart(FormTag.YOUR_DOUBLE);
                SetDataChart(FormTag.YOUR_DETAL);
                SetDataChart(FormTag.YOUR_PITCH);
            }


            if (yourmfcc != null && refmfcc != null && yourmfcc.ProcessDone && refmfcc.ProcessDone)
            {
                // TO DO: Process Bar
                string log = string.Format("**********************************************************\nCompare : Your Path - {0}\n          Ref Path - {1}\n", yourPath, refPath);
                log += "Distance of 2 Vec Delta MFCC: ";

                double dis = DTWUtilWrapper.DistanceOf2Vector(yourmfcc.Mfcc, refmfcc.Mfcc, false);
                double fac = yourmfcc.Mfcc.Count > refmfcc.Mfcc.Count ? refmfcc.Mfcc.Count : yourmfcc.Mfcc.Count;
                double cos = dis / fac;

                log += string.Format("Dis MFCC: {0:0.###} Cos  {1:0.###} \n", cos, ScoreMath.Score(cos));
                // TO DO: Process Bar

                log += "Distance of 2 Vec Pitch: ";

                double resPitch = DTWUtilWrapper.DistanceOf2Vector(yourpitch.Pitchs, refpitch.Pitchs, true);
                double facD     = refpitch.Pitchs.Count > yourpitch.Pitchs.Count ? yourpitch.Pitchs.Count : refpitch.Pitchs.Count;
                double cosp     = resPitch / facD;
                log += string.Format("{0:0.###}  \n", cosp);

                List <double> res = DTWUtilWrapper.DistanceOf2Array3DHorizon(yourmfcc.Mfcc, refmfcc.Mfcc, false);
                _mfccViewer.MFCC = res;

                LogUtil.Info(log);
                ShowValueCostMFCC(string.Format("{0:0.###}", ScoreMath.Score(cos)));
                ShowValueCostPitch(string.Format("{0:0.###}", resPitch));
            }
        }
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            bool refpeak = false;

            if (_refChanged)
            {
                _refWav = new WavFileWrapper(refPath);

                if (_refWav.Load())
                {
                    _refMfcc = new MFCCWrapper(_refWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    if (option.NormalizeAudio)
                    {
                        refpeak = option.NormalizeAudio;
                        peakRef = _refWav.Peak();
                    }

                    _refMfcc.Process();

                    _refPitch = new PitchWrapper(_refWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        _refPitch.SetMedianWindowSize(option.MedianWindow);
                    }
                    _refPitch.Process();
                    /// Debug.WriteLine("Process Ref file completed Time {0}", DateTime.Now);
                }
            }
            if (_refMfcc != null && _refMfcc.ProcessDone)
            {
                SetDataChart(FormTag.REF_WAVE);
                Debug.WriteLine("Process Ref: Draw Wave Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_FREQ);
                Debug.WriteLine("Process Ref: Draw Freq Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_MFCC);
                Debug.WriteLine("Process Ref: Draw MFCC Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DOUBLE);
                Debug.WriteLine("Process Ref: Draw Double Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DETAL);
                Debug.WriteLine("Process Ref: Draw Detal Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_PITCH);
                Debug.WriteLine("Process Ref: Draw Pitch Done {0}", DateTime.Now);
            }

            Debug.WriteLine("Set data chart Ref Ref Done {0}", DateTime.Now);


            if (_yourChanged)
            {
                _yourWav = new WavFileWrapper(_yourPath);

                if (_yourWav.Load())
                {
                    int  size     = _yourWav.FullData.Count;
                    uint startPnt = (uint)(_startSelected * size);
                    uint endPnt   = (uint)(_endSelected * size);
                    Debug.WriteLine("Select Data voice: Start {0} End {1}", startPnt, endPnt);
                    _yourWav.SelectedWave(startPnt, endPnt);

                    if (refpeak)
                    {
                        _yourWav.NormalizeWave(peakRef);
                    }

                    _yourMfcc = new MFCCWrapper(_yourWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    _yourMfcc.Process();

                    _yourPitch = new PitchWrapper(_yourWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        _yourPitch.SetMedianWindowSize(option.MedianWindow);
                    }
                    _yourPitch.Process();
                }
            }

            if (_yourMfcc != null && _yourMfcc.ProcessDone)
            {
                // TO DO: Process Bar
                SetDataChart(FormTag.YOUR_WAVE);
                SetDataChart(FormTag.YOUR_MFCC);
                SetDataChart(FormTag.YOUR_FREQ);
                SetDataChart(FormTag.YOUR_DOUBLE);
                SetDataChart(FormTag.YOUR_DETAL);
                SetDataChart(FormTag.YOUR_PITCH);
            }

            if (_yourMfcc != null && _refMfcc != null && _yourMfcc.ProcessDone && _refMfcc.ProcessDone)
            {
                //// TO DO: Process Bar
                //string log = string.Format("\nCompare : Your Path - {0}\n          Ref Path - {1}\n", _yourPath, refPath);

                //// TO DO: Process Bar
                //log += "Distance of 2 Vec Pitch: ";
                //float resPitch = DTWUtilWrapper.DistanceOf2Vector(_yourPitch.Pitchs, _refPitch.Pitchs, true);
                //log += string.Format("{0:0.###}", resPitch);

                //// TO DO: Process Bar
                //log += "Compute DistanceOf2Array3DHorizon:";
                //List<float> res = DTWUtilWrapper.DistanceOf2Array3DHorizon(_yourMfcc.DetalMfcc, _refMfcc.DetalMfcc, true);
                //_mfccViewer.MFCC = res;


                //log += "Distance of 2 Vec Delta MFCC: ";
                //float resMFCC = DTWUtilWrapper.DistanceOf2Array3D(_yourMfcc.Mfcc, _refMfcc.Mfcc, true);

                //log += string.Format("{0:0.###}", resMFCC);

                ////float sum = 0.0f;
                ////for (int i = 0; i < res.Count; i++)
                ////{
                ////    log += string.Format("  {0}: {1}", i, res[i]);
                ////    sum += res[i];
                ////}
                ////ShowValueCostMFCC(string.Format("{0:0.###}", res / res.Count));
                //LogUtil.Info(log);

                ////ShowValueCostPitch(string.Format("{0:0.###}", resPitch));

                // TO DO: Process Bar
                string log = string.Format("**********************************************************\nCompare : Your Path - {0}\n          Ref Path - {1}\n", _yourPath, refPath);
                log += "Distance of 2 Vec Delta MFCC: ";
                //float resMFCC = DTWUtilWrapper.DistanceOf2Array3D(yourmfcc.Mfcc, refmfcc.Mfcc, true);
                double dis = DTWUtilWrapper.DistanceOf2Vector(_yourMfcc.Mfcc, _refMfcc.Mfcc, false);
                double fac = _yourMfcc.Mfcc.Count > _refMfcc.Mfcc.Count ? _refMfcc.Mfcc.Count : _yourMfcc.Mfcc.Count;
                double cos = dis / fac;
                //log += string.Format("Dis MFCC: {0:0.###} Score MFCC: {1:0.###}\n", 10 *dis / fac, -4.51297 * Math.Log10(-0.083653 * dis / fac + 1));
                log += string.Format("Dis MFCC: {0:0.###} Cos  {1:0.###} \n", cos, ScoreMath.Score(cos));
                // TO DO: Process Bar

                log += "Distance of 2 Vec Pitch: ";

                double resPitch = DTWUtilWrapper.DistanceOf2Vector(_yourPitch.Pitchs, _refPitch.Pitchs, true);
                double facD     = _refPitch.Pitchs.Count > _yourPitch.Pitchs.Count ? _yourPitch.Pitchs.Count : _refPitch.Pitchs.Count;
                double cosp     = resPitch / facD;
                log += string.Format("{0:0.###}  \n", cosp);


                // log += string.Format(" Score {0:0.###} {1:0.###} {2:0.###}  \n", );
                // TO DO: Process Bar
                //log += "Distance of Component MFCC:\n";
                List <double> res = DTWUtilWrapper.DistanceOf2Array3DHorizon(_yourMfcc.Mfcc, _refMfcc.Mfcc, false);
                _mfccViewer.MFCC = res;
                //for (int i = 0; i < res.Count; i++) {
                //	log += string.Format("  {0}: {1}\n", i, res[i]);
                //}

                LogUtil.Info(log);
                ShowValueCostMFCC(string.Format("{0:0.###}", ScoreMath.Score(cos)));

                ShowValueCostPitch(string.Format("{0:0.###}", resPitch));
            }
        }
Example #7
0
        public string Reg(string path, int start, int end)
        {
            if (_words == null || _words.Count == 0)
            {
                return(" Models Failed");
            }
            WavFileWrapper Wav = new WavFileWrapper(path);

            LogUtil.Info("*******************Reg*******************\n");
            LogUtil.Info("Load Wave: {0}\n", path);
            if (Wav.Load())
            {
                Wav.NormalizeWave(1.0f);
                LogUtil.Info("Load Wave: {0}   -- OK\n", path);
                if (VCContext.Instance.MFCCOptions.ShiftSampleToZero)
                {
                    LogUtil.Info("Shift Sample To Zero: --   -- OK\n");
                    Wav.ShifToZero();
                }

                Wav.SelectedWave((uint)start, (uint)end);

                MFCCWrapper           Mfcc = new MFCCWrapper(Wav, VCContext.Instance.MFCCOptions.TimeFrame, VCContext.Instance.MFCCOptions.TimeShift, VCContext.Instance.MFCCOptions.CepFilter, VCContext.Instance.MFCCOptions.LowFreq, VCContext.Instance.MFCCOptions.HighFreq, VCContext.Instance.MFCCOptions.NumCeps, 2);
                bool                  res  = Mfcc.Process();
                List <List <double> > data = null;
                if (res)
                {
                    switch (VCContext.Instance.MFCCOptions.TrainCofficientType)
                    {
                    case 0:
                        data = Mfcc.Mfcc;
                        break;

                    case 1:
                        data = Mfcc.DetalMfcc;
                        break;

                    case 2:
                        data = Mfcc.DoubleDetalMfcc;
                        break;

                    default:
                        data = Mfcc.Mfcc;
                        break;
                    }

                    LogUtil.Info("Load Wave: {0}   Process MFCC -- OK\n", path);
                    int    reg = 0;
                    double max = _models[reg].LogProbability(data);

                    LogUtil.Info("HModel = {0}  Log Value = {1}\n", _words[reg], max);
                    for (int i = 1; i < _models.Count; i++)
                    {
                        double cur = _models[i].LogProbability(data);
                        LogUtil.Info("HModel = {0}  Log Value = {1}\n", _words[i], cur);
                        if (max < cur)
                        {
                            max = cur;
                            reg = i;
                        }
                    }
                    LogUtil.Info("HModel = {0}  Log Value = {1}   Reg = {2}\n", _words[reg], max, _words[reg]);
                    return(_words[reg]);
                }
                else
                {
                    LogUtil.Info("Load Wave: {0}   -- FAILED\n", path);
                }
            }
            return("NONE");
        }
Example #8
0
        public bool Train()
        {
            _words  = new List <string>();
            _hmms   = new List <string>();
            _models = new List <HMMWrapper>();

            foreach (TrainFilesCarrier.TrainFileRow ent in tbEntry)
            {
                if (!_words.Contains(ent.Word))
                {
                    _words.Add(ent.Word);
                    LogUtil.Info("Word : {0}\n", ent.Word);
                }
            }

            foreach (string word in _words)
            {
                List <string> files = new List <string>();
                LogUtil.Info("List File  for Word : {0}\n", word);
                VCDir.CreateDirectory(VCDir.Instance.TrainDirMFCC + word);
                VCDir.CreateDirectory(VCDir.Instance.TrainDirHMM);
                foreach (TrainFilesCarrier.TrainFileRow ent in tbEntry)
                {
                    if (word.Equals(ent.Word))
                    {
                        string         audio = VCDir.Instance.TrainDirAudio + ent.Path;
                        string         mfcc  = VCDir.Instance.TrainDirMFCC + ent.Path;
                        WavFileWrapper Wav   = new WavFileWrapper(audio);

                        if (Wav.Load())
                        {
                            Wav.NormalizeWave(1.0f);
                            if (VCContext.Instance.MFCCOptions.ShiftSampleToZero)
                            {
                                Wav.ShifToZero();
                            }

                            Wav.SelectedWave((uint)ent.Start, (uint)ent.End);
                            MFCCWrapper Mfcc = new MFCCWrapper(Wav, VCContext.Instance.MFCCOptions.TimeFrame, VCContext.Instance.MFCCOptions.TimeShift, VCContext.Instance.MFCCOptions.CepFilter, VCContext.Instance.MFCCOptions.LowFreq, VCContext.Instance.MFCCOptions.HighFreq, VCContext.Instance.MFCCOptions.NumCeps, 2);
                            Mfcc.UserStandardization = VCContext.Instance.MFCCOptions.UseStandardization;

                            bool res = Mfcc.Process();
                            res &= Mfcc.SaveMFCC(mfcc + ".Mfcc" + ".xml");
                            res &= Mfcc.SaveDeltaMFCC(mfcc + ".Delta" + ".xml");
                            res &= Mfcc.SaveDoubleMFCC(mfcc + ".Double" + ".xml");
                            if (res)
                            {
                                switch (VCContext.Instance.MFCCOptions.TrainCofficientType)
                                {
                                case 0:
                                    files.Add(mfcc + ".Mfcc" + ".xml");
                                    break;

                                case 1:
                                    files.Add(mfcc + ".Delta" + ".xml");
                                    break;

                                case 2:
                                    files.Add(mfcc + ".Double" + ".xml");
                                    break;
                                }
                            }
                            LogUtil.Info("File : W - {0} Path - {1} MFCC process - {2}\n", ent.Word, VCDir.Instance.TrainDirMFCC + ent.Path + ".xml", (res) ? "Completed" : "Failed");
                        }
                    }
                }

                HMMWrapper hmm = new HMMWrapper(VCContext.Instance.MFCCOptions.TrainHMMState, VCContext.Instance.MFCCOptions.TrainGMMComponent, VCContext.Instance.MFCCOptions.TrainGMMCovVar);
                bool       ok  = hmm.Trainning(files);
                LogUtil.Info("Train word: {0}  - {1}\n", word, (ok)? "Completed": "Failed");
                if (ok)
                {
                    hmm.Save(VCDir.Instance.TrainDirHMM + word + ".xml");
                    _models.Add(hmm);
                    _hmms.Add(word + ".xml");
                    LogUtil.Info("Save {0} Model to {1}\n", word, VCDir.Instance.TrainDirHMM + word + ".xml");
                }
            }

            Save(VCDir.Instance.TrainXmlFile);
            return(true);
        }
Example #9
0
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            bool reg = (bool)e.Argument;

            if (_yourChanged)
            {
                _yourWav = new WavFileWrapper(_yourPath);

                if (_yourWav.Load())
                {
                    _yourWav.NormalizeWave(1.0);
                    option = VCContext.Instance.MFCCOptions;
                    LogUtil.Info("Load Wave: {0}   -- OK\n", _yourPath);
                    if (option.ShiftSampleToZero)
                    {
                        LogUtil.Info("Shift Sample To Zero: --   -- OK\n");
                        _yourWav.ShifToZero();
                    }

                    int  size     = _yourWav.FullData.Count;
                    uint startPnt = (uint)(_startSelected * size);
                    uint endPnt   = (uint)(_endSelected * size);
                    Debug.WriteLine("Select Data voice: Start {0} End {1}", startPnt, endPnt);
                    _yourWav.SelectedWave(startPnt, endPnt);

                    _yourMfcc = new MFCCWrapper(_yourWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    _yourMfcc.UserStandardization = option.UseStandardization;
                    _yourMfcc.Process();

                    _yourPitch = new PitchWrapper(_yourWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType, option.DropUnPitch);
                    if (option.UseMedian)
                    {
                        _yourPitch.SetMedianWindowSize(option.MedianWindow);
                    }
                    _yourPitch.Process();
                }
            }

            if (_yourMfcc != null && _yourMfcc.ProcessDone)
            {
                // TO DO: Process Bar
                SetDataChart(FormTag.YOUR_WAVE);
                SetDataChart(FormTag.YOUR_MFCC);
                SetDataChart(FormTag.YOUR_FREQ);
                SetDataChart(FormTag.YOUR_DOUBLE);
                SetDataChart(FormTag.YOUR_DETAL);
                SetDataChart(FormTag.YOUR_PITCH);
            }
            e.Result = reg;
            if (reg)
            {
                if (_yourMfcc != null)
                {
                    List <List <double> > data = null;

                    switch (VCContext.Instance.MFCCOptions.TrainCofficientType)
                    {
                    case 0:
                        data = _yourMfcc.Mfcc;
                        break;

                    case 1:
                        data = _yourMfcc.DetalMfcc;
                        break;

                    case 2:
                        data = _yourMfcc.DoubleDetalMfcc;
                        break;
                    }
                    Action act = new Action(() =>
                    {
                        reg_lb.Text = _trainTask.Reg(data);
                    });

                    Invoke(act);
                }
            }
        }
Example #10
0
        private void showWaveSound()
        {
            _yourWav = new WavFileWrapper(_yourPath);
            if (_yourWav.Load())
            {
                waveViewer.WaveData = _yourWav.FullData;
                waveViewer.FitToScreen();
                vadVoice();
                if (_regMode)
                {
                    uint size  = (uint)_yourWav.FullData.Count;
                    uint begin = (uint)(_startSelected * size);
                    uint end   = (uint)(_endSelected * size);
                    _yourWav.NormalizeWave(1.0f);
                    option = VCContext.Instance.MFCCOptions;
                    LogUtil.Info("Load Wave: {0}   -- OK\n", _yourPath);
                    if (option.ShiftSampleToZero)
                    {
                        LogUtil.Info("Shift Sample To Zero: --   -- OK\n");
                        _yourWav.ShifToZero();
                    }


                    Debug.WriteLine("Select Data voice: Start {0} End {1}", begin, end);
                    _yourWav.SelectedWave(begin, end);

                    _yourMfcc = new MFCCWrapper(_yourWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    _yourMfcc.UserStandardization = option.UseStandardization;


                    if (_yourMfcc != null && _yourMfcc.Process())
                    {
                        List <List <double> > data = null;

                        switch (VCContext.Instance.MFCCOptions.TrainCofficientType)
                        {
                        case 0:
                            data = _yourMfcc.Mfcc;
                            break;

                        case 1:
                            data = _yourMfcc.DetalMfcc;
                            break;

                        case 2:
                            data = _yourMfcc.DoubleDetalMfcc;
                            break;
                        }
                        Action act = new Action(() =>
                        {
                            reg_lb.Text = _trainTask.Reg(data);
                        });

                        Invoke(act);
                    }
                    else
                    {
                        MessageBox.Show(" Cant Extraction file {0}\n", _yourPath);
                    }
                }
            }
        }
Example #11
0
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            bool refpeak = false;

            if (refChanged)
            {
                _refWav = new WavFileWrapper(refPath);
                //_refWav = new WavFileWrapper(@"C:\Users\Jimmy\Desktop\Human Voice Detector\HumanVoiceDetector\bin\Debug\Echo IVRresult_id=21774831&t=audio&r=1434196481.wav"); ;
                if (_refWav.Load())
                {
                    refmfcc = new MFCCWrapper(_refWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    if (option.NormalizeAudio)
                    {
                        refpeak = option.NormalizeAudio;
                    }

                    refmfcc.Process();
                    refpitch = new PitchWrapper(_refWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType);
                    refpitch.Process();
                    // Debug.WriteLine("Process Ref file completed Time {0}", DateTime.Now);
                }
            }
            if (refmfcc != null && refmfcc.ProcessDone)
            {
                SetDataChart(FormTag.REF_WAVE);
                //Debug.WriteLine("Process Ref: Draw Wave Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_FREQ);
                //Debug.WriteLine("Process Ref: Draw Freq Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_MFCC);
                //Debug.WriteLine("Process Ref: Draw MFCC Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DOUBLE);
                //Debug.WriteLine("Process Ref: Draw Double Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_DETAL);
                //Debug.WriteLine("Process Ref: Draw Detal Done {0}", DateTime.Now);
                SetDataChart(FormTag.REF_PITCH);
                //Debug.WriteLine("Process Ref: Draw Pitch Done {0}", DateTime.Now);
            }

            Debug.WriteLine("Set data chart Ref Ref Done {0}", DateTime.Now);


            if (yourChanged)
            {
                _yourWav = new WavFileWrapper(yourPath);

                if (_yourWav.Load())
                {
                    yourmfcc = new MFCCWrapper(_yourWav, option.TimeFrame, option.TimeShift, option.CepFilter, option.LowFreq, option.HighFreq, option.NumCeps, 4);
                    if (widthWave != 0)
                    {
                        uint startPnt = (uint)((float)startSelected / widthWave * _yourWav.FullData.Count());
                        uint endPnt   = (uint)((float)endSelected / widthWave * _yourWav.FullData.Count());
                        _yourWav.SelectedWave(startPnt, endPnt);
                    }

                    if (refpeak)
                    {
                        _yourWav.NormalizeWave(peakRef);
                    }
                    yourmfcc.Process();

                    yourpitch = new PitchWrapper(_yourWav, option.PitchTimeFrame, option.PitchTimeShift, option.PitchLowFreq, option.PitchHighFreq, option.PitchType);
                    yourpitch.Process();
                }
            }
            if (yourmfcc != null && yourmfcc.ProcessDone)
            {
                // TO DO: Process Bar
                SetDataChart(FormTag.YOUR_WAVE);
                SetDataChart(FormTag.YOUR_MFCC);
                SetDataChart(FormTag.YOUR_FREQ);
                SetDataChart(FormTag.YOUR_DOUBLE);
                SetDataChart(FormTag.YOUR_DETAL);
                SetDataChart(FormTag.YOUR_PITCH);
            }


            if (yourmfcc != null && refmfcc != null && yourmfcc.ProcessDone && refmfcc.ProcessDone)
            {
                // TO DO: Process Bar
                string log = string.Format("\nCompare : Your Path - {0}\n          Ref Path - {1}\n", yourPath, refPath);
                log += "Distance of 2 Vec Delta MFCC: ";
                float resMFCC = DTWUtilWrapper.DistanceOf2Array3D(yourmfcc.Mfcc, refmfcc.Mfcc);
                ShowValueCostMFCC(string.Format("{0:0.###}", resMFCC));
                log += string.Format("{0:0.###}", resMFCC);
                // TO DO: Process Bar
                log += "Distance of 2 Vec Pitch: ";
                float resPitch = DTWUtilWrapper.DistanceOf2Vector(yourpitch.Pitchs, refpitch.Pitchs);
                log += string.Format("{0:0.###}", resPitch);

                // TO DO: Process Bar
                log += "Compute DistanceOf2Array3DHorizon:";
                List <float> res = DTWUtilWrapper.DistanceOf2Array3DHorizon(yourmfcc.Mfcc, refmfcc.Mfcc);
                _mfccViewer.MFCC = res;

                for (int i = 0; i < res.Count; i++)
                {
                    log += string.Format("  {0}: {1}", i, res[i]);
                }
                LogUtil.WriteLog(LogLevel.INFO, log);

                ShowValueCostPitch(string.Format("{0:0.###}", resPitch));
            }
        }