我正在尝试不断地听取IoT设备上的特定关键字,例如“Alexa”。当触发时,我想进一步识别要执行的命令。
目前我正在使用一个无限循环,因为物联网有2GB的内存并且因此滞后很多,所以效率似乎不高。虽然这个解决方案似乎适用于x64环境。
private async void SetupTheContinuousSpeechRecognitionForAlexa()
{
try
{
speechRecognizerAlexa = new SpeechRecognizer();
speechRecognizerAlexa.Timeouts.BabbleTimeout = TimeSpan.FromSeconds(0);
speechRecognizerAlexa.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(0);
speechRecognizerAlexa.Timeouts.EndSilenceTimeout = TimeSpan.FromSeconds(0);
speechRecognizerAlexa.Constraints.Add(new SpeechRecognitionListConstraint(new string[] { "alexa", "tiger" }));
await speechRecognizerAlexa.CompileConstraintsAsync();
while (true)
{
try
{
var speechResult = await speechRecognizerAlexa.RecognizeAsync();
if (speechResult.Confidence == SpeechRecognitionConfidence.High || speechResult.Confidence == SpeechRecognitionConfidence.Medium || speechResult.Confidence == SpeechRecognitionConfidence.Low)
{
IsAlexaVoiceTriggered = true;
var helloResult = PlayTheString("How can I help you", false);
OnSpeechRecognitionCommandClicked();
}
else if (isSpeechEnabled)
{
IsAlexaVoiceTriggered = false;
}
}
catch
{
}
}
}
catch (Exception ex)
{
this.log.Error("Failed in SetupTheContinousSpeechRecognitionForAlexa " + ex.Message);
}
}
有没有其他人试图在物联网环境中实现这一目标,如果是这样,我该如何进一步优化呢?
谢谢。