Stop() public method

Stop and reset the WaveOut device
public Stop ( ) : void
return void
コード例 #1
0
ファイル: SoundManager.cs プロジェクト: biud436/CefMV
 public void StopSound(string id)
 {
     NAudio.Vorbis.VorbisWaveReader data = _soundMap[id];
     if (data != null)
     {
         soundPlayer.Stop();
         data.Position = 0;
         data.Dispose();
         _soundMap.Remove(id);
     }
 }
コード例 #2
0
ファイル: SoundManager.cs プロジェクト: biud436/CefMV
 public void StopMusic(string id)
 {
     NAudio.Vorbis.VorbisWaveReader data = _musicMap[id];
     if (data != null)
     {
         musicPlayer.Stop();
         data.Position = 0;
         data.Dispose();
         _musicMap.Remove(id);
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: ryo-okabayashi/sound
        static void Main(string[] args)
        {
            // for recording
            waveFileWriter = new WaveFileWriter(@"C:\rec\out.wav", new WaveFormat(44100, 2));

            var sound = new MySound();
            sound.SetWaveFormat(44100, 2);
            sound.init();
            waveOut = new WaveOut();
            waveOut.Init(sound);
            waveOut.Play();

            ConsoleKeyInfo keyInfo;
            bool loop = true;
            while (loop)
            {
                keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Q)
                {
                    waveOut.Stop();
                    waveOut.Dispose();
                    waveFileWriter.Close();
                    waveFileWriter.Dispose();
                    loop = false;
                }
            }
        }
コード例 #4
0
ファイル: SpeakerPlayback.cs プロジェクト: virqin/MumbleSharp
 public void Stop()
 {
     if (_waveOut.PlaybackState != PlaybackState.Stopped)
     {
         _waveOut.Stop();
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: rmichela/Acoustico
        static void Main(string[] args)
        {
            var adj = new AdjustableTFunc {Value = 1600};

            var tFuncWaveProvider = new TFuncWaveProvider
                {
            //                  Amplitude = TFunc.Sin(new Frequency(adj.TFunc))
            //                  Amplitude = TFunc.Sin(new Frequency(t => TFuncs.Sin(Frequency.Hertz(1))(t) + 1000))
                    Amplitude = TFunc.Sin(TFunc.Sin(Frequency.Hertz(2)) + 1000)
                };
            var waveOut = new WaveOut();
            waveOut.Init(tFuncWaveProvider);
            waveOut.Play();

            Console.WriteLine("Press q to kill");
            char k;
            while ((k = Console.ReadKey().KeyChar) != 'q')
            {
                if (k == 'u')
                {
                    adj.Value+=10;
                }
                if (k == 'd')
                {
                    adj.Value-=10;
                }
                Console.Write(" ");
                Console.WriteLine(adj.Value);
            }

            waveOut.Stop();
            waveOut.Dispose();
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: matthewschmude/Sound-Board
        public void DisposeWave()
        {
            try
            {
                if (output != null)
                {
                    if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                    {
                        output.Stop();
                        output.Dispose();
                        output = null;
                    }
                }

                if (stream != null)
                {
                    stream.Dispose();
                    stream = null;
                }

                if (outputLocal != null)
                {
                    if (outputLocal.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                    {
                        outputLocal.Stop();
                        outputLocal.Dispose();
                        outputLocal = null;
                    }
                }

                if (stream2 != null)
                {
                    stream2.Dispose();
                    stream2 = null;
                }
            }

            catch (NAudio.MmException)
            {
                throw;
            }
        }
コード例 #7
0
		private async Task PlayAsync(Action onFinished, Action<Viseme> onVisemeHit, CancellationToken token)
		{
			try
			{
				using (var m = new MemoryStream(_tts.waveStreamData))
				{
					using (var reader = new WaveFileReader(m))
					{
						using (var player = new WaveOut())
						{
							player.Init(reader);
							player.Play();

							var visemes = _tts.visemes;

							int nextViseme = 0;
							double nextVisemeTime = 0;

							while (player.PlaybackState == PlaybackState.Playing)
							{
								if (onVisemeHit != null)
								{
									var s = reader.CurrentTime.TotalSeconds;
									if (s >= nextVisemeTime)
									{
										var v = visemes[nextViseme];
										nextViseme++;
										if (nextViseme >= visemes.Length)
											nextVisemeTime = double.PositiveInfinity;
										else
											nextVisemeTime += v.duration;

										onVisemeHit(v.viseme);
									}
								}

								await Task.Delay(1);
								if (token.IsCancellationRequested)
									break;

								//Console.WriteLine("...next");
							}
							player.Stop();
							onFinished?.Invoke();
						}
					}
				}
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				throw e;
			}
		}
コード例 #8
0
 public void Stop()
 {
     if (waveOut != null)
     {
         if (waveOut.PlaybackState != PlaybackState.Stopped)
         {
             waveOut.Stop();
         }
         Changed("IsPlaying");
     }
     NoPlay = true;
 }
コード例 #9
0
ファイル: NAudioSineWave.cs プロジェクト: aadennis/TonesApp
 public void PlayTone(int frequency, double duration) {
     _sineWave.Frequency = frequency;
     ;
     _sineWave.SetWaveFormat(44100, 1);
     using (_waveOut = new WaveOut()) {
         _waveOut.DeviceNumber = 0;
         _waveOut.Init(_sineWave);
         _waveOut.Play();
         System.Threading.Thread.Sleep(2000);
         _waveOut.Stop();
         _waveOut = null;
     }
 }
コード例 #10
0
        private void DoAudioPlayback()
        {
            var waveOut = new WaveOut();

            waveOut.DesiredLatency = 80;
            waveOut.Init(_waveProvider);

            waveOut.Play();

            while (IsPlaying)
            {
                Thread.Sleep(50);
            }

            waveOut.Stop();
        }
コード例 #11
0
 public static void disposeWave()
 {
     if (output != null)
     {
         if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
         {
             output.Stop();
         }
         output.Dispose();
     }
     if (stream != null)
     {
         stream.Dispose();
         stream = null;
     }
 }
コード例 #12
0
        private static void Main(string[] args)
        {
            // Initialization
            Console.OutputEncoding = Encoding.UTF8;
            var ape = new ApeReader(args[0]);
            DisplayInformation(ape.Handle);

            // Set up the player.
            IWavePlayer player = new WaveOut();
            player.Init(ape);
            player.Play();

            // Listen for key presses to pause/play audio.
            var isPlaying = true;
            do
            {
                var keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Spacebar)
                {
                    if (isPlaying)
                    {
                        player.Pause();
                        isPlaying = false;
                    }
                    else
                    {
                        player.Play();
                        isPlaying = true;
                    }
                }

                // If we hit the end of the stream in terms of actual audio data.
                if (isPlaying && ape.Position == ape.Length)
                {
                    player.Stop();
                }

            } while (player.PlaybackState != PlaybackState.Stopped);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: sebllll/LTCSharp
        static void Main(string[] args)
        {
            var waveOut = new WaveOut();
            var encoder = new Source();
            waveOut.Init(encoder);
            waveOut.Play();

            Stopwatch timer = new Stopwatch();
            timer.Start();
            while (timer.Elapsed < new TimeSpan(0, 0, 5))
            {
                encoder.SetTimecode(new LTCSharp.Timecode(
                    timer.Elapsed.Hours,
                    timer.Elapsed.Minutes,
                    timer.Elapsed.Seconds,
                    (int) ((float)timer.Elapsed.Milliseconds / 1000.0f * 30.0f)));
                Thread.Sleep(10);
            }
            timer.Stop();

            waveOut.Stop();
            waveOut.Dispose();
        }
コード例 #14
0
ファイル: Form1.cs プロジェクト: Gaulford/BitsOfBytes
        public void PlayMp3FromUrl(string url)
        {
            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 (WaveStream blockAlignedStream =
                    new BlockAlignReductionStream(
                        WaveFormatConversionStream.CreatePcmStream(
                            new Mp3FileReader(ms))))
                {
                    using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
                    {
                        waveOut.Init(blockAlignedStream);
                        waveOut.PlaybackStopped += (sender, e) =>
                        {
                            waveOut.Stop();
                        };

                        waveOut.Play();
                        waiting = true;
                        stop.WaitOne(TimeWait);
                        waiting = false;
                    }
                }
            }
        }
コード例 #15
0
ファイル: Mp3.cs プロジェクト: mer3abec/OOSE-project
 /// <summary>
 /// Stops play back and relise all resorces.
 /// </summary>
 public void stop()
 {
     try
     {
         if (output != null)
         {
             if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
             {
                 output.Stop();
             }
             output.Dispose();
             output = null;
         }
         if (stream != null)
         {
             stream.Dispose();
             stream = null;
         }
     }
     catch (Exception)
     {
         stream = null;
     }
 }
コード例 #16
0
ファイル: Cw_winForm.cs プロジェクト: richmanfx/cw_win_4
        private void SoundWord()
        {
            // Считываем параметры с движков регуляторов

             // Беконечная работа - если слово условно звучит одну секунду, то это на 1 год
             if (infinity_work_flag)
                 numberofwords = 31536000;
             else
                 numberofwords = trackBar_N.Value;

             interval = trackBar_Pause.Value;

             speed = trackBar_Speed.Value;
             tone = trackBar_Tone.Value;

            // Инициализация звуковой карты (NAudio library)
            WaveOut MyWaveOut = new WaveOut();
            var sineWaveProvider = new SineWaveProvider32();
            sineWaveProvider.SetWaveFormat(16000, 1); // 16кГц, моно
            sineWaveProvider.Frequency = tone;          // Тон посылки
            sineWaveProvider.Amplitude = 0.5f;          // Амплитуда посылки
            MyWaveOut.Init(sineWaveProvider);

            // Воспроизведение слова
            int dot = speed_calibr / speed;    // Длительность точки
            int dash = 3 * dot;                // Длительность тире
            int dash_conjoint = dash;          // Промежуток между слитными буквами типа <KN>

            // Если стоит галка "Пауза при старте", то использовать паузу перед началом
            if (checkBox_StartPause.Checked)
            {
                startpause_flag = true;                // Использовать паузу
                Thread.Sleep(startpause * 1000);	   // Задержка в секундах перед началом передачи
            }

            // Выводим случайные слова из массива

            Random rnd = new Random();

            if(non_random_flag)
            {
                numberofwords = AllWords.Length;        // При отмене случайного выбора слов выводим все слова
            }                                           // один раз

            for (int i = 1; i <= numberofwords; i++)
            {
             int num;

             // Обрабатываем кнопку "СТОП"
             Application.DoEvents();
             if (!working_flag)
                 break;          //останавливаем воспроизведение слов

             if (!non_random_flag)
             {
                 num = rnd.Next(0, AllWords.Length);	// Номер случайного слова
             }
             else
             {
                 num = i-1;
             }

             string word = AllWords[num].ToUpper();     // Получаем случайное слово в верхнем
                                                        // регистре
             for (int j = 0; j < word.Length; j++)      // Перебираем буквы в слове
             {

                 // Обрабатываем кнопку "СТОП"
                 Application.DoEvents();
                 if (!working_flag)
                     break;          //останавливаем воспроизведение

                // Воспроизводим букву
                char symbol = word[j];

                // Слитные буквы для <AS> и т.п.
                if (symbol == '<')
                    dash_conjoint = dot;	            // "<" - слитное слово

                 if (symbol == '>')
                {
                    dash_conjoint = dash;			    // ">" - раздельное слово
                    Thread.Sleep(dash_conjoint);
                }

                    // Цифры
                    if(symbol == '0')
                    {
                        MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                        MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                        MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                        MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                        MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                        Thread.Sleep(dash_conjoint);
                    }

                     if(symbol == '1')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if(symbol == '2')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if(symbol == '3')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if(symbol == '4')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if(symbol == '5')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if(symbol == '6')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if(symbol == '7')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if(symbol == '8')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if(symbol == '9')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     // Буквы
                     if (symbol == 'A' || symbol == 'А')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'B' || symbol == 'Б')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'C' || symbol == 'Ц')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'D' || symbol == 'Д')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'E' || symbol == 'Е' || symbol == 'Ё')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'F' || symbol == 'Ф')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'G' || symbol == 'Г')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'H' || symbol == 'Х')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'I' || symbol == 'И')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'J' || symbol == 'Й')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'K' || symbol == 'К')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'L' || symbol == 'Л')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'M' || symbol == 'М')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'N' || symbol == 'Н')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'O' || symbol == 'О')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'P' || symbol == 'П')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'Q' || symbol == 'Щ')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'R' || symbol == 'Р')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'S' || symbol == 'С')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'T' || symbol == 'Т')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'U' || symbol == 'У')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'V' || symbol == 'Ж')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'W' || symbol == 'В')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'X' || symbol == 'Ь')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'Y' || symbol == 'Ы')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'Z' || symbol == 'З')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'Ч')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'Ш')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'Э')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'Ю')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     if (symbol == 'Я')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash_conjoint);
                     }

                     // Символы
                     if (symbol == '=')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '?')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '/')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '@')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot);  MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '.' && russianpunktuation_flag)
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '.' && !russianpunktuation_flag)
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == ',' && russianpunktuation_flag)
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == ',' && !russianpunktuation_flag)
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == ';')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == ':')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '!' && russianpunktuation_flag)
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '!' && !russianpunktuation_flag)
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '-')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '\'')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

             } // End For j

             if (non_random_flag)
             {
                 screen_Out(word);              // вывод на label непрерывно
             }
             else
             {
                 screen_Out_By_10(i, word);     // вывод на label по 10 слов
             }

             int dynamic_interval = 1;          // Длительность динамического интервала между словами
             if (dynamic_interval_flag)
             {
                 dynamic_interval = word.Length;
             }

             Thread.Sleep(interval * dash * dynamic_interval);     // Пауза между словами

            } // End for(i)

            // Звершить работу со звуковой картой
            MyWaveOut.Dispose();
            MyWaveOut = null;
        }
