Esempio n. 1
0
        public SoundEffect(string a_soundFile, float a_vol, Event ev)
        {
            soundFileName = ev.SoundName;
            IWaveSource input = CodecFactory.Instance.GetCodec(a_soundFile);
            IWaveSource final = input;

            if (ev.UseEcho)
            {
                DmoEchoEffect echo = new DmoEchoEffect(input);
                echo.LeftDelay  = ev.EchoAmount;
                echo.RightDelay = ev.EchoAmount;
                echo.WetDryMix  = 40;
                final           = echo;
            }

            soundOut1        = new DirectSoundOut(100, System.Threading.ThreadPriority.AboveNormal);
            soundOut1.Device = Helper.Out;
            soundOut1.Initialize(final);
            soundOut1.Volume = a_vol;
            soundOut1.Play();

            if (Helper.Mic != Helper.Out)
            {
                IWaveSource waveSource2 = CodecFactory.Instance.GetCodec(a_soundFile);
                IWaveSource final2      = waveSource2;

                if (ev.UseEcho)
                {
                    DmoEchoEffect echo = new DmoEchoEffect(waveSource2);
                    echo.LeftDelay  = ev.EchoAmount;
                    echo.RightDelay = ev.EchoAmount;
                    echo.WetDryMix  = 40;
                    final2          = echo;
                }

                soundOut2        = new DirectSoundOut(100, System.Threading.ThreadPriority.AboveNormal);
                soundOut2.Device = Helper.Mic;
                soundOut2.Initialize(final2);
                soundOut2.Volume = a_vol;
                soundOut2.Play();
            }

            timer          = new Timer(1000);
            timer.Elapsed += Timer_Elapsed;
            timer.Start();
        }
Esempio n. 2
0
        static void Foo()
        {
            //create a new soundIn instance for using input devices
            using (var soundIn = new WasapiCapture(true, AudioClientShareMode.Shared, 30))
            {
                //important: always initialize the soundIn instance before creating the
                //SoundInSource. The SoundInSource needs the WaveFormat of the soundIn,
                //which gets determined by the soundIn.Initialize method.
                soundIn.Initialize();

                //wrap a sound source around the soundIn instance
                //in order to prevent playback interruptions, set FillWithZeros to true
                //otherwise, if the SoundIn does not provide enough data, the playback stops
                IWaveSource source = new SoundInSource(soundIn)
                {
                    FillWithZeros = true
                };

                //wrap a EchoEffect around the previously created "source"
                //note: disposing the echoSource will also dispose
                //the previously created "source"
                using (var echoSource = new DmoEchoEffect(source))
                {
                    //start capturing data
                    soundIn.Start();

                    //create a soundOut instance to play the data
                    using (var soundOut = new WasapiOut())
                    {
                        //initialize the soundOut with the echoSource
                        //the echoSource provides data from the "source" and applies the echo effect
                        //the "source" provides data from the "soundIn" instance
                        soundOut.Initialize(echoSource);

                        //play
                        soundOut.Play();

                        Console.WriteLine("Press any key to exit the program.");
                        Console.ReadKey();
                    }
                }
            }
        }
Esempio n. 3
0
        public void TestSpeech()
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();

            using (MemoryStream stream = new MemoryStream())
            {
                synth.SetOutputToWaveStream(stream);
                synth.Speak("This is a test.");
                stream.Seek(0, SeekOrigin.Begin);
                IWaveSource     source     = new WaveFileReader(stream);
                EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
                var             soundOut   = new WasapiOut();
                DmoEchoEffect   echoSource = new DmoEchoEffect(source);
                soundOut.Initialize(echoSource);
                soundOut.Stopped += (s, e) => waitHandle.Set();
                soundOut.Play();
                waitHandle.WaitOne();
                soundOut.Dispose();
                source.Dispose();
            }
        }
 public void TestSpeech()
 {
     SpeechSynthesizer synth = new SpeechSynthesizer();
     using (MemoryStream stream = new MemoryStream())
     {
         synth.SetOutputToWaveStream(stream);
         synth.Speak("This is a test.");
         stream.Seek(0, SeekOrigin.Begin);
         IWaveSource source = new WaveFileReader(stream);
         EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
         var soundOut = new WasapiOut();
         DmoEchoEffect echoSource = new DmoEchoEffect(source);
         soundOut.Initialize(echoSource);
         soundOut.Stopped += (s, e) => waitHandle.Set();
         soundOut.Play();
         waitHandle.WaitOne();
         soundOut.Dispose();
         source.Dispose();
     }
 }