public override WAVSound GenerateWordSequence(List <string> wordList, List <double> silenceList)
        {
            List <WAVSound> wordSoundList = new List <WAVSound>();

            foreach (string word in wordList)
            {
                WAVSound wordSound = GenerateWord(word);
                if (wordSound != null)
                {
                    wordSoundList.Add(wordSound);
                }
            }
            if (silenceList.Count > wordList.Count)
            {
                while (silenceList.Count > wordList.Count)
                {
                    silenceList.RemoveAt(silenceList.Count - 1);
                }                                                                                            // The silence list must not be longer than the wordlist.
            }
            WAVSound wordSequenceSound = null;

            if (wordSoundList.Count > 0)
            {
                wordSequenceSound = WAVSound.Join(wordSoundList, silenceList);
            }

            //    WAVSound wordSequenceSound = WAVSound.Join(wordSoundList, silenceList);
            return(wordSequenceSound);
        }
        public override WAVSound GenerateWord(string word)
        {
            int      wordIndex = wordToSoundMappingList.FindIndex(m => m.Word == word);
            WAVSound wordSound = null;

            if (wordIndex >= 0)
            {
                WordToSoundMapping wordToSoundMapping = wordToSoundMappingList[wordIndex];
                List <WAVSound>    wavSoundList       = new List <WAVSound>();
                foreach (string soundName in wordToSoundMapping.SoundNameList)
                {
                    FormantSpecification formantSpecification = SpecificationList.Find(s => s.Name == soundName);
                    if (formantSpecification != null)
                    {
                        formantSpecification.GenerateSettingsSequence();
                        WAVSound sound = GenerateSound(formantSpecification);
                        wavSoundList.Add(sound);
                    }
                }
                if (wavSoundList.Count > 0)
                {
                    wordSound = WAVSound.Join(wavSoundList, null);
                }
            }
            return(wordSound);
        }
Пример #3
0
        public virtual SpeechType GetFrameSpeechType(WAVSound frame)
        // , int channel, double lowPassCutoffFrequency, double lowPassRatioThreshold,
        //                                 double energyThreshold, double silenceThreshold)
        {
            double zeroCrossingRate = frame.GetRelativeNumberOfZeroCrossings(channel);
            double averageEnergy    = frame.GetAverageEnergy(channel);

            if (averageEnergy < silenceThreshold)
            {
                return(SpeechType.Silence);
            }
            else
            {
                WAVSound lowPassFilteredFrame = frame.Copy();
                lowPassFilteredFrame.LowPassFilter(lowPassCutoffFrequency);
                double lowPassFilteredAverageEnergy = lowPassFilteredFrame.GetAverageEnergy(channel);
                double energyRatio = lowPassFilteredAverageEnergy / averageEnergy;
                if ((energyRatio > lowPassRatioThreshold) && (averageEnergy > energyThreshold) && (zeroCrossingRate < zeroCrossingRateThreshold))
                {
                    return(SpeechType.Voiced);
                }
                else if (zeroCrossingRate < zeroCrossingRateThreshold)
                {
                    return(SpeechType.Voiced);
                }
                else
                {
                    return(SpeechType.Unvoiced);
                }
            }
        }
        private void modifySoundButton_Click(object sender, EventArgs e)
        {
            speechVisualizer.MarkerList = new List <SoundMarker>();

            speechModifier.TopFraction = double.Parse(topFractionTextBox.Text);
            double  relativeStartPitch = double.Parse(relativeStartPitchTextBox.Text);
            double  relativeEndPitch   = double.Parse(relativeEndPitchTextBox.Text);
            Boolean adjustDuration     = Boolean.Parse(adjustDurationComboBox.SelectedItem.ToString());
            double  relativeDuration   = double.Parse(relativeDurationTextBox.Text); // Only relevant if adjustDuration = true.

            WAVSound modifiedSound = speechModifier.Modify(currentSound, relativeStartPitch, relativeEndPitch, adjustDuration, relativeDuration);


            //   modifiedSound.MedianFilter(5);
            //  modifiedSound.LowPassFilter(1500);
            //  modifiedSound.SetMaximumNonClippingVolume();

            //   modifiedSound.SetMaximumNonClippingVolume();
            SoundPlayer soundPlayer = new SoundPlayer();

            modifiedSound.GenerateMemoryStream();
            modifiedSound.WAVMemoryStream.Position = 0; // Manually rewind stream
            soundPlayer.Stream = null;
            soundPlayer.Stream = modifiedSound.WAVMemoryStream;
            soundPlayer.PlaySync();
            speechVisualizer.SetRange(0, modifiedSound.GetDuration(), -32768, 32768);
            speechVisualizer.SetPitchPeriodSpecification(null);
            speechVisualizer.SetSound(modifiedSound);

            currentSound = modifiedSound.Copy();

            soundTypeIdentificationButton.Enabled = true;
            findPitchPeriodsButton.Enabled        = false;
            findPitchMarksButton.Enabled          = false;
        }
