예제 #1
0
        private void StartSpeak(object info)
        {
            if (this.InvokeRequired)
            {
                OneArgumentDel del = new OneArgumentDel(this.StartSpeak);
                this.Invoke(del, info);
                return;
            }
            string speechText = info as string;

            Program.OutputMessage("StartSpeek : {0}", speechText);

            if (string.IsNullOrEmpty(speechText))
            {
                Program.OutputMessage("StartSpeak: No text to speak");
                return;
            }

            //cmdPause.Enabled = false;
            //cmdPause.Text = "Pause";
            //cmdStop.Enabled = false;
            if (_speachSyn != null)
            {
                try
                {
                    _speachSyn.Dispose();
                }
                catch (Exception e)
                {
                    Program.OutputMessage("Exception thrown : {0}\r\n{1}", e.Message, e.StackTrace);
                }
            }

            _speechState             = SynthesizerState.Ready;
            _speachSyn               = new SpeechSynthesizer();
            _speachSyn.StateChanged += _speachSyn_StateChanged;

            int volume = 100;
            int speed  = 0;

            int.TryParse(txtVolume.Text, out volume);
            int.TryParse(cbSpeed.SelectedItem as string, out speed);
            string voice = cbVoice.SelectedItem as string;

            if (string.IsNullOrEmpty(voice))
            {
                voice = cbVoice.Items[0].ToString();
            }

            _speachSyn.SelectVoice(voice);
            _speachSyn.Volume = volume;
            _speachSyn.Rate   = speed;
            _speachSyn.SetOutputToDefaultAudioDevice();
            _speachSyn.SpeakAsync(speechText);
        }
예제 #2
0
        private void InitiateResumeSpeech(object info)
        {
            if (this.InvokeRequired)
            {
                OneArgumentDel del = new OneArgumentDel(this.InitiateResumeSpeech);
                this.Invoke(del, info);
                return;
            }

            if (_speechState == SynthesizerState.Paused)
            {
                _speachSyn.Resume();
            }
        }
예제 #3
0
        private void InitiateReadClipboardText(object info)
        {
            if (this.InvokeRequired)
            {
                OneArgumentDel del = new OneArgumentDel(this.InitiateTextToSpeech);
                this.Invoke(del, info);
                return;
            }

            string readText = null;

            if (Clipboard.ContainsText())
            {
                readText = Clipboard.GetText();
                StartSpeak(readText);
            }
        }
예제 #4
0
        private void InitiateSpeechStop(object info)
        {
            if (_speechState != SynthesizerState.Speaking)
            {
                return;
            }

            if (this.InvokeRequired)
            {
                OneArgumentDel del = new OneArgumentDel(this.InitiateSpeechStop);
                this.Invoke(del, info);
                return;
            }

            if (this._speachSyn != null)
            {
                this._speachSyn.Dispose();
                this._speachSyn = null;
            }
        }
예제 #5
0
        private void InitiateTextToSpeech(object info)
        {
            if (this.InvokeRequired)
            {
                OneArgumentDel del = new OneArgumentDel(this.InitiateTextToSpeech);
                this.Invoke(del, info);
                return;
            }

            string selText = null;

            if (GetSelectedText(out selText))
            {
                if (!string.IsNullOrEmpty(selText))
                {
                    string tmpSelText = selText.Trim(new char[] { '\r', '\n', ' ', '\t' });
                    if (selText.Length > 2)
                    {
                        //System.Threading.ThreadPool.QueueUserWorkItem(this.StartSpeakStub, selText);
                        StartSpeak(selText);
                        //UpdateMessage(selText);
                        return;
                    }
                }
            }
            _getSpeechTextUsingClipboard = true;
            _dtClipboardGetTextStart     = DateTime.Now;
            SendKeys.SendWait("^c");
            _sendKeysCounter++;

            // sometime clipboard registration is stopping to work, this is to detect if clipboard registration is
            // no more working and trying to re-register it
            int localCounter = _sendKeysCounter;

            System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.CheckIfSpeechStarted), localCounter);
        }