The LexiconRuntime provides a few useful events that you can subscribe to:
OnSpeechStatusUpdated | Called when the speech to text status changes (e.g. silence vs sending) |
OnSpeechToTextResults | Called whenever speech to text results are updated, including intermediary results |
OnKeywordDetected | Called whenever speech to text recognizes a keyword |
OnLexiconResults | Called when Lexicon has finished processing all the results for an utterance |
To subscribe to these events, create an instance of the appropriate delegate and assign it to the event:
using System.Collections.Generic;
using UnityEngine;
using Mixspace.Lexicon;
public class LexiconRuntimeEvents : MonoBehaviour
{
void OnEnable()
{
LexiconRuntime.OnSpeechStatusUpdated += OnSpeechStatusUpdated;
LexiconRuntime.OnSpeechToTextResults += OnSpeechToTextResults;
LexiconRuntime.OnKeywordDetected += OnKeywordDetected;
LexiconRuntime.OnLexiconResults += OnLexiconResults;
}
void OnDisable()
{
LexiconRuntime.OnSpeechStatusUpdated -= OnSpeechStatusUpdated;
LexiconRuntime.OnSpeechToTextResults -= OnSpeechToTextResults;
LexiconRuntime.OnKeywordDetected -= OnKeywordDetected;
LexiconRuntime.OnLexiconResults -= OnLexiconResults;
}
void OnSpeechStatusUpdated(LexiconSpeechStatus status)
{
Debug.Log("Speech Status: " + status);
}
void OnSpeechToTextResults(LexiconSpeechResult speechResult)
{
if (speechResult.IsFinal)
{
Debug.Log("Speech Transcript: " + speechResult.Transcript);
}
}
void OnKeywordDetected(LexiconSpeechResult.KeywordResult keywordResult)
{
Debug.Log("Found Keyword: " + keywordResult.Keyword);
}
void OnLexiconResults(List<LexiconRuntimeResult> results)
{
foreach (LexiconRuntimeResult result in results)
{
Debug.Log("Matched Intent: " + result.Intent.ActionName + ", confidence: " + result.Confidence);
}
}
}