Пример #5
0
        private void addButton_Click(object sender, EventArgs e)
        {
            string          soundName     = soundNameTextBox.Text;
            List <WAVSound> soundList     = new List <WAVSound>();
            List <string>   selectedFiles = new List <string>();

            foreach (int checkedIndex in soundListListView.CheckedIndices)
            {
                selectedFiles.Add(files[checkedIndex]);
            }
            foreach (string file in selectedFiles)
            {
                WAVSound sound = new WAVSound();
                sound.LoadFromFile(file);
                soundList.Add(sound);
            }
            if (recognizer.ContainsSound(soundName))
            {
                if (MessageBox.Show("Overwrite existing instance?", "Sound available", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    recognizer.RemoveSound(soundName);
                    recognizer.AppendSound(soundName, soundList);
                }
            }
            else
            {
                recognizer.AppendSound(soundName, soundList);
            }
        }
        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;
            }
        }
Пример #7
0
        public void SetSound(WAVSound sound)
        {
            this.sound = sound;
            if (sound == null)
            {
                Refresh();
                return;
            }
            SetRange(0, sound.GetDuration(), -32768, 32768);
            horizontalTickMarkList = new List <double>();
            if (!pitchPanelVisible)
            {
                soundPanelFraction = 1;
            }
            nominalTopPanelHeight = (int)Math.Round(soundPanelFraction * this.Height);
            soundPanelHeight      = nominalTopPanelHeight - dividerHeight;
            pitchPanelHeight      = this.Height - soundPanelHeight - dividerHeight;
            double tickMarkPosition = xMin;

            while (tickMarkPosition <= xMax)
            {
                horizontalTickMarkList.Add(tickMarkPosition);
                tickMarkPosition += tickMarkSpacing;
            }
            this.zoomLevel   = 1;
            scrollbarVisible = false;
            PlotSoundAndPitch();
        }
