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

时间:2015-03-25 15:20:58

标签: windows-phone-8 cortana

Windows cortana的新更新,总是采用倾听模式,类似于Google" OK Google"命令,即使手机处于待机状态,也允许用户激活Cortana。它是"嘿Cortana"。

以同样的方式启动我的应用程序时,我希望有一个始终听的模式,它只能听取特定的一组单词(就像#34;嘿Cortana"),然后回复它因此。

1 个答案:

答案 0 :(得分:2)

您可以使用ContinuousRecognitionSession for 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