示例#1
0
    public void Init() {

      cfg.logInfo("ENGINE - " + Name, "Init recognizer");
      
      engine.SpeechRecognized          += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
      engine.RecognizeCompleted        += new EventHandler<RecognizeCompletedEventArgs>(recognizer_RecognizeCompleted);
      engine.AudioStateChanged         += new EventHandler<AudioStateChangedEventArgs>(recognizer_AudioStateChanged);
      engine.SpeechHypothesized        += new EventHandler<SpeechHypothesizedEventArgs>(recognizer_SpeechHypothesized);
      engine.SpeechDetected            += new EventHandler<SpeechDetectedEventArgs>(recognizer_SpeechDetected);
      engine.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);

      engine.UpdateRecognizerSetting("CFGConfidenceRejectionThreshold", (int) (this.Confidence * 100));

      engine.MaxAlternates              = cfg.MaxAlternates;
      engine.InitialSilenceTimeout      = cfg.InitialSilenceTimeout;
      engine.BabbleTimeout              = cfg.BabbleTimeout;
      engine.EndSilenceTimeout          = cfg.EndSilenceTimeout;
      engine.EndSilenceTimeoutAmbiguous = cfg.EndSilenceTimeoutAmbiguous;

      if (!cfg.Adaptation) {
        engine.UpdateRecognizerSetting("AdaptationOn", 0);
      }

      cfg.logInfo("ENGINE - " + Name, "AudioLevel: "                 + engine.AudioLevel);
      cfg.logInfo("ENGINE - " + Name, "MaxAlternates: "              + engine.MaxAlternates);
      cfg.logInfo("ENGINE - " + Name, "BabbleTimeout: "              + engine.BabbleTimeout);
      cfg.logInfo("ENGINE - " + Name, "InitialSilenceTimeout: "      + engine.InitialSilenceTimeout);
      cfg.logInfo("ENGINE - " + Name, "EndSilenceTimeout: "          + engine.EndSilenceTimeout);
      cfg.logInfo("ENGINE - " + Name, "EndSilenceTimeoutAmbiguous: " + engine.EndSilenceTimeoutAmbiguous);

      tracker = new PitchTracker();
      tracker.SampleRate = 16000.0f;
      tracker.PitchDetected += OnPitchDetected;
    }
示例#2
0
        public void Start(DetectionAlgorithm algorithm)
        {
            if (algorithm == DetectionAlgorithm.AUTOCORRELATION)
            {
                ptracker = new PitchTracker();
                ptracker.PitchDetected += ptracker_PitchDetected;
                ptracker.SampleRate = _microphone.SampleRate;
            }
            else if (algorithm == DetectionAlgorithm.YIN)
            {
                yin = new Yin(_microphone.SampleRate, _bufferSize/4);
            }

            _microphone.Start();
        }
示例#3
0
        public void Start(DetectionAlgorithm algorithm)
        {
            if (algorithm == DetectionAlgorithm.AUTOCORRELATION)
            {
                ptracker = new PitchTracker();
                ptracker.PitchDetected += ptracker_PitchDetected;
                ptracker.SampleRate     = _microphone.SampleRate;
            }
            else if (algorithm == DetectionAlgorithm.YIN)
            {
                yin = new Yin(_microphone.SampleRate, _bufferSize / 4);
            }

            _microphone.Start();
        }
示例#4
0
 private void OnPitchDetected(PitchTracker sender, PitchTracker.PitchRecord pitchRecord) {
   // During the call to PitchTracker.ProcessBuffer, this event will be fired zero or more times,
   // depending how many pitch records will fit in the new and previously cached buffer.
   //
   // This means that there is no size restriction on the buffer that is passed into ProcessBuffer.
   // For instance, ProcessBuffer can be called with one large buffer that contains all of the
   // audio to be processed, or just a small buffer at a time which is more typical for realtime
   // applications. This PitchDetected event will only occur once enough data has been accumulated
   // to do another detect operation.
   /*
   cfg.logInfo("PITCH", "MidiCents: " + pitchRecord.MidiCents
                      + " MidiNote: " + pitchRecord.MidiNote
                      + " Pitch: " + pitchRecord.Pitch
                      + " RecordIndex: " + pitchRecord.RecordIndex);*/
   double d = pitchRecord.Pitch;
   if (d > 0) { pitch.Add(d); }
 }
