用于捕捉照片的语音命令

时间:2015-07-05 13:04:10

标签: c# windows-phone-8.1

我在Windows Phone 8.1应用中使用Windows.Media.Capture.MediaCapture来捕获照片。我想通过语音命令(例如,如果用户说'奶酪')触发照片捕获过程,而不是按钮。如何检测这样的语音命令?

1 个答案:

答案 0 :(得分:1)

您可以使用SpeechRecognizer class

以下是来自MSDN的示例:

private async void StartRecognizing_Click(object sender, RoutedEventArgs e)
{
    // Create an instance of SpeechRecognizer.
    var speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer();

    // Compile the dictation grammar by default.
    await speechRecognizer.CompileConstraintsAsync();

    // Start recognition.
    Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync();

    // Do something with the recognition result.
    var messageDialog = new Windows.UI.Popups.MessageDialog(speechRecognitionResult.Text, "Text spoken");
    await messageDialog.ShowAsync();
}