Speech Synthesis (using system. Speech. synthesis in. net3.0)

Source: Internet
Author: User

Speech Synthesis

1. Use speech synthesis

Speechsynthesizer synth = new speechsynthesizer ();

 

// Obtain the names of all voice installed on the local machine

String voicestring = "";

 

Foreach (installedvoice IV in synth. getinstalledvoices ())

{

Voicestring + = IV. voiceinfo. Name + ",";

}

 

// Determine the voice to be used based on The Voice name attribute

Synth. selectvoice ("VW Lily ");

// Synthesize speech based on text content

Synth. Speak (this. textbox1.text );

Synth. Speak ("Hubei Province, the People's Republic of China ");

2. Build ssml

Promptbuilder myprompt = new promptbuilder ();

 

// Start the main speaking style

Promptstyle mainstyle = new promptstyle ();

Mainstyle. Rate = promptrate. medium;

Mainstyle. volume = promptvolume. volume;

Myprompt. startstyle (mainstyle );

 

// Alert the listener

Myprompt. appendaudio (New uri (

"File: // C:" Windows "" Media "" yy.wav ")," Attention! "); // The appendaudio function combines WAV Files with outputs,

// If the wav file is not found, you can use an equivalent text file, that is, the second parameter.

Myprompt. appendtext ("Here are some important messages .");

 

// Here's the first important message

Myprompt. appendtextwithpronunciation ("winfx", "W n ɛ F ɛ Ks"); // The appendtextwithpronunciation function allows you to specify the correct pronunciation of a word.

Myprompt. appendtext ("is a great platform .");

 

// And the second one

Myprompt. appendtextwithhint ("asp", sayas. spellout); // The appendtextwithhint function marks the acronym.

// Example of sayas enumerated values: sayas. numberordinal sayas. daymonth sayas. spellout sayas. Telephone sayas. Text sayas. time24

Myprompt. appendtext (

"Is an acronym for Active Server Pages. Whereas an ASP is a snake .");

 

Myprompt. appendbreak ();

 

// Let's emphasise how important these messages are

Promptstyle interimstyle = new promptstyle ();

Interimstyle. Emphasis = promptemphasis. Strong;

Myprompt. startstyle (interimstyle );

Myprompt. appendtext ("Please remember these two things .");

Myprompt. endstyle ();

 

// Then we can revert to the main speaking style

Myprompt. appendbreak ();

Myprompt. appendtext ("thank you ");

 

Myprompt. endstyle ();

// Now let's get the synthesizer to render this message

Speechsynthesizer synth = new speechsynthesizer ();

Synth. selectvoice ("VW Lily ");

Synth. speakasync (myprompt); // Asynchronous Method Different from speak

 

3. Save the constructed ssml in the ssml file.

Using (streamwriter promptwriter = new streamwriter ("C:" "prompt. ssml "))

{

Promptwriter. Write (myprompt. toxml ());

}

4. Save the constructed voice into a WAV file.

// If the speakasync method is used earlier, it cannot be output as a WAV file.

// The output can only be completed after the voice is broadcast.

Synth. setoutputtowavefile ("C:" "message.wav ");

Synth. Speak (myprompt );

Synth. setoutputtonull ();

5. Restore to voice based on the information saved in the ssml File

Speechsynthesizer synth = new speechsynthesizer ();

Promptbuilder savedprompt = new promptbuilder ();

Savedprompt. appendssml ("C:" "prompt. ssml ");

Synth. selectvoice ("VW Lily ");

Synth. Speak (savedprompt );

 

6. display the text position being read through the highlight of the speech progress event

Speechsynthesizer synth = new speechsynthesizer ();

Synth. speakprogress + = new eventhandler <speakprogresseventargs> (synth_speakprogress );

Void synth_speakprogress (Object sender, speakprogresseventargs E)

{

This. textbox1.hideselection = false;

This. textbox1.select (E. characterposition, E. charactercount );

}

Source code

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.