StopRecording() public method

Stop recording
public StopRecording ( ) : void
return void
Ejemplo n.º 1
0
        private void Stoprecording()
        {
            if (m_timer != null)
            {
                m_timer.Stop();
            }

            {
                if (sourceStream != null)
                {
                    if (waveOut != null) //stops sound from playing and disposes
                    {
                        waveOut.Stop();
                        waveOut.Dispose();
                        waveOut = null;
                    }
                    if (sourceStream != null) //stops sourcestream from recording and disposes
                    {
                        sourceStream.StopRecording();
                        sourceStream.Dispose();
                        sourceStream = null;
                    }

                    return;
                }
            }
        }
Ejemplo n.º 2
0
        // Method that stops recording
        private void stop_Click(object sender, EventArgs e)
        {
            Recognition_Form form = new Recognition_Form(null, null, null);

            form.Show();

            this.microResultLabel = form.ms_result;
            this.mfcc_result      = form.mfcc_result;
            this.lpc_result       = form.lpc_result;


            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }
            if (waveWriter != null)
            {
                waveWriter.Dispose();
                waveWriter = null;
            }
            openWav(wavSaveName);
            recording_timer.Stop();
            wavSaveName = null;
            System.Threading.Tasks.Task.Run(() =>
            {
                processWavFile(algo);
            });
            // processWavFile(algo);
        }
 public void Stop()
 {
     reAcquireMicrophone = false;
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
     }
 }
Ejemplo n.º 4
0
 public static void PrepareMic()
 {
     WaveIn waveIn = new WaveIn();
     waveIn.WaveFormat = new WaveFormat(SAMPLE_FREQ, 16, 1);
     waveIn.StartRecording();
     waveIn.StopRecording();
     waveIn.Dispose();
 }
Ejemplo n.º 5
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     //if (waveOut != null)
     //{
     //    waveOut.Stop();
     //    waveOut.Dispose();
     //    waveOut = null;
     //}
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
         sourceStream.Dispose();
         sourceStream = null;
         writer.Dispose();
         writer.Close();
         bw = new BackgroundWorker();
         //identify();
     }
 }
Ejemplo n.º 6
0
        private void recordBtn_Click(object sender, EventArgs e)
        {
            if (setMode)
            {
                try
                {
                    String filename = "Class" + LoginForm.classSec + "_kidWordAudio/test.wav";
                    recordBtn.Text       = "STOP";
                    wavSource            = new NAudio.Wave.WaveIn();
                    wavSource.WaveFormat = new NAudio.Wave.WaveFormat(44100, 1);

                    wavSource.DataAvailable    += new EventHandler <NAudio.Wave.WaveInEventArgs>(wavSource_DataAvail);
                    wavSource.RecordingStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(wavSource_RecordingStop);

                    wavFile = new NAudio.Wave.WaveFileWriter(filename, wavSource.WaveFormat);
                    wavSource.StartRecording();
                    setMode = false;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                //When you press "STOP", it automatically compares
                wavSource.StopRecording();

                String recordWAV_file = "Class" + LoginForm.classSec + "_kidWordAudio/test.wav";
                String refWAV_file    = "Class" + LoginForm.classSec + "_kidWordAudio/" + levels[curPos] + ";.wav";

                java.io.File f1 = new java.io.File(recordWAV_file);
                java.io.File f2 = new java.io.File(refWAV_file);

                if (!f1.exists() || !f2.exists())
                {
                    MessageBox.Show("WARNING: One of the files might be missing!");
                }
                else
                {
                    float compute_Result = compareAudio(recordWAV_file, refWAV_file);
                    if (compute_Result >= 10.0)
                    {
                        MessageBox.Show("Matched: " + compute_Result.ToString() + "\n You Win !");
                    }
                    else
                    {
                        MessageBox.Show("Matched: " + compute_Result.ToString() + "\n Try Again !");
                    }
                }
                recordBtn.Text = "RECORD";
                setMode        = true;
            }
        }
Ejemplo n.º 7
0
        private void btn_RECSTOP_Click(object sender, EventArgs e)
        {
            if (!isRecording)
            {
                if (cmb_InputsList.SelectedItem == null)
                {
                    MessageBox.Show("Error! \n No Input Selected, Please select an Audio Input before recording");
                    return;
                }

                SaveFileDialog save = new SaveFileDialog();
                save.Filter = "Wave File(*.wav)|*.wav;";
                if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }
                else
                {
                    lst_samplelist.Items.Add(save.FileName);
                }

                int deviceNumber = cmb_InputsList.SelectedIndex;

                InputStream = new NAudio.Wave.WaveIn();
                InputStream.DeviceNumber = deviceNumber;
                InputStream.WaveFormat   = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

                InputStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(InputStream_DataAvailable);
                waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, InputStream.WaveFormat);

                InputStream.StartRecording();

                btn_RECSTOP.Text = "STOP";
                isRecording      = true;
            }
            else
            {
                if (InputStream != null)
                {
                    InputStream.StopRecording();
                    InputStream.Dispose();
                    InputStream = null;
                }
                if (waveWriter != null)
                {
                    waveWriter.Dispose();
                    waveWriter = null;
                }
                btn_RECSTOP.Text = "REC";
                isRecording      = false;
            }
        }
