Speech text in Notepad (C#)

Today I will show you how speech text in Notepad
  1. I added four buttons to toolStrip
  2. Change button's names as play,pause,resume,stop
  3. Then you have add some library
  4. Right click on Referrences choose Add References...
  5. Then search for theSystem.Speech

  6. Select it and press OK
  7. Then import the following libraris
  8. using System.Speech;
    using System.Speech.Synthesis;
  9. Now make a globle variable as follow. At the end of the main function you can declera it.
  10. SpeechSynthesizer rd = new SpeechSynthesizer();
  11. The put the following codes
  12. Play
    if(GetRichBox().Text !="")
                {
                    rd.Dispose();
                    rd = new SpeechSynthesizer();
                    rd.SpeakAsync(GetRichBox().Text);
                }
                else
                {
                    MessageBox.Show("Notepad is empty !!");
                }
    Pause
    if(rd !=null)
                {
                    if(rd.State==SynthesizerState.Speaking)
                    {
                        rd.Pause();              
                    }
                }
    Resume
    if (rd != null)
                {
                    if (rd.State == SynthesizerState.Paused)
                    {
                        rd.Resume();
                    }
                }
    Stop
    if(rd!=null)
                {
                    rd.Dispose();
                }
  13. Now run your programm. Enjoy!!

No comments:

Post a Comment