Do not know if you have found that under the System.Speech.Synthesis namespace there is a SpeechSynthesizer class, it can specify the text content to read aloud, and, this class is also very simple to use, how simple to what extent? Try.
First of all, create a new project, whatever you build any project, you can test it anyway.
Then, add a reference to the System.speech assembly, which I don't need to teach you, you can not do it, as long as you use VS can not understand this.
Introduce the System.Speech.Synthesis namespace, and finally, watch, a few lines of code.
private void
Button1_Click (object sender, EventArgs e)
{
if (string). Isnullorwhitespace (Txttoread.text))
{return
;
}
A new one speech on the
SpeechSynthesizer sp = new SpeechSynthesizer ();
Sp. Speakcompleted + = (s, arg) => button1. Enabled = true;
began to read
button1. Enabled = false;
Sp. Speakasync (Txttoread.text);
}
Call the Speak method to start listening to the MM speech, I am calling here is an asynchronous version.
Run, enter some text, start reading, you will hear a mm of the sound of nature.
How's that feel?
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/csharp/