コード例 #17
0
ファイル: WSRSpeaker.cs プロジェクト: jdelhommeau/WSRMacro
    private void RunSession(WaveOut WaveOut, WaveStream stream, string match) {
      played.Add(match);
      WSRConfig.GetInstance().logInfo("PLAYER", "[" + device + "]" + "Start Player");
      Stopwatch timer = new Stopwatch(); timer.Start();

      using (WaveChannel32 volumeStream = new WaveChannel32(stream)) {
        volumeStream.Volume = match == "TTS" ? WSRConfig.GetInstance().SpkVolTTS / 100f : WSRConfig.GetInstance().SpkVolPlay / 100f;
        WaveOut.Init(volumeStream);
        WaveOut.Play();
        while (stream.CurrentTime < stream.TotalTime && played.Contains(match) && timer.ElapsedMilliseconds < 1000 * 60 * 8) {
          Thread.Sleep(100);
        }
        WaveOut.Stop();
        stream.Dispose();
      }

      WSRConfig.GetInstance().logInfo("PLAYER", "[" + device + "]" + "End Player");
      played.Remove(match);
    }
コード例 #18
0
ファイル: NAudioInteractor.cs プロジェクト: awlawl/Maestro
        private void PlayInThread(object data)
        {
            string filename = (string)data;

            _waveOutDevice = new WaveOut();
            WaveChannel32 inputStream = null;
            WaveStream mp3Reader = null;

            try
            {
                if (SupportedFileTypes.CanBePlayed(filename))
                {
                    mp3Reader = new Mp3FileReader(filename);

                    inputStream = new WaveChannel32(mp3Reader);
                }
                else
                {
                    throw new InvalidOperationException("Unsupported extension");
                }

                _waveOutDevice.Init(inputStream);
                _waveOutDevice.Volume = _volume;
                _waveOutDevice.PlaybackStopped += _waveOutDevice_PlaybackStopped;
                _waveOutDevice.Play();

                Log.Debug("Playing " + filename);

                Thread.Sleep(mp3Reader.TotalTime);
            }
            catch (Exception exc)
            {
                Log.Debug("Error while playing song " + filename + ":" + exc.ToString());
            }
            finally
            {
                _waveOutDevice.Stop();
                if (mp3Reader!=null)
                    mp3Reader.Close();

                if (inputStream!=null)
                    inputStream.Close();

                _waveOutDevice.Dispose();
            }
        }
