Windows Cortana 总是从应用程序内部监听

Windows Cortana always listen from inside app

windows cortana 的新更新具有始终监听模式,类似于 Google 的 "OK Google" 命令,允许用户在 phone 待命。这是 "hey Cortana".

以同样的方式启动我的应用程序时,我希望有一个始终监听模式,它只能监听特定的单词集(就像 "hey Cortana"),并相应地响应它.

您可以使用 ContinuousRecognitionSession 实现连续听写 Windows 10.

private SpeechRecognizer speechRecognizer;
private CoreDispatcher dispatcher;
private StringBuilder dictatedTextBuilder;

this.dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
this.speechRecognizer = new SpeechRecognizer();
SpeechRecognitionCompilationResult result =

await speechRecognizer.CompileConstraintsAsync();
speechRecognizer.ContinuousRecognitionSession.ResultGenerated +=
ContinuousRecognitionSession_ResultGenerated;

private async void ContinuousRecognitionSession_ResultGenerated(
SpeechContinuousRecognitionSession sender,
SpeechContinuousRecognitionResultGeneratedEventArgs args)
{

if (args.Result.Confidence == SpeechRecognitionConfidence.Medium ||
  args.Result.Confidence == SpeechRecognitionConfidence.High)
  {
    dictatedTextBuilder.Append(args.Result.Text + " ");

    await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
      dictationTextBox.Text = dictatedTextBuilder.ToString();
      btnClearText.IsEnabled = true;
    });
  }
else
{
  await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
      dictationTextBox.Text = dictatedTextBuilder.ToString();
    });
}
}

这里是完整的example