/// <summary> /// Method to start/stop recording from the main microphone /// </summary> private void Record_button_Click(object sender, RoutedEventArgs e) { // In case user whants to start a recording session if (!isRecordingOn) { // Ask user in which file to store audio data string newfilePath = getFileName(); if (newfilePath == "") { return; } ; // dialog canceled OR failed filePath = newfilePath; // Set some UI stuff ChosenFileLabel.Text = "File: " + TransformFilePath.GetCanonicalName(filePath, ".wav"); StartRecodingButton.Content = "Stop recording"; StartRecodingButton.BorderBrush = Brushes.Purple; StartRecodingButton.Foreground = Brushes.Purple; waveForm.Points.Clear(); // Set the input settings of the audio recorder waveIn = new WaveIn(); waveIn.DeviceNumber = selectedRecordingDevice; waveIn.DataAvailable += waveIn_DataAvailable; // event to handle packs of recorded data waveIn.RecordingStopped += waveIn_RecordingStopped; // event to notify user about finished recording int channels = 1; // mono waveIn.WaveFormat = new WaveFormat(sampleRate, channels); // set some helpers recorder = new RecordWAVandMP3(filePath, waveIn.WaveFormat); // helper to save recorded data visualizer = new VisualizeAudioData(waveForm); // helper to visualize recorded data // Starting recording waveIn.StartRecording(); isRecordingOn = !isRecordingOn; } // In case user whants to stop the recording else { // Set some UI stuff StartRecodingButton.Content = "Start recording"; StartRecodingButton.BorderBrush = Brushes.Blue; StartRecodingButton.Foreground = Brushes.Blue; // stopping the recording waveIn.StopRecording(); // Recording is in progress no more isRecordingOn = !isRecordingOn; } }
// method to check if file was selected private void NoiseChoosingWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // check if file was selected if (isFileSelected) { MainWindow.NoiseFile = TransformFilePath.GetCanonicalName(filePath, ".wav"); // remember file name in main window MainWindow.FullNoiseFile = filePath; ClosedWithResult(this, e); } else { ClosedWithoutResult(this, e); } }
// Method to check if recording is on when closing the window private void RecordingWindow_Closing(object sender, CancelEventArgs e) { if (isRecordingOn) { MessageBox.Show("Finish recording first!"); e.Cancel = true; return; } // check if file was selected if (isFileSelected) { MainWindow.SpeechFile = TransformFilePath.GetCanonicalName(filePath, ".wav"); // remember file name in main window MainWindow.FullSpeechFile = filePath; ClosedWithResult(this, e); } else { ClosedWithoutResult(this, e); } }
private void OpenNoiseAudio_button_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = ".wav"; // Default file extension dlg.Filter = "Audio documents (.wav)|*.wav"; // Filter files by extension dlg.InitialDirectory = TransformFilePath.GetParentDirectoryPath() + @"\Audio\Noise"; // Show save file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { isFileSelected = true; filePath = dlg.FileName; ChosenFileLabel.Content = "File: " + TransformFilePath.GetCanonicalName(filePath, ".wav"); // enable done button DoneButton.IsEnabled = true; } }