Пример #8
0
        public void FindSpeechTypeVariation(WAVSound sound)
        // , int channel, double frameDuration, double frameShift,
        //                      double lowPassCutoffFrequency, double lowPassRatioThreshold, double energyThreshold, double silenceThreshold)
        {
            WAVFrameSet frameSet = new WAVFrameSet(sound, frameDuration, frameShift);

            speechTypeSpecification = new SpeechTypeSpecification();
            double time = 0;

            for (int ii = 0; ii < frameSet.FrameList.Count; ii++)
            {
                WAVSound   frame      = frameSet.FrameList[ii];
                SpeechType speechType = this.GetFrameSpeechType(frame); //
                // SpeechType speechType = this.GetFrameSpeechType(frame, channel, lowPassCutoffFrequency, lowPassRatioThreshold, energyThreshold, silenceThreshold);
                time = frameSet.StartTimeList[ii] + frameDuration / 2;  // The speech type is assigned to the center of the frame
                speechTypeSpecification.TimeSpeechTypeTupleList.Add(new Tuple <double, SpeechType>(time, speechType));
            }
            // Finally, to make sure that the speech type can be interpolated over the entire sound, set the
            // end values:
            SpeechType firstSpeechType = speechTypeSpecification.TimeSpeechTypeTupleList[0].Item2;

            speechTypeSpecification.TimeSpeechTypeTupleList.Insert(0, new Tuple <double, SpeechType>(0, firstSpeechType));
            SpeechType lastSpeechType = speechTypeSpecification.TimeSpeechTypeTupleList.Last().Item2;
            double     duration       = sound.GetDuration();

            if (speechTypeSpecification.TimeSpeechTypeTupleList.Last().Item1 < duration) // Will ALMOST always be the case, unless the duration is an exact multiple of the frame shift
            {
                speechTypeSpecification.TimeSpeechTypeTupleList.Add(new Tuple <double, SpeechType>(duration, lastSpeechType));
            }
            for (int jj = 0; jj < numberOfAdjustmentSteps; jj++)
            {
                Adjust();
            }
        }
 private void recordToolStripButton_Click(object sender, EventArgs e)
 {
     if (recordToolStripButton.Text.Contains("Start"))  // A bit ugly, but OK
     {
         recordToolStripButton.Text = "Stop recording";
         wavRecorder          = new WAVRecorder();
         wavRecorder.DeviceId = 0;
         wavRecorder.Start();
     }
     else
     {
         wavRecorder.Stop();
         byte[] recordedBytes = wavRecorder.GetAllRecordedBytes();
         if (recordedBytes != null)
         {
             if (recordedBytes.Length > 0)
             {
                 WAVSound sound = new WAVSound("", wavRecorder.SampleRate, wavRecorder.NumberOfChannels, wavRecorder.NumberOfBitsPerSample);
                 sound.AppendSamplesAsBytes(recordedBytes);
                 soundVisualizer.SetSound(sound);
             }
         }
         recordToolStripButton.Text         = "Start recording";
         playSoundButton.Enabled            = true;
         saveSoundToolStripMenuItem.Enabled = true;
     }
 }
 private void startRecordingButton_Click(object sender, EventArgs e)
 {
     if (wavRecorder == null)
     {
         wavRecorder                 = new WAVRecorder();
         wavRecorder.SampleRate      = 16000;
         wavRecorder.StorageDuration = 10;
     }
     if (!wavRecorder.IsRecording)
     {
         recognizeButton.Enabled = false;
         recordingButton.Text    = "Stop recording";
         wavRecorder.Start();
     }
     else
     {
         wavRecorder.Stop();
         byte[] recordedBytes = wavRecorder.GetAllRecordedBytes();
         if (recordedBytes != null)
         {
             if (recordedBytes.Length > 0)
             {
                 WAVSound sound = new WAVSound("", wavRecorder.SampleRate, wavRecorder.NumberOfChannels, wavRecorder.NumberOfBitsPerSample);
                 sound.AppendSamplesAsBytes(recordedBytes);
                 sound.SetMaximumNonClippingVolume();
                 soundVisualizer.SetSound(sound);
             }
         }
         recordingButton.Text    = "Start recording";
         recognizeButton.Enabled = true;
     }
 }
 private void RecognitionLoop(WAVSound soundToRecognize)
 {
     //      Monitor.Enter(recognitionLockObject);
     try
     {
         soundToRecognize.GenerateMemoryStream();
         speechRecognitionEngine.SetInputToWaveStream(soundToRecognize.WAVMemoryStream);
         RecognitionResult r = speechRecognitionEngine.Recognize();
         if (r != null)
         {
             OnSoundRecognized(r);
         }
         if (extractDetectedSounds)
         {
             OnSoundDetected(soundToRecognize.Copy());
         }
         recognizerBusy = false;
     }
     catch
     {
         // Nothing to do here - try-catch needed to avoid (rare) crashes when the WAVE stream cannot be found.
     }
     finally
     {
         recognizerBusy = false; // Needed if the catch is triggered.
     }
     //   Monitor.Exit(recognitionLockObject);
 }
        public void SetSound(WAVSound sound)
        {
            this.sound = sound;
            if (sound == null)
            {
                return;
            }                              // 20160912
            if (soundSequenceList == null)
            {
                soundSequenceList = new List <WAVSound>();
            }
            soundSequenceList.Add(this.sound.Copy());
            this.xMin        = 0;
            this.xMax        = (float)sound.GetDuration();
            scrollbarVisible = false;
            SetRange(xMin, xMax, MINIMUM_SAMPLE_VALUE, MAXIMUM_SAMPLE_VALUE);
            OnViewingAreaChanged();
            horizontalTickMarkList = new List <float>();
            float tickMarkPosition = (float)xMin;

            while (tickMarkPosition <= xMax)
            {
                horizontalTickMarkList.Add(tickMarkPosition);
                tickMarkPosition += tickMarkSpacing;
            }
            OnAssignedSoundChanged();
            Invalidate();
        }
