1. 引入头文件
using UnityEngine.Windows.Speech;
2. 设置识别词
public string[] keywords = new string[] { "下一步", "上一步" };
3. Start方法里面开启识别
if (keywords != null)
{
recognizer = new KeywordRecognizer(keywords, confidence);
recognizer.OnPhraseRecognized += Recognizer_OnPhraseRecognized;
recognizer.Start();
}
4. 结果函数写自己逻辑代码
private void Recognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
word = args.text;
}
Args.text就是当前识别词结果,与设置好的识别词做比较即可
注意:需要开启语音服务和键盘输入建议