简体   繁体   中英

Listen for Voice Commands within WP8 App?

I currently have a Windows Phone 8 app that has several voice commands defined in a VCD file. This works great for when users want to ask a question when the app is not in the foreground.

However, is there a way to initiate a "listening" box that listens for the same voice commands, when the app is in the foreground? So the user doesn't have to hold start, say app name, then command - just tap mic, command.

Something like this:

private void microphone_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    // listen for command
        // answer command question
}

I saw that you can implement speech recognition, but is there a way to do voice commands?

using Windows.Phone.Speech.VoiceCommands;
// ...

// Standard boilerplate method in the App class in App.xaml.cs
private async void Application_Launching(object sender, LaunchingEventArgs e)
{
    try // try block recommended to detect compilation errors in VCD file
    {
        await VoiceCommandService.InstallCommandSetsFromFileAsync(new Uri("ms-appx:///YourVCDFile.xml"));
    }
    catch (Exception ex)
    {
        // Handle exception
    }
}

The above snippet comes from Speech-Enabling a Windows Phone 8 App with Voice Commands from MSDN http://msdn.microsoft.com/en-us/magazine/jj721592.aspx

Read the article and I think you should be in a fairly OK state.

** ADDENDUM **

There is a part 2 of the article at http://msdn.microsoft.com/en-us/magazine/jj863134.aspx and you have details on how to present a in app UI and make use of it here http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206963(v=vs.105).aspx

To show a UI inside your application you would make use of SpeechRecognizerUI.RecognizeWithUIAsync(...) as demonstrated by the second URI above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM