public void TestPhonemes()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                synth.SetOutputToWaveStream(stream);

                synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>This is your <phoneme alphabet=\"ipa\" ph=\"leɪkɒn\">Lakon</phoneme>.</s></speak>");

                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈdɛltə\">delta</phoneme> system.</s></speak>");
                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"bliːiː\">Bleae</phoneme> <phoneme alphabet=\"ipa\" ph=\"θuːə\">Thua</phoneme> system.</s></speak>");
                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the Amnemoi system.</s></speak>");
                //synth.Speak("You are travelling to the Barnard's Star system.");
                stream.Seek(0, SeekOrigin.Begin);

                IWaveSource source = new WaveFileReader(stream);

                var soundOut = new WasapiOut();
                soundOut.Stopped += (s, e) => waitHandle.Set();

                soundOut.Initialize(source);
                soundOut.Play();

                waitHandle.WaitOne();
                soundOut.Dispose();
                source.Dispose();
            }
        }
Example #2
0
        private CodecFactory()
        {
            _codecs = new Dictionary<object, CodecFactoryEntry>();
            Register("mp3", new CodecFactoryEntry(s =>
            {
                if (Mp3MediafoundationDecoder.IsSupported)
                    return new Mp3MediafoundationDecoder(s);
                return new DmoMp3Decoder(s);
            },
                "mp3", "mpeg3"));
            Register("wave", new CodecFactoryEntry(s =>
            {
                IWaveSource res = new WaveFileReader(s);
                if (res.WaveFormat.WaveFormatTag != AudioEncoding.Pcm &&
                    res.WaveFormat.WaveFormatTag != AudioEncoding.IeeeFloat &&
                    res.WaveFormat.WaveFormatTag != AudioEncoding.Extensible)
                {
                    res.Dispose();
                    res = new MediaFoundationDecoder(s);
                }
                return res;
            },
                "wav", "wave"));
            Register("flac", new CodecFactoryEntry(s => new FlacFile(s),
                "flac", "fla"));
            Register("aiff", new CodecFactoryEntry(s => new AiffReader(s),
                "aiff", "aif", "aifc"));

            if (AacDecoder.IsSupported)
            {
                Register("aac", new CodecFactoryEntry(s => new AacDecoder(s),
                    "aac", "adt", "adts", "m2ts", "mp2", "3g2", "3gp2", "3gp", "3gpp", "m4a", "m4v", "mp4v", "mp4",
                    "mov"));
            }

            if (WmaDecoder.IsSupported)
            {
                Register("wma", new CodecFactoryEntry(s => new WmaDecoder(s),
                    "asf", "wm", "wmv", "wma"));
            }

            if (Mp1Decoder.IsSupported)
            {
                Register("mp1", new CodecFactoryEntry(s => new Mp1Decoder(s),
                    "mp1", "m2ts"));
            }

            if (Mp2Decoder.IsSupported)
            {
                Register("mp2", new CodecFactoryEntry(s => new Mp1Decoder(s),
                    "mp2", "m2ts"));
            }

            if (DDPDecoder.IsSupported)
            {
                Register("ddp", new CodecFactoryEntry(s => new DDPDecoder(s),
                    "mp2", "m2ts", "m4a", "m4v", "mp4v", "mp4", "mov", "asf", "wm", "wmv", "wma", "avi", "ac3", "ec3"));
            }
        }
        public void Speak(string script, string voice, int echoDelay, int distortionLevel, int chorusLevel, int reverbLevel, int compressLevel, bool radio)
        {
            if (script == null) { return; }

            try
            {
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                using (MemoryStream stream = new MemoryStream())
                {
                    if (String.IsNullOrWhiteSpace(voice))
                    {
                        voice = configuration.StandardVoice;
                    }
                    if (voice != null)
                    {
                        try
                        {
                            synth.SelectVoice(voice);
                        }
                        catch { }
                    }

                    synth.Rate = configuration.Rate;

                    synth.SetOutputToWaveStream(stream);
                    string speech = SpeechFromScript(script);
                    if (speech.Contains("<phoneme"))
                    {
                        speech = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"" + locale + "\"><s>" + speech + "</s></speak>";
                        synth.SpeakSsml(speech);
                    }
                    else
                    {
                        synth.Speak(speech);
                    }
                    stream.Seek(0, SeekOrigin.Begin);

                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(Environment.GetEnvironmentVariable("AppData") + @"\EDDI\speech.log", true)) { file.WriteLine("" + System.Threading.Thread.CurrentThread.ManagedThreadId + ": Turned script " + script + " in to speech " + speech); }

                    IWaveSource source = new WaveFileReader(stream);

                    // We need to extend the duration of the wave source if we have any effects going on
                    if (chorusLevel != 0 || reverbLevel != 0 || echoDelay != 0)
                    {
                        // Add a base of 500ms plus 10ms per effect level over 50
                        source = source.AppendSource(x => new ExtendedDurationWaveSource(x, 500 + Math.Max(0, (configuration.EffectsLevel - 50) * 10)));
                    }

                    // Add various effects...

                    // We always have chorus
                    if (chorusLevel != 0)
                    {
                        source = source.AppendSource(x => new DmoChorusEffect(x) { Depth = chorusLevel, WetDryMix = Math.Min(100, (int)(180 * ((decimal)configuration.EffectsLevel) / ((decimal)100))), Delay = 16, Frequency = 2, Feedback = 25 });
                    }

                    // We only have reverb and echo if we're not transmitting or receiving
                    if (!radio)
                    {
                        if (reverbLevel != 0)
                        {
                            // We tone down the reverb level with the distortion level, as the combination is nasty
                            source = source.AppendSource(x => new DmoWavesReverbEffect(x) { ReverbTime = (int)(1 + 999 * ((decimal)configuration.EffectsLevel) / ((decimal)100)), ReverbMix = Math.Max(-96, -96 + (96 * reverbLevel / 100) - distortionLevel) });
                        }

                        if (echoDelay != 0)
                        {
                            // We tone down the echo level with the distortion level, as the combination is nasty
                            source = source.AppendSource(x => new DmoEchoEffect(x) { LeftDelay = echoDelay, RightDelay = echoDelay, WetDryMix = Math.Max(5, (int)(10 * ((decimal)configuration.EffectsLevel) / ((decimal)100)) - distortionLevel), Feedback = Math.Max(0, 10 - distortionLevel / 2) });
                        }
                    }

                    if (configuration.EffectsLevel > 0 && distortionLevel > 0)
                    {
                        source = source.AppendSource(x => new DmoDistortionEffect(x) { Edge = distortionLevel, Gain = -6 - (distortionLevel / 2), PostEQBandwidth = 4000, PostEQCenterFrequency = 4000 });
                    }

                    if (radio)
                    {
                        source = source.AppendSource(x => new DmoDistortionEffect(x) { Edge = 7, Gain = -4 - distortionLevel / 2, PostEQBandwidth = 2000, PostEQCenterFrequency = 6000 });
                        source = source.AppendSource(x => new DmoCompressorEffect(x) { Attack = 1, Ratio = 3, Threshold = -10 });
                    }

                    EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
                    var soundOut = new WasapiOut();
                    soundOut.Initialize(source);
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    activeSpeeches.Add(soundOut);
                    soundOut.Play();

                    // Add a timeout, in case it doesn't come back
                    waitHandle.WaitOne(source.GetTime(source.Length));

                    // It's possible that this has been disposed of, so ensure that it's still there before we try to finish it
                    lock (activeSpeeches)
                    {
                        if (activeSpeeches.Contains(soundOut))
                        {
                            activeSpeeches.Remove(soundOut);
                            soundOut.Stop();
                            soundOut.Dispose();
                        }
                    }

                    source.Dispose();
                }
            }
            catch (Exception ex)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(Environment.GetEnvironmentVariable("AppData") + @"\EDDI\speech.log", true)) { file.WriteLine("" + System.Threading.Thread.CurrentThread.ManagedThreadId + ": Caught exception " + ex); }
            }
        }
 public void TestDropOff()
 {
     SpeechSynthesizer synth = new SpeechSynthesizer();
     using (MemoryStream stream = new MemoryStream())
     {
         synth.SetOutputToWaveStream(stream);
         synth.Speak("Testing drop-off.");
         stream.Seek(0, SeekOrigin.Begin);
         IWaveSource source = new WaveFileReader(stream);
         EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
         var soundOut = new WasapiOut();
         soundOut.Initialize(source);
         soundOut.Stopped += (s, e) => waitHandle.Set();
         soundOut.Play();
         waitHandle.WaitOne();
         soundOut.Dispose();
         source.Dispose();
     }
     SpeechService.Instance.Speak("Testing drop-off.", null, 50, 1, 30, 40, 0, true);
 }
 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 TestFlatten()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                synth.SetOutputToWaveStream(stream);
                synth.Speak("This is a test for flattening");
                stream.Seek(0, SeekOrigin.Begin);

                IWaveSource source = new WaveFileReader(stream);
                Equalizer equalizer = Equalizer.Create10BandEqualizer(source);
                equalizer.SampleFilters[0].SetGain(-9.6f);
                equalizer.SampleFilters[1].SetGain(-9.6f);
                equalizer.SampleFilters[2].SetGain(-9.6f);
                equalizer.SampleFilters[3].SetGain(-3.9f);
                equalizer.SampleFilters[4].SetGain(2.4f);
                equalizer.SampleFilters[5].SetGain(11.1f);
                equalizer.SampleFilters[6].SetGain(15.9f);
                equalizer.SampleFilters[7].SetGain(15.9f);
                equalizer.SampleFilters[8].SetGain(15.9f);
                equalizer.SampleFilters[9].SetGain(16.7f);

                var soundOut = new WasapiOut();
                soundOut.Stopped += (s, e) => waitHandle.Set();

                soundOut.Initialize(equalizer.ToWaveSource());
                soundOut.Play();

                waitHandle.WaitOne();

                soundOut.Dispose();
                equalizer.Dispose();
                source.Dispose();
            }
        }
        public void TestRandomVoice()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            List<InstalledVoice> availableVoices = new List<InstalledVoice>();
            foreach (InstalledVoice voice in new SpeechSynthesizer().GetInstalledVoices())
            {
                if (voice.Enabled == true && voice.VoiceInfo.Culture.TwoLetterISOLanguageName == "en" && (voice.VoiceInfo.Name.StartsWith("IVONA") || voice.VoiceInfo.Name.StartsWith("CereVoice") || voice.VoiceInfo.Name == "Microsoft Anna"))
                {
                    availableVoices.Add(voice);
                }
            }
            foreach (InstalledVoice availableVoice in availableVoices)
            {
                Console.WriteLine(availableVoice.VoiceInfo.Name);
            }

            for (int i = 0; i < 10; i++)
            {
                using (MemoryStream stream = new MemoryStream())
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    string selectedVoice = availableVoices.OrderBy(x => Guid.NewGuid()).FirstOrDefault().VoiceInfo.Name;
                    Console.WriteLine("Selected voice is " + selectedVoice);
                    synth.SelectVoice(selectedVoice);

                    synth.SetOutputToWaveStream(stream);
                    //synth.Speak("Anaconda golf foxtrot lima one niner six eight requesting docking.");
                    synth.Speak("Anaconda.");
                    stream.Seek(0, SeekOrigin.Begin);

                    IWaveSource source = new WaveFileReader(stream);

                    var soundOut = new WasapiOut();
                    soundOut.Stopped += (s, e) => waitHandle.Set();

                    soundOut.Initialize(source);
                    soundOut.Play();

                    waitHandle.WaitOne();

                    soundOut.Dispose();
                    source.Dispose();
                }
            }
        }
        public void TestDistortion()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                foreach (InstalledVoice voice in synth.GetInstalledVoices())
                {
                    Console.WriteLine(voice.VoiceInfo.Name);
                }

                synth.SetOutputToWaveStream(stream);
                synth.Speak("Anaconda golf foxtrot lima one niner six eight requesting docking.");
                stream.Seek(0, SeekOrigin.Begin);

                IWaveSource source = new WaveFileReader(stream);
                DmoDistortionEffect distortedSource = new DmoDistortionEffect(source);
                distortedSource.Edge = 10;
                distortedSource.PreLowpassCutoff = 4800;

                var soundOut = new WasapiOut();
                soundOut.Stopped += (s, e) => waitHandle.Set();

                soundOut.Initialize(distortedSource);
                soundOut.Play();

                waitHandle.WaitOne();

                soundOut.Dispose();
                distortedSource.Dispose();
                source.Dispose();
            }
        }
