private void speakButton_Click(object sender, EventArgs e)
        {
            string sentence = sentenceTextBox.Text;

            if (sentence != "")
            {
                speechVisualizer.MarkerList = new List <SoundMarker>();
                speechVisualizer.SetPitchPeriodSpecification(null);

                string voiceName = voiceSelectionComboBox.SelectedItem.ToString();
                speechSynthesizer.SetOutputToWaveFile("./tmpOutput.wav", new SpeechAudioFormatInfo(16000, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
                speechSynthesizer.Speak(sentence);
                speechSynthesizer.SetOutputToDefaultAudioDevice();
                speechSynthesizer.SelectVoice(voiceName);
                speechSynthesizer.Speak(sentence);
                currentSound = new WAVSound();
                currentSound.LoadFromFile("./tmpOutput.wav");

                double startTime = currentSound.GetFirstTimeAboveThreshold(0, 10, 20);
                double endTime   = currentSound.GetLastTimeAboveThreshold(0, 10, 20);
                currentSound = currentSound.Extract(startTime, endTime);
                speechVisualizer.SetRange(0, currentSound.GetDuration(), -32768, 32768);
                speechVisualizer.SetSound(currentSound);
                speechVisualizer.Invalidate();

                soundTypeIdentificationButton.Enabled = true;
                playSoundButton.Enabled            = true;
                modifySoundButton.Enabled          = true;
                saveSoundToolStripMenuItem.Enabled = true;
            }
        }
Beispiel #2
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);
        }