private void clearWave()
 {
     if (waveOut != null && waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (waveToMe != null && waveToMe.PlaybackState == NAudio.Wave.PlaybackState.Playing)
     {
         waveToMe.Stop();
         waveToMe.Dispose();
         waveToMe = null;
     }
     if (waveReader != null)
     {
         waveReader.Dispose();
         waveReader = null;
     }
     if (waveReaderToMe != null)
     {
         waveReaderToMe.Dispose();
         waveReaderToMe = null;
     }
 }
Esempio n. 2
0
        private double GetLengthToDouble(string Path)
        {
            NAudio.Wave.Mp3FileReader  mp3FileReader;
            NAudio.Wave.WaveFileReader waveFileReader;
            TimeSpan timeSpan = new TimeSpan();

            try
            {
                if (System.IO.Path.GetExtension(Path) == ".mp3")
                {
                    mp3FileReader = new NAudio.Wave.Mp3FileReader(Path);
                    timeSpan      = mp3FileReader.TotalTime;
                    mp3FileReader.Dispose();
                }
                if (System.IO.Path.GetExtension(Path) == ".wav")
                {
                    waveFileReader = new NAudio.Wave.WaveFileReader(Path);
                    waveFileReader.Dispose();
                    timeSpan = waveFileReader.TotalTime;
                }
                return(timeSpan.TotalSeconds);
            }
            catch (Exception)
            {
                return(0.0d);
            }
        }
Esempio n. 3
0
 private void DisposeAll()
 {
     if (player != null)
     {
         player.Dispose();
     }
     if (wave != null)
     {
         wave.Dispose();
     }
 }
Esempio n. 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            string newword   = textBox1.Text.Split('.')[0] + ".wav";
            var    inputfile = new MediaFile {
                Filename = textBox1.Text
            };
            var outputfile = new MediaFile {
                Filename = newword
            };

            audioPath = newword;

            using (var engine = new Engine())
            {
                engine.Convert(inputfile, outputfile);
            }

            NAudio.Wave.WaveFileReader reader = new NAudio.Wave.WaveFileReader(audioPath);
            currentMp3Duration = reader.TotalTime;
            reader.Dispose();

            DictationGrammar defaultDictationGrammar = new DictationGrammar();

            defaultDictationGrammar.Name    = "default dictation";
            defaultDictationGrammar.Enabled = true;

            DictationGrammar spellingDictationGrammar =
                new DictationGrammar("grammar:dictation#spelling");

            spellingDictationGrammar.Name    = "spelling dictation";
            spellingDictationGrammar.Enabled = true;

            DictationGrammar customDictationGrammar =
                new DictationGrammar("grammar:dictation");

            customDictationGrammar.Name    = "question dictation";
            customDictationGrammar.Enabled = true;

            _speechRecog.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(_speechRecog_SpeechRecognized);
            _speechRecog.SetInputToWaveFile(newword);
            _speechRecog.UpdateRecognizerSetting("CFGConfidenceRejectionThreshold", 80);
            _speechRecog.UpdateRecognizerSetting("HighConfidenceThreshold", 80);
            _speechRecog.UpdateRecognizerSetting("NormalConfidenceThreshold", 80);
            _speechRecog.UpdateRecognizerSetting("LowConfidenceThreshold", 80);
            _speechRecog.LoadGrammar(defaultDictationGrammar);
            _speechRecog.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(GetLines(Properties.Resources.Oxfords_3000_2)))));
            _speechRecog.LoadGrammar(spellingDictationGrammar);
            _speechRecog.LoadGrammar(customDictationGrammar);
            _speechRecog.RecognizeAsync(RecognizeMode.Multiple);
            _speechRecog.RecognizeCompleted += _speechRecog_RecognizeCompleted;
        }
 private void DisposeWave()
 {
     if (waveOut != null)
     {
         if (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing) waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (wFileReader != null)
     {
         wFileReader.Dispose();
         wFileReader = null;
     }
 }
Esempio n. 6
0
        private string GetLength(string Path)
        {
            NAudio.Wave.Mp3FileReader  mp3FileReader;
            NAudio.Wave.WaveFileReader waveFileReader;
            TimeSpan timeSpan = new TimeSpan();

            try
            {
                if (System.IO.Path.GetExtension(Path) == ".mp3")
                {
                    mp3FileReader = new NAudio.Wave.Mp3FileReader(Path);
                    timeSpan      = mp3FileReader.TotalTime;
                    mp3FileReader.Dispose();
                }
                if (System.IO.Path.GetExtension(Path) == ".wav")
                {
                    waveFileReader = new NAudio.Wave.WaveFileReader(Path);
                    waveFileReader.Dispose();
                    timeSpan = waveFileReader.TotalTime;
                }
                int    dd = timeSpan.Days;
                int    hh = timeSpan.Hours;
                int    mm = timeSpan.Minutes;
                int    ss = timeSpan.Seconds;
                string t  = "";
                if (dd > 0)
                {
                    t += $"{dd}D:";
                }
                if (hh > 0)
                {
                    t += $"{hh}H:";
                }
                if (mm > 0)
                {
                    t += $"{mm}M:";
                }
                if (ss > 0)
                {
                    t += $"{ss}s";
                }
                return(t);
            }
            catch (Exception)
            {
                return("");
            }
        }
Esempio n. 7
0
        private void DisposeWave()
        {
            if (directSoundOut != null)
            {
                directSoundOut.Stop();
                directSoundOut.Dispose();
                directSoundOut = null;
            }
            if (wavReader != null)
            {
                wavReader.Dispose();
                wavReader = null;
            }

            btnOpenFile.Enabled = true;
        }
        private void DisposeWave()
        {
            output = new NAudio.Wave.DirectSoundOut();
            if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
            {
                output.Stop();
            }
            output.Dispose();
            output = null;

            if (wave != null)
            {
                wave.Dispose();
                wave = null;
            }
        }
Esempio n. 9
0
 private 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;
     }
 }
