// Method to get audio sample from an already existing item
        private void OpenAudio_button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt       = ".wav";                    // Default file extension
            dlg.Filter           = "Wave audio (.wav)|*.wav"; // Filter files by extension
            dlg.InitialDirectory = TransformFilePath.GetParentDirectoryPath() + @"\Audio\Speech";

            // Show save file dialog box
            bool?result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                filePath             = dlg.FileName;
                ChosenFileLabel.Text = "File: " + filePath.Substring(filePath.LastIndexOf('\\') + 1);
                isFileSelected       = true;

                // enabe done button
                DoneButton.IsEnabled = true;

                // set ui stuff
                SelectAudioButton.BorderBrush = Brushes.Purple;
                SelectAudioButton.Foreground  = Brushes.Purple;
            }
        }
Exemplo n.º 2
0
        // Method to convert audio files
        private void ConvertAudio_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";
            dlg.Title            = "Load audio to convert";

            string noiseToConvertFilePath;

            // Show save file dialog box
            bool?result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                noiseToConvertFilePath = dlg.FileName;
            }
            else
            {
                return;
            }

            // ask for destination

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt       = ".wav";
            sfd.InitialDirectory = TransformFilePath.GetParentDirectoryPath() + @"\Audio";
            sfd.Title            = "Save new audio";

            string newNoise;

            // Show save file dialog box
            result = sfd.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                newNoise = sfd.FileName;
            }
            else
            {
                return;
            }

            // convert existing file into a new one with 'desired' Hz
            using (var reader = new WaveFileReader(noiseToConvertFilePath))
            {
                var newFormat = new WaveFormat(desiredHz, 16, 1);
                using (var conversionStream = new WaveFormatConversionStream(newFormat, reader))
                {
                    WaveFileWriter.CreateWaveFile(newNoise, conversionStream);
                }
            }
        }
        /// <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;
            }
        }
Exemplo n.º 4
0
 // 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);
            }
        }
        // Method to get file name in which to store audio from user
        string getFileName()
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName         = "AudioSample";             // Default file name
            dlg.DefaultExt       = ".wav";                    // Default file extension
            dlg.Filter           = "Wave audio (.wav)|*.wav"; // Filter files by extension
            dlg.InitialDirectory = TransformFilePath.GetParentDirectoryPath() + @"\Audio\Speech";

            // Show save file dialog box
            bool?result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                return(dlg.FileName);
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
 public override string ToString()
 {
     return($"{TransformFilePath.FullName().Highlight()} => {ConfigFilePath.Name.Highlight()}");
 }