Пример #13
0
        private void editorPlayButton_Click(object sender, EventArgs e)
        {
            saveSoundToolStripMenuItem.Enabled = true;
            editorFormantSpecification.FundamentalFrequency = speechSynthesizer.FundamentalFrequency;
            editorFormantSpecification.SamplingFrequency    = speechSynthesizer.SamplingFrequency;
            editorFormantSpecification.GenerateSettingsSequence();
            speechSynthesizer.StorePitch = true;
            WAVSound sound = speechSynthesizer.GenerateSound(editorFormantSpecification);
            //  List<double> pitchList = speechSynthesizer.PitchList;
            //  augmentedSoundVisualizer.SetSound(sound, pitchList);

            int selectedIndex = formantSpecificationListBox.SelectedIndex;

            editorSpeechVisualizer.SetSound(sound);
            List <List <double> > timePitchPeriodList = speechSynthesizer.TimePitchPeriodList;

            editorSpeechVisualizer.SetTimePitchPeriodList(timePitchPeriodList);
            ShowFormantSpecification(selectedIndex);
            SoundPlayer soundPlayer = new SoundPlayer();

            sound.GenerateMemoryStream();
            sound.WAVMemoryStream.Position = 0; // Manually rewind stream
            soundPlayer.Stream             = null;
            soundPlayer.Stream             = sound.WAVMemoryStream;
            soundPlayer.PlaySync();
        }
Пример #14
0
        private void speakSentenceButton_Click(object sender, EventArgs e)
        {
            speechSynthesizer.Volume = double.Parse(volumeTextBox.Text);
            string wordString = sentenceToSpeakTextBox.Text;

            if (wordString != "")
            {
                List <string> wordList    = wordString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                List <double> silenceList = new List <double>()
                {
                };
                for (int ii = 0; ii < (wordList.Count - 1); ii++)
                {
                    silenceList.Add(0.05);
                }
                WAVSound    sentenceSound = speechSynthesizer.GenerateWordSequence(wordList, silenceList);
                SoundPlayer soundPlayer   = new SoundPlayer();
                sentenceSound.GenerateMemoryStream();
                sentenceSound.WAVMemoryStream.Position = 0; // Manually rewind stream
                soundPlayer.Stream = null;
                soundPlayer.Stream = sentenceSound.WAVMemoryStream;
                soundPlayer.PlaySync();
                sentenceSpeechVisualizer.SetSound(sentenceSound);
            }
        }
 public void SetSound(WAVSound sound, List <double> pitchList)
 {
     this.sound     = sound;
     this.pitchList = pitchList;
     SetRange(0, sound.GetDuration(), 0, 1);
     PlotSoundAndPitch();
 }
        private void raiseVolumeButton_Click(object sender, EventArgs e)
        {
            WAVSound sound = soundVisualizer.Sound;

            sound.SetRelativeVolume(VOLUME_RAISE_STEP);
            soundVisualizer.SetSound(sound);
        }
 private void recordingButton_Click(object sender, EventArgs e)
 {
     if (!recording)
     {
         recording = true;
         recorder.Start();
         recordingButton.Text = "Stop recording";
     }
     else
     {
         recorder.Stop();
         byte[] recordedBytes = recorder.GetAllRecordedBytes();
         if (recordedBytes != null)
         {
             if (recordedBytes.Length > 0)
             {
                 WAVSound sound = new WAVSound("", recorder.SampleRate, recorder.NumberOfChannels, recorder.NumberOfBitsPerSample);
                 sound.AppendSamplesAsBytes(recordedBytes);
                 soundVisualizer.SetSound(sound);
             }
         }
         recordingButton.Text = "Start recording";
         saveSoundToolStripMenuItem.Enabled = true;
         raiseVolumeButton.Enabled          = true;
         reduceVolumeButton.Enabled         = true;
         playButton.Enabled      = true;
         playButton.Enabled      = true;
         filterToolStrip.Enabled = true;
         recording = false;
     }
 }