コード例 #19
0
ファイル: WSRSpeaker.cs プロジェクト: Oniric75/WSRMacro
        public bool StreamMP3(string url)
        {
            if (url == null) { return false; }

              speaking = true;
              WSRConfig.GetInstance().logInfo("PLAYER", "Stream MP3 Player");

              using (var ms = new MemoryStream())
              using (var 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 (var mp3Reader = new Mp3FileReader(ms))
            using (var pcmStream = WaveFormatConversionStream.CreatePcmStream(mp3Reader))
            using (var baStream = new BlockAlignReductionStream(pcmStream))
            using (var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback())) {
              waveOut.Init(baStream);
              waveOut.Play();
              played.Add(url);
              while (baStream.CurrentTime < baStream.TotalTime && played.Contains(url)) {
            Thread.Sleep(100);
              }
              played.Remove(url);
              waveOut.Stop();
            }
              }

              WSRConfig.GetInstance().logInfo("PLAYER", "End MP3 Player");
              speaking = false;
              return true;
        }
コード例 #20
0
ファイル: WSRSpeaker.cs プロジェクト: Oniric75/WSRMacro
        public bool PlayMP3(string fileName)
        {
            if (fileName == null) { return false; }

              if (fileName.StartsWith("http")) {
            return StreamMP3(fileName);
              }

              speaking = true;
              WSRConfig.GetInstance().logInfo("PLAYER", "Start MP3 Player");
              using (var ms = File.OpenRead(fileName))
              using (var mp3Reader = new Mp3FileReader(ms))
              using (var pcmStream = WaveFormatConversionStream.CreatePcmStream(mp3Reader))
              using (var baStream = new BlockAlignReductionStream(pcmStream))
              using (var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback())) {
            waveOut.Init(baStream);
            waveOut.Play();
            played.Add(fileName);
            while (baStream.CurrentTime < baStream.TotalTime && played.Contains(fileName)) {
              Thread.Sleep(100);
            }
            played.Remove(fileName);
            waveOut.Stop();

              }
              WSRConfig.GetInstance().logInfo("PLAYER", "End MP3 Player");
              speaking = false;
              return true;
        }
