如果使用SRGS XML文件定义要侦听的特定语法,则使用语法识别器。关于SRGS XML文件格式的详细信息可以在MSDN网站上找到。

一旦您有了SRGS XML语法,就将它放到项目的流文件夹中。实现了与关键字识别相同的语法识别。
Step 1: 加载 SRGS Grammar
Step 2: 处理OnPhraseRecognized事件.
Step 3: 开始Grammar recognizer

using UnityEngine;
using UnityEngine.Windows.Speech;
using System;

public class GrammerRecognizerBehaviour : MonoBehaviour {

GrammarRecognizer grammerRecognizer;

// Use this for initialization
void Start () {
	// pass path of your grammar XML in the constructor
	grammerRecognizer = new GrammarRecognizer ("Grammer path from streaming asset folder");
	grammerRecognizer.OnPhraseRecognized += OnGrammerRecognized;
	grammerRecognizer.Start ();
}

void OnGrammerRecognized(PhraseRecognizedEventArgs args)
{
	// write your own logic
}

}

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