如何在 SpeechRecognizer 中实现像 "Hey Cortana" 这样的激活短语?
How to implement activation phrase like "Hey Cortana" in SpeechRecognizer?
在 Universal Windows 演示应用程序 (link) 的 SpeechAndTTS 示例中,即使是连续的听写示例也需要用户单击一个按钮才能启动识别器。
所以我的问题是我们如何实现一个始终监听的 SpeechRecognizer?当听到类似 "Hey Cortana" 或 "Okay Google" 的声音时激活。
我能想到的最接近的是
- 在 speechRecoginzer 上放置一个
SpeechRecognitionListConstraint
,它只听 "wake up word"(例如 "Hey Cortana")
- 在
ResultGenerated
事件处理程序中,检查 "Hey Cortana" 是否有 medium/high 的可信度。如果听不到"Hey Cortana",使用speechRecognizer.CompileConstraintsAsync()
强制识别器再次收听。
- 在
Completed
事件处理程序中,使用 speechRecognizer.CompileConstraintsAsync()
强制识别器再次侦听。
我检查的另一件事是 speechRecognizer
上的 Timeouts
。 https://msdn.microsoft.com/en-us/library/windows.media.speechrecognition.speechrecognizertimeouts.aspx
但看来我们不能无限 InitialSilenceTimeout
。
那么,有没有一种直接的方法可以让 speechRecognizer 在听到 "wake up phrase" 之前不会停止收听?
So my question is how can we implement an always listening SpeechRecognizer? Activated when hearing something like "Hey Cortana" or "Okay Google".
我们知道,当应用程序已经 运行 在前台时,我们无法将 Cortana 实现到我们的应用程序中,我们需要使用 SpeechRecognition. But we can done this job using .
even the continuous dictation examples requires the user to click on a button to start the recognizer.
是的,但这是因为await speechRecognizer.ContinuousRecognitionSession.StartAsync()
是在按钮点击事件中,session在这个事件中开始工作。要使其在没有按钮单击事件的情况下启动,您可以在 Page 的 OnNavigateTo
方法中启动此会话,并在 OnNavigateFrom
方法中停止此会话。当然,您可以在听到 "wake up phrase" 时停止此会话。
我同意你的想法,你可以强制它在 Completed
事件中监听,但我更喜欢在 SpeechContinuousRecognitionSession.Completed | completed event 中像这样使用 speechRecognizer.ContinuousRecognitionSession.StartAsync()
:
if (args.Status != SpeechRecognitionResultStatus.Success)
{
if (args.Status == SpeechRecognitionResultStatus.TimeoutExceeded)
{
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
// Show the state on UI
});
await speechRecognizer.ContinuousRecognitionSession.StartAsync();
}
...
}
而对于时间限制,我刚刚测试过,默认情况下Continuous dictation
会持续大约5秒没有声音,然后进入超时状态。而且我还测试了这样设置时间:
speechRecognizer.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(10.0);
它在我身边起作用。
其实你的场景,可以参考一个官方视频:Cortana and Speech Platform In Depth。在此视频的示例中,它听了两个句子:"take a note" 和 "save trip"。
在 Universal Windows 演示应用程序 (link) 的 SpeechAndTTS 示例中,即使是连续的听写示例也需要用户单击一个按钮才能启动识别器。
所以我的问题是我们如何实现一个始终监听的 SpeechRecognizer?当听到类似 "Hey Cortana" 或 "Okay Google" 的声音时激活。
我能想到的最接近的是
- 在 speechRecoginzer 上放置一个
SpeechRecognitionListConstraint
,它只听 "wake up word"(例如 "Hey Cortana") - 在
ResultGenerated
事件处理程序中,检查 "Hey Cortana" 是否有 medium/high 的可信度。如果听不到"Hey Cortana",使用speechRecognizer.CompileConstraintsAsync()
强制识别器再次收听。 - 在
Completed
事件处理程序中,使用speechRecognizer.CompileConstraintsAsync()
强制识别器再次侦听。
我检查的另一件事是 speechRecognizer
上的 Timeouts
。 https://msdn.microsoft.com/en-us/library/windows.media.speechrecognition.speechrecognizertimeouts.aspx
但看来我们不能无限 InitialSilenceTimeout
。
那么,有没有一种直接的方法可以让 speechRecognizer 在听到 "wake up phrase" 之前不会停止收听?
So my question is how can we implement an always listening SpeechRecognizer? Activated when hearing something like "Hey Cortana" or "Okay Google".
我们知道,当应用程序已经 运行 在前台时,我们无法将 Cortana 实现到我们的应用程序中,我们需要使用 SpeechRecognition. But we can done this job using
even the continuous dictation examples requires the user to click on a button to start the recognizer.
是的,但这是因为await speechRecognizer.ContinuousRecognitionSession.StartAsync()
是在按钮点击事件中,session在这个事件中开始工作。要使其在没有按钮单击事件的情况下启动,您可以在 Page 的 OnNavigateTo
方法中启动此会话,并在 OnNavigateFrom
方法中停止此会话。当然,您可以在听到 "wake up phrase" 时停止此会话。
我同意你的想法,你可以强制它在 Completed
事件中监听,但我更喜欢在 SpeechContinuousRecognitionSession.Completed | completed event 中像这样使用 speechRecognizer.ContinuousRecognitionSession.StartAsync()
:
if (args.Status != SpeechRecognitionResultStatus.Success)
{
if (args.Status == SpeechRecognitionResultStatus.TimeoutExceeded)
{
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
// Show the state on UI
});
await speechRecognizer.ContinuousRecognitionSession.StartAsync();
}
...
}
而对于时间限制,我刚刚测试过,默认情况下Continuous dictation
会持续大约5秒没有声音,然后进入超时状态。而且我还测试了这样设置时间:
speechRecognizer.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(10.0);
它在我身边起作用。
其实你的场景,可以参考一个官方视频:Cortana and Speech Platform In Depth。在此视频的示例中,它听了两个句子:"take a note" 和 "save trip"。