Unity MRTK语音输入

SpeechInputHandler

文档上是说注册KeyWord的方式取代创建controllers,但是我试了试没什么用,个人推测是SpeechHandler里面的命令配置没有你要注册的KeyWord也就是这是两个文件,但是SpeechInputHandler对这个命令也没有报错,有待考究。
贴下过程:

  • 在speech input里面注册你的keyword
  • 添加组件SpeechInputHandler。添加你的keyword,设置它的方法。
  • 然后进行部署

实现接口 IMixedRealitySpeechHandler

public class 名字 : MonoBehaviour, Microsoft.MixedReality.Toolkit.Input.IMixedRealitySpeechHandler
{
    bool registeredForInput = false;

    /// <summary>
    /// 表示这个需要侦听
    /// </summary>
    private void OnEnable()
    {
        if (!registeredForInput)
        {
            if (CoreServices.InputSystem != null)
            {
                CoreServices.InputSystem.RegisterHandler<IMixedRealitySpeechHandler>(this);
                registeredForInput = true;
            }
        }
    }
    /// <summary>
    /// 表示这个不用侦听了
    /// </summary>
    private void OnDisable()
    {
        if (registeredForInput)
        {
            CoreServices.InputSystem.UnregisterHandler<IMixedRealitySpeechHandler>(this);
            registeredForInput = false;
        }
    }
    public void OnSpeechKeywordRecognized(SpeechEventData eventData)
    {
        switch (eventData.Command.Keyword.ToLower())
        {
            case "命令":
                方法();
                break;

        }
    }

}

参考

https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/Input/Speech.html?q=Speech

原文地址:https://www.cnblogs.com/code-fun/p/14210871.html