In. net, but the support for Chinese speech has not yet been added, we want to achieve Chinese pronunciation or Chinese speech recognition, you must first install Microsoft's Speech Application SDK (SASDK). The latest version is SAPI 5.1, which can recognize Chinese, Japanese, and English languages. You can download it here:Http://www.microsoft.com/speech/download/sdk51/, requiredTo install the Speech SDK 5.1 and 5.1 Language Pack files, you can select the supported Language for the 5.1 Language Pack Installation.
After the installation, we can start the development of the speech program. Of course, before that, we need to add SAPI. dll to the reference through the example shown in.
Below we design a class that can read both Chinese and English languages:
We will implement this class in singleton mode. The code of the class is as follows, which will be explained in detail:
Public class Speach
{
Private static Speach _ 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 void SpeakChina (string strSpeak)
{
SetChinaVoice ();
Speak (strSpeak );
}
Private void SpeakEnglishi (string strSpeak)
{
SetEnglishVoice ();
Speak (strSpeak );
}
Public void AnalyseSpeak (string strSpeak)
{
Int iCbeg = 0;
Int iEbeg = 0;
Bool IsChina = true;
For (int I = 0; I <strSpeak. Length; I ++)
{
Char chr = strSpeak [I];
If (IsChina)
{
If (chr <= 122 & chr> = 65)
{
Int iLen = I-iCbeg;
String strValue = strSpeak. Substring (iCbeg, iLen );
SpeakChina (strValue );
IEbeg = I;
IsChina = false;
}
}
Else
{
If (chr> 122 | chr <65)
{
Int iLen = I-iEbeg;
String strValue = strSpeak. Substring (iEbeg, iLen );
This. SpeakEnglishi (strValue );
ICbeg = I;
IsChina = true;
}
& Nb