Ejemplo n.º 8
0
 private void stopButton_Click(object sender, EventArgs e)
 {
     state = "stop";
     playButton.Enabled   = true;
     recordButton.Enabled = true;
     if (waveOut != null)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
         sourceStream.Dispose();
         sourceStream = null;
     }
     if (waveWriter != null)
     {
         waveWriter.Dispose();
         waveWriter = null;
     }
 }
Ejemplo n.º 9
0
 private void microphoneList_SelectedIndexChanged(object sender, EventArgs e)
 {
     deviceNumber = microphoneList.SelectedIndex;
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
     }
     sourceStream = new NAudio.Wave.WaveIn();
     sourceStream.DeviceNumber   = deviceNumber;
     sourceStream.WaveFormat     = conductor.GetWaveFormat();// new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
     bytesPerSample              = (sourceStream.WaveFormat.BitsPerSample / 8) * sourceStream.WaveFormat.Channels;
     sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
     sourceStream.StartRecording();
 }
        private void stopRecordSound()
        {
            if (_sourceStream != null)
            {
                _sourceStream.StopRecording();
                _sourceStream.Dispose();
                _sourceStream = null;
            }

            if (_waveWriter != null)
            {
                _waveWriter.Dispose();
                _waveWriter = null;
            }
        }
Ejemplo n.º 11
0
 public void editorSesDinlemeDurdur()
 {
     if (waveOut != null)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
         sourceStream.Dispose();
         sourceStream = null;
     }
 }
        private void stopRecordSound()
        {
            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }

            if (waveWriter != null)
            {
                waveWriter.Dispose();
                waveWriter = null;
            }
        }
Ejemplo n.º 13
0
        //Timer event
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            time--;
            CountDownBlk.Text = string.Format("0{0}:{1}", time / 60, time % 60);
            if (time < 5)
            {
                if (time % 2 == 0)
                {
                    CountDownBlk.Foreground = Brushes.Red;
                }
                else
                {
                    CountDownBlk.Foreground = Brushes.DarkRed;
                }
            }

            if (time == 0)
            {
                dispatcherTimer.Stop();
                wavSource.StopRecording();
                polyLine.Points.Clear();
                ReadAudioForm3.backButton.Enabled   = true;
                ReadAudioForm3.submitButton.Enabled = true;
                ReadAudioForm3.ActiveForm.Size      = new System.Drawing.Size(322, 400);

                //The recorded voice of the student
                String recordWAV_file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\RecordWAV\" + lvlStr + ".wav";
                //The reference sample of the teacher
                String refWAV_file = "Class" + LoginForm.classSec + "_kidAudio/" + lvlStr.ToLower() + ".wav";

                java.io.File f1 = new java.io.File(recordWAV_file);
                java.io.File f2 = new java.io.File(refWAV_file);

                //compare
                if (!f1.exists() || !f2.exists())
                {
                    MessageBox.Show("WARNING: One of the files might be missing!");
                }
                else
                {
                    CallCompareAudio(recordWAV_file, refWAV_file);
                }


                //MessageBox.Show("DONE");
                time = 10;
            }
        }
