C # Speech Recognition (text to speech, voice to text)

Source: Internet
Author: User
Tags sapi





C # Speech Recognition (text to speech, voice to text)


Recently intends to study the speech recognition, but found that there is very little C # on the Internet, the complete code to put their own learning experience, and share with you.






Download API:



1) SpeechSDK51.exe (67.0 MB)



2) SpeechSDK51LangPack.exe (81.0 MB)



API can not be downloaded, but if your vs is English, but want to use Chinese voice, then you need to download the API, in order to install.



PS: My vs is English, can't speak Chinese, for this I have tangled up all morning. API, thank you: XAF, http://smartsoft.5d6d.com/thread-8819-1-1.html)






Text To Speech:



This is quite simple.



1) The Microsoft Speech Object Library Reference in the COM tab



2) using Speechlib;



3) Spvoiceclass voice = new Spvoiceclass ();//sapi 5.1



SpVoice voice = new SpVoice ();//sapi 5.4



4) Voice. Voice = Voice. Getvoices (String. Empty, String. Empty). Item (3);



5) Voice. Speak ("What you have to say");






PS: In the fourth step is the choice of language, different APIs may not be the same, the Internet is said to be 0, but I use the API is 3.









Voice to text:



PublicClass Sprecognition {Privatestatic Sprecognition _instance =NullPrivate Speechlib.ispeechrecogrammar ISRG;Private Speechlib.spsharedrecocontextclass Ssrcontex =Null PublicDelegatevoid Stringevent (String str);Public Stringevent Setmessage; Private Sprecognition () {Ssrcontex =New Spsharedrecocontextclass (); ISRG = Ssrcontex.creategrammar (1); Speechlib._ispeechrecocontextevents_recognitioneventhandler Rechandle =New _ispeechrecocontextevents_recognitioneventhandler (contexrecognition); Ssrcontex.recognition + = Rechandle; }Publicvoid Beginrec () {Isrg. Dictationsetstate (speechrulestate.sgdsactive); }Publicstatic sprecognition instance () {if (_instance = null) _instance = new sprecognition (); return _instance;} public void Closerec () {Isrg. Dictationsetstate (speechrulestate.sgdsinactive); } private void contexrecognition (int IIndex, object obj, Speechlib.speechrecognitiontype type, Speechlib.ispeechrecoresult result) {if (setmessage! = 0,-1, true)); } } }








I hope the above code is useful for everyone. S



C # Speech Recognition (text to speech, voice to text)


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.