Users can register and listen for hypothesis and phrase completed events. Start() and Stop() methods respectively enable and disable dictation recognition. Once done with the recognizer, it must be disposed using Dispose() method to release the resources it uses. It will release these resources automatically during garbage collection at an additional performance cost if they are not released prior to that.
#pragma strict
public class DictationScript extends MonoBehaviour {
@SerializeField
private var m_Hypotheses: Text;
@SerializeField
private var m_Recognitions: Text;
private var m_DictationRecognizer: DictationRecognizer;
function Start() {
m_DictationRecognizer = new DictationRecognizer();
m_DictationRecognizer.DictationResult += function(text, confidence) {
Debug.LogFormat("Dictation result: {0}", text);
m_Recognitions.text += text + "\n";
};
m_DictationRecognizer.DictationHypothesis += function(text) {
Debug.LogFormat("Dictation hypothesis: {0}", text);
m_Hypotheses.text += text + Env;
};
m_DictationRecognizer.DictationComplete += function(completionCause) {
if (cause != DictationCompletionCause.Complete)
Debug.LogErrorFormat("Dictation completed unsuccessfully: {0}.", cause);
};
m_DictationRecognizer.DictationError += function(error, hresult) {
Debug.LogErrorFormat("Dictation error: {0}; HResult = {1}.", error, hresult);
};
m_DictationRecognizer.Start();
}
}
public class DictationScript : MonoBehaviour
{
[SerializeField]
private Text m_Hypotheses;
[SerializeField]
private Text m_Recognitions;
private DictationRecognizer m_DictationRecognizer;
void Start()
{
m_DictationRecognizer = new DictationRecognizer();
m_DictationRecognizer.DictationResult += (text, confidence) =>
{
Debug.LogFormat("Dictation result: {0}", text);
m_Recognitions.text += text + "\n";
};
m_DictationRecognizer.DictationHypothesis += (text) =>
{
Debug.LogFormat("Dictation hypothesis: {0}", text);
m_Hypotheses.text += text + Env;
};
m_DictationRecognizer.DictationComplete += (completionCause) =>
{
if (cause != DictationCompletionCause.Complete)
Debug.LogErrorFormat("Dictation completed unsuccessfully: {0}.", cause);
};
m_DictationRecognizer.DictationError += (error, hresult) =>
{
Debug.LogErrorFormat("Dictation error: {0}; HResult = {1}.", error, hresult);
};
m_DictationRecognizer.Start();
}
}