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)