示例#5
0
 public override void Start() {
   base.Start();
   tracker = new PitchTracker();
   tracker.SampleRate = 16000.0f;
   tracker.PitchDetected += OnPitchDetected;
 }
示例#6
0
 void ptracker_PitchDetected(PitchTracker sender, PitchTracker.PitchRecord pitchRecord)
 {
     setNumbers(pitchRecord.Pitch);
 }
示例#7
0
        bool Recording      = false;                            //as default, the string of notes are not being recorded

        private void startBtn_Click(object sender, EventArgs e) // this button is meant to be where the notes played become listed
        {
            InitializeSound();                                  // sets up sourcestream, datain event, buffer and waveout for data to be sent

            //the below is all for saving the .wav file as it goes along. come back to later

            //try
            //{
            //    waveWriter = new NAudio.Wave.WaveFileWriter(SFD.FileName, sourceStream.WaveFormat);
            //    //attempts to create a filewriter using the openfiledialogue path and the sourcesream waveformat

            //
            //}
            //catch (NullReferenceException) //both these errors occur when no file has been selected
            //{
            //    System.Windows.MessageBox.Show("Please select save file name and location");
            //    return;
            //}
            //catch (ArgumentException)
            //{
            //    System.Windows.MessageBox.Show("Please select save file name and location");
            //    return;
            //}



            try
            {
                sourceStream.StartRecording();
            }
            catch (NAudio.MmException exception) //this error may occur when no input device is connected
            {
                System.Windows.MessageBox.Show("No Input Device available");
            }
            //  waveOut.Play();
            m_pitchTracker            = new PitchTracker();     //initilises class for detecting pitch
            m_pitchTracker.SampleRate = m_sampleRate;           // sample rate is set to 44100.0f as standard
            //    m_pitchTracker.PitchDetected += OnPitchDetected;    //
            m_audioBuffer = new float[(int)Math.Round(m_sampleRate * m_timeInterval / 1000.0)];
            StartTimer();
            // UpdateDisplay();
            //we need to initialise the customsheetmusicstaff item here once its done
            //Also call the "fittoscreen" method
            /*StartTimer(); */                  //starts the timer. this was meant as part of the sheetmusic timing indications
            title = titleBox.Text;              //Set the given title name to the title at the top of the sheet music form.
                                                //SheetMusicForm frm = new SheetMusicForm();      // initialises the sheet music form
                                                //frm.Show();                                     // shows the form

            //  ControlPanels.PianoRoll pRoll = new ControlPanels.PianoRoll();  //this was an experiment to try and create a pianoroll style layout
            ControlPanels.MyPianoRollCreator pRoll = new ControlPanels.MyPianoRollCreator();
            var host = new Window();                                        //xml forms can not be diplayed in the same way normal forms can. they need a "host"

            host.Content = pRoll;                                           //fills that host with the xaml code i produced to draw the pianoroll style form
            host.Show();
            ControlPanels.RollCreaterControls pRollControlls = new ControlPanels.RollCreaterControls();
            //var host2 = new Window();                                        //xml forms can not be diplayed in the same way normal forms can. they need a "host"
            //host2.Content = pRollControlls;                                           //fills that host with the xaml code i produced to draw the pianoroll style form
            //host2.MaxHeight = 92;
            //host2.MaxWidth = 592;
            //host2.WindowStyle = WindowStyle.ToolWindow ;
            //host2.Show();


            RecordString    = "";                                           //the string of notes is cleared from last time
            Recording       = true;                                         //the notes are being recorded
            stopBtn.Enabled = true;
            // Change Color of button
            composerBtn.BackColor = Color.PowderBlue;
        }
示例#8
0
 void ptracker_PitchDetected(PitchTracker sender, PitchTracker.PitchRecord pitchRecord)
 {
     setNumbers(pitchRecord.Pitch);
 }