Ejemplo n.º 1
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            string soundLink = GetGUISoundLink();

            if (soundLink == "")
            {
                return;
            }
            SaveFileDialog dialog = new SaveFileDialog();

            if (radio_mp3.Checked)
            {
                dialog.Filter   = "MP3 File (*.mp3)|*.mp3";
                dialog.FileName = "tts.mp3";
            }
            else
            {
                dialog.Filter   = "WAV File (*.wav)|*.wav";
                dialog.FileName = "tts.wav";
            }

            var s = dialog.ShowDialog();

            if (s == DialogResult.OK)
            {
                if (!Program.bOldWindows && !(radio_mp3.Checked && Math.Abs(Pitch - 1f) <= 0.01f))
                {
                    using (var mf = new MediaFoundationReader(soundLink))
                    {
                        PitchProvider             = new SmbPitchShiftingSampleProvider(mf.ToSampleProvider().ToMono());
                        PitchProvider.PitchFactor = Pitch;
                        if (radio_mp3.Checked)
                        {
                            MediaFoundationEncoder.EncodeToMp3(PitchProvider.ToWaveProvider(), dialog.FileName, 48000);
                        }
                        else
                        {
                            WaveFileWriter.CreateWaveFile(dialog.FileName, PitchProvider.ToWaveProvider());
                        }

                        MessageBox.Show(downloaded);
                    }
                }
                else
                {
                    using (var wc = new WebClient())
                    {
                        wc.DownloadFile(soundLink, dialog.FileName);
                        MessageBox.Show(downloaded);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string fileDir     = AppContext.BaseDirectory;
            var    inPath      = SPath.Combine(fileDir, "了解真相快三退.wav");
            var    semitone    = Math.Pow(2, 1.0 / 12);
            var    upOneTone   = semitone * semitone * semitone * semitone * semitone;
            var    downOneTone = 1.0 / (upOneTone);
            var    tfile       = TagLib.File.Create(inPath);

            using (var reader = new MediaFoundationReader(inPath))
            {
                var pitch = new SmbPitchShiftingSampleProvider(reader.ToSampleProvider());
                pitch.PitchFactor = (float)(((double)new Random().Next(60, 115)) / 100);
                string tempFileNameGuid   = Guid.NewGuid().ToString();
                string tempFilePath       = SPath.Combine(fileDir, tempFileNameGuid + ".wav");
                string outputFileNameGuid = Guid.NewGuid().ToString();
                string outWavFilePath     = SPath.Combine(fileDir, outputFileNameGuid + ".wav");
                string outMp3FilePath     = SPath.Combine(fileDir, outputFileNameGuid + ".mp3");
                WaveFileWriter.CreateWaveFile(tempFilePath, pitch.ToWaveProvider());
                ConvertWavToMp3(tempFilePath, outMp3FilePath, tfile.Properties.AudioBitrate);
                //playSampleProvider(pitch);
                using (var mp3Reader = new Mp3FileReader(outMp3FilePath))
                    using (var conversionStream = new WaveFormatConversionStream(reader.WaveFormat, mp3Reader))
                        WaveFileWriter.CreateWaveFile(outWavFilePath, conversionStream);
                if (File.Exists(tempFilePath))
                {
                    File.Delete(tempFilePath);
                }
            }
        }
Ejemplo n.º 3
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            string         soundLink = GetGUISoundLink();
            SaveFileDialog dialog    = new SaveFileDialog();

            dialog.Filter   = "MP3 File (*.mp3)|*.mp3";
            dialog.FileName = "tts.mp3";
            var s = dialog.ShowDialog();

            if (s == DialogResult.OK)
            {
                if (!Program.bOldWindows)
                {
                    using (var mf = new MediaFoundationReader(soundLink))
                    {
                        PitchProvider             = new SmbPitchShiftingSampleProvider(mf.ToSampleProvider().ToMono());
                        PitchProvider.PitchFactor = Pitch;
                        MediaFoundationEncoder.EncodeToMp3(PitchProvider.ToWaveProvider(), dialog.FileName, 48000);
                        MessageBox.Show(downloaded);
                    }
                }
                else
                {
                    using (var wc = new WebClient())
                    {
                        wc.DownloadFile(soundLink, dialog.FileName);
                        MessageBox.Show(downloaded);
                    }
                }
            }
        }