基于Unity3D的语音转文字功能的实现

Unity文字转语音功能的实现(注意:只适应于Windows10操作系统,需打开win10 Cortana 语音功能)

代码如下:详情请看Unity官网https://docs.unity3d.com/ScriptReference/Windows.Speech.KeywordRecognizer.html

(包含关键字识别,语法识别和听写识别)

using System.Collections;  
using System.Collections.Generic;  
using UnityEngine;  
using UnityEngine.Windows.Speech; 

public class AddSpeechTestNoneless : MonoBehaviour {  
	public string[] keyWords = new string[]{"确认","开始","返回","暂停"};  
	public ConfidenceLevel confidenLevel = ConfidenceLevel.Medium;  
	PhraseRecognizer recognizer;  
	void Start () {  
		recognizer = new KeywordRecognizer (keyWords, confidenLevel);  
		recognizer.OnPhraseRecognized += Display;  // 注册事件  
		recognizer.Start ();  
	}  

	public void Display(PhraseRecognizedEventArgs args){  
		string str = args.text;  
		Debug.Log (str.ToString ());  
	}  
}  

你可能感兴趣的:(Unity3D)