Dispose() public method

Dispose method
public Dispose ( ) : void
return void
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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.º 3
0
 //Event arguments to stop recording
 private void wavSource_RecordingStopped(object sender, EventArgs e)
 {
     wavSource.Dispose();
     wavSource = null;
     wavFile.Close();
     wavFile.Dispose();
     wavFile = null;
 }
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 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.º 6
0
 private void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
 {
     if (waveSource != null)
     {
         waveSource.Dispose();
         waveSource = null;
     }
     if (waveFile != null)
     {
         //  waveFile.Dispose();
         //  waveFile = null;
     }
 }
Ejemplo n.º 7
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.º 8
0
        //Event args to stop recording events
        private void wavSource_RecordingStop(object sender, NAudio.Wave.StoppedEventArgs e)
        {
            if (wavSource != null)
            {
                wavSource.Dispose();
                wavSource = null;
            }

            if (wavFile != null)
            {
                wavFile.Dispose();
                wavFile = null;
            }
            //recBtn.Enabled = true;
        }
        private void stopRecordSound()
        {
            if (_sourceStream != null)
            {
                _sourceStream.StopRecording();
                _sourceStream.Dispose();
                _sourceStream = null;
            }

            if (_waveWriter != null)
            {
                _waveWriter.Dispose();
                _waveWriter = null;
            }
        }
Ejemplo n.º 10
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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.º 19
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;
                }
            }
        }