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 ();}