MS speech sdk5.1 read Control

Source: Internet
Author: User

1. Open Vs and create a new form project

2. Add reference: Microsoft Speech Object Library Reference on the com Tab

Add references in the code area.

Using speechlib;
Using system. Threading; // This reference is a thread class used to save voice files.

3. Add two buttons in the text box

4. Enter the following code under a button:

Speechvoicespeakflags flag = speechvoicespeakflags. svsflagsasync;
Spvoice voice = new spvoice ();
Voice. Voice = voice. getvoices (string. Empty, String. Empty). Item (3 );
// Item (0) Word male Sam
// Item (1) Male Mike
// Item (2) Word Female Mary
// Chinese pronunciation of Item (3). If it is English, it is pronounced one by letter.
Voice. Speak (textBox1.Text, flag );

Code explanation: the most important thing is that the SPVoice class is the core of this DEMO. Then, the annotations below the Item (3) option clearly explain what it means. There is another SPEAK method later. I don't need to say it. I know what it means! Of course, there are still many ways to check the SpVoice object. The Microsoft Speech API also has pause/ResumeSetVoice/GetVoiceSetRate|SetRateSetVolume/GetVolumeAccording to his meaning, these methods know more about how to pause and continue to set the sound reading speed. For more object methods, refer to his API

5. Enter the following code in another button:

SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags. SVSFlagsAsync;
SpVoice voice = new SpVoice ();
Voice. Voice = voice. getvoices (string. Empty, String. Empty). Item (3 );

 

Speechstreamfilemode spfilemode = speechstreamfilemode. ssfmcreateforwrite;

Spfilestream = new spfilestream ();
Spfilestream. Open (@ "C:/test.wav", spfilemode, false );
Voice. audiooutputstream = spfilestream; // set the output of voice to stream.
Voice. Speak (textbox1.text. Trim (), flag );
Voice. WaitUntilDone (Timeout. Infinite); // Using System. Threading;

SpFileStream. Close ();

In fact, this code is similar to the previous Code. It just saves the sound as a voice file through a stream.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.