运行我的代码时出现此错误: 抛出异常:mscorlib.ni.dll中的'System.UnauthorizedAccessException' WinRT信息:访问被拒绝
到达此行时会抛出异常: await recog.ContinuousRecognitionSession.StartAsync();
namespace yesorno
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void button_Click(object sender, RoutedEventArgs e)
{
Language newlanguage = new Language("en-US");
SpeechRecognizer recog = new SpeechRecognizer(newlanguage);
StorageFile mygr = await Package.Current.InstalledLocation.GetFileAsync(@"Grammar\Commands.xml");
SpeechRecognitionGrammarFileConstraint gc = new SpeechRecognitionGrammarFileConstraint(mygr);
recog.Constraints.Add(gc);
SpeechRecognitionCompilationResult cr = await recog.CompileConstraintsAsync();
Debug.Write(cr.Status);
if (cr.Status==SpeechRecognitionResultStatus.Success)
{
await recog.ContinuousRecognitionSession.StartAsync();
}
else
{
}
}
private void recog_result(SpeechContinuousRecognitionSession sender,SpeechContinuousRecognitionResultGeneratedEventArgs args)
{
switch (args.Result.Text)
{
case "yes":
Debug.Write("yes");
break;
case "no":
Debug.Write("no");
break;
}
}
}
}
任何帮助将不胜感激。感谢。
在Windows 10和Win10 ioT上尝试过它