コード例 #21
0
 private void OnMp3RepositionTestClick(object sender, EventArgs e)
 {
     var filename = SelectInputFile();
     if (filename == null) return;
     var wo = new WaveOut();
     var af = new AudioFileReader(filename);
     wo.Init(af);
     var f = new Form();
     var b = new Button() { Text = "Play" };
     b.Click += (s, a) => wo.Play();
     var b2 = new Button() { Text = "Stop", Left = b.Right };
     b2.Click += (s, a) => wo.Stop();
     var b3 = new Button { Text = "Rewind", Left = b2.Right };
     b3.Click += (s, a) => af.Position = 0;
     f.FormClosed += (s, a) => { wo.Dispose(); af.Dispose(); };
     f.Controls.Add(b);
     f.Controls.Add(b2);
     f.Controls.Add(b3);
     f.ShowDialog(this);
 }
コード例 #22
0
 private void StartPlayingThisClip(AudioClipToPlay clip, double curSec)
 {
     cxzxc(string.Format("start of {0} {1}-{2}", clip.Filename, clip.SecFileStart, clip.SecFileEnd));
     // create the device
     IWavePlayer waveOutDevice = new WaveOut();
     var deviceAndShit = new DeviceAndItsData(waveOutDevice, clip);
     lock (this) { devicesPlaying.Add(deviceAndShit); }
     Thread ttt = new Thread(() =>
     {
         using (var reader = OpenAudioFile(clip.Filename))
         {
             deviceAndShit.WaveReader = reader;
             // init the playback stuff
             waveOutDevice.Init(reader);
             var syncOffsetSec = curSec - clip.SecOffset; // would be 0 if curSec == clip.SecOffset
             var clipSecStart = clip.SecFileStart + syncOffsetSec;
             var clipSecEnd = clip.SecFileEnd;
             reader.CurrentTime = TimeSpan.FromSeconds(clipSecStart + NAUDIO_SYNC_OFFSET);
             var endTs = TimeSpan.FromSeconds(clipSecEnd + NAUDIO_SYNC_OFFSET);
             var sleepTs = TimeSpan.FromSeconds(NAUDIO_SLEEP_FRAME_TIME);
             deviceAndShit.PlaybackStateRequest = PlaybackState.Playing;
             waveOutDevice.Play();
             while (reader.CurrentTime < endTs)
             {
                 Thread.Sleep(sleepTs);
                 if (waveOutDevice.PlaybackState == PlaybackState.Playing && deviceAndShit.PlaybackStateRequest == PlaybackState.Paused)
                     waveOutDevice.Pause();
                 if (waveOutDevice.PlaybackState == PlaybackState.Paused && deviceAndShit.PlaybackStateRequest == PlaybackState.Playing)
                     waveOutDevice.Play();
                 if (deviceAndShit.StopHasBeenInvoked)
                     break;
                 if (waveOutDevice.PlaybackState == PlaybackState.Stopped)
                     break;
             }
             waveOutDevice.Stop(); // no harm calling stop 2x right?
             lock (this) {
                 devicesPlaying.Remove(deviceAndShit);
                 devicesPaused.Remove(deviceAndShit);
             }
             cxzxc(string.Format("stop of {0} {1}-{2}", clip.Filename, clip.SecFileStart, clip.SecFileEnd));
         }
     });
     ttt.Start();
 }
