In the previous blog, Microsoft's voice platform is generally referred to as TTS. It is implemented using the class SpeechSynthesizer in the Xiangwei SDK.
First, let's look at the simplest method:
SpeechSynthesizer speech = newSpeechSynthesizer ();
Speech. setoutputtodefaauaudiodevice ();
Speech. Volume = 50;
Speech. Rate = 0;
Speech. Speak ("this is the audio content! ");
The setoutputtodefaauaudiodevice method is a required method, indicating that the voice is played on the current default playback device. There are several other methods, namely, output to a stream or file, and Volume indicates the Volume during playback, the value ranges from 0 to 100, the Rate is the speed, and the value ranges from-10 to 10. The Speak method of the last row is to start reading the content. It seems that it is not very difficult, but now there is a problem: when reading aloud, the UI of the program is stuck until the reading is complete, this user experience will certainly not work. What should I do? One method is custom multithreading, and the other is to call the asynchronous Speak method of SpeechSynthesizer, that is, SpeakAsync.
What should I do if I want to make some changes when reading a piece of text? It can be implemented using PromptBuilder. This is a collection class. It stores multiple text information and adds corresponding expression attributes to the text information to achieve different expressions of each sentence, for example, the following code:
Speech = newSpeechSynthesizer ();
Speech. setoutputtodefaauaudiodevice ();
Speech. Volume = 100;
Speech. Rate = 0;
PromptBuilder pb = newPromptBuilder ();
Pb. AppendText ("First sentence,", PromptRate. Fast );
Pb. AppendText ("Second sentence,", PromptRate. Slow );
Speech. SpeakAsync (pb );
When reading two sentences, the speed of speech is different.
For more information about the Microsoft voice platform, see http://msdn.microsoft.com/en-us/library/dd266409 (v = office.14). aspx
This article is from "Gui Su Wei" blog, please be sure to keep this source http://axzxs.blog.51cto.com/730810/1246583