翻译微软官方HoloLens开发课程 语音识别
该脚本挂在摄像机上using System.Collections;using System.Collections.Generic;using System.Linq;using UnityEngine;using UnityEngine.Windows.Speech; //关键字识别的APIpublic class SpeechManagerrr : MonoBeh
该脚本挂在摄像机上
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Windows.Speech; //关键字识别的API
public class SpeechManagerrr : MonoBehaviour {
KeywordRecognizer recognizer; //能识别关键字S
//存放关键字的字典
private Dictionary<string, System.Action> keyWord = new Dictionary<string, System.Action>();
void Start () {
keyWord.Add("Hi", () => { FindObjectOfType<Cbuerrr>().OnTapped(); });
//初始化关键字识别器
recognizer = new KeywordRecognizer(keyWord.Keys.ToArray());
recognizer.OnPhraseRecognized += Recognizer_OnPhraseRecognized;
recognizer.Start();
}
private void Recognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
System.Action action;
if (keyWord.TryGetValue(args.text, out action))
{
action();
}
}
}
更多推荐
所有评论(0)