Пример #18
0
        private void SpeakSentence(object sender, EventArgs e)
        {
            if (sentenceBox.Items.Count == 0)
            {
                return;
            }

            List <string> wordList    = new List <string>(sentenceBox.Items.Count);
            List <double> silenceList = new List <double>(sentenceBox.Items.Count);

            foreach (var v in sentenceBox.Items)
            {
                string word = v as string;
                wordList.Add(word);
                silenceList.Add(0.5);
            }

            WAVSound sentence = _synthesizer.GenerateWordSequence(wordList, silenceList);

            SoundPlayer soundPlayer = new SoundPlayer();

            sentence.GenerateMemoryStream();
            sentence.WAVMemoryStream.Position = 0; // Manually rewind stream
            soundPlayer.Stream = null;             //TODO varför?
            soundPlayer.Stream = sentence.WAVMemoryStream;
            soundPlayer.Play();
        }
        private int AdjustPitchMark(WAVSound sound, int nominalPitchMarkIndex, int adjustmentIndexRange) //, double relativePeakThreshold, double energyComputationTimeRange)
        {
            int        absoluteMaximum = Math.Abs(sound.Samples[0][nominalPitchMarkIndex]);
            int        threshold       = (int)Math.Round(relativePeakThreshold * absoluteMaximum);
            List <int> indicesOfLocalMaximaAboveThreshold = sound.GetIndicesOfLocalExtremaAboveThreshold(nominalPitchMarkIndex, adjustmentIndexRange, adjustmentIndexRange, threshold);
            int        adjustedPitchMarkIndex             = nominalPitchMarkIndex; //  sound.GetSampleIndexAtTime(timeOfAbsoluteMaximum); // Fallback value.
            double     minimumPreviousEnergy       = double.MaxValue;
            int        energyComputationIndexRange = (int)Math.Round(energyComputationTimeRange * sound.SampleRate);

            for (int ii = 0; ii < indicesOfLocalMaximaAboveThreshold.Count; ii++)
            {
                int indexOfLocalMaximumAboveThreshold = indicesOfLocalMaximaAboveThreshold[ii];
                int energyComputationEndIndex         = indexOfLocalMaximumAboveThreshold - 1;
                if (energyComputationEndIndex >= sound.Samples[0].Count)
                {
                    energyComputationEndIndex = sound.Samples[0].Count - 1;
                }
                int energyComputationStartIndex = indexOfLocalMaximumAboveThreshold - energyComputationIndexRange;
                if (energyComputationStartIndex < 0)
                {
                    energyComputationStartIndex = 0;
                }
                double localEnergy = sound.GetLocalEnergy(energyComputationStartIndex, energyComputationEndIndex);
                if (localEnergy < minimumPreviousEnergy)
                {
                    minimumPreviousEnergy  = localEnergy;
                    adjustedPitchMarkIndex = indexOfLocalMaximumAboveThreshold;
                }
            }
            return(adjustedPitchMarkIndex);
        }
        private void highpassFilterButton_Click(object sender, EventArgs e)
        {
            double   highpassCutoffFrequency = double.Parse(highpassFilterCutoffTextBox.Text);
            WAVSound sound = soundVisualizer.Sound.Copy();

            sound.HighPassFilter(highpassCutoffFrequency);
            soundVisualizer.SetSound(sound);
        }
 private void OnSoundGenerated(WAVSound sound)
 {
     if (SoundGenerated != null)
     {
         EventHandler <WAVSoundEventArgs> handler = SoundGenerated;
         WAVSoundEventArgs e = new WAVSoundEventArgs(sound);
         handler(this, e);
     }
 }
 private void OnSoundDetected(WAVSound detectedSound)
 {
     if (SoundRecognized != null)
     {
         EventHandler <WAVSoundEventArgs> handler = SoundDetected;
         WAVSoundEventArgs e = new WAVSoundEventArgs(detectedSound);
         handler(this, e);
     }
 }
