Preparation
To use speech recognition and speech synthesis technology in. net, you need to use Microsoft's speech SDK.ProgramYou must use the speech application SDK. The speech SDK can be used in Alibaba SDK 5.1 and 5.1 Language Pack. The former is an development kit, but only supports English. The latter is a Language Pack for Chinese and Japanese, after installation, Chinese characters are supported.
SDK Composition
Drill
1. Open vs2005, create a Windows application, add a label, A RichTextBox (used to input the text to be read), and a button to the design form. And set the text attributes of the label and button respectively. For example
2. Add necessary references. Select "project"> "add reference"> "com" and click "Microsoft Speech Object Library" to exit.
3. Double-click the button to add events to it. InCodeAdd a namespace at the top of the page. The Code is as follows:
Using speechlib;
4. The event handler code of the button is as follows.
Private void button#click (Object sender, eventargs E)
{
Spvoiceclass voice = new spvoiceclass ();
Voice. Voice = voice. getvoices (string. Empty, String. Empty). Item (3); // where 3 is Chinese and 024 is English
Voice. Speak (richtextbox1.text, speechvoicespeakflags. svsfdefault );
}
5. Press F5 to run the task. Enter the text in the blank area and click "read aloud". Try the result.
Spvoiceclass
Attribute
Description
Alertboundary
Gets or sets the pause line.
Allowaudiooutputformatchangesonnextset
Set whether to allow the sound to automatically adjust to the appropriate status to adapt to its audio output.
Audiooutput
. Gets or sets the audio output object used by the current sound.
Audiooutputstream
Gets or sets the audio output stream object used by the current sound.
Eventinterests
Gets or sets the event type returned by the current sound.
Priority
Gets or sets the voice priority.
Rate
Get or set the reading speed.
Status
Returns an ispeechvoicestatus object used to display the status of the current read and event.
Synchronousspeaktimeout
Gets or sets a time interval to identify how long a synchronization speak and speakstream will terminate after an output device is not obtained, in milliseconds.
Voice
Obtains or sets the pronunciation object.
Volume
Obtains or sets the sound size.
Method
Description
Displayui
Whether to display detailed settings in the control panel.
Getaudiooutputs
Returns an available audio output tag.
Getvoices
Returns an available pronunciation object.
Isuisupported
Determines whether the control can be achieved by controlling the audio settings of the Cotton Board.
Pause
Pause reading ..
Resume
Resume pause and Resume playback.
Skip
In the current text stream, jump forward or backward for a certain distance and then play back.
Speak
Read a string.
Speakcompleteevent
Get a time handle for reading.
Speakstream
Read a text stream or sound file.
Waituntildone
The process is blocked until the sound is played completely or times out ..
. (This article is only the first article in this series. Other content will be discussed later. You are welcome to contact me .)
. Net speech recognition and speech synthesis (ii) speech synthesis Improvement
In. net speech recognition and speech synthesis (I) This article introduces some basic knowledge about speech synthesis, that is, first J creates a spvoiceclass class object, then, the getvoices method of the object is called to obtain a pronunciation object. However, by setting the parameters of this method, only Chinese pronunciation or English pronunciation objects can be created, but there is no way to mix Chinese and English texts. To solve this problem, you can determine the ASC code of each character in the string to determine whether the input string is Chinese or English. The following is the judgment code.
1 Public bool analyse (string strspeak)
2 {
3 int icbeg = 0;
4 int iebeg = 0;
5 bool ischina = true;
6 for (INT I = 0; I 7 {
8 char CHR = strspeak [I];
9 If (ischina)
10 {
11 if (CHR <= 122 & CHR> = 65)
12 {
13 int ilen = I-icbeg;
14 string strvalue =
15strspeak. substring (icbeg, ilen);
16 speakchina (strvalue);
17 iebeg = I;
1 8 ischina = false;
19}
20}
21 else
22 {
23 if (CHR> 122 | CHR <65)
24 {
25 int ilen = I-iebeg;
26 string strvalue =
27strspeak. substring (iebeg, ilen);
28 This. speakenglishi (strvalue);
29 icbeg = I;
30 ischina = true;
31}
32}
33}
34 return ischina;
35}
for parameters of the Speak method, the first is a string type, and the second is an enumeration of the speechvoicespeakflags type. When svsfdefault is set, the first parameter is the text to be read. If svsfisfilename is set, the first parameter is the file name of the text to be read, instead of the content to be read.
The following describes the speakstream method of this class. This method has two parameters, the first is speechbasestream, and the second is an enumeration of the speechvoicespeakflags type like speak. Speechbasestream is an interface that inherits three objects. These three objects are similar. First, we will introduce spfilestream. Spfilestream has three common methods: read, seek, and write. The read method can create a *. Wav file. The following Code demonstrates how to create a file:
Spfilestreamclass fs1 = new spfilestreamclass ();
Spvoiceclass v = new spvoiceclass ();
Fs1.open (textbox1.text, speechstreamfilemode. ssfmcreateforwrite, false );
// Textbox1.text is the path of the file to be created.
V. audiooutputstream = fs1;
String [] Ss = new string [4] {"this", "is", "A", "Demo "};
Foreach (string s in SS)
{
V. Speak (S, speechvoicespeakflags. svsflagsasync );
}
Fs1.close ();
The following code is used to show the speak and speakstream:
spfilestreamclass fs1 = new spfilestreamclass ();
spfilestreamclass fs2 = new spfilestreamclass ();
spvoiceclass v = new spvoiceclass ();
fs1.open (textbox1.text, speechstreamfilemode. ssfmopenforread, false);
fs2.open (textbox2.text, speechstreamfilemode. ssfmopenforread, false);
v. speak ("This is the first sound file", speechvoicespeakflags. svsflagsasync);
v. speakstream (fs1, speechvoicespeakflags. svsflagsasync);
v. speak ("this is the second sound file", speechvoicespeakflags. svsflagsasync);
v. speakstream (fs2, speechvoicespeakflags. svsflagsasync);
fs1.close ();
fs2.close ();