c#语音识别与合成

来源:互联网 发布:千姿竹羊毛衫淘宝 编辑:程序博客网 时间:2024/05/12 16:39

1.语音识别:ASR_——将语音转变为文字
语音合成:TTS——将文字转变为语音
2.文字to语音:
1)在COM选项卡里面的Microsoft Speech object library引用
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(“你要说的话”);
需设定保存文件的格式,可以是。docx,doc,.txt等
3.语音to文字:
private SpRecognition()
{
ssrContex = new SpSharedRecoContextClass();
isrg = ssrContex.CreateGrammar(1);
SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler recHandle =
new _ISpeechRecoContextEvents_RecognitionEventHandler(ContexRecognition);
ssrContex.Recognition += recHandle;
}
public void BeginRec()
{
isrg.DictationSetState(SpeechRuleState.SGDSActive);
}
public static 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 != null)
{
SetMessage(result.PhraseInfo.GetText(0, -1, true));
}
}

0 0
原创粉丝点击