Пример #23
0
 private void populateRandomKnown(List <WAVSound> list)
 {
     for (int i = 0; i < KNOWN_SOUNDS_PER_TEST; i++)
     {
         int      randWord   = random.Next(testSound.Count);
         int      randSample = random.Next(testSound[randWord].Count);
         WAVSound sound      = testSound[randWord][randSample];
         list.Add(sound);
     }
 }
        private void saveSoundToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "WAV files (*.wav)|*.wav";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                WAVSound savedSound = soundVisualizer.Sound.Copy(); //  recorderVisualizer.Sound.Copy();
                savedSound.SaveToFile(saveFileDialog.FileName);
            }
        }
Пример #25
0
        public WAVSound Modify(WAVSound sound, double relativeStartPitch, double relativeEndPitch, Boolean adjustDuration, double relativeDuration)
        {
            // First, find the speech type variation:
            //  speechTypeEstimator = new SpeechTypeEstimator();
            speechTypeEstimator.FindSpeechTypeVariation(sound);

            /*    speechTypeEstimator.FindSpeechTypeVariation(sound, 0, frameDuration, frameShift, speechTypeLowPassCutoffFrequency, speechTypeLowPassRatioThreshold,
             *      speechTypeEnergyThreshold, speechTypeSilenceThreshold);
             *  speechTypeEstimator.Adjust(3);
             *  speechTypeEstimator.Adjust(3); // repeat the adjustment to remove double errors.  */
            SpeechTypeSpecification speechTypeSpecification = speechTypeEstimator.SpeechTypeSpecification;

            // Next, find the pitch periods:
            PitchPeriodEstimator pitchPeriodEstimator = new PitchPeriodEstimator();

            pitchPeriodEstimator.ComputePitchPeriods(sound, 0.0, sound.GetDuration()); //, minimumPitchPeriod, maximumPitchPeriod, frameShift); // 0.0120, 0.01, 0.03);
            pitchPeriodEstimator.AdjustAndInterpolate(speechTypeSpecification);        //, pitchPeriodDeltaTime, setUnvoicedPitch); // 0.005, true);
            PitchPeriodSpecification pitchPeriodSpecification = pitchPeriodEstimator.PitchPeriodSpecification;

            // Then, find the pitch marks:
            pitchMarkEstimator = new PitchMarkEstimator();
            pitchMarkEstimator.FindPitchMarks(sound, speechTypeSpecification, pitchPeriodSpecification); // , 0.0025, 0.0025, 0.45, 0.002);
            List <double> pitchMarkTimeList = pitchMarkEstimator.PitchMarkTimeList;

            // Then, change the pitch of the sound
            double   originalDuration       = sound.GetDuration();
            double   desiredDuration        = originalDuration * relativeDuration;
            double   actualRelativeDuration = relativeDuration; // Valid if the pitch is unchanged ...
            WAVSound pitchChangedSound;

            if ((Math.Abs(relativeStartPitch - 1) > double.Epsilon) || (Math.Abs(relativeEndPitch - 1) > double.Epsilon)) // To save some time, if only duration is to be changed..
            {
                pitchChangedSound = ChangePitch(sound, pitchMarkTimeList, relativeStartPitch, relativeEndPitch);
                // The pitch change also changes the duration of the sound:
                double newDuration = pitchChangedSound.GetDuration();
                actualRelativeDuration = desiredDuration / newDuration; // ...but if the pitch is changed, the duration changes too.
            }
            else
            {
                pitchChangedSound         = sound;             // No copying needed here, a reference is sufficient.
                modifiedPitchMarkTimeList = pitchMarkTimeList; // No pitch change => use original pitch marks.
            }

            // If the adjustDuration is true, change the duration, using the stored pitchmark time list (to avoid repeating the three steps above):
            if (adjustDuration)
            {
                WAVSound durationChangedSound = ChangeDuration(pitchChangedSound, modifiedPitchMarkTimeList, actualRelativeDuration);
                return(durationChangedSound);
            }
            else
            {
                return(pitchChangedSound);
            }
        }
        private void HandlePanelMouseDoubleClick(object sender, MouseEventArgs e)
        {
            WAVSound sound     = ((SoundVisualizer)sender).Sound;
            string   tagString = (string)((SoundVisualizer)sender).Tag;

            string[] tagStringSplit = tagString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int      xIndex         = int.Parse(tagStringSplit[0]);
            int      yIndex         = int.Parse(tagStringSplit[1]);

            OnItemDoubleClicked(xIndex, yIndex);
        }
        private void playButton_Click(object sender, EventArgs e)
        {
            SoundPlayer soundPlayer = new SoundPlayer();
            WAVSound    sound       = soundVisualizer.Sound.Copy();

            sound.GenerateMemoryStream();
            sound.WAVMemoryStream.Position = 0; // Manually rewind stream
            soundPlayer.Stream             = null;
            soundPlayer.Stream             = sound.WAVMemoryStream;
            soundPlayer.PlaySync();
        }
