private void btnRecord_Click(object sender, RoutedEventArgs e) { if (sourceList.SelectedItems.Count == 0) { return; } else { try { SaveFileDialog save = new SaveFileDialog(); save.Filter = "Wave Files (*.wav)|*.wav;"; save.ShowDialog(); save.DefaultExt = "wav"; int deviceNum = sourceList.SelectedIndex; SourceStream = new NAudio.Wave.WaveIn(); SourceStream.DeviceNumber = deviceNum; SourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNum).Channels); SourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, SourceStream.WaveFormat); SourceStream.StartRecording(); StopWatch(); stopWatch.Start(); } catch (ArgumentException) { System.Windows.MessageBox.Show("No file was created"); } } }
public SetMicrophone() { InitializeComponent(); int waveInDevices = NAudio.Wave.WaveIn.DeviceCount; for (int waveInDevice = 0; waveInDevice < waveInDevices; waveInDevice++) { NAudio.Wave.WaveInCapabilities deviceInfo = NAudio.Wave.WaveIn.GetCapabilities(waveInDevice); microphoneList.Items.Add(waveInDevice + ": " + deviceInfo.ProductName); } microphoneList.SelectedIndex = 0; sensitivity.SelectedIndex = 0; sourceStream = new NAudio.Wave.WaveIn(); sourceStream.DeviceNumber = 0; sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(0).Channels); bytesPerChannel = (sourceStream.WaveFormat.BitsPerSample / 8); bytesPerSample = bytesPerChannel * sourceStream.WaveFormat.Channels; sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); sourceStream.StartRecording(); }
private void recordBatton_Click(object sender, EventArgs e) { if (deviceListBox.SelectedItems.Count == 0) { MessageBox.Show("Nie wybrano żadnego urządzenia"); } else { SaveFileDialog save = new SaveFileDialog(); save.Filter = "Wave File (*.wav)|*.wav;"; if (save.ShowDialog() != DialogResult.OK) { return; } messageBox.Text = " "; messageBox.Text += "Recording...\n"; int deviceNumber = deviceListBox.SelectedIndex; 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(); } }
//this ensures that all resources are correctly closed and disposed of when recording is stopped private void stopRecording() { 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; } if (waveWriter != null) { waveWriter.Dispose(); waveWriter = null; } isRecording = false; return; } }
//Now, when you click record, it's going to start a timer //and the user can give as many repetitions in one input //this is to enhance the audio input percentage private void recBtn_Click(object sender, EventArgs e) { try { backBtn.Enabled = false; String filename = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\RecordWAV\" + lvlStr + ".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(); slideDown(sender, e); //Amount of time to take voice input seconds = 5; //startRecord(sender, e); timeLabel.Visible = true; secsLabel.Visible = true; secsLabel.Text = Convert.ToString(seconds); countTimer.Start(); //setMode = false; } catch (Exception) { throw; } }
private void btnSpeech_Click(object sender, EventArgs e) { if (this.checkSubscriptionKey()) { this.btnSpeech.Enabled = false; if (this.micClient == null) { this.CreateMicrophoneRecoClient(); } this.micClient.StartMicAndRecognition(); //if (identify) //{ string fileName = "C:\\Users\\Mac\\Desktop\\check.wav"; int deviceNumber = 0; sourceStream = new NAudio.Wave.WaveIn(); sourceStream.DeviceNumber = deviceNumber; sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(16000, 1); sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); waveWriter = new NAudio.Wave.WaveFileWriter(fileName, sourceStream.WaveFormat); sourceStream.StartRecording(); //} } }
private void StartAudio() { try { //List<NAudio.Wave.WaveInCapabilities> sources = new List<NAudio.Wave.WaveInCapabilities>(); //for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++) //{ // System.Windows.Forms.ListViewItem item = new System.Windows.Forms.ListViewItem(NAudio.Wave.WaveIn.GetCapabilities(i).ProductName); // //sourceList.Items.Add(item.Text); //} //SaveFileDialog save = new SaveFileDialog(); //save.Filter = "Wave Files (*.wav)|*.wav;"; //save.ShowDialog(); //save.DefaultExt = "wav"; btnRecord.Content = "Recording..."; //int deviceNum = sourceList.SelectedIndex; SourceStream = new NAudio.Wave.WaveIn(); //SourceStream.DeviceNumber = deviceNum; SourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(0).Channels); SourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); //waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, SourceStream.WaveFormat); waveWriter = new NAudio.Wave.WaveFileWriter(@"D:\Recordings\" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".wav", SourceStream.WaveFormat); SourceStream.StartRecording(); StopWatch(); stopWatch.Start(); } catch (ArgumentException) { System.Windows.MessageBox.Show("No file was created"); btnRecord.Content = "Record"; } }
private void button1_Click(object sender, EventArgs e) { try { wavein = new NAudio.Wave.WaveIn() { DeviceNumber = devicelist.SelectedIndex - 1 }; wavein.WaveFormat = new NAudio.Wave.WaveFormat(48000, 2); wavein.BufferMilliseconds = 200; //wavein.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(wi_DataAvailable); wavein.DataAvailable += wi_DataAvailable; bwp = new NAudio.Wave.BufferedWaveProvider(wavein.WaveFormat); bwp.DiscardOnBufferOverflow = true; String[] serverIP = textBox1.Text.Split(':'); tcpclnt_sound = new TcpClient(serverIP[0], Int32.Parse(serverIP[1]) + 1); stm_s = tcpclnt_sound.GetStream(); wavein.StartRecording(); logbox.AppendText("Command \"" + "@@ speak_tcp" + "\" sended.\n"); } catch (Exception ex) { logbox.AppendText(ex.Message, Color.Red); crash++; } }
//Record/Stop, user can record with many tries as possible private void recStpBtn_Click(object sender, EventArgs e) { //When pressed first, start recording if (mode) { try { recStpBtn.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(@"C:\Pres_Proto\V2\MetroFrameworkDLLExample\RecordWAV\" + lvlStr + ".wav", wavSource.WaveFormat); wavSource.StartRecording(); mode = false; } catch (System.IO.IOException ex) { MessageBox.Show(ex.ToString()); } } //Else stop recording else { recStpBtn.Text = "Record"; wavSource.StopRecording(); mode = true; } }
private void button5_Click(object sender, EventArgs e) { if (sourceList.SelectedItems.Count == 0) { return; } 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(); }
// obsluga przycisku nagraj private void buttonRecord_Click(object sender, EventArgs e) { // jesli cos nie jest nagrywane if (wasRecored == false) { //jesli nie znaleziono urządzeń (mikrofonu) if (listBoxDevices.SelectedItems.Count == 0) { return; } // jesli nie została wybrana scieżka do zapisu nagrania wyświetl komunikat if (fileRecordPath == "") { MessageBox.Show("Wybierz miejsce w którym chcesz zapisać plik!"); } else { // nagrywanie do wczesniej wybranego pliku int deviceNumber = listBoxDevices.SelectedIndex; sourceStream = new NAudio.Wave.WaveIn(); sourceStream.DeviceNumber = deviceNumber; sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels); // nadanie czestotliwosci nagrywania, i standardu mono czy stereo wynikającego z urządzenia sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); waveFileWriter = new NAudio.Wave.WaveFileWriter(fileRecordPath, sourceStream.WaveFormat); sourceStream.StartRecording(); buttonRecord.Text = "Nagrywanie..."; wasRecored = true; } } else if (wasRecored == true) // jesli jest już coś nagrywane to zatrzymaj obecne nagrywanie i zmien tekst na przyciskach { if (soundOut != null) { soundOut.Stop(); soundOut.Dispose(); soundOut = null; buttonRecord.Text = "Nagraj"; } if (sourceStream != null) { sourceStream.StopRecording(); sourceStream.Dispose(); sourceStream = null; buttonRecord.Text = "Nagraj"; } if (waveFileWriter != null) { waveFileWriter.Dispose(); waveFileWriter = null; buttonRecord.Text = "Nagraj"; } labelRecording.Text = ""; } }
private void btnStopSpeech_Click(object sender, EventArgs e) { this.micClient.EndMicAndRecognition(); //this.micClient = null; boxSpeech.Text = ""; btnSpeech.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; } string _selectedFile = "C:\\Users\\Mac\\Desktop\\check.wav"; if (identify) { identifySpeaker(_selectedFile); } }
/// <summary> /// constructs the recorder which means setting up a first input stream /// that is passed to the volume control /// </summary> public Recorder() { waveIn = new NAudio.Wave.WaveIn(); waveIn.WaveFormat = new NAudio.Wave.WaveFormat(8000, 1); waveIn.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(waveIn_DataAvailableVolume); aggregator = new SampleAggregator(); waveIn.StartRecording(); }
void RecognizeAudio() { g.Clear(Color.White); Console.Text = "Say something! \n"; ProcessedBox.Text = BasicDep.Text = AnswerBox.Text = SentiBox.Text = KeywordBox.Text = ""; label1.Visible = true; panel1.Visible = true; button1.Enabled = false; /*---------------------------------------Audio wave--------------------------------*/ List <NAudio.Wave.WaveInCapabilities> sources = new List <NAudio.Wave.WaveInCapabilities>(); for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++) { sources.Add(NAudio.Wave.WaveIn.GetCapabilities(i)); } sourceList.Items.Clear(); foreach (var source in sources) { ListViewItem item = new ListViewItem(source.ProductName); item.SubItems.Add(new ListViewItem.ListViewSubItem(item, source.Channels.ToString())); sourceList.Items.Add(item); } sourceList.TopItem.Selected = true; string path = Directory.GetCurrentDirectory() + @"\question.wav"; if (System.IO.File.Exists(path)) { // Note that no lock is put on the // file and the possibility exists // that another process could do // something with it between // the calls to Exists and Delete. System.IO.File.Delete(path); } FileStream save = System.IO.File.Create(path); 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, sourceStream.WaveFormat); sourceStream.StartRecording(); //await Task.Delay(10000); /*---------------------------------------Audio Wave end----------------------------*/ }
public void RecordAndSaveWin() { m_oSourceStream = new NAudio.Wave.WaveIn(); m_oSourceStream.DeviceNumber = m_iDeviceNumber; m_oSourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(m_iDeviceNumber).Channels); m_oSourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(SourceStreamDataAvailableEvent); m_oWaveWriter = new NAudio.Wave.WaveFileWriter(m_sFileName, m_oSourceStream.WaveFormat); m_oSourceStream.StartRecording(); }
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 = 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(); }
//Record voice private void recordBtn_Click(object sender, EventArgs e) { if (setMode) { try { String filename = @"C:\Pres_Proto\MetroFrameworkDLLExample\RecordWAV\" + letters[curPos] + ".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 = @"C:\Pres_Proto\MetroFrameworkDLLExample\RecordWAV\" + letters[curPos] + ".wav"; String refWAV_file = "Class" + LoginForm.classSec + "_kidAudio/" + letters[curPos] + ".wav"; File f1 = new File(recordWAV_file); File f2 = new 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; } }
//Used to play out what is recording private void button2_Click(object sender, EventArgs e) { sourcestream.DeviceNumber = 0; int deviceNumber = SourceList.SelectedItems[0].Index; sourcestream = new NAudio.Wave.WaveIn(); sourcestream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(0).Channels); NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourcestream); wavout = new NAudio.Wave.DirectSoundOut(); wavout.Init(waveIn); sourcestream.StartRecording(); wavout.Play(); }
public void RecordAndPlay() { m_oSourceStream = new NAudio.Wave.WaveIn(); m_oSourceStream.DeviceNumber = m_iDeviceNumber; m_oSourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(m_iDeviceNumber).Channels); NAudio.Wave.WaveInProvider oWaveIn = new NAudio.Wave.WaveInProvider(m_oSourceStream); m_oWaveOut = new NAudio.Wave.DirectSoundOut(); m_oWaveOut.Init(oWaveIn); m_oSourceStream.StartRecording(); m_oWaveOut.Play(); }
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 = 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(); }
//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; }
/// <summary> /// saves a recording to a temporary file; a new input stream is used /// </summary> /// <param name="filename"></param> public void Record(String filename) { waveFile = new NAudio.Wave.WaveFileWriter(filename, new NAudio.Wave.WaveFormat(8000, 1)); // unbound any resources flowing to the volume control if (waveIn != null) { waveIn.Dispose(); } waveIn = new NAudio.Wave.WaveIn(); waveIn.WaveFormat = new NAudio.Wave.WaveFormat(8000, 1); waveIn.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(waveIn_DataAvailableRecording); waveIn.RecordingStopped += new EventHandler <NAudio.Wave.StoppedEventArgs>(waveIn_RecordingStopped); waveIn.StartRecording(); }
//Starts the recording process from computer mic public void Start_Recording(string File_Form) { string audio_location = File_Form; int deviceNumber = 0; sourcestream = new NAudio.Wave.WaveIn(); sourcestream.DeviceNumber = deviceNumber; sourcestream.WaveFormat = new NAudio.Wave.WaveFormat(44100, 1); sourcestream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourcestream_DataAvalible); try { wavewriter = new NAudio.Wave.WaveFileWriter(audio_location, sourcestream.WaveFormat); } catch {; } sourcestream.StartRecording(); label1.Text = "Recording"; }
public bool StopRecording() { if (waveOut != null) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } if (sourceStream != null) { sourceStream.StopRecording(); sourceStream.Dispose(); sourceStream = null; } return(true); }
private void Record_Click(object sender, EventArgs e) { try { int device = sourceList.SelectedItems[0].Index; sourceStream = new NAudio.Wave.WaveIn(); sourceStream.DeviceNumber = device; sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(sampleRate, NAudio.Wave.WaveIn.GetCapabilities(device).Channels); sourceStream.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); waveWriter = new NAudio.Wave.WaveFileWriter(ms, sourceStream.WaveFormat); sourceStream.StartRecording(); } catch { MessageBox.Show("Please Select An Audio Device", "Missing Audio Device", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public AudioCapturer(int sT = 25, int r = 44100) { m_rate = r; m_sampleTime = sT; m_sampleCount = (sT * r / 1000); m_Sensitivity = 0.04f; m_waveSource = new NAudio.Wave.WaveIn(); m_waveSource.WaveFormat = new NAudio.Wave.WaveFormat(r, 16, 1); m_lastSample = new List <float>(); m_actualSample = new List <float>(); m_laudPeak = new List <float>(); m_waveSource.DataAvailable += waveSourceDataAvailable; m_isRecording = false; }
private void trackBar1_Scroll(object sender, EventArgs e) { if (waveOut != null) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } if (sourceStream != null) { sourceStream.StopRecording(); sourceStream.Dispose(); sourceStream = null; } upgrate(trackBar1.Value); a = trackBar1.Value; textBox1.Text = Convert.ToString(trackBar1.Value); }
public void StopRecording() { try { if (waveOut != null) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } try { if (sourceStream != null) { //th.Abort(); sourceStream.StopRecording(); sourceStream.Dispose(); sourceStream = null; } } catch (Exception e) { Console.WriteLine(e.Message); } try { if (waveWriter != null) { waveWriter.Dispose(); waveWriter = null; } } catch (Exception e) { Console.WriteLine(e.Message); } } catch (Exception e2) { Console.WriteLine(e2.Message); } }
/// <summary> /// when recording is stopped the current input stream and filewriter are discarded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void waveIn_RecordingStopped(object sender, NAudio.Wave.StoppedEventArgs e) { if (waveIn != null) { waveIn.Dispose(); waveIn = new NAudio.Wave.WaveIn(); waveIn.WaveFormat = new NAudio.Wave.WaveFormat(8000, 1); waveIn.DataAvailable += new EventHandler <NAudio.Wave.WaveInEventArgs>(waveIn_DataAvailableVolume); aggregator = new SampleAggregator(); waveIn.StartRecording(); } if (waveFile != null) { waveFile.Dispose(); waveFile = null; } }
public void StopRecording() { if (m_oWaveOut != null) { m_oWaveOut.Stop(); m_oWaveOut.Dispose(); m_oWaveOut = null; } if (m_oSourceStream != null) { m_oSourceStream.StopRecording(); m_oSourceStream.Dispose(); m_oSourceStream = null; } if (m_oWaveWriter != null) { m_oWaveWriter.Dispose(); m_oWaveWriter = null; } }
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; } }
public SetMicrophone() { InitializeComponent(); int waveInDevices = NAudio.Wave.WaveIn.DeviceCount; for (int waveInDevice = 0; waveInDevice < waveInDevices; waveInDevice++) { NAudio.Wave.WaveInCapabilities deviceInfo = NAudio.Wave.WaveIn.GetCapabilities(waveInDevice); microphoneList.Items.Add(waveInDevice+": "+deviceInfo.ProductName); } microphoneList.SelectedIndex = 0; sensitivity.SelectedIndex = 0; sourceStream = new NAudio.Wave.WaveIn(); sourceStream.DeviceNumber = 0; sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(0).Channels); bytesPerChannel = (sourceStream.WaveFormat.BitsPerSample / 8); bytesPerSample = bytesPerChannel * sourceStream.WaveFormat.Channels; sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); sourceStream.StartRecording(); }
private void button3_Click(object sender, EventArgs e) { if (timer != null) { timer.Stop(); } if (screenshotTimer != null) { screenshotTimer.Stop(); } if (waveOut != null) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } if (sourceStream != null) { sourceStream.StopRecording(); sourceStream.Dispose(); sourceStream = null; } }
//Now, when you click record, it's going to start a timer //and the user can give as many repetitions in one input //this is to enhance the audio input percentage private void recBtn_Click(object sender, EventArgs e) { try { backBtn.Enabled = false; String filename = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\RecordWAV\" + lvlStr + ".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(); slideDown(sender, e); //Amount of time to take voice input seconds = 5; //startRecord(sender, e); timeLabel.Visible = true; secsLabel.Visible = true; secsLabel.Text = Convert.ToString(seconds); countTimer.Start(); //setMode = false; } catch (Exception) { throw; } }
private void buttonSaveWave_Click(object sender, EventArgs e) { if (listViewAudioSources.SelectedItems.Count == 0) return; SaveFileDialog save = new SaveFileDialog(); save.Filter = "Wave File (*.wav)|*.wav;"; if (save.ShowDialog() != DialogResult.OK) return; textBoxRecordingLocation.Text = save.FileName; int deviceNumber = listViewAudioSources.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(); }
//private void buttonStartRecording_Click(object sender, EventArgs e) //{ // if (listViewAudioSources.SelectedItems.Count == 0) return; // int deviceNumber = listViewAudioSources.SelectedItems[0].Index; // sourceStream = new NAudio.Wave.WaveIn(); // sourceStream.DeviceNumber = deviceNumber; // sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels); // NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream); // waveOut = new NAudio.Wave.DirectSoundOut(); // waveOut.Init(waveIn); // sourceStream.StartRecording(); // waveOut.Play(); //} private void buttonStopRecording_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; } }
//Record/Stop, user can record with many tries as possible private void recStpBtn_Click(object sender, EventArgs e) { //When pressed first, start recording if (mode) { try { recStpBtn.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(@"C:\Pres_Proto\V2\MetroFrameworkDLLExample\RecordWAV\" + lvlStr + ".wav", wavSource.WaveFormat); wavSource.StartRecording(); mode = false; } catch (System.IO.IOException ex) { MessageBox.Show(ex.ToString()); } } //Else stop recording else { recStpBtn.Text = "Record"; wavSource.StopRecording(); mode = true; } }
//Record voice private void recordBtn_Click(object sender, EventArgs e) { if (setMode) { try { String filename = @"C:\Pres_Proto\MetroFrameworkDLLExample\RecordWAV\" + letters[curPos] + ".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 = @"C:\Pres_Proto\MetroFrameworkDLLExample\RecordWAV\" + letters[curPos] + ".wav"; String refWAV_file = "Class" + LoginForm.classSec + "_kidAudio/" + letters[curPos] + ".wav"; File f1 = new File(recordWAV_file); File f2 = new 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; } }
private void buttonRecStart_Click(object sender, EventArgs e) { if (listViewSources.SelectedItems.Count == 0) { Console.WriteLine("No device selected."); return; } int deviceNumber = listViewSources.SelectedItems[0].Index; labelRecDevice.Text = deviceNumber.ToString(); 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>(waveIn_DataAvailable); sourceStream.StartRecording(); if (checkBoxPlayback.Checked) { NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream); waveOut = new NAudio.Wave.DirectSoundOut(NAudio.Wave.WaveOut.GetCapabilities(outputDevice).ProductGuid); waveOut.Init(waveIn); waveOut.Play(); } else { NAudio.Wave.WaveIn waveIn = new NAudio.Wave.WaveIn(); } pictureBoxRecording.BackColor = Color.Red; }
private void StartRecording() { // Check if there are sources for input sound int numResource = NAudio.Wave.WaveIn.DeviceCount; if (numResource == 0) return; // Use the first source as default sourceStream = new NAudio.Wave.WaveIn(); // Set wave format sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(16000, 16, 1); NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream); //waveOut = new NAudio.Wave.DirectSoundOut(); //waveOut.Init(waveIn); sourceStream.StartRecording(); //waveOut.Play(); // plays the audio, serve as demo, can be deleted sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable); // Save the file temporarily in the audio folder, note that previous recording will be overwritten waveWriter = new NAudio.Wave.WaveFileWriter("audio/temp.wav", sourceStream.WaveFormat); }
private void StopRecording() { /* 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; } }
private void buttonRecStop_Click(object sender, EventArgs e) { if (waveOut != null) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } if(sourceStream != null) { sourceStream.StopRecording(); sourceStream.Dispose(); sourceStream = null; } pictureBoxRecording.BackColor = Color.Black; }