Пример #1
0
        private void NotifyIntel(Intel intel)
        {
            if (InvokeRequired)
            {
                this.Invoke((NotifyIntel)NotifyIntel, intel);
                return;
            }

            IntelPresentation intelDisplay = new IntelPresentation(intel);

            if (intelBindingSource.Count > 0)
            {
                intelBindingSource.Insert(0, intel);
            }
            else
            {
                intelBindingSource.Add(intel);
            }

            if (listIntel.Items.Count > 0)
            {
                listIntel.Items.Insert(0, intelDisplay);
            }
            else
            {
                listIntel.Items.Add(intelDisplay);
            }

            if (Properties.Settings.Default.TextToSpeech)
            {
                synthesizerMessages.Enqueue(intelDisplay);
                if (!backgroundIntelSound.IsBusy)
                {
                    backgroundIntelSound.RunWorkerAsync();
                }
            }
            else if (Properties.Settings.Default.PlayIntelSound)
            {
                SystemSounds.Exclamation.Play();
            }
        }
Пример #2
0
        private void backgroundIntelSound_DoWork(object sender, DoWorkEventArgs e)
        {
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                try
                {
                    lock (this)
                    {
                        this.lastSynth = synth;
                    }

                    string selectedVoiceName = Properties.Settings.Default.TextToSpeechVoice;
                    if (!string.IsNullOrEmpty(selectedVoiceName))
                    {
                        synth.SelectVoice(selectedVoiceName);
                    }
                    synth.Rate = Properties.Settings.Default.TextToSpeechRate;

                    int maxItel      = Properties.Settings.Default.TextToSpeechMaxMessages;
                    int skippedIntel = 0;

                    for (int intel = 0; synthesizerMessages.Count > 0 && intel <= maxItel; intel++)
                    {
                        if (Properties.Settings.Default.SkipOlderIntel)
                        {
                            // keep looping through the queue until there are
                            // less then maxIntel messages remaining
                            int intelToKeep = Math.Max(maxItel, 0);

                            while (synthesizerMessages.Count > intelToKeep)
                            {
                                IntelPresentation message = synthesizerMessages.Dequeue();
                                // set the text of the message anyway.
                                setMessageText(message.ToString());
                                skippedIntel++;
                            }
                        }

                        // since we may have skipped everything, we should check if the queue is empty
                        if (synthesizerMessages.Count == 0)
                        {
                            break;
                        }

                        if (Analyzer.Active)
                        {
                            IntelPresentation message = synthesizerMessages.Dequeue();
                            setMessageText(message.ToString());
                            synth.Speak(message.ToSpeech());
                        }
                        else
                        {
                            setMessageText("Intel Paused.");
                            return;
                        }
                    }

                    if (skippedIntel > 0)
                    {
                        string text = IntelSettings.Default.ReadSkipIntel;
                        text = text.Replace("[count]", skippedIntel.ToString());

                        setMessageText(text);
                        synth.Speak(text);
                    }

                    if (synthesizerMessages.Count > 0)
                    {
                        string text = IntelSettings.Default.ReadAdditionalIntelReports;
                        text = text.Replace("[count]", synthesizerMessages.Count.ToString());

                        setMessageText(text);
                        synth.Speak(text);
                    }

                    synthesizerMessages.Clear();
                    setMessageText("");
                }
                finally
                {
                    lock (this)
                    {
                        this.lastSynth = null;
                    }
                }
            }
        }