C# Cortana语音激活以编程方式

C# Cortana voice activation programmatically
2020-11-21
  •  译文(汉语)
  •  原文(英语)

我正在尝试以编程方式调用Cortana.

我已经在使用此代码启动Cortana

await Launcher.LaunchUriAsync(new Uri("bing://home"));

问题是,要进行搜索,您必须单击Cortana中的麦克风按钮.

我想要的是,当Cortana启动时,不应该提示用户按mic按钮进行搜索.正如在Cortana中,无论何时我想或至少在它打开时都开始收听.

这可能吗?如果是这样,那又如何?

解决过程1

由于应用开发人员可以随意开始记录用户的发言内容引起的隐私问题,因此这种情况极不可能发生.

解决过程2

您是否尝试过在Windows 10上使用ContinuousRecognitionSession

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();
    });
}
}

这是完整的例子

也考虑在前景上使用Cortana集成您的应用程序.在这里看看

速聊1:
是的,我知道语音识别器以及如何将Cortana集成到应用程序中.我的要求不同,我想通过蓝牙或其他应用程序调用Cortana.但是,除非按下扬声器按钮或更近,否则您永远不会开始自己听音乐,否则您会说"嗨,Cortana!"

I am trying to invoke Cortana programmatically.

I am already using this code to start Cortana

await Launcher.LaunchUriAsync(new Uri("bing://home"));

The problem is that in order to make a search you have to click the mic button in Cortana.

I want is that when Cortana starts the user should not be promted to press the mic button in order to make a search. As in Cortana starts listening whenever I want or at least when it opens up.

Is this possible? If so then how?

Solutions1

It's highly unlikely, due to the privacy concerns with an app developer being able to arbitrarily start recording what the user is saying.

Solutions2

Have you tried using ContinuousRecognitionSession on 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();
    });
}
}

Here is the complete example

Considering integrate your app using Cortana on foreground too. Take a look here

Talk1:
Yes I am aware of the speechrecognizer and how to integrate Cortana in an app. My requirement was different, I wanted to invoke Cortana through bluetooth or through another app. But She never starts listening on it's own unless the speaker button is pushed or more recently, you say "Hey Cortana!"
转载于:https://stackoverflow.com/questions/28398098/c-sharp-cortana-voice-activation-programmatically

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入