Example #9
0
        private CodecFactory()
        {
            _codecs = new Dictionary <object, CodecFactoryEntry>();
            Register("mp3", new CodecFactoryEntry((s) =>
            {
                //if (MP3.MP3MediafoundationDecoder.IsSupported)
                //    return new MP3.MP3MediafoundationDecoder(s);
                //else
                //    return new MP3.MP3FileReader(s).DataStream;
                return(new MP3.DmoMP3Decoder(s));
            },
                                                  "mp3", "mpeg3"));
            Register("wave", new CodecFactoryEntry((s) =>
            {
                IWaveSource res = new WAV.WaveFileReader(s);
                if (res.WaveFormat.WaveFormatTag != AudioEncoding.Pcm &&
                    res.WaveFormat.WaveFormatTag != AudioEncoding.IeeeFloat &&
                    res.WaveFormat.WaveFormatTag != AudioEncoding.Extensible)
                {
                    res.Dispose();
                    res = new MediaFoundation.MediaFoundationDecoder(s);
                }
                return(res);
            },
                                                   "wav", "wave"));
            Register("flac", new CodecFactoryEntry((s) =>
            {
                return(new FLAC.FlacFile(s));
            },
                                                   "flac", "fla"));

            if (AAC.AACDecoder.IsSupported)
            {
                Register("aac", new CodecFactoryEntry((s) =>
                {
                    return(new AAC.AACDecoder(s));
                },
                                                      "aac", "adt", "adts", "m2ts", "mp2", "3g2", "3gp2", "3gp", "3gpp", "m4a", "m4v", "mp4v", "mp4", "mov"));
            }

            if (WMA.WMADecoder.IsSupported)
            {
                Register("wma", new CodecFactoryEntry((s) =>
                {
                    return(new WMA.WMADecoder(s));
                },
                                                      "asf", "wm", "wmv", "wma"));
            }

            if (MP1.MP1Decoder.IsSupported)
            {
                Register("mp1", new CodecFactoryEntry((s) =>
                {
                    return(new MP1.MP1Decoder(s));
                },
                                                      "mp1", "m2ts"));
            }

            if (MP2.MP2Decoder.IsSupported)
            {
                Register("mp2", new CodecFactoryEntry((s) =>
                {
                    return(new MP1.MP1Decoder(s));
                },
                                                      "mp2", "m2ts"));
            }

            if (DDP.DDPDecoder.IsSupported)
            {
                Register("ddp", new CodecFactoryEntry((s) =>
                {
                    return(new DDP.DDPDecoder(s));
                },
                                                      "mp2", "m2ts", "m4a", "m4v", "mp4v", "mp4", "mov", "asf", "wm", "wmv", "wma", "avi", "ac3", "ec3"));
            }
        }
        public void TestPhonemes()
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            using (MemoryStream stream = new MemoryStream())
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                synth.SetOutputToWaveStream(stream);

                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"viˈga\">Vega</phoneme> system.</s></speak>");
                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ækɜˈnɑ\">Achenar</phoneme> system.</s></speak>");
                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈsɪɡni\">Cygni</phoneme> system.</s></speak>");
                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈsɪɡnəs\">Cygnus</phoneme> system.</s></speak>");
                // synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ʃɪnˈrɑːrtə\">Shinrarta</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈdezɦrə\">Dezhra</phoneme> system.</s></speak>");
                //synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the <phoneme alphabet=\"ipa\" ph=\"ˈnjuːənɛts\">Reorte</phoneme> system.</s></speak>");
                synth.SpeakSsml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><speak version = \"1.0\" xmlns = \"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-GB\"><s>You are travelling to the Eravate system.</s></speak>");

                stream.Seek(0, SeekOrigin.Begin);

                IWaveSource source = new WaveFileReader(stream);

                var soundOut = new WasapiOut();
                soundOut.Stopped += (s, e) => waitHandle.Set();

                soundOut.Initialize(source);
                soundOut.Play();

                waitHandle.WaitOne();
                soundOut.Dispose();
                source.Dispose();
            }
        }
