Voice prompt (source code on the. NET platform)

Source: Internet
Author: User

1. Third-party

1-1 InterOP. speechlib. dll

2 source code:

2-1 space reference

Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. windows. forms; using speechlib; using system. threading; // This reference is a thread class used to save voice files.

2-2 read text (voice prompt)

/// <Summary> /// read text /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> private void button#click (Object sender, eventargs e) {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) Word male Mike // Item (2) Word Female Mary // Item (3) chinese pronunciation. If it is English, it depends on words and letters. Pronounce voice. Speak ("query completed! ", Flag );}

2-3 Save the prompt voice to XX path

Private void button2_click (Object sender, eventargs e) {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 ();}

 

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.