但是,这个方法本身并不知道你给的字符串是什么语言,所以需要我们它这个字符串用什么语言读出。
SpVoiceClass 类的Voice 属性就是用来设置语种的,我们可以通过SpVoiceClass 的GetVoices方法得到所有的语种列表,
然后在根据参数选择相应的语种,比如设置语种为汉语如下所示:
private void SetChinaVoice()
{
  voice.Voice = voice.GetVoices(string.Empty,string.Empty).Item(0) ;
}
   0表示是汉用,1234都表示英语,就是口音不同。
   这样,我们就设置了语种,如果结合发音方法,我们就可以设计出一个只发汉语语音的方法
private void SpeakChina(string strSpeak)
{
  SetChinaVoice() ;
  Speak(strSpeak) ;
}
   只发英语语音的方法也是类似的,上面程序里有。
   对于一段中英文混合的语言,我们让程序读出混合语音的方法就是:编程把这段语言的中英文分开,对于
中文调用SpeakChina方法,英文调用SpeakEnglishi方法;至于怎样判断一个字符是英文还是中文,我采用的是判断
asc码的方法,具体的类方法是通过AnalyseSpeak实现的。
   这样,对于一段中英文混合文字,我们只需把它作为参数传递给AnalyseSpeak就可以了,他能够完成中英文
的混合发音。
   当然,对于发音的暂定、继续、停止等操作,上面也给出了简单的方法调用,很容易明白。
   下面简单介绍一下中文语音识别的方法:
   先把该语音识别的类源代码贴在下面,然后再做说明:
public class SpRecognition 

  
private static SpRecognition _Instance = null ; 
  
private SpeechLib.ISpeechRecoGrammar isrg ; 
  
private SpeechLib.SpSharedRecoContextClass ssrContex =null
  
private System.Windows.Forms.Control cDisplay ; 
  
private SpRecognition() 
  

   ssrContex 
= new SpSharedRecoContextClass() ; 
   isrg 
= ssrContex.CreateGrammar(1) ; 
   SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler recHandle 
= new _ISpeech
RecoContextEvents_RecognitionEventHandler(ContexRecognition) ; 
   ssrContex.Recognition 
+= recHandle ; 
  }
 
  
public void BeginRec(Control tbResult) 
  

   isrg.DictationSetState(SpeechRuleState.SGDSActive) ; 
   cDisplay 
= tbResult ; 
  }
 
  
public static SpRecognition instance() 
  

   
if (_Instance == null
    _Instance 
= new SpRecognition() ; 
    
return _Instance ; 
  }
 
  
public void CloseRec() 
Posted on 2006-04-01 12:13  李通通  阅读(326)  评论(0编辑  收藏  举报