Ejemplo n.º 14
0
        private void button_stop_Click(object sender, EventArgs e)
        {
            waveOut?.Stop();
            waveOut?.Dispose();
            waveOut = null;

            sourceStream?.StopRecording();
            sourceStream?.Dispose();
            sourceStream = null;

            waveWriter?.Dispose();
            waveWriter = null;

            //Label
            this.Label_Status.Text = "待機中";
        }
Ejemplo n.º 15
0
        void Disconnect()
        {
            if (connected)
            {
                connected             = false;
                source.DataAvailable -= waveIn_DataAvailable;
                source.StopRecording();
                waveOut.Stop();

                sendVoice.Close();
                receiveVoice.Close();
                source.Dispose();
                waveOut.Dispose();

                alcc.Dispose();
            }
        }
Ejemplo n.º 16
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (waveOut != null)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
         sourceStream.Dispose();
         sourceStream = null;
     }
     if (waveWriter != null)
     {
         waveWriter.Dispose();
         waveWriter = null;
     }
 }
Ejemplo n.º 17
0
 private void frmRecording_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (waveOut != null)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (sourceStream != null)
     {
         sourceStream.StopRecording();
         sourceStream.Dispose();
         sourceStream = null;
     }
     if (waveWriter != null)
     {
         waveWriter.Dispose();
         waveWriter = null;
     }
 }
Ejemplo n.º 18
0
 public void StopRecording()
 {
     _recording = false;
     _videoSource.SignalToStop();
     _videoSource.NewFrame -= video_NewFrame;
     _ffmpegIn.Flush();
     _ffmpegIn.Dispose();
     if (_isAudio)
     {
         waveSource.StopRecording();
         waveSource.DataAvailable    -= waveSource_DataAvailable;
         waveSource.RecordingStopped -= waveSource_RecordingStopped;
         _audioPipe.Flush();
         _audioPipe.Dispose();
     }
     Process.WaitForExit();
     //  MessageBox.Show((startTime - DateTime.Now).TotalSeconds.ToString());
     // _writer.Close();
     //_writer.Dispose();
 }
Ejemplo n.º 19
0
        private void btnParar_Click(object sender, EventArgs e)
        {
            if (waveOut != null)
            {
                waveOut.Stop();
                waveOut.Dispose();
                waveOut = null;
            }
            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }
            if (waveWriter != null)
            {
                waveWriter.Dispose();
                waveWriter = null;
            }

            btnIniciar.Enabled   = true;
            btnParar.Enabled     = false;
            WaveAudioLevel.Value = 0;
        }
Ejemplo n.º 20
0
        private void waveIn_RecordingStopped(object sender, EventArgs e)
        {
            if (writeToFile == 1)
            {
                waveIn.Dispose();
                waveIn = null;
                writer.Close();
                writer = null;

                int bytes_to_read = (rec_times + 1) * 6400;
                byte[] wav_bytes = new byte[bytes_to_read];

                WaveFileReader wfr = new WaveFileReader("file.wav");

                if (wfr.Length < bytes_to_read)
                {
                    wfr.Read(wav_bytes, 0, (int)wfr.Length);
                }
                else
                {
                    wfr.Position = wfr.Length - 1 - bytes_to_read;
                    wfr.Read(wav_bytes, 0, bytes_to_read);

                }
                wfr.Dispose();
                wfr.Close();

                WaveIn second_waveIn = new WaveIn();
                second_waveIn.DeviceNumber = 0;
                second_waveIn.WaveFormat = new WaveFormat(16000, 2);
                WaveFileWriter second_writer = new WaveFileWriter("cmd.wav", second_waveIn.WaveFormat);
                second_waveIn.StartRecording();
                second_writer.Write(wav_bytes, 0, bytes_to_read);
                second_waveIn.StopRecording();

                second_waveIn.Dispose();
                second_waveIn = null;
                second_writer.Close();
                second_writer = null;

                listBox1.Items.Add("CONVERTING");
                listBox1.SelectedIndex = listBox1.Items.Count - 1;

                Wav2Flac("cmd.wav", "file.flac");

                result = GoogleSpeechRequest(16000);
                string res = result;
                int k = res.IndexOf("utterance\":\"") + "utterance\":\"".Length;
                int k1 = res.IndexOf("\"", k + 1);
                string cmd = res.Substring(k, k1 - k);
                listBox1.Items.Add("RECOGNIZED");
                richTextBox1.Text += cmd + "\n";

                File.Delete("cmd.wav");
                rec_times = 0;
                writeToFile = 0;
            }
            else

                if (writeToFile == 0)
                {
                    waveIn.Dispose();
                    waveIn = null;
                    writer.Close();
                    writer = null;
                }
        }
