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

来源:互联网 发布:淘宝自动回复内容 编辑:程序博客网 时间:2024/04/29 13:44

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 ());  }  }  

阅读全文
1 0
原创粉丝点击