Follow these steps:
- Add reference "System.Speech" from Assemblies >> Framework tab. To know how to add reference to your project click: http://gsbprogramming.blogspot.in/2014/07/how-to-add-reference-to-your-project-in.html
- Add namespace: Using System.Speech.Synthesis;
- Create object of SpeechSynthesizer as:
- Now use "reader" object to enable speech as:
or
reader.SpeakAsync("message");
replace message with whatever you want to speak
Difference between reader.Speak( ) and reader.SpeakAsync( ) is that reader.Speak( ) will speak synchronously i.e. when speaking is finished only then next statements will execute while in reader.SpeakAsync( ) speaking is asynchronously i.e. speaking will be carried out on background and next statements can be executed simultaneously .
Note: If you are using reader.SpeakAsync( ) on button click then please use :
reader.Dispose( );
reader=new SpeechSynthesizer( );
and then
reader.SpeakAsync("message");
because when your click the button more than once continously speaking will be continued as many time as user has clicked the button
so to avoid this please use above .
No comments:
Post a Comment