Esempio n. 10
0
 private void DisposeWave()
 {
     if (output != null)
     {
         if (buttonMute.Visible == true)
         {
             output.Stop();
         }
         output.Dispose();
         output = null;
     }
     if (wave != null)
     {
         wave.Dispose();
         wave = null;
     }
 }
 public override void dispose()
 {
     lock (this)
     {
         try
         {
             if (reader != null)
             {
                 reader.Dispose();
             }
             if (waveOut != null)
             {
                 waveOut.Dispose();
             }
         }
         catch (Exception) { }
         base.dispose();
     }
 }
Esempio n. 12
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            tempImage.Dispose();
            WMPLib.IWMPPlaylist playlist = mediaPlayer.playlistCollection.newPlaylist("Current Playlist");
            mediaPlayer.currentPlaylist = playlist;
            mediaPlayer.Dispose();
            wave.Dispose();
            foreach (string file in readPlaylist)
            {
                if (file.EndsWith(".temp.wav"))
                {
Retry:
                    try
                    {
                        File.Delete(file);
                    }
                    catch
                    {
                    }
                }
            }
        }
Esempio n. 13
0
        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;
            }
        }
Esempio n. 14
0
 private void Play_TTS_file(string filename)
 {
     Console.WriteLine("In Play_TTS_file start");
     NAudio.Wave.WaveFileReader audio = new NAudio.Wave.WaveFileReader(filename);
     NAudio.Wave.IWavePlayer player = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback());
     player.Init(audio);
     player.Play();
     while (true)
     {
         if (player.PlaybackState == NAudio.Wave.PlaybackState.Stopped)
         {
             player.Dispose();
             //MessageBox.Show("disposed");
             audio.Close();
             audio.Dispose();
             break;
         }
     };
     Console.WriteLine("After Play_TTS_File while loop");
 }
Esempio n. 15
0
        public void DoPlay()
        {
            try
            {
                Console.WriteLine();
                Console.WriteLine("playing track. press space to play/pause; ESC to stop");
                System.Threading.Thread.Sleep(1000);

                NAudio.Wave.WaveOutEvent   wavout    = new NAudio.Wave.WaveOutEvent();
                NAudio.Wave.WaveFileReader wavreader = new NAudio.Wave.WaveFileReader(_beatFile.GetWavFilename());

                wavout.Init(wavreader);
                wavout.Play();

                int index = 0;
                List <BeatInstance> bl = _beatFile.GetAllBeats();

                while (wavout.PlaybackState != NAudio.Wave.PlaybackState.Stopped)
                {
                    if (System.Console.KeyAvailable)
                    {
                        switch (System.Console.ReadKey(true).Key)
                        {
                        case ConsoleKey.Spacebar:
                            if (wavout.PlaybackState == NAudio.Wave.PlaybackState.Paused)
                            {
                                wavout.Play();
                            }
                            else if (wavout.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                            {
                                wavout.Pause();
                            }
                            break;

                        case ConsoleKey.Escape:
                            Console.WriteLine("stopped playback");
                            wavout.Stop();
                            break;

                        case ConsoleKey.OemPeriod:
                            Console.WriteLine("{0}", wavreader.CurrentTime.TotalSeconds);
                            break;
                        }
                    }

                    while (index < bl.Count && bl[index].TriggerTime <= wavreader.CurrentTime.TotalSeconds)
                    {
                        if (!_playQuiet)
                        {
                            ViewOneBeat(bl[index]);
                        }

                        index++;
                    }

                    System.Threading.Thread.Sleep(10);
                }

                wavout.Dispose();
                wavreader.Dispose();
            }
            catch (Exception ex)
            {
                throw new Exception("error playing track", ex);
            }
        }