Today I will show you how speech text in Notepad
- I added four buttons to toolStrip
- Change button's names as play,pause,resume,stop
- Then you have add some library
- Right click on Referrences choose Add References...
- Then search for theSystem.Speech
- Select it and press OK
- Then import the following libraris
using System.Speech;
using System.Speech.Synthesis;
- Now make a globle variable as follow. At the end of the main function you can declera it.
SpeechSynthesizer rd = new SpeechSynthesizer();
- The put the following codes
- 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();
}
- Now run your programm. Enjoy!!
No comments:
Post a Comment