Exemplo n.º 1
0
        public List <SoundFeature> GetLPCAndCepstralSeries(string lpcNamePrefix, int lpcOrder, string cepstralNamePrefix, int cepstralOrder)
        {
            List <SoundFeature> lpcSoundFeatureList = new List <SoundFeature>();

            for (int ii = 0; ii < lpcOrder; ii++)
            {
                SoundFeature soundFeature = new SoundFeature();
                soundFeature.Name = lpcNamePrefix + (ii + 1).ToString(); // LPCs enumerated from 1.
                soundFeature.SetSize(frameList.Count);
                lpcSoundFeatureList.Add(soundFeature);
            }
            List <SoundFeature> cepstralSoundFeatureList = new List <SoundFeature>();

            for (int ii = 0; ii <= cepstralOrder; ii++)
            {
                SoundFeature soundFeature = new SoundFeature();
                soundFeature.Name = cepstralNamePrefix + ii.ToString();
                soundFeature.SetSize(frameList.Count);
                cepstralSoundFeatureList.Add(soundFeature);
            }
            List <double> lpcCoefficients = null;

            for (int iFrame = 0; iFrame < frameList.Count; iFrame++)
            {
                WAVSound frame = frameList[iFrame];
                lpcCoefficients = frame.ComputeLPCCoefficients(lpcOrder);
                for (int ii = 0; ii < lpcOrder; ii++)
                {
                    lpcSoundFeatureList[ii].ValueList[iFrame] = lpcCoefficients[ii];
                }
                List <double> cepstralCoefficients = frame.ComputeCepstralCoefficients(lpcCoefficients, cepstralOrder);
                for (int ii = 0; ii <= cepstralOrder; ii++)
                {
                    cepstralSoundFeatureList[ii].ValueList[iFrame] = cepstralCoefficients[ii];
                }
            }
            //
            // The first cepstral coefficient (c0) is equal to the (non-normalized) autocorrelation,
            // and can usually be removed in speech recognition (the autocorrelation is typically computed
            // elsewhere, as a separate feature).
            //
            // Moreover the second cepstral coefficient (c1) is identical to the first LPC coefficient,
            // and so can also be removed.
            //
            cepstralSoundFeatureList.RemoveAt(0); // Remove c0
            cepstralSoundFeatureList.RemoveAt(0); // Remove c1
            List <SoundFeature> soundFeatureList = new List <SoundFeature>();

            soundFeatureList.AddRange(lpcSoundFeatureList);
            soundFeatureList.AddRange(cepstralSoundFeatureList);
            return(soundFeatureList);
        }
        private void ShowTestSoundFeature(SoundFeature soundFeature)
        {
            featureComparisonPlotPanel.Clear();
            featureComparisonPlotPanel.VerticalAutoRange = true;
            DataSeries dataSeries = new DataSeries();

            dataSeries.Generate(soundFeature.Name, soundFeature.TimeList, soundFeature.ValueList);
            dataSeries.SetPointVisibilityState(true);
            dataSeries.SetPointConnectionState(true);
            dataSeries.SetLineColor(Color.Cyan);
            dataSeries.SetPointColor(Color.Blue);
            featureComparisonPlotPanel.AddDataSeries(dataSeries);
        }
Exemplo n.º 3
0
        //
        public SoundFeature GetRelativeNumberOfZeroCrossingsSeries(string name)
        {
            SoundFeature rnzcFeature = new SoundFeature();

            rnzcFeature.Name = name;
            rnzcFeature.SetSize(frameList.Count);
            for (int iFrame = 0; iFrame < frameList.Count; iFrame++)
            {
                WAVSound frame = frameList[iFrame];
                double   relativeNumberOfZeroCrossings = frame.GetRelativeNumberOfZeroCrossings(0); // 0 = channel index (again assuming mono).
                rnzcFeature.ValueList[iFrame] = relativeNumberOfZeroCrossings;
            }
            return(rnzcFeature);
        }
