Hololens Unity 开发之 语音识别

本文详细介绍了在Hololens Unity开发中实现语音识别的三种方式:短语识别、关键词识别和听写识别。通过KeywordRecognizer和GrammarRecognizer进行短语和关键词识别,并提供代码示例。同时,讲解了DictationRecognizer用于听写的使用,强调了开启Microphone和InternetClient权限的重要性。最后,提到了如何在应用中同时使用这两种识别方式。
摘要由CSDN通过智能技术生成

一、概述

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.

  1. In the Unity Editor, go to the player settings by navigating to "Edit > Project Settings > Player"
  2. Click on the "Windows Store" tab
  3. 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:

  1. Specify which phrases to listen for using a KeywordRecognizer or GrammarRecognizer
  2. Handle the OnPhraseRecognized event and take action corresponding to the phrase recognized

使用短语识别嘞~需要做两个步骤:

  1. 指定需要监听的 短语 或者 关键词
  2. 处理识别到 短语 或者 关键词 之后的事件回调 ~ 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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值