Example #11
0
        public ClientForm()
        {
            InitializeComponent();
            blipReader = new WaveFileReader("base/sounds/general/sfx-blipmale.wav");
            blipPlayer.Initialize(FluentExtensions.Loop(blipReader));
            backgroundPB.BackColor = Color.Transparent;
            backgroundPB.Load("base/background/default/defenseempty.png");
            backgroundPB.Controls.Add(charLayerPB);
            charLayerPB.BackColor = Color.Transparent;
            charLayerPB.Image = null;
            charLayerPB.Controls.Add(deskLayerPB);
            deskLayerPB.BackColor = Color.Transparent;
            deskLayerPB.Load("base/background/default/defbench.png");
            deskLayerPB.Controls.Add(chatBGLayerPB);
            chatBGLayerPB.Load("base/misc/chat.png");
            chatBGLayerPB.BackColor = Color.Transparent;
            chatBGLayerPB.Controls.Add(objectLayerPB);
            objectLayerPB.BackColor = Color.Transparent;
            objectLayerPB.Image = null;
            objectLayerPB.Controls.Add(displayMsg1);
            objectLayerPB.Controls.Add(displayMsg2);
            objectLayerPB.Controls.Add(displayMsg3);
            nameLabel.BackColor = Color.Transparent;
            objectLayerPB.Controls.Add(nameLabel);
            objectLayerPB.Controls.Add(testimonyPB);
            displayMsg1.BackColor = Color.Transparent;
            displayMsg2.BackColor = Color.Transparent;
            displayMsg3.BackColor = Color.Transparent;
            arrowLeft.Load("base/misc/btn_arrowLeft.png");
            arrowLeft.Enabled = false;
            arrowLeft.Visible = false;
            arrowRight.Load("base/misc/btn_arrowRight.png");
            arrowRight.Enabled = false;
            arrowRight.Visible = false;
            btn_objection.Image = Image.FromFile("base/misc/btn_objection_off.png");
            btn_objection.Visible = true;
            btn_holdit.Image = Image.FromFile("base/misc/btn_holdit_off.png");
            btn_holdit.Visible = true;
            btn_takethat.Image = Image.FromFile("base/misc/btn_takethat_off.png");
            btn_takethat.Visible = true;
            btn_back.Parent = courtRecordPB;
            btn_present.Parent = courtRecordPB;
            btn_edit.Parent = courtRecordPB;

            crTitle.BackColor = Color.Transparent;
            crTitle.Parent = courtRecordPB;
            courtRecordPB.Controls.Add(evi1);
            courtRecordPB.Controls.Add(evi2);
            courtRecordPB.Controls.Add(evi3);
            courtRecordPB.Controls.Add(evi4);
            courtRecordPB.Controls.Add(evi5);
            courtRecordPB.Controls.Add(evi6);
            courtRecordPB.Controls.Add(evi7);
            courtRecordPB.Controls.Add(evi8);
            courtRecordPB.Controls.Add(evi9);
            courtRecordPB.Controls.Add(evi10);
            courtRecordPB.Controls.Add(evi11);
            courtRecordPB.Controls.Add(evi12);
            courtRecordPB.Controls.Add(evi13);
            courtRecordPB.Controls.Add(evi14);
            courtRecordPB.Controls.Add(evi15);
            courtRecordPB.Controls.Add(evi16);
            courtRecordPB.Controls.Add(evi17);
            courtRecordPB.Controls.Add(evi18);

            //btn_Exclaim.Parent = uiPanel;
            //btn_Mute.Parent = uiPanel;
            //txtColorChanger.Parent = uiPanel;
            //defHealthBar.Parent = uiPanel;
            //proHealthBar.Parent = uiPanel;
            clearDispMsg();
            setDispMsgColor(Color.White);

            //displayMsg.Text = "Sample Text";
            //Refresh();
        }