Exemplo n.º 4
0
        public IWRRecognitionResult RecognizeSingle(WAVSound sound)
        {
            // Compute the features of the current sound
            sound.SubtractMean();
            double startTime = sound.GetFirstTimeAboveThreshold(0, soundExtractionMovingAverageLength,
                                                                soundExtractionThreshold);
            double endTime = sound.GetLastTimeAboveThreshold(0, soundExtractionMovingAverageLength,
                                                             soundExtractionThreshold);
            WAVSound extractedInstance = sound.Extract(startTime, endTime);

            if (extractedInstance == null)
            {
                return(null);
            }                                               // 20170114
            extractedInstance.PreEmphasize(preEmphasisThresholdFrequency);
            WAVFrameSet frameSet = new WAVFrameSet(extractedInstance, frameDuration, frameShift);

            frameSet.ApplyHammingWindows(alpha);
            SoundFeatureSet     soundFeatureSet            = new SoundFeatureSet();
            List <SoundFeature> autoCorrelationFeatureList = frameSet.GetAutoCorrelationSeries("AutoCorrelation", autoCorrelationOrder);

            soundFeatureSet.FeatureList.AddRange(autoCorrelationFeatureList);
            List <SoundFeature> lpcAndCepstralFeatureList = frameSet.GetLPCAndCepstralSeries("LPC", lpcOrder, "Cepstral", cepstralOrder);

            soundFeatureSet.FeatureList.AddRange(lpcAndCepstralFeatureList);
            SoundFeature relativeNumberOfZeroCrossingsFeature = frameSet.GetRelativeNumberOfZeroCrossingsSeries("RNZC");

            soundFeatureSet.FeatureList.Add(relativeNumberOfZeroCrossingsFeature);

            soundFeatureSet.SetNormalizedTime();
            soundFeatureSet.Interpolate(numberOfValuesPerFeature);

            IWRRecognitionResult recognitionResult = new IWRRecognitionResult();

            recognitionResult.SoundFeatureSet = soundFeatureSet;
            if (averageSoundFeatureSetList != null)
            {
                foreach (SoundFeatureSet averageSoundFeatureSet in averageSoundFeatureSetList)
                {
                    double deviation = SoundFeatureSet.GetDeviation(averageSoundFeatureSet, soundFeatureSet, weightList);
                    string soundName = averageSoundFeatureSet.Information;
                    recognitionResult.DeviationList.Add(new Tuple <string, double>(soundName, deviation));
                }
                recognitionResult.DeviationList.Sort((a, b) => a.Item2.CompareTo(b.Item2));
            }
            return(recognitionResult);
        }
Exemplo n.º 5
0
        public List <SoundFeature> GetAutoCorrelationSeries(string namePrefix, int autoCorrelationOrder)
        {
            List <SoundFeature> soundFeatureList = new List <SoundFeature>();

            for (int ii = 0; ii < autoCorrelationOrder; ii++)
            {
                SoundFeature soundFeature = new SoundFeature();
                soundFeature.Name = namePrefix + (ii + 1).ToString(); // No reason to compute order 0 (=1).
                soundFeature.SetSize(frameList.Count);
                soundFeatureList.Add(soundFeature);
            }
            for (int iFrame = 0; iFrame < frameList.Count; iFrame++)
            {
                WAVSound      frame = frameList[iFrame];
                List <double> autoCorrelationCoefficients = frame.ComputeNormalizedAutoCorrelationCoefficients(1, autoCorrelationOrder);
                for (int ii = 0; ii < autoCorrelationOrder; ii++)
                {
                    soundFeatureList[ii].ValueList[iFrame] = autoCorrelationCoefficients[ii];
                }
            }
            return(soundFeatureList);
        }
        private void ShowComparisonSoundFeature(SoundFeature comparisonSoundFeature)
        {
            DataSeries dataSeries = new DataSeries();

            dataSeries.Generate(comparisonSoundFeature.Name, comparisonSoundFeature.TimeList, comparisonSoundFeature.ValueList);
            dataSeries.SetPointVisibilityState(true);
            dataSeries.SetPointConnectionState(true);
            dataSeries.SetLineColor(Color.Black);
            dataSeries.SetPointColor(Color.Red);
            List <double> verticalErrorBarList = new List <double>();

            for (int ii = 0; ii < comparisonSoundFeature.VarianceList.Count; ii++)
            {
                double standardDeviation = Math.Sqrt(comparisonSoundFeature.VarianceList[ii]);
                verticalErrorBarList.Add(standardDeviation);
            }
            dataSeries.AddSymmetricVerticalErrorBars(verticalErrorBarList);
            dataSeries.SetVerticalErrorBarSerifVisibilityState(true);
            dataSeries.SetErrorBarRelativeSerifLength(0.002);
            dataSeries.SetVerticalErrorBarsVisibilityState(true);
            featureComparisonPlotPanel.AddDataSeries(dataSeries);
        }
