翻译微软官方HoloLens开发课程 语音识别

来源:互联网 发布:统一网络加速器 编辑:程序博客网 时间:2024/06/11 00:38

 该脚本挂在摄像机上

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();
        }
    }
}

原创粉丝点击