C # text-to-speech DEMO

Source: Internet
Author: User

Recently, Google, a whimsy player who wants to play with text-to-Speech games, found that Microsoft has a tts sdk, checked the relevant information, and found that it was really good. Then he started to play with the Microsoft Speech sdk demo.

The latest Version on the Internet seems to be Microsoft Speech SDK Version 5.1 first.

Is http://www.52z.com/soft/22068.html

First install the first SDK and then install the Language Pack. Only the Language Pack is installed to support Chinese reading.

Then start our C # text-to-speech applet.

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, including the Microsoft Speech API and 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.

Now you can have a good time playing with your DEMO. You can also add a lot of functions to make it a program with the same examples in the SDK!


Ps: I feel that Microsoft's voice is not soft. I have seen some good online text-to-sound systems on the Internet.

Http://ecl..com/ListenToThis/

Related Article

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.