Exemplo n.º 7
0
        public void AppendSound(string name, List <WAVSound> instanceList)
        {
            List <SoundFeatureSet> soundFeatureSetList = new List <SoundFeatureSet>();

            // Compute the sound feature set for each instance
            foreach (WAVSound soundInstance in instanceList)
            {
                soundInstance.SubtractMean();
                double startTime = soundInstance.GetFirstTimeAboveThreshold(0, soundExtractionMovingAverageLength,
                                                                            soundExtractionThreshold);
                double endTime = soundInstance.GetLastTimeAboveThreshold(0, soundExtractionMovingAverageLength,
                                                                         soundExtractionThreshold);
                WAVSound extractedInstance = soundInstance.Extract(startTime, endTime);
                extractedInstance.PreEmphasize(preEmphasisThresholdFrequency);
                WAVFrameSet frameSet = new WAVFrameSet(extractedInstance, frameDuration, frameShift);
                frameSet.ApplyHammingWindows(alpha);
                SoundFeatureSet     soundFeatureSet            = new SoundFeatureSet();
                List <SoundFeature> autoCorrelationFeatureList = frameSet.GetAutoCorrelationSeries("AutoCorrelation", autoCorrelationOrder);
                soundFeatureSet.FeatureList.AddRange(autoCorrelationFeatureList);
                List <SoundFeature> lpcAndCepstralFeatureList = frameSet.GetLPCAndCepstralSeries("LPC", lpcOrder, "Cepstral", cepstralOrder);
                soundFeatureSet.FeatureList.AddRange(lpcAndCepstralFeatureList);
                SoundFeature relativeNumberOfZeroCrossingsFeature = frameSet.GetRelativeNumberOfZeroCrossingsSeries("RNZC");
                soundFeatureSet.FeatureList.Add(relativeNumberOfZeroCrossingsFeature);

                soundFeatureSet.SetNormalizedTime();
                soundFeatureSet.Interpolate(numberOfValuesPerFeature);
                soundFeatureSetList.Add(soundFeatureSet);
            }
            SoundFeatureSet averageSoundFeatureSet = SoundFeatureSet.GenerateAverage(soundFeatureSetList);

            averageSoundFeatureSet.Information = name; // The name of the stored sound.
            if (averageSoundFeatureSetList == null)
            {
                averageSoundFeatureSetList = new List <SoundFeatureSet>();
            }
            averageSoundFeatureSetList.Add(averageSoundFeatureSet);
            averageSoundFeatureSetList.Sort((a, b) => a.Information.CompareTo(b.Information)); // Perhaps remove?
            OnAvailableSoundsChanged();
        }
        private void ShowTestSoundAndComparisonFeatures()
        {
            featureComparisonPlotPanel.Clear();
            int selectedFeatureIndex = featureComparisonComboBox.SelectedIndex;
            // Plot the feature values from the test sound:
            SoundFeature soundFeature = recognitionResult.SoundFeatureSet.FeatureList[selectedFeatureIndex];

            ShowTestSoundFeature(soundFeature);

            // A bit ugly, but OK...
            if (deviationListBox.SelectedIndex >= 0)
            {
                string selectedComparisonSound =
                    deviationListBox.Items[deviationListBox.SelectedIndex].ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];

                SoundFeatureSet comparisonSoundFeatureSet = recognizer.AverageSoundFeatureSetList.Find(s => s.Information == selectedComparisonSound);
                if (comparisonSoundFeatureSet != null)  // Should always be the case...
                {
                    SoundFeature comparisonSoundFeature = comparisonSoundFeatureSet.FeatureList[selectedFeatureIndex];
                    ShowComparisonSoundFeature(comparisonSoundFeature);
                }
            }
        }
        private void AppendFeatureSeries(int selectedSoundIndex, int selectedFeatureIndex)
        {
            SoundFeature averageSoundFeature = recognizer.AverageSoundFeatureSetList[selectedSoundIndex].FeatureList[selectedFeatureIndex];
            string       featureName         = averageSoundFeature.Name;
            DataSeries   dataSeries          = new DataSeries();

            dataSeries.Generate(featureName, averageSoundFeature.TimeList, averageSoundFeature.ValueList);
            dataSeries.SetPointVisibilityState(true);
            dataSeries.SetPointConnectionState(true);
            dataSeries.SetLineColor(Color.Black);
            dataSeries.SetPointColor(Color.Red);
            List <double> verticalErrorBarList = new List <double>();

            for (int ii = 0; ii < averageSoundFeature.VarianceList.Count; ii++)
            {
                double standardDeviation = Math.Sqrt(averageSoundFeature.VarianceList[ii]);
                verticalErrorBarList.Add(standardDeviation);
            }
            dataSeries.AddSymmetricVerticalErrorBars(verticalErrorBarList);
            dataSeries.SetVerticalErrorBarSerifVisibilityState(true);
            dataSeries.SetErrorBarRelativeSerifLength(0.002);
            featurePlotPanel.AddDataSeries(dataSeries);
        }