コード例 #23
0
ファイル: MusicTwo.cs プロジェクト: DCNick3/MidToCArray
 private static void _Beep(int frequency, int duration)
 {
     WaveOut wo = new WaveOut();
     SquareWaveProvider wp = new SquareWaveProvider();
     if (frequency != 0)
     {
         wp.Frequency = frequency;
         wo.Init(wp);
         wo.Play();
     }
     Thread.Sleep(duration);
     if (frequency != 0)
         wo.Stop();
     wo.Dispose();
 }
コード例 #24
0
ファイル: JewSaver.cs プロジェクト: JuzzWuzz/TheSaver
    public static void PlayMp3FromUrl()
    {
        return;
        /*royalty free african music. because we are africa.*/
        Random random = new Random();
        string url = urls[random.Next(urls.Count())];
        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 (WaveStream blockAlignedStream =
                new BlockAlignReductionStream(
                    WaveFormatConversionStream.CreatePcmStream(
                        new Mp3FileReader(ms))))
            {
                using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
                {
                    waveOut.Init(blockAlignedStream);
                    waveOut.Play();
                    while (waveOut.PlaybackState == PlaybackState.Playing)
                    {
                        if (stop)
                        {
                            waveOut.Stop();
                            while (waveOut.PlaybackState != PlaybackState.Stopped)
                                Console.Write("Exiting");
                            Environment.Exit(0);
                            return;
                        }

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

                }
            }
        }
    }
コード例 #25
0
        private void PlayAudioFromConnection(TcpClient client)
        {
            var inputStream = new BufferedStream(client.GetStream());

            var bufferedWaveProvider = new BufferedWaveProvider(waveFormat);
            var savingWaveProvider = new SavingWaveProvider(bufferedWaveProvider, "temp.wav");

            var player = new WaveOut();
            player.Init(savingWaveProvider);
            player.Play();

            while (client.Connected)
            {
                if (terminate)
                {
                    client.Close();
                    break;
                }

                var available = client.Available;
                if (available > 0)
                {
                    var buffer = new byte[available];
                    var bytes = inputStream.Read(buffer, 0, buffer.Length);
                    bufferedWaveProvider.AddSamples(buffer, 0, bytes);
                    Console.WriteLine("{0} \t {1} bytes", client.Client.RemoteEndPoint, bytes);
                }
            }

            player.Stop();
            savingWaveProvider.Dispose();
        }