Example #12
0
        private void animTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                if ((soundTime > 4 && curSoundTime < (soundTime - 4)) | (soundTime > 0 & soundTime < 4 & curSoundTime < soundTime))
                    curSoundTime++;
                else if ((soundTime > 0 && curSoundTime == (soundTime - 4)) | (soundTime > 0 & soundTime < 4 & curSoundTime == soundTime))
                {
                    soundTime = 0; // This prevents the song from playing repeatedly every 60 ms
                    if (!mute)
                        sfxPlayer.Play();
                }

                if (preAnimTime > 0 && curPreAnim != null)
                {
                    if (curPreAnimTime < preAnimTime)
                    {
                        //if (charLayerPB.Image.FrameDimensionsList.Length > curPreAnimTime)
                        //charLayerPB.Image.SelectActiveFrame(new System.Drawing.Imaging.FrameDimension(charLayerPB.Image.FrameDimensionsList[curPreAnimTime]), curPreAnimTime);
                        curPreAnimTime++;
                    }
                    else
                    {
                        curPreAnimTime = 0;
                        curPreAnimTime = 0;
                        curPreAnim = null;

                        if (latestMsg.cmdCommand == Command.Present)
                        {
                            sfxPlayer.Stop();
                            wr = new WaveFileReader("base/sounds/general/sfx-shooop.wav");
                            sfxPlayer.Initialize(wr);
                            if (!mute)
                                sfxPlayer.Play();

                            switch (iniParser.GetSide(latestMsg.strName))
                            {
                                case "def":
                                    testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                    System.Threading.Thread.Sleep(100);
                                    testimonyPB.Location = new Point(173, 13);
                                    testimonyPB.Size = new Size(70, 70);
                                    testimonyPB.Image = eviList[Convert.ToInt32(latestMsg.strMessage.Split('|').Last())].icon;
                                    break;
                                case "pro":
                                    testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceLeft.gif");
                                    System.Threading.Thread.Sleep(100);
                                    testimonyPB.Location = new Point(13, 13);
                                    testimonyPB.Size = new Size(70, 70);
                                    testimonyPB.Image = eviList[Convert.ToInt32(latestMsg.strMessage.Split('|').Last())].icon;
                                    break;
                                case "hld":
                                    testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceLeft.gif");
                                    System.Threading.Thread.Sleep(100);
                                    testimonyPB.Location = new Point(13, 13);
                                    testimonyPB.Size = new Size(70, 70);
                                    testimonyPB.Image = eviList[Convert.ToInt32(latestMsg.strMessage.Split('|').Last())].icon;
                                    break;
                                case "hlp":
                                    testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                    System.Threading.Thread.Sleep(100);
                                    testimonyPB.Location = new Point(173, 13);
                                    testimonyPB.Size = new Size(70, 70);
                                    testimonyPB.Image = eviList[Convert.ToInt32(latestMsg.strMessage.Split('|').Last())].icon;
                                    break;
                                default:
                                    testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                    System.Threading.Thread.Sleep(100);
                                    testimonyPB.Location = new Point(173, 13);
                                    testimonyPB.Size = new Size(70, 70);
                                    testimonyPB.Image = eviList[Convert.ToInt32(latestMsg.strMessage.Split('|').Last())].icon;
                                    break;
                            }

                            latestMsg.strMessage = latestMsg.strMessage.Split('|')[0];
                        }

                        setCharSprite("base/characters/" + latestMsg.strName + "/(b)" + iniParser.GetAnim(latestMsg.strName, latestMsg.anim) + ".gif");
                        charLayerPB.Enabled = true;
                        prepWriteDispBoxes(latestMsg, latestMsg.textColor);
                        return;
                    }
                }
                /* else
                {
                    curPreAnimTime = 0;
                    curPreAnimTime = 0;
                    curPreAnim = null;

                    if (latestMsg != null)
                    {
                        charLayerPB.Load("base/characters/" + latestMsg.strName + "/(b)" + latestMsg.anim + ".gif");
                        prepWriteDispBoxes(latestMsg, latestMsg.textColor);
                    }
                } */
            }
            catch (Exception ex)
            {
                if (Program.debug)
                    MessageBox.Show(ex.Message + ".\r\n" + ex.StackTrace.ToString(), "AODXClient", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #13
0
        private void performCallout()
        {
            switch (latestMsg.callout)
            {
                case 0:

                    break;

                case 1:

                    nameLabel.Visible = false;
                    displayMsg1.Visible = false;
                    displayMsg2.Visible = false;
                    displayMsg3.Visible = false;
                    objectLayerPB.Image = Image.FromFile("base/misc/ani_objection.gif");
                    if (File.Exists("base/characters/" + latestMsg.strName + "/objection.wav"))
                        wr = new WaveFileReader("base/characters/" + latestMsg.strName + "/objection.wav");
                    else
                        wr = new WaveFileReader("base/sounds/general/sfx_objection.wav");

                    sfxPlayer.Initialize(wr);
                    if (!mute)
                        sfxPlayer.Play();

                    System.Threading.Thread.Sleep(1000);
                    break;

                case 2:

                    nameLabel.Visible = false;
                    displayMsg1.Visible = false;
                    displayMsg2.Visible = false;
                    displayMsg3.Visible = false;
                    objectLayerPB.Image = Image.FromFile("base/misc/ani_holdit.gif");
                    if (File.Exists("base/characters/" + latestMsg.strName + "/holdit.wav"))
                        wr = new WaveFileReader("base/characters/" + latestMsg.strName + "/holdit.wav");
                    else
                        wr = new WaveFileReader("base/sounds/general/sfx_objection.wav");

                    sfxPlayer.Initialize(wr);
                    if (!mute)
                        sfxPlayer.Play();

                    System.Threading.Thread.Sleep(1000);
                    break;

                case 3:

                    nameLabel.Visible = false;
                    displayMsg1.Visible = false;
                    displayMsg2.Visible = false;
                    displayMsg3.Visible = false;
                    objectLayerPB.Image = Image.FromFile("base/misc/ani_takethat.gif");
                    if (File.Exists("base/characters/" + latestMsg.strName + "/takethat.wav"))
                        wr = new WaveFileReader("base/characters/" + latestMsg.strName + "/takethat.wav");
                    else
                        wr = new WaveFileReader("base/sounds/general/sfx_objection.wav");

                    sfxPlayer.Initialize(wr);
                    if (!mute)
                        sfxPlayer.Play();

                    System.Threading.Thread.Sleep(1000);
                    break;

                case 4:
                    testimonyPB.Location = new Point(0, 3);
                    testimonyPB.Size = new Size(256, 111);
                    testimonyPB.Image = Image.FromFile("base/misc/ani_witnessTestimony2.gif");
                    wr = new WaveFileReader("base/sounds/general/sfx-testimony.wav");

                    sfxPlayer.Initialize(wr);
                    if (!mute)
                        sfxPlayer.Play();

                    System.Threading.Thread.Sleep(3500);
                    break;

                case 5:
                    testimonyPB.Location = new Point(0, 3);
                    testimonyPB.Size = new Size(256, 111);
                    testimonyPB.Image = Image.FromFile("base/misc/ani_crossexamination.gif");
                    System.Threading.Thread.Sleep(300);
                    wr = new WaveFileReader("base/sounds/general/sfx-testimony2.wav");

                    sfxPlayer.Initialize(wr);
                    if (!mute)
                        sfxPlayer.Play();

                    System.Threading.Thread.Sleep(1200);
                    sfxPlayer.Stop();
                    System.Threading.Thread.Sleep(800);

                    break;
            }

            nameLabel.Visible = true;
            displayMsg1.Visible = true;
            displayMsg2.Visible = true;
            displayMsg3.Visible = true;
            objectLayerPB.Image = null;
            testimonyPB.Image = null;
        }
Example #14
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                clientSocket.EndReceive(ar);

                if (byteData[0] == 8)
                {
                    EviData data = new EviData(byteData);

                    Evidence evi = new Evidence();
                    evi.name = data.strName;
                    evi.desc = data.strDesc;
                    evi.note = data.strNote;
                    evi.index = data.index;

                    using (MemoryStream ms = new MemoryStream(data.dataBytes))
                    {
                        evi.icon = Image.FromStream(ms, false, true);
                    }

                    bool found = false;
                    foreach (Evidence item in eviList)
                    {
                        if (item.index == evi.index)
                        {
                            found = true;
                            item.name = evi.name;
                            item.note = evi.note;
                            item.desc = evi.desc;
                            item.icon = evi.icon;
                            break;
                        }
                    }
                    if (found == false)
                        eviList.Add(evi);

                    testimonyPB.Location = new Point(257, 3);
                    testimonyPB.BringToFront();
                    PictureBox icon = new PictureBox();
                    icon.Image = evi.icon;
                    icon.Location = new Point(6, 5);
                    icon.Size = new Size(70, 70);
                    icon.BringToFront();
                    testimonyPB.Invoke((MethodInvoker)delegate
                    {
                        //perform on the UI thread
                        testimonyPB.Controls.Add(icon);
                    });
                    Label name = new Label();
                    name.Text = evi.name;
                    name.Location = new Point(91, 8);
                    name.Size = new Size(155, 17);
                    name.TextAlign = ContentAlignment.MiddleCenter;
                    name.ForeColor = Color.DarkOrange;
                    name.BackColor = Color.Transparent;
                    //name.Font = new Font(fonts.Families[0], 12.0f, FontStyle.Bold);
                    name.BringToFront();
                    testimonyPB.Invoke((MethodInvoker)delegate
                    {
                        //perform on the UI thread
                        testimonyPB.Controls.Add(name);
                    });
                    Label note = new Label();
                    note.Text = evi.note;
                    note.Location = new Point(92, 26);
                    note.Size = new Size(153, 44);
                    //note.Font = new Font(fonts.Families[0], 12.0f);
                    note.BackColor = Color.Transparent;
                    note.BringToFront();
                    testimonyPB.Invoke((MethodInvoker)delegate
                    {
                        //perform on the UI thread
                        testimonyPB.Controls.Add(note);
                    });
                    Label desc = new Label();
                    desc.Text = evi.desc;
                    desc.Location = new Point(9, 81);
                    desc.Size = new Size(238, 45);
                    //desc.Font = new Font(fonts.Families[0], 12.0f);
                    desc.BackColor = Color.Transparent;
                    desc.ForeColor = Color.White;
                    desc.BringToFront();
                    testimonyPB.Invoke((MethodInvoker)delegate
                    {
                        //perform on the UI thread
                        testimonyPB.Controls.Add(desc);
                    });
                    testimonyPB.Size = new Size(256, 127);
                    testimonyPB.Image = Image.FromFile("base/misc/inventory_update.png");
                    wr = new WaveFileReader("base/sounds/general/sfx-selectjingle.wav");

                    sfxPlayer.Initialize(wr);
                    if (!mute)
                        sfxPlayer.Play();

                    for (int x = 0; x <= 64; x++)
                    {
                        testimonyPB.Location = new Point(256 - (4 * x), 3);
                        //icon.Location = new Point(256 + 6 - (2 * x), 3 + 5);
                        //name.Location = new Point(256 + 91 - (2 * x), 3 + 8);
                        //note.Location = new Point(256 + 92 - (2 * x), 3 + 26);
                        //desc.Location = new Point(256 + 9 - (2 * x), 3 + 81);
                        icon.Refresh();
                        name.Refresh();
                        note.Refresh();
                        desc.Refresh();
                    }

                    System.Threading.Thread.Sleep(3000);

                    for (int x = 0; x <= 64; x++)
                    {
                        testimonyPB.Location = new Point(0 - (4 * x), 3);
                        //icon.Location = new Point(6 - (2 * x), 3 + 5);
                        //name.Location = new Point(91 - (2 * x), 3 + 8);
                        //note.Location = new Point(92 - (2 * x), 3 + 26);
                        //desc.Location = new Point(9 - (2 * x), 3 + 81);
                        icon.Refresh();
                        name.Refresh();
                        note.Refresh();
                        desc.Refresh();
                    }

                    testimonyPB.Image = null;
                    name.Dispose();
                    icon.Dispose();
                    desc.Dispose();
                    note.Dispose();
                }
                else
                {
                    Data msgReceived = new Data(byteData);

                    //Accordingly process the message received
                    switch (msgReceived.cmdCommand)
                    {
                        case Command.Login:
                            break;

                        case Command.Logout:
                            break;

                        case Command.ChangeMusic:
                            if (msgReceived.strMessage != null && msgReceived.strMessage != "" & msgReceived.strName != null)
                            {
                                appendTxtLogSafe("<<<" + msgReceived.strName + " changed the music to " + msgReceived.strMessage + ">>>\r\n");
                                musicReader = new DmoMp3Decoder("base/sounds/music/" + msgReceived.strMessage);

                                if (musicPlayer.PlaybackState != PlaybackState.Stopped)
                                    musicPlayer.Stop();
                                musicPlayer.Initialize(musicReader);
                                if (!mute)
                                    musicPlayer.Play();
                            }
                            break;

                        case Command.ChangeHealth:
                            if (msgReceived.strName == "def")
                            {
                                if (msgReceived.strMessage == "-1")
                                    defHealth--;
                                else if (msgReceived.strMessage == "+1")
                                    defHealth++;
                            }
                            else if (msgReceived.strName == "pro")
                            {
                                if (msgReceived.strMessage == "-1")
                                    proHealth--;
                                else if (msgReceived.strMessage == "+1")
                                    proHealth++;
                            }

                            updateHealth();
                            break;

                        case Command.Message:
                        case Command.Present:
                            if (latestMsg != null && msgReceived.strName == latestMsg.strName)
                            {
                                newGuy = false;
                            }
                            else
                            {
                                newGuy = true;
                                testimonyPB.Image = null;
                            }

                            latestMsg = msgReceived;
                            objectLayerPB.Image = null;
                            objectLayerPB.Location = new Point(0, 0);
                            objectLayerPB.Size = new Size(256, 192);

                            if (msgReceived.callout <= 3)
                            {
                                sendEnabled = false;
                                curPreAnimTime = 0;
                                curPreAnimTime = 0;
                                curPreAnim = null;
                                soundTime = 0;
                                curSoundTime = 0;

                                if (msgReceived.callout > 0)
                                    performCallout();

                                if (iniParser.GetSoundName(msgReceived.strName, msgReceived.anim) != "1" && iniParser.GetSoundTime(msgReceived.strName, msgReceived.anim) > 0 & File.Exists("base/sounds/general/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav"))
                                {
                                    sfxPlayer.Stop();
                                    wr = new WaveFileReader("base/sounds/general/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav");
                                    sfxPlayer.Initialize(wr);
                                    soundTime = iniParser.GetSoundTime(msgReceived.strName, msgReceived.anim);
                                }

                                /*  if (iniParser.GetSoundName(msgReceived.strName, msgReceived.anim) != "1" && iniParser.GetSoundTime(msgReceived.strName, msgReceived.anim) > 0 & (File.Exists("base/sounds/general/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav") | File.Exists("base/characters/" + latestMsg.strName + "/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav")))
                                {
                                    sfxPlayer.Stop();
                                    if (File.Exists("base/characters/" + latestMsg.strName + "/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav"))
                                        wr = new WaveFileReader("base/characters/" + latestMsg.strName + "/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav");
                                    else
                                        wr = new WaveFileReader("base/sounds/general/" + iniParser.GetSoundName(latestMsg.strName, latestMsg.anim) + ".wav");
                                    sfxPlayer.Initialize(wr);
                                    soundTime = iniParser.GetSoundTime(msgReceived.strName, msgReceived.anim);
                                } */

                                if (iniParser.GetAnimType(msgReceived.strName, msgReceived.anim) == 5)
                                    ChangeSides(true);
                                else
                                    ChangeSides();

                                //If there is no pre-animation
                                if (iniParser.GetAnimType(msgReceived.strName, msgReceived.anim) == 5 | iniParser.GetPreAnim(msgReceived.strName, msgReceived.anim) == null | iniParser.GetPreAnimTime(msgReceived.strName, msgReceived.anim) <= 0)
                                {
                                    charLayerPB.Enabled = true;
                                    setCharSprite("base/characters/" + msgReceived.strName + "/(b)" + iniParser.GetAnim(msgReceived.strName, msgReceived.anim) + ".gif");
                                    if (msgReceived.cmdCommand == Command.Present)
                                    {
                                        sfxPlayer.Stop();
                                        wr = new WaveFileReader("base/sounds/general/sfx-shooop.wav");
                                        sfxPlayer.Initialize(wr);
                                        if (!mute)
                                            sfxPlayer.Play();

                                        switch (iniParser.GetSide(msgReceived.strName))
                                        {
                                            case "def":
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(173, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                            case "pro":
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceLeft.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(13, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                            case "hld":
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceLeft.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(13, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                            case "hlp":
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(173, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                            default:
                                                testimonyPB.Image = Image.FromFile("base/misc/ani_evidenceRight.gif");
                                                System.Threading.Thread.Sleep(100);
                                                testimonyPB.Location = new Point(173, 13);
                                                testimonyPB.Size = new Size(70, 70);
                                                testimonyPB.Image = eviList[Convert.ToInt32(msgReceived.strMessage.Split('|').Last())].icon;
                                                break;
                                        }

                                        msgReceived.strMessage = msgReceived.strMessage.Split('|')[0];
                                    }
                                    prepWriteDispBoxes(msgReceived, msgReceived.textColor);
                                }
                                else //if there is a pre-animation
                                {
                                    //charLayerPB.Enabled = false;
                                    setCharSprite("base/characters/" + msgReceived.strName + "/" + iniParser.GetPreAnim(msgReceived.strName, msgReceived.anim) + ".gif");
                                    preAnimTime = iniParser.GetPreAnimTime(msgReceived.strName, msgReceived.anim);
                                    curPreAnim = iniParser.GetPreAnim(msgReceived.strName, msgReceived.anim);
                                }
                                //dispTextRedraw.Enabled = true;
                            }
                            else
                            {
                                performCallout();
                            }
                            break;

                        case Command.List:
                            appendTxtLogSafe("<<<" + strName + " has entered the courtroom>>>\r\n");
                            break;

                        case Command.DataInfo:
                            //Do the stuff with the incoming server data here

                            //The user has logged into the system so we now request the server to send
                            //the names of all users who are in the chat room
                            Data msgToSend = new Data();
                            msgToSend.cmdCommand = Command.Login;
                            msgToSend.strName = strName;

                            byteData = new byte[1048576];
                            byteData = msgToSend.ToByte();

                            clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null);

                            byteData = new byte[1048576];
                            break;

                        case Command.PacketSize:
                            break;
                    }

                    if (msgReceived.strMessage != null & msgReceived.cmdCommand == Command.Message | msgReceived.cmdCommand == Command.Login | msgReceived.cmdCommand == Command.Logout)
                    {
                        if (msgReceived.callout <= 3)
                            appendTxtLogSafe(msgReceived.strMessage + "\r\n");
                    }

                    if (msgReceived.cmdCommand != Command.PacketSize)
                        byteData = new byte[1048576];
                    else
                        byteData = new byte[Convert.ToInt32(msgReceived.strMessage)];
                }

                clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);

            }
            catch (SocketException)
            {
                if (MessageBox.Show("You have been kicked from the server.", "AODXClient", MessageBoxButtons.OK) == DialogResult.OK)
                {
                    Close();
                }
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                if (Program.debug)
                    MessageBox.Show(ex.Message + ".\r\n" + ex.StackTrace.ToString(), "AODXClient: " + strName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #15
0
        private CodecFactory()
        {
            _codecs = new Dictionary<object, CodecFactoryEntry>();
            Register("mp3", new CodecFactoryEntry((s) =>
            {
                //if (MP3.MP3MediafoundationDecoder.IsSupported)
                //    return new MP3.MP3MediafoundationDecoder(s);
                //else
                //    return new MP3.MP3FileReader(s).DataStream;
                return new MP3.DmoMP3Decoder(s);
            },
                "mp3", "mpeg3"));
            Register("wave", new CodecFactoryEntry((s) =>
            {
                IWaveSource res = new WAV.WaveFileReader(s);
                if (res.WaveFormat.WaveFormatTag != AudioEncoding.Pcm &&
                    res.WaveFormat.WaveFormatTag != AudioEncoding.IeeeFloat &&
                    res.WaveFormat.WaveFormatTag != AudioEncoding.Extensible)
                {
                    res.Dispose();
                    res = new MediaFoundation.MediaFoundationDecoder(s);
                }
                return res;
            },
                "wav", "wave"));
            Register("flac", new CodecFactoryEntry((s) =>
            {
                return new FLAC.FlacFile(s);
            },
                "flac", "fla"));

            if (AAC.AACDecoder.IsSupported)
            {
                Register("aac", new CodecFactoryEntry((s) =>
                {
                    return new AAC.AACDecoder(s);
                },
                    "aac", "adt", "adts", "m2ts", "mp2", "3g2", "3gp2", "3gp", "3gpp", "m4a", "m4v", "mp4v", "mp4", "mov"));
            }

            if (WMA.WMADecoder.IsSupported)
            {
                Register("wma", new CodecFactoryEntry((s) =>
                {
                    return new WMA.WMADecoder(s);
                },
                    "asf", "wm", "wmv", "wma"));
            }

            if (MP1.MP1Decoder.IsSupported)
            {
                Register("mp1", new CodecFactoryEntry((s) =>
                {
                    return new MP1.MP1Decoder(s);
                },
                    "mp1", "m2ts"));
            }

            if (MP2.MP2Decoder.IsSupported)
            {
                Register("mp2", new CodecFactoryEntry((s) =>
                {
                    return new MP1.MP1Decoder(s);
                },
                    "mp2", "m2ts"));
            }

            if (DDP.DDPDecoder.IsSupported)
            {
                Register("ddp", new CodecFactoryEntry((s) =>
                {
                    return new DDP.DDPDecoder(s);
                },
                    "mp2", "m2ts", "m4a", "m4v", "mp4v", "mp4", "mov", "asf", "wm", "wmv", "wma", "avi", "ac3", "ec3"));
            }
        }
        public void Speak(string speech, string voice, int echoDelay, int distortionLevel, int chorusLevel, int reverbLevel, int compressLevel, bool wait = true, int priority = 3)
        {
            if (speech == null) { return; }

            Thread speechThread = new Thread(() =>
            {
                string finalSpeech = null;
                try
                {
                    using (SpeechSynthesizer synth = new SpeechSynthesizer())
                    using (MemoryStream stream = new MemoryStream())
                    {
                        if (string.IsNullOrWhiteSpace(voice))
                        {
                            voice = configuration.StandardVoice;
                        }
                        if (voice != null && !voice.Contains("Microsoft Server Speech Text to Speech Voice"))
                        {
                            try
                            {
                                Logging.Debug("Selecting voice " + voice);
                                synth.SelectVoice(voice);
                                Logging.Debug("Selected voice " + synth.Voice.Name);
                            }
                            catch (Exception ex)
                            {
                                Logging.Error("Failed to select voice " + voice, ex);
                            }
                        }

                        Logging.Debug("Post-selection");
                        Logging.Debug("Configuration is " + configuration == null ? "<null>" : JsonConvert.SerializeObject(configuration));
                        synth.Rate = configuration.Rate;
                        Logging.Debug("Rate is " + synth.Rate);
                        synth.Volume = configuration.Volume;
                        Logging.Debug("Volume is " + synth.Volume);

                        synth.StateChanged += new EventHandler<StateChangedEventArgs>(synth_StateChanged);
                        Logging.Debug("Tracking state changes");
                        synth.SetOutputToWaveStream(stream);
                        Logging.Debug("Output set to stream");
                        if (speech.Contains("<phoneme") || speech.Contains("<break"))
                        {
                            Logging.Debug("Speech is SSML");
                            if (configuration.DisableSsml)
                            {
                                Logging.Debug("Disabling SSML at user request");
                                // User has disabled SSML so remove it
                                finalSpeech = Regex.Replace(speech, "<.*?>", string.Empty);
                                synth.Speak(finalSpeech);
                            }
                            else
                            {
                                Logging.Debug("Obtaining best guess culture");
                                string culture = bestGuessCulture(synth);
                                Logging.Debug("Best guess culture is " + culture);
                                finalSpeech = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"" + bestGuessCulture(synth) + "\"><s>" + speech + "</s></speak>";
                                Logging.Debug("SSML speech: " + finalSpeech);
                                try
                                {
                                    Logging.Debug("Speaking SSML");
                                    synth.SpeakSsml(finalSpeech);
                                    Logging.Debug("Finished speaking SSML");
                                }
                                catch (Exception ex)
                                {
                                    Logging.Error("Best guess culture of " + bestGuessCulture(synth) + " for voice " + synth.Voice.Name + " was incorrect", ex);
                                    Logging.Info("SSML does not work for the chosen voice; falling back to normal speech");
                                    // Try again without Ssml
                                    finalSpeech = Regex.Replace(speech, "<.*?>", string.Empty);
                                    synth.Speak(finalSpeech);
                                }
                            }
                        }
                        else
                        {
                            Logging.Debug("Speech does not contain SSML");
                            Logging.Debug("Speech: " + speech);
                            finalSpeech = speech;
                            Logging.Debug("Speaking normal speech");
                            synth.Speak(finalSpeech);
                            Logging.Debug("Finished speaking normal speech");
                        }
                        Logging.Debug("Seeking back to the beginning of the stream");
                        stream.Seek(0, SeekOrigin.Begin);

                        Logging.Debug("Setting up source from stream");
                        IWaveSource source = new WaveFileReader(stream);

                        // We need to extend the duration of the wave source if we have any effects going on
                        if (chorusLevel != 0 || reverbLevel != 0 || echoDelay != 0)
                        {
                            // Add a base of 500ms plus 10ms per effect level over 50
                            Logging.Debug("Extending duration by " + 500 + Math.Max(0, (configuration.EffectsLevel - 50) * 10) + "ms");
                            source = source.AppendSource(x => new ExtendedDurationWaveSource(x, 500 + Math.Max(0, (configuration.EffectsLevel - 50) * 10)));
                        }

                        // Add various effects...
                        Logging.Debug("Effects level is " + configuration.EffectsLevel + ", chorus level is " + chorusLevel + ", reverb level is " + reverbLevel + ", echo delay is " + echoDelay);
                        // We always have chorus
                        if (chorusLevel != 0)
                        {
                            Logging.Debug("Adding chorus");
                            source = source.AppendSource(x => new DmoChorusEffect(x) { Depth = chorusLevel, WetDryMix = Math.Min(100, (int)(180 * ((decimal)configuration.EffectsLevel) / ((decimal)100))), Delay = 16, Frequency = (configuration.EffectsLevel / 10), Feedback = 25 });
                        }

                        // We only have reverb and echo if we're not transmitting or receiving
                        //if (!radio)
                        //{
                        if (reverbLevel != 0)
                        {
                            Logging.Debug("Adding reverb");
                            // We tone down the reverb level with the distortion level, as the combination is nasty
                            source = source.AppendSource(x => new DmoWavesReverbEffect(x) { ReverbTime = (int)(1 + 999 * ((decimal)configuration.EffectsLevel) / ((decimal)100)), ReverbMix = Math.Max(-96, -96 + (96 * reverbLevel / 100) - distortionLevel) });
                        }

                        if (echoDelay != 0)
                        {
                            Logging.Debug("Adding echo");
                            // We tone down the echo level with the distortion level, as the combination is nasty
                            source = source.AppendSource(x => new DmoEchoEffect(x) { LeftDelay = echoDelay, RightDelay = echoDelay, WetDryMix = Math.Max(5, (int)(10 * ((decimal)configuration.EffectsLevel) / ((decimal)100)) - distortionLevel), Feedback = Math.Max(0, 10 - distortionLevel / 2) });
                        }
                        //}

                        if (configuration.EffectsLevel > 0 && distortionLevel > 0)
                        {
                            Logging.Debug("Adding distortion");
                            source = source.AppendSource(x => new DmoDistortionEffect(x) { Edge = distortionLevel, Gain = -distortionLevel / 2, PostEQBandwidth = 4000, PostEQCenterFrequency = 4000 });
                        }

                        //if (radio)
                        //{
                        //    source = source.AppendSource(x => new DmoDistortionEffect(x) { Edge = 7, Gain = -distortionLevel / 2, PostEQBandwidth = 2000, PostEQCenterFrequency = 6000 });
                        //    source = source.AppendSource(x => new DmoCompressorEffect(x) { Attack = 1, Ratio = 3, Threshold = -10 });
                        //}

                        if (priority < activeSpeechPriority)
                        {
                            Logging.Debug("About to StopCurrentSpeech");
                            StopCurrentSpeech();
                            Logging.Debug("Finished StopCurrentSpeech");
                        }

                        Logging.Debug("Creating waitHandle");
                        EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
                        Logging.Debug("Setting up soundOut");
                        var soundOut = GetSoundOut();
                        Logging.Debug("Setting up soundOut");
                        soundOut.Initialize(source);
                        Logging.Debug("Configuring waitHandle");
                        soundOut.Stopped += (s, e) => waitHandle.Set();

                        Logging.Debug("Starting speech");
                        StartSpeech(soundOut, priority);

                        Logging.Debug("Waiting for speech");
                        // Add a timeout, in case it doesn't come back with the signal
                        waitHandle.WaitOne(source.GetTime(source.Length));
                        Logging.Debug("Finished waiting for speech");

                        Logging.Debug("Stopping speech (just to be sure)");
                        StopCurrentSpeech();
                        Logging.Debug("Disposing of speech source");
                        source.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error("Failed to speak \"" + finalSpeech + "\"", ex);
                }
            });
            Logging.Debug("Setting thread name");
            speechThread.Name = "Speech service speak";
            Logging.Debug("Setting thread background");
            speechThread.IsBackground = true;
            try
            {
                Logging.Debug("Starting speech thread");
                speechThread.Start();
                if (wait)
                {
                    Logging.Debug("Waiting for speech thread");
                    speechThread.Join();
                    Logging.Debug("Finished waiting for speech thread");
                }
            }
            catch (ThreadAbortException tax)
            {
                Thread.ResetAbort();
                Logging.Error(speech, tax);
            }
            catch (Exception ex)
            {
                Logging.Error(speech, ex);
                speechThread.Abort();
            }
        }