我正在尝试激活台式机(Windows 10)上的麦克风以实现一些语音识别代码。这是我开箱即用的简单UWP应用程序:
致电ContinuousRecognitionSession.StartAsync()
投掷:
ex = {System.UnauthorizedAccessException: Access is denied.
public MainPage()
{
this.InitializeComponent();
initializeSpeechRecognizer();
}
// Initialize Speech Recognizer and start async recognition
private async void initializeSpeechRecognizer()
{
// Initialize recognizer
mRecognizer = new SpeechRecognizer();
// Load Grammer file constraint
string fileName = String.Format(SRGS_FILE);
var path = Package.Current.InstalledLocation;
StorageFile grammarContentFile = await path.GetFileAsync(fileName);
SpeechRecognitionGrammarFileConstraint grammarConstraint = new SpeechRecognitionGrammarFileConstraint(grammarContentFile);
// Add to grammer constraint
mRecognizer.Constraints.Add(grammarConstraint);
// Compile grammer
SpeechRecognitionCompilationResult compilationResult = await mRecognizer.CompileConstraintsAsync();
Debug.WriteLine("Status: " + compilationResult.Status.ToString());
Debug.WriteLine("Result: " + compilationResult.ToString());
}
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
try
{
await mRecognizer.ContinuousRecognitionSession.StartAsync();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
我已将Microphone
添加到Manifest功能中。
我桌面上的麦克风处于活动状态且正常工作。
我目前的语言是en-US,它列在SupportedTopicLanguages中
和SupportedGrammarLanguages属性。
Visual Studio 2017以管理员模式运行。