一、概述
HoloToolKit Unity 包提供了三种 语音输入的方式 :
Phrase Recognition 短语识别
* KeywordRecognizer 单一关键词识别
* GrammarRecognizer 语法识别
Dictation Recognition 听写识别
* DictationRecognizer 将声音识别转化为文字
Note: KeywordRecognizer 和 GrammarRecognizer 是主动活跃识别的方式~ 也就是说调用开始识别的方法,那么久处于活跃状态开始识别,而DictationRecognizer只要注册了就就在默默的监听语音输入,一旦监听到关键词~那么久触发回调~
二、Unity开发打开Microphone权限
下面是官方文档 讲解 如何打开microphone权限
The Microphone capability must be declared for an app to leverage Voice input.
- In the Unity Editor, go to the player settings by navigating to "Edit > Project Settings > Player"
- Click on the "Windows Store" tab
- In the "Publishing Settings > Capabilities" section, check the Microphone capability
三、Phrase Recognition 短语识别
To enable your app to listen for specific phrases spoken by the user then take some action, you need to:
- Specify which phrases to listen for using a KeywordRecognizer or GrammarRecognizer
- Handle the OnPhraseRecognized event and take action corresponding to the phrase recognized
使用短语识别嘞~需要做两个步骤:
- 指定需要监听的 短语 或者 关键词
- 处理识别到 短语 或者 关键词 之后的事件回调 ~ OnPhraseRecognized
1、 关键词识别 (直接Demo代码~)
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.Windows.Speech;using System.Linq;
public class VoiceInputDemo : MonoBehaviour {
public Material yellow;
public Material red;
public Material blue;
public Material green;
/// <summary>
/// 关键词识别对象
/// </summary>
private KeywordRecognizer keywordRecognizer;
/// <summary>
/// 存放关键词的字典
/// </summary>
private