diff --git a/AcapellaDownloader/Form1.cs b/AcapellaDownloader/Form1.cs index 529e493..ac066d0 100644 --- a/AcapellaDownloader/Form1.cs +++ b/AcapellaDownloader/Form1.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Globalization; +using System.IO; using System.Linq; using System.Net; using System.Threading; @@ -33,12 +34,24 @@ private void btnDownload_Click(object sender, EventArgs e) var s = dialog.ShowDialog(); if (s == DialogResult.OK) { - 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); + 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); + + } } } } @@ -100,20 +113,34 @@ private void btnPlay_Click(object sender, EventArgs e) } void PlaySound(string link, int WaveOutDeviceId) { - using (var mf = new MediaFoundationReader(link)) - using (var wo = new WaveOutEvent()) + using (Stream ms = new MemoryStream()) { - wo.DeviceNumber = WaveOutDeviceId; - PitchProvider = new SmbPitchShiftingSampleProvider(mf.ToSampleProvider().ToMono()); - PitchProvider.PitchFactor = Pitch; - wo.Init(PitchProvider); - wo.Volume = VoiceVolume; - wo.Play(); - while (wo.PlaybackState == PlaybackState.Playing) + using (Stream stream = WebRequest.Create(link).GetResponse().GetResponseStream()) + { + byte[] buffer = new byte[4096]; + int read; + while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) + { + ms.Write(buffer, 0, read); + } + } + + ms.Position = 0; + using (WaveStream mf = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(ms)))) + using (var wo = new WaveOutEvent()) { - PitchProvider.PitchFactor = Pitch; - wo.Volume = VoiceVolume; - Thread.Sleep(500); + wo.DeviceNumber = WaveOutDeviceId; + PitchProvider = new SmbPitchShiftingSampleProvider(mf.ToSampleProvider().ToMono()); + PitchProvider.PitchFactor = Pitch; + wo.Init(PitchProvider); + wo.Volume = VoiceVolume; + wo.Play(); + while (wo.PlaybackState == PlaybackState.Playing) + { + PitchProvider.PitchFactor = Pitch; + wo.Volume = VoiceVolume; + Thread.Sleep(500); + } } } } diff --git a/AcapellaDownloader/Program.cs b/AcapellaDownloader/Program.cs index 2ce0a88..446a00b 100644 --- a/AcapellaDownloader/Program.cs +++ b/AcapellaDownloader/Program.cs @@ -4,10 +4,17 @@ namespace AcapellaDownloader { static class Program { + public static bool bOldWindows = false; [STAThread] static void Main() { - string[] commandLineArgs = Environment.GetCommandLineArgs(); + var OsVersion = Environment.OSVersion.Version; + if (OsVersion.Major <= 6 && OsVersion.Minor <= 1) + { + bOldWindows = true; + } + + string[] commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs.Length > 1) { CLI.PassCLI(commandLineArgs); diff --git a/README.md b/README.md index f926481..ea600a0 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,5 @@ Use --voice-list argument to get all voice id's #### Example: AcapellaDownloader.exe -t Test string 1 2 3 -v enu_willhappy_22k_ns.bvcu -o test.mp3 ## Requirements -Windows 8 or Windows 10 +Windows 7 (without changing pitch on download), Windows 8 or Windows 10 +