Пример #28
0
        /// <summary>
        /// Returns the winner
        /// Item1: Sound name
        /// Item2: Deviation
        /// Item3: Recognized
        /// </summary>
        /// <param name="sound"></param>
        /// <returns></returns>
        private Tuple <string, double, bool> recognize(WAVSound sound, IsolatedWordRecognizer recognizer)
        {
            RecognitionResult recognitionResult = recognizer.RecognizeSingle(sound);

            Tuple <string, double> best = recognitionResult.DeviationList[0];
            bool recognized             = best.Item2 < recognizer.RecognitionThreshold;

            //Console.WriteLine("min = " + recognitionResult.DeviationList[0].Item2 +
            //    ", max = " + recognitionResult.DeviationList[recognitionResult.DeviationList.Count-1].Item2);

            return(Tuple.Create(best.Item1, best.Item2, recognized));
        }
Пример #29
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 playSoundButton_Click(object sender, EventArgs e)
        {
            playSoundButton.Enabled = false;
            WAVSound    sound       = soundVisualizer.Sound.Copy(); // recorderVisualizer.Sound.Copy();
            SoundPlayer soundPlayer = new SoundPlayer();

            sound.GenerateMemoryStream();
            sound.WAVMemoryStream.Position = 0; // Manually rewind stream
            soundPlayer.Stream             = null;
            soundPlayer.Stream             = sound.WAVMemoryStream;
            soundPlayer.PlaySync();
            playSoundButton.Enabled = true;
        }