在我的UWP應用程序中,默認的聽寫語法不能識別語音。但是,當我使用編程列表約束時,它是完全可以識別的。下面是我的代碼的語音識別部分供參考。如果我不評論第五行,這工作正常。我在做下面的錯誤:在我的UWP應用程序中,默認的聽寫語法不能識別語音。
speechRecognizer = new SpeechRecognizer();
bool PermissionGained = await CheckMicrophonePermission();
if (PermissionGained)
{
//speechRecognizer.Constraints.Add(new SpeechRecognitionListConstraint(Grammar.GrammarCommands.GrammarConstraintList));
await speechRecognizer.CompileConstraintsAsync();
//recognize speech input at any point of time
speechRecognizer.ContinuousRecognitionSession.ResultGenerated +=
async (s, e1) =>
{
if ((e1.Result != null))
{
await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
async() =>
{
await ParsespeechCommand(e1.Result);
});
speechRecognizer.ContinuousRecognitionSession.Resume();
}
};
await speechRecognizer.ContinuousRecognitionSession.StartAsync(SpeechContinuousRecognitionMode.PauseOnRecognition);
}
我從你的代碼做了一個演示(用列表代替Grammar.GrammarCommands.GrammarConstraintList),一切正常。你可以設置斷點並檢查Grammar.GrammarCommands.GrammarConstraintList是否正確得到你的應用程序? –
對不起,我無法正確解釋我的問題。這段代碼與列表約束完美匹配,因爲您也經歷過,但我不想使用列表約束,我想使用默認的聽寫語法,以便識別任何自由的語音。所以,在上面的代碼中,我不想使用評論的第5行,這意味着使用默認的聽寫語法。我清楚了嗎? –
我明白了。只是嘗試不使用約束。我不是以英語爲母語的人。有時它也不認識。但大部分時間都可以工作。同樣使用默認的聽寫語法並不意味着完全可以識別自由語音。請參閱[預定義語法](https://msdn.microsoft.com/en-us/windows/uwp/input-and-devices/speech-interactions#Constraints)。 –