private void button10_Click(object sender, EventArgs e) { var client = new MongoClient("mongodb://localhost"); var database = client.GetDatabase("docs"); var fs = new GridFSBucket(database); //var aaa = fs.Find() var test = fs.DownloadAsBytesByName("Muzika"); MemoryStream memStream = new MemoryStream(test); //OpenFileDialog open = new OpenFileDialog(); //open.Filter = "Audio File (*.mp3;*.wav)|*.mp3;*.wav;"; //if (open.ShowDialog() != DialogResult.OK) return; DisposeWave(); // if (open.FileName.EndsWith(".mp3")) // { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(memStream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); // } // else if (open.FileName.EndsWith(".wav")) //{ // NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName)); // stream = new NAudio.Wave.BlockAlignReductionStream(pcm); //} //else throw new InvalidOperationException("Not a correct audio file type."); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); }
private void openFileButton_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Audio File (*.mp3;*.wav)|*.mp3;*.wav;"; if (open.ShowDialog() != DialogResult.OK) return; DisposeWave(); if (open.FileName.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (open.FileName.EndsWith(".wav")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else throw new InvalidOperationException("Not a correct audio file type."); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); pauseButton.Enabled = true; }
private void button1_Click(object sender, EventArgs e) {/*Array.Sort();*/ OpenFileDialog OPPOEpe = new OpenFileDialog(); OPPOEpe.Filter = "Wawe file (*.mp3|*mp3;) "; if (OPPOEpe.ShowDialog() != DialogResult.OK) { return; } DisposeWave(); NAudio.Wave.WaveStream p = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(OPPOEpe.FileName)); button1.Text = p.WaveFormat.ToString(); stream = new NAudio.Wave.BlockAlignReductionStream(p); TimeSpan error = new TimeSpan(0, 0, 0); TimeSpan error1 = new TimeSpan(0, 0, 1); TimeSpan error2 = new TimeSpan(1, 0, 1); NAudio.Wave.WaveOffsetStream str = new NAudio.Wave.WaveOffsetStream(stream, error, error1, error2); gavnout = new NAudio.Wave.DirectSoundOut(); str.Skip(100); gavnout.Init(str); gavnout.Play(); }
private void bt_Abrir_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Audio File (*.mp3;*.wav)|*.mp3;*.wav;"; if (open.ShowDialog() != DialogResult.OK) { return; } DisposeWave(); if (open.FileName.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (open.FileName.EndsWith(".wav")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else { throw new InvalidOperationException("Not a correct audio file type."); } output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); bt_Play_Stop.Enabled = true; }
public void play(string path) { NAudio.Wave.WaveStream a = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(path)); NAudio.Wave.BlockAlignReductionStream stream = new NAudio.Wave.BlockAlignReductionStream(a); this.output.Init(stream); this.output.Play(); }
//druga himna void output_PlaybackStopped(object sender, NAudio.Wave.StoppedEventArgs e) { if (notClosed) { try { DisposeWave(); byte[] gostPesma = AuxLib.LoadSoundFromGridFS(gost.Ime + "himna"); MemoryStream gostStream = new MemoryStream(gostPesma); NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(gostStream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } }
private void gg(string name) { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(@"C:\Program Files (x86)\Mektep\sound\" + name)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); }
/// <summary> /// Plays sound from start /// </summary> public void PlaySound() { if (fileName.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(fileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (fileName.EndsWith(".wav")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(fileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else { throw new InvalidOperationException("Not a correct audio file type. Supports mp3 and wav only!"); } if (output == null) { output = new NAudio.Wave.DirectSoundOut(); } output.Init(stream); output.Play(); }
private void GoalSoundPlay() { goalSound.Position = 0; NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(goalSound)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); Thread.Sleep(3000); this.DisposeWave(); }
private void DisposeWave() { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Stop(); output.Dispose(); output = null; } if (stream != null) { stream.Dispose(); stream = null; } }
public Main() { InitializeComponent(); AMFParser.Initialize(); ///////////////////////////////////////////////////////////////////////// /// Setting up automatic audio playback (NAudio) MemoryStream mp3file = new MemoryStream(Properties.Resources.ECLiPSE_CyberMotion); NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(mp3file)); NAudio.Wave.BlockAlignReductionStream stream = new NAudio.Wave.BlockAlignReductionStream(pcm); NAudio.Wave.DirectSoundOut output = new NAudio.Wave.DirectSoundOut(700); //audio latency (to stop crackling) output.PlaybackStopped += (pbss, pbse) => { System.Threading.Thread.Sleep(1000); stream.Position = 0; output.Play(); }; output.Init(stream); output.Play(); ///////////////////////////////////////////////////////////////////////// //users.dat holds captured usernames and uuids locally //format: username > xxxxx-xxxx-xxx...(36 character uuid) if (!File.Exists("users.dat")) { File.Create("users.dat").Close(); } foreach (string line in File.ReadAllLines("users.dat")) { uuid_combobox.Items.Add(line); } if (uuid_combobox.Items.Count > 0) { uuid_combobox.SelectedIndex = 0; } //gets and lists all available network interfaces NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface nic in nics) { if (nic.OperationalStatus == OperationalStatus.Up) { adapter_combobox.Items.Add(String.Format("{0}: {1}", nic.Name, nic.Id)); } } if (adapter_combobox.Items.Count > 0) { adapter_combobox.SelectedIndex = 0; } }
private void button9_Click(object sender, EventArgs e) { FileStream Tstream; OpenFileDialog ofd = new OpenFileDialog(); var client = new MongoClient("mongodb://localhost"); var database = client.GetDatabase("docs"); var fs = new GridFSBucket(database); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Tstream = new System.IO.FileStream(ofd.FileName, FileMode.Open, FileAccess.Read); //SoundPlayer simpleSound = new SoundPlayer(stream); //simpleSound.Play(); var split = ofd.SafeFileName.Split('.'); if (split[1] != "mp3") { MessageBox.Show("Izaberite mp3 fajl!"); return; } DisposeWave(); NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(Tstream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); // } // else if (open.FileName.EndsWith(".wav")) //{ // NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName)); // stream = new NAudio.Wave.BlockAlignReductionStream(pcm); //} //else throw new InvalidOperationException("Not a correct audio file type."); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); //GridFSUploadOptions opcije = new GridFSUploadOptions(); //opcije.ContentType = "audio/mp3"; //opcije.ChunkSizeBytes = Convert.ToInt32(stream.Length)/4; //int duzina = Convert.ToInt32(stream.Length); //byte[] bajtovi = new byte[duzina]; //stream.Seek(0, SeekOrigin.Begin); //int bytesRead = stream.Read(bajtovi, 0, duzina); //fs.UploadFromBytes(ofd.SafeFileName, bajtovi, opcije); //FormaPesma = ofd.SafeFileName; } }
private void button2_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "MP3 File (*.mp3|*.mp3;"; if (dialog.ShowDialog() != DialogResult.OK) { return; } NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(dialog.FileName)); NAudio.Wave.BlockAlignReductionStream stream = new NAudio.Wave.BlockAlignReductionStream(pcm); NAudio.Wave.DirectSoundOut output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); }
private void button2_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "MP3 File (*.mp3)|*.mp3;"; if (open.ShowDialog() != DialogResult.OK) { return; } DisposeWave(); NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); pauseMP3Button.Enabled = true; }
private void FInfoZaMec_Load(object sender, EventArgs e) { try { //TO DO : UCITATI I FORMATIRATI INFORMACIJE O OBA TIMA I O STADIONU I UPISATI U RTB.. //prvo za domacina AuxLib.PrikaziDomacinaRTB(RTBDomacinInfo, domacin.Ime); AuxLib.PrikaziGostaRTB(RTBGostInfo, gost.Ime); AuxLib.PrikaziStadionRTB(RTBStadionInfo, stadion.Ime); //------------------------- //ucitavanje slika iz gridFS-a this.PBDomacinZastava.Image = AuxLib.LoadImageFromGridFS(domacin.Ime + "zastava"); this.PBGostZastava.Image = AuxLib.LoadImageFromGridFS(gost.Ime + "zastava"); this.PBStadionZastava.Image = AuxLib.LoadImageFromGridFS(stadion.Ime + "stadion"); //-------------------------- //ucitamo himnu iz baze kao byte array byte[] domacinPesma = AuxLib.LoadSoundFromGridFS(domacin.Ime + "himna"); //napravis stream MemoryStream domacinStream = new MemoryStream(domacinPesma); //prekines ako ima neka pesma prethodno ( za svaki slucaj ); DisposeWave(); //pcm pd strima NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(domacinStream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); //init,hendler za drugu himnu i play output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.PlaybackStopped += output_PlaybackStopped; output.Play(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
static void Main(string[] args) { if (args.Count() == 0) { Console.WriteLine("Basic text to speach converter"); Console.WriteLine("Expecting text in the command line parameter"); Environment.Exit(0); } Console.WriteLine("Creating Amazon Polly client"); Amazon.Polly.AmazonPollyClient cl = new Amazon.Polly.AmazonPollyClient(RegionEndpoint.USWest2); Amazon.Polly.Model.SynthesizeSpeechRequest req = new Amazon.Polly.Model.SynthesizeSpeechRequest(); req.Text = String.Join(" ", args); req.VoiceId = Amazon.Polly.VoiceId.Salli; req.OutputFormat = Amazon.Polly.OutputFormat.Mp3; req.SampleRate = "8000"; req.TextType = Amazon.Polly.TextType.Text; Console.WriteLine("Sending Amazon Polly request: " + req.Text); Amazon.Polly.Model.SynthesizeSpeechResponse resp = cl.SynthesizeSpeech(req); MemoryStream local_stream = new MemoryStream(); resp.AudioStream.CopyTo(local_stream); local_stream.Position = 0; Console.WriteLine("Got mp3 stream, lenght: " + local_stream.Length.ToString()); NAudio.Wave.Mp3FileReader reader = new NAudio.Wave.Mp3FileReader(local_stream); NAudio.Wave.WaveStream wave_stream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(reader); NAudio.Wave.BlockAlignReductionStream ba_stream = new NAudio.Wave.BlockAlignReductionStream(wave_stream); NAudio.Wave.WaveOut wout = new NAudio.Wave.WaveOut(); Console.Write("Playing stream..."); wout.Init(ba_stream); wout.Play(); while (wout.PlaybackState == NAudio.Wave.PlaybackState.Playing) { Thread.Sleep(100); } Console.WriteLine("..Done"); }
private void btnOpen_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Sound Files (*.mp3;*.wav)|*.mp3;*.wav;"; open.ShowDialog(); DisposeWave(); //wave = new NAudio.Wave.WaveFileReader(open.FileName); if (open.FileName.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.Mp3FileReader(open.FileName); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (open.FileName.EndsWith(".wav")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } output = new NAudio.Wave.WaveOutEvent(); output.Init(new NAudio.Wave.WaveChannel32(stream)); output.Play(); StopWatch(); if (stopWatch.IsRunning) { stopWatch.Stop(); } else { stopWatch.Start(); } btnPausePlay.IsEnabled = true; }catch (ArgumentException) { System.Windows.MessageBox.Show("Choose a real file"); } }
private void DisposeWave() { //dispose of song from stream. To ensure no memory leaks if (stream == null) { txtNowPlaying.Text = "Nothing to stop..."; } if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); } output.Dispose(); output = null; } if (stream != null) { stream.Dispose(); stream = null; } }
private void FInfoZaMec_Load(object sender, EventArgs e) { try { //vraca vraca objekte i upisuje podatke u richtextboxove domacin = AuxLib.PrikaziDomacinaRTB(this.RTBDomacinInfo, domacinIme); gost = AuxLib.PrikaziDomacinaRTB(this.RTBGostInfo, gostIme); stadion = AuxLib.PrikaziStadionRTB(this.RTBStadionInfo, domacin); //------------------------- //ucitavanje slika iz gridFS-a this.PBDomacinZastava.Image = AuxLib.LoadImageFromGridFS(this.domacinIme + "zastava"); this.PBGostZastava.Image = AuxLib.LoadImageFromGridFS(this.gostIme + "zastava"); this.PBStadionZastava.Image = AuxLib.LoadImageFromGridFS(stadion.Ime + "stadion"); //-------------------------- //ucitamo himnu iz baze kao byte array byte[] domacinPesma = AuxLib.LoadSoundFromGridFS(domacinIme + "himna"); //napravis stream MemoryStream domacinStream = new MemoryStream(domacinPesma); //prekines ako ima neka pesma prethodno ( za svaki slucaj ); DisposeWave(); //pcm pd strima NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(domacinStream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); //init,hendler za drugu himnu i play output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.PlaybackStopped += output_PlaybackStopped; output.Play(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
public void DisposeWave() { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); } output.Dispose(); output = null; } if (wave != null) { wave.Dispose(); wave = null; } if (stream != null) { stream.Dispose(); stream = null; } }
private void lstSongBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { foreach (Song find in songDll) { if (lstSongBox.SelectedItem.ToString() == find.gsSongName) { DisposeWave(); //check if mp3 or wav if (find.gsSongURL.EndsWith(".mp3")) { //take the pcm data into a new stream and play the mp3 file NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(find.gsSongURL)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (find.gsSongURL.EndsWith(".wav")) { //do the same as the above but with a wav file NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(find.gsSongURL)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else { throw new InvalidOperationException("Not a correct audio file type"); } output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); btnPlay.IsEnabled = true; btnStop.IsEnabled = true; btnPause.IsEnabled = true; txtNowPlaying.Text = "Now playing: " + lstSongBox.SelectedItem.ToString(); } } }
private void FInfoZaMec_Load(object sender, EventArgs e) { try { //vraca vraca objekte i upisuje podatke u richtextboxove domacin = AuxLib.PrikaziDomacinaRTB(this.RTBDomacinInfo, domacinIme); gost = AuxLib.PrikaziDomacinaRTB(this.RTBGostInfo, gostIme); stadion = AuxLib.PrikaziStadionRTB(this.RTBStadionInfo, domacin); //------------------------- //ucitavanje slika iz gridFS-a this.PBDomacinZastava.Image = AuxLib.LoadImageFromGridFS(this.domacinIme + "zastava"); this.PBGostZastava.Image = AuxLib.LoadImageFromGridFS(this.gostIme + "zastava"); this.PBStadionZastava.Image = AuxLib.LoadImageFromGridFS( stadion.Ime + "stadion"); //-------------------------- //ucitamo himnu iz baze kao byte array byte[] domacinPesma = AuxLib.LoadSoundFromGridFS(domacinIme+"himna"); //napravis stream MemoryStream domacinStream = new MemoryStream(domacinPesma); //prekines ako ima neka pesma prethodno ( za svaki slucaj ); DisposeWave(); //pcm pd strima NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(domacinStream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); //init,hendler za drugu himnu i play output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.PlaybackStopped += output_PlaybackStopped; output.Play(); } catch(Exception ex) { MessageBox.Show(ex.Message); return; } }
private void button9_Click(object sender, EventArgs e) { FileStream stream; OpenFileDialog ofd = new OpenFileDialog(); var client = new MongoClient("mongodb://localhost"); var database = client.GetDatabase("docs"); var fs = new GridFSBucket(database); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { stream = new System.IO.FileStream(ofd.FileName, FileMode.Open, FileAccess.Read); //SoundPlayer simpleSound = new SoundPlayer(stream); //simpleSound.Play(); var split = ofd.SafeFileName.Split('.'); if(split[1] != "mp3") { MessageBox.Show("Izaberite mp3 fajl!"); return; } GridFSUploadOptions opcije = new GridFSUploadOptions(); opcije.ContentType = "audio/mp3"; opcije.ChunkSizeBytes = Convert.ToInt32(stream.Length)/4; int duzina = Convert.ToInt32(stream.Length); byte[] bajtovi = new byte[duzina]; stream.Seek(0, SeekOrigin.Begin); int bytesRead = stream.Read(bajtovi, 0, duzina); fs.UploadFromBytes(ofd.SafeFileName, bajtovi, opcije); } }
private void button8_Click(object sender, EventArgs e) { Image slika; FileStream stream; var client = new MongoClient("mongodb://localhost"); var database = client.GetDatabase("docs"); var fs = new GridFSBucket(database); OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { stream = new System.IO.FileStream(ofd.FileName, FileMode.Open, FileAccess.Read); slika = Image.FromStream(stream); GridFSUploadOptions opcije = new GridFSUploadOptions(); opcije.ContentType = "image/jpg"; opcije.ChunkSizeBytes = Convert.ToInt32(stream.Length); int duzina = Convert.ToInt32(stream.Length); byte[] bajtovi = new byte[duzina]; stream.Seek(0, SeekOrigin.Begin); int bytesRead = stream.Read(bajtovi, 0, duzina); fs.UploadFromBytes("Test", bajtovi, opcije); } MessageBox.Show("done"); }
public Soundsystem() { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream( new NAudio.Wave.Mp3FileReader("sounds/ambience-wind1.mp3")); ambience = new NAudio.Wave.BlockAlignReductionStream(pcm); pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream( new NAudio.Wave.Mp3FileReader("music/zombi-drone.mp3")); drone = new NAudio.Wave.BlockAlignReductionStream(pcm); fire1 = new NAudio.Wave.WaveFileReader("sounds/gun-fire1.wav"); fire2 = new NAudio.Wave.WaveFileReader("sounds/gun-fire2.wav"); empty = new NAudio.Wave.WaveFileReader("sounds/gun-empty.wav"); load = new NAudio.Wave.WaveFileReader("sounds/gun-load.wav"); hitflesh1 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh1.wav"); hitflesh2 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh2.wav"); hitflesh3 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh3.wav"); hitmetal1 = new NAudio.Wave.WaveFileReader("sounds/hit-metal1.wav"); hitmetal2 = new NAudio.Wave.WaveFileReader("sounds/hit-metal2.wav"); hitmetal3 = new NAudio.Wave.WaveFileReader("sounds/hit-metal3.wav"); hitrock = new NAudio.Wave.WaveFileReader("sounds/hit-rock1.wav"); hitglass = new NAudio.Wave.WaveFileReader("sounds/hit-glass1.wav"); walk1 = new NAudio.Wave.WaveFileReader("sounds/walk1.wav"); walk2 = new NAudio.Wave.WaveFileReader("sounds/walk2.wav"); walk3 = new NAudio.Wave.WaveFileReader("sounds/walk3.wav"); walk4 = new NAudio.Wave.WaveFileReader("sounds/walk4.wav"); walk5 = new NAudio.Wave.WaveFileReader("sounds/walk5.wav"); walk6 = new NAudio.Wave.WaveFileReader("sounds/walk6.wav"); walk7 = new NAudio.Wave.WaveFileReader("sounds/walk7.wav"); walk8 = new NAudio.Wave.WaveFileReader("sounds/walk8.wav"); zombi1 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan1.wav"); zombi2 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan2.wav"); zombi3 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan3.wav"); zombi4 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan4.wav"); zombi5 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan5.wav"); zombi6 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan6.wav"); zombi7 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan7.wav"); fire1_channel = new NAudio.Wave.WaveChannel32(fire1); fire1_channel.Volume = 0.0f; fire2_channel = new NAudio.Wave.WaveChannel32(fire2); fire2_channel.Volume = 0.0f; load_channel = new NAudio.Wave.WaveChannel32(load); load_channel.Volume = 0.0f; empty_channel = new NAudio.Wave.WaveChannel32(empty); empty_channel.Volume = 0.0f; hitglass_channel = new NAudio.Wave.WaveChannel32(hitglass); hitglass_channel.Volume = 0.0f; hitflesh1_channel = new NAudio.Wave.WaveChannel32(hitflesh1); hitflesh1_channel.Volume = 0.0f; hitflesh2_channel = new NAudio.Wave.WaveChannel32(hitflesh2); hitflesh2_channel.Volume = 0.0f; hitflesh3_channel = new NAudio.Wave.WaveChannel32(hitflesh3); hitflesh3_channel.Volume = 0.0f; hitrock_channel = new NAudio.Wave.WaveChannel32(hitrock); hitrock_channel.Volume = 0.0f; hitmetal1_channel = new NAudio.Wave.WaveChannel32(hitmetal1); hitmetal1_channel.Volume = 0.0f; hitmetal2_channel = new NAudio.Wave.WaveChannel32(hitmetal2); hitmetal2_channel.Volume = 0.0f; hitmetal3_channel = new NAudio.Wave.WaveChannel32(hitmetal3); hitmetal3_channel.Volume = 0.0f; walk1_channel = new NAudio.Wave.WaveChannel32(walk1); walk1_channel.Volume = 0.0f; walk2_channel = new NAudio.Wave.WaveChannel32(walk2); walk2_channel.Volume = 0.0f; walk3_channel = new NAudio.Wave.WaveChannel32(walk3); walk3_channel.Volume = 0.0f; walk4_channel = new NAudio.Wave.WaveChannel32(walk4); walk4_channel.Volume = 0.0f; walk5_channel = new NAudio.Wave.WaveChannel32(walk5); walk5_channel.Volume = 0.0f; walk6_channel = new NAudio.Wave.WaveChannel32(walk6); walk6_channel.Volume = 0.0f; walk7_channel = new NAudio.Wave.WaveChannel32(walk7); walk7_channel.Volume = 0.0f; walk8_channel = new NAudio.Wave.WaveChannel32(walk8); walk8_channel.Volume = 0.0f; zombi1_channel = new NAudio.Wave.WaveChannel32(zombi1); zombi1_channel.Volume = 0.0f; zombi2_channel = new NAudio.Wave.WaveChannel32(zombi2); zombi2_channel.Volume = 0.0f; zombi3_channel = new NAudio.Wave.WaveChannel32(zombi3); zombi3_channel.Volume = 0.0f; zombi4_channel = new NAudio.Wave.WaveChannel32(zombi4); zombi4_channel.Volume = 0.0f; zombi5_channel = new NAudio.Wave.WaveChannel32(zombi5); zombi5_channel.Volume = 0.0f; zombi6_channel = new NAudio.Wave.WaveChannel32(zombi6); zombi6_channel.Volume = 0.0f; zombi7_channel = new NAudio.Wave.WaveChannel32(zombi7); zombi7_channel.Volume = 0.0f; mikseri = new NAudio.Wave.WaveMixerStream32(); ambience_channel = new NAudio.Wave.WaveChannel32(ambience); ambience_channel.Volume = 0.2f; drone_channel = new NAudio.Wave.WaveChannel32(drone); drone_channel.Volume = 0.5f; mikseri.AddInputStream(fire1_channel); mikseri.AddInputStream(fire2_channel); mikseri.AddInputStream(empty_channel); mikseri.AddInputStream(load_channel); mikseri.AddInputStream(hitflesh1_channel); mikseri.AddInputStream(hitflesh2_channel); mikseri.AddInputStream(hitflesh3_channel); mikseri.AddInputStream(hitmetal1_channel); mikseri.AddInputStream(hitmetal2_channel); mikseri.AddInputStream(hitmetal3_channel); mikseri.AddInputStream(hitrock_channel); mikseri.AddInputStream(hitglass_channel); mikseri.AddInputStream(walk1_channel); mikseri.AddInputStream(walk2_channel); mikseri.AddInputStream(walk3_channel); mikseri.AddInputStream(walk4_channel); mikseri.AddInputStream(walk5_channel); mikseri.AddInputStream(walk6_channel); mikseri.AddInputStream(walk7_channel); mikseri.AddInputStream(walk8_channel); mikseri.AddInputStream(zombi1_channel); mikseri.AddInputStream(zombi2_channel); mikseri.AddInputStream(zombi3_channel); mikseri.AddInputStream(zombi4_channel); mikseri.AddInputStream(zombi5_channel); mikseri.AddInputStream(zombi6_channel); mikseri.AddInputStream(zombi7_channel); mikseri.AddInputStream(ambience_channel); mikseri.AddInputStream(drone_channel); mikseri.AutoStop = false; output = new NAudio.Wave.DirectSoundOut(); output.Init(mikseri); soundson = true; output.Play(); }
private void button9_Click(object sender, EventArgs e) { FileStream Tstream; OpenFileDialog ofd = new OpenFileDialog(); var client = new MongoClient("mongodb://localhost"); var database = client.GetDatabase("docs"); var fs = new GridFSBucket(database); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Tstream = new System.IO.FileStream(ofd.FileName, FileMode.Open, FileAccess.Read); //SoundPlayer simpleSound = new SoundPlayer(stream); //simpleSound.Play(); var split = ofd.SafeFileName.Split('.'); if(split[1] != "mp3") { MessageBox.Show("Izaberite mp3 fajl!"); return; } DisposeWave(); NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(Tstream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); // } // else if (open.FileName.EndsWith(".wav")) //{ // NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName)); // stream = new NAudio.Wave.BlockAlignReductionStream(pcm); //} //else throw new InvalidOperationException("Not a correct audio file type."); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); //GridFSUploadOptions opcije = new GridFSUploadOptions(); //opcije.ContentType = "audio/mp3"; //opcije.ChunkSizeBytes = Convert.ToInt32(stream.Length)/4; //int duzina = Convert.ToInt32(stream.Length); //byte[] bajtovi = new byte[duzina]; //stream.Seek(0, SeekOrigin.Begin); //int bytesRead = stream.Read(bajtovi, 0, duzina); //fs.UploadFromBytes(ofd.SafeFileName, bajtovi, opcije); //FormaPesma = ofd.SafeFileName; } }
private void FInfoZaMec_Load(object sender, EventArgs e) { try { //TO DO : UCITATI I FORMATIRATI INFORMACIJE O OBA TIMA I O STADIONU I UPISATI U RTB.. //prvo za domacina AuxLib.PrikaziDomacinaRTB(RTBDomacinInfo, domacin.Ime); AuxLib.PrikaziGostaRTB(RTBGostInfo, gost.Ime); AuxLib.PrikaziStadionRTB(RTBStadionInfo, stadion.Ime); //------------------------- //ucitavanje slika iz gridFS-a this.PBDomacinZastava.Image = AuxLib.LoadImageFromGridFS(domacin.Ime + "zastava"); this.PBGostZastava.Image = AuxLib.LoadImageFromGridFS(gost.Ime + "zastava"); this.PBStadionZastava.Image = AuxLib.LoadImageFromGridFS(stadion.Ime + "stadion"); //-------------------------- //ucitamo himnu iz baze kao byte array byte[] domacinPesma = AuxLib.LoadSoundFromGridFS(domacin.Ime+"himna"); //napravis stream MemoryStream domacinStream = new MemoryStream(domacinPesma); //prekines ako ima neka pesma prethodno ( za svaki slucaj ); DisposeWave(); //pcm pd strima NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(domacinStream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); //init,hendler za drugu himnu i play output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.PlaybackStopped += output_PlaybackStopped; output.Play(); } catch(Exception ex) { MessageBox.Show(ex.Message); return; } }
public void StartRending(System.IO.DirectoryInfo baseTempDir, List <VocalUtau.Calculators.BarkerCalculator.BgmPreRender> BList, string RendToWav = "") { _IsRending = true; _ExitRending = false; if (RendingStateChange != null) { RendingStateChange(this); } string ProcessIDStr = Process.GetCurrentProcess().Id.ToString(); DirectoryInfo tempDir = baseTempDir.CreateSubdirectory("temp"); DirectoryInfo cacheDir = baseTempDir.CreateSubdirectory("cache"); string TrackFileName = tempDir.FullName + "\\Bgm_" + CacheSignal + ".wav"; FileStream Fs; headSize = InitFile(out Fs, TrackFileName); Semaphore semaphore = new Semaphore(1, 1, "VocalUtau.WavTool." + ProcessIDStr + ".Bgm_" + CacheSignal); for (int i = 0; i < BList.Count; i++) { if (BList[i].DelayTime > 0) { int ByteTime = (int)(IOHelper.NormalPcmMono16_Format.AverageBytesPerSecond * BList[i].DelayTime); ByteTime -= ByteTime % 2; byte[] byteL = new byte[ByteTime]; Array.Clear(byteL, 0, ByteTime); Fs.Write(byteL, 0, ByteTime); } semaphore.WaitOne(); try { int ByteTime = (int)(IOHelper.NormalPcmMono16_Format.AverageBytesPerSecond * BList[i].PassTime); ByteTime -= ByteTime % 2; using (NAudio.Wave.AudioFileReader reader = new NAudio.Wave.AudioFileReader(BList[i].FilePath)) { int JumpLoops = ByteTime / 2; using (NAudio.Wave.Wave32To16Stream w16 = new NAudio.Wave.Wave32To16Stream(reader)) { using (NAudio.Wave.WaveStream wfmt = new NAudio.Wave.BlockAlignReductionStream(w16)) { using (NAudio.Wave.WaveStream wout = new NAudio.Wave.WaveFormatConversionStream(IOHelper.NormalPcmMono16_Format, wfmt)) { while (wout.Position < wout.Length) { if (_ExitRending) { break; } byte[] by = new byte[2]; int rd = wout.Read(by, 0, 2); if (JumpLoops > 0) { JumpLoops--; } else { Fs.Write(by, 0, 2); } /* for (int w = 1; w < w16.WaveFormat.Channels; w++) * { * int rdr = w16.Read(by, 0, 2); * }*/ } } } } } } catch {; } Fs.Flush(); semaphore.Release(); if (_ExitRending) { break; } } _IsRending = false; long total = Fs.Length; byte[] head = IOHelper.GenerateHead((int)(total - headSize)); Fs.Seek(0, SeekOrigin.Begin); Fs.Write(head, 0, head.Length); Fs.Flush(); Fs.Close(); _ExitRending = false; if (RendingStateChange != null) { RendingStateChange(this); } if (RendToWav != "") { File.Copy(TrackFileName, RendToWav, true); try { File.Delete(TrackFileName); } catch {; } } }
//druga himna void output_PlaybackStopped(object sender, NAudio.Wave.StoppedEventArgs e) { if(notClosed) { try { DisposeWave(); byte[] gostPesma = AuxLib.LoadSoundFromGridFS(gost.Ime + "himna"); MemoryStream gostStream = new MemoryStream(gostPesma); NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(gostStream)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } }
//string stopButtonState = "Stop"; private void play_pause(object sender, EventArgs e) { if (output == null) { OpenFileDialog open = new OpenFileDialog(); open.InitialDirectory = musicDir; open.Filter = "Audio File (*.mp3;*.wav)|*.mp3;*.wav;"; if (open.ShowDialog() != DialogResult.OK) return; DisposeWave(); if (open.FileName.EndsWith(".mp3")) { NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else if (open.FileName.EndsWith(".wav")) { NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName)); stream = new NAudio.Wave.BlockAlignReductionStream(pcm); } else throw new InvalidOperationException("Not a correct audio file type."); output = new NAudio.Wave.DirectSoundOut(); output.Init(stream); output.Play(); } else if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Pause(); else if (output.PlaybackState == NAudio.Wave.PlaybackState.Paused) output.Play(); } }
//Sourced from: http://stackoverflow.com/questions/184683/play-audio-from-a-stream-using-c-sharp private void PlayMp3FromUrl(string url) { try { //Poor practice CheckForIllegalCrossThreadCalls = false; using (Stream ms = new MemoryStream()) { using (Stream stream = WebRequest.Create(url) .GetResponse().GetResponseStream()) { byte[] buffer = new byte[32768]; int read; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } } ms.Position = 0; using (NAudio.Wave.WaveStream blockAlignedStream = new NAudio.Wave.BlockAlignReductionStream( NAudio.Wave.WaveFormatConversionStream.CreatePcmStream( new NAudio.Wave.Mp3FileReader(ms)))) { using (NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback())) { waveOut.Init(blockAlignedStream); waveOut.Play(); while (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing) { System.Threading.Thread.Sleep(100); } } } } } catch { msgbox msgbox = new msgbox(false, "An error has happened whilst attempting to play the soundbyte."); msgbox.Show(); } button9.Enabled = true; currentlyPlayingSB = false; }