Ejemplo n.º 21
0
        private async void tlumaczenienamorsapluszapis(object sender, EventArgs e)
        {
            textBox2.Text = null;
            if (sourceList.SelectedItems.Count == 0)
            {
                MessageBox.Show("Wybierz źródło nagrywania");
            }
            else
            {
                SaveFileDialog save = new SaveFileDialog();
                save.Filter = "Wave File (*.wav)|*.wav;";
                if (save.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                int deviceNumber = sourceList.SelectedItems[0].Index;

                sourceStream = new NAudio.Wave.WaveIn();
                sourceStream.DeviceNumber   = deviceNumber;
                sourceStream.WaveFormat     = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
                sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
                waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, sourceStream.WaveFormat);
                sourceStream.StartRecording();
                char[] tablica = null;
                String input   = textBox1.Text;
                input = input.ToUpper();
                Dictionary <char, String> morse = new Dictionary <char, String>()
                {
                    { 'A', ".-" },
                    { 'Ą', ".-.-" },
                    { 'B', "-..." },
                    { 'C', "-.-." },
                    { 'Ć', "-.-.." },
                    { 'D', "-.." },
                    { 'E', "." },
                    { 'Ę', "..-.." },
                    { 'F', "..-." },
                    { 'G', "--." },
                    { 'H', "...." },
                    { 'I', ".." },
                    { 'J', ".---" },
                    { 'K', "-.-" },
                    { 'L', ".-.." },
                    { 'Ł', ".-..-" },
                    { 'M', "--" },
                    { 'N', "-." },
                    { 'Ń', "--.--" },
                    { 'O', "---" },
                    { 'Ó', "---." },
                    { 'P', ".--." },
                    { 'Q', "--.-" },
                    { 'R', ".-." },
                    { 'S', "..." },
                    { 'Ś', "...-..." },
                    { 'T', "-" },
                    { 'U', "..-" },
                    { 'V', "...-" },
                    { 'W', ".--" },
                    { 'X', "-..-" },
                    { 'Y', "-.--" },
                    { 'Z', "--.." },
                    { 'Ż', "--..-." },
                    { 'Ź', "--..-" },
                    { '0', "-----" },
                    { '1', ".----" },
                    { '2', "..---" },
                    { '3', "...--" },
                    { '4', "....-" },
                    { '5', "....." },
                    { '6', "-...." },
                    { '7', "--..." },
                    { '8', "---.." },
                    { '9', "----." },
                };
                for (int i = 0; i < input.Length; i++)
                {
                    if (i > 0)
                    {
                        textBox2.Text += "/";
                        await Task.Delay(2000);
                    }
                    if (input[i] == ' ')
                    {
                        await Task.Delay(5000);
                    }
                    else
                    {
                        char c = input[i];
                        if (morse.ContainsKey(c))
                        {
                            textBox2.Text += morse[c];
                        }
                        tablica = morse[c].ToCharArray();



                        for (int i2 = 0; i2 < tablica.Length; i2++)
                        {
                            if (tablica[i2] == '.')
                            {
                                Action beep = () => Console.Beep(1000, 600); await Task.Delay(2000); beep.BeginInvoke(null, null);
                            }
                            if (tablica[i2] == '-')
                            {
                                Action beep2 = () => Console.Beep(1000, 1000); await Task.Delay(2000); beep2.BeginInvoke(null, null);
                            }
                        }
                    }
                }



                if (waveOut != null)
                {
                    await Task.Delay(1000);

                    waveOut.Stop();
                    waveOut.Dispose();
                    waveOut = null;
                }
                if (sourceStream != null)
                {
                    await Task.Delay(1000);

                    sourceStream.StopRecording();
                    sourceStream.Dispose();
                    sourceStream = null;
                }
                if (waveWriter != null)
                {
                    await Task.Delay(1000);

                    waveWriter.Dispose();
                    waveWriter = null;
                }
            }
        }