// 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;
            }
        }
예제 #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);
                }
            }
        }
        // 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("");
            }
        }
예제 #4
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;
            }
        }