using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Windows.Speech;
using System;
using System.Text;
public class DictionManager : MonoBehaviour
{
public static DictionManager Ins;
[Tooltip("A text area for the recognizer to display the recognized strings.")]
//public Text DictationDisplay;
private DictationRecognizer dictationRecognizer;
public InputField Inp;
private void Awake()
{
Ins = this;
}
void OnEnable()
{
//短语识别系统关闭
PhraseRecognitionSystem.Shutdown();
dictationRecognizer = new DictationRecognizer();
//订阅事件
dictationRecognizer.DictationHypothesis += DictationRecognizer_DictationHypothesis;
dictationRecognizer.DictationResult += DictationRecognizer_DictationResult;
dictationRecognizer.DictationComplete += DictationRecognizer_DictationComplete;
dictationRecognizer.DictationError += DictationRecognizer_DictationError;
dictationRecognizer.Start();
}
private void DictationRecognizer_DictationError(string error, int hresult)
{
//DictationDisplay.text = "error";
}
private void DictationRecognizer_DictationComplete(DictationCompletionCause cause)
{
//DictationDisplay.text = "complete:";
//如果在听写开始后第一个5秒内没听到任何声音,将会超时
//如果识别到了一个结果但是之后20秒没听到任何声音,也会超时
if (cause == DictationCompletionCause.TimeoutExceeded)
{
//超时后本例重新启动听写识别器
//DictationDisplay.text += "Dictation has timed out.";
dictationRecognizer.Stop();
//DictationDisplay.text += "Dictation restart.";
dictationRecognizer.Start();
}
}
private void DictationRecognizer_DictationResult(string text, ConfidenceLevel confidence)
{
//DictationDisplay.text = "result:";
//DictationDisplay.text += text;
Inp.text += text;
}
private void DictationRecognizer_DictationHypothesis(string text)
{
//DictationDisplay.text = "Hypothesis:";
//DictationDisplay.text += text;
}
void OnDisable()
{
dictationRecognizer.Stop();
dictationRecognizer.DictationHypothesis -= DictationRecognizer_DictationHypothesis;
dictationRecognizer.DictationResult -= DictationRecognizer_DictationResult;
dictationRecognizer.DictationComplete -= DictationRecognizer_DictationComplete;
dictationRecognizer.DictationError -= DictationRecognizer_DictationError;
dictationRecognizer.Dispose();
//短语识别系统开启
PhraseRecognitionSystem.Restart();
}
}
Hololens2语音听写输入
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 语音输入是HoloLens三大基本输入方式之一。Unity上有三种形式在应用上添加语音输入,分别是: 1.使用Ke...
- 首先要尽量避免使用同音字。比如使、所以的以高兴的兴,分析的析等,这些字的同音字特别多,要找半天,语音输入辨析能力有...
- 前言:小白第一次接入科大讯飞语音听写,接入还是比较简单的,先看效果图无UI界面 Demo地址拿去 效果图有两部分,...
- IM即时通讯聊天输入框,包括自增长输入框,插入图片,输入语音等模块,可自我拓展表情等其他模块 gitHub地址:h...