In .NET, there is better support for English voice, but the support of Chinese voice has not been added yet, we want to implement Chinese pronunciation or Chinese speech recognition, you must install Microsoft's Speech Application SDK (Sasdk), it The latest version is SAPI 5.1 he can identify, day, and English, you can download: http://www.microsoft.com/speech/download/SDK51/, you need to install these two files SPK 5.1 and 5.1 Language Pack, where 5.1 Language Pack selects the language that is installed. After installation, we can start the development of the voice program. Of course, before this, we need to add SAPI.dll to the reference to the reference as shown below. We design a class that can read English Mixed language: We will Using a single case mode, the code of the class is as follows, we will explain it in detail: public Class Speach
{
Private static sperach _instance = null;
Private Speechlib.spvoiceClass Voice = NULL;
Private Speach ()
{
Buildspeach ();
}
Public Static Speach Instance ()
{
IF (_Instance == null)
_INSTANCE = New Speach ();
Return_INSTANCE;
}
Private void setChinavoice ()
{
Voice.Voice = Voice.GetVoices (String.empty, String.empty) .Item (0);
}
Private void setENGLISHVOICE ()
{
Voice.Voice = Voice.GetVoices (String.empty, String.empty) .Item (1);
}
Private vid SpeakChina (String Strspeak)
{
SetChinaVoice ();
SPEAK (STRSPEAK);
}
Private vid Speakenglishi (String Strspeak)
{
SetENGLISHVOICE ();
SPEAK (STRSPEAK);
}
Public void Analysis (String STRSPEAK)
{
INT ICBEG = 0;
INT IEBEG = 0;
Bool ischina = True;
For (int i = 0; i { Char chr = strspeak [i]; IF (ischina) { IF (chr <= 122 && chr> = 65) { INT ILEN = I - ICBEG; String strign = strspeak.substring (icbeg, ilen); SpeakChina (Strvalue); IEBEG = I; Ischina = false; } } Else { IF (chr> 122 || chr <65) { INT ILEN = i - IEBEG; String strign = strspeak.substring (IEBEG, ILEN); THIS.SPEAKENGLISHI (STRVALUE); ICBEG = i; Ischina = true;} } } // end for IF (ischina) { INT Ilen = strspeak.length - icbeg; String strign = strspeak.substring (icbeg, ilen); SpeakChina (Strvalue); } Else { INT Ilen = strspeak.length - IEBEG; String strign = strspeak.substring (IEBEG, ILEN); Speakenglishi (STRVALUE); } } Private void buildspeach () { IF (voice == null) Voice = new spvoiceclass (); } Public Int Volume { get { Return Voice.Volume; } set { Voice.SetVolume ((Ushort) (Value); } } Public int Rate { get { Return voice.rate; } set { Voice.Setrate (Value); } } Private vid Speak (String Strspeck) { Try { Voice.SPEAK (STRSPEACK, Speechvoicespeakflags.svsflagsasync); } Catch (Exception Err) { Throw (New Exception ":" Err.Message)); } } Public void stop () { Voice.SPEAK (String.empty, Speechlib.SpeechVoicespeakflags.svsfpurgebeForespeak); } Public void pause () { Voice.PAUSE (); } Public void continue () { Voice.Resume (); } } // End class is in private speechlib.spvoiceclass voice = null; here, we define a class for pronunciation, and when calling this class for the first time, it is initialized with the buildspeach method. We also define two attributes Volume and Rate, which can set the volume and speed. We know that spvoiceclass has a speak method, our pronunciation is mainly to deliver a string, which is responsible for reading the string, as shown below. Private vid Speak (String Strspeck) { Try { Voice.SPEAK (STRSPEACK, Speechvoicespeakflags.svsflagsasync); } Catch (Exception Err) { Throw (New Exception ":" Err.Message)); } The speechvoicespeakflags.svsflagsasync represents asynchronous pronunciation.