Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a PhraseList that includes every word (wildcard)?

I'm trying to create a Windows Phone 8 application that includes a voice command. The voice command goes something along the lines of "What are the top songs by [artist]", and so I need to use some kind of wildcard for "[artist]" that will allow the user to say any artist. How might I do this without listing out every artist in the world in a PhraseList?

like image 683
MatthewSot Avatar asked Nov 10 '12 05:11

MatthewSot


2 Answers

This is definately possible.

SHORT ANSWER This is possible in Windows Phone 8.1 with so called PhraseTopics.

LONG VERSION

At first you need to declare the ID_CAP_SPEECH_RECOGNITION and ID_CAP_MICROPHONE requirements.

Afterwards you create a VCD (Voice Command Description) File. This File is basically a XML File that "tells" the Phone what to listen for. (Note A ListenFor element can include an asterisk character inside a pair of curly braces to implement wildcard functionality. For more information, see Voice command element and attribute reference (Windows Phone Store apps).) (taken from MSDN) In your case this file would for example look like this:

 <?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
  <CommandSet xml:lang="en-us" Name="SuperMusicFinder">
    <!-- Command set for all US English commands-->
    <CommandPrefix>SuperMusicFinder</CommandPrefix>
    <Example>Find Top 10 from Europe</Example>

    <Command Name="findCharts">
      <Example>Find Europe Top 40</Example>
      <ListenFor>Find [Europe Top40] {chartlist}</ListenFor>
      <ListenFor>Get [US Top100] charts {chartlist}</ListenFor>
      <Feedback>Looking up the charts for you-...</Feedback>
      <Navigate />
      <!-- Navigation defaults to Main page -->
    </Command>

    <Command Name="topSongs">
      <Example>Show top songs by Pharrell Williams</Example>
      <ListenFor>Show [number] {num} songs by [Pink]{artist} </ListenFor>
      <ListenFor>Give me [number] {num} songs by [Beethoven]{artist}</ListenFor>
      <ListenFor>Show [top songs] by [Pharell Williams]</ListenFor>
      <Feedback>Okay, I got that. I will look up the songs you want!</Feedback>
      <Navigate Target="/artistSong.xaml"/>
    </Command>

    <PhraseList Label="num">
      <Item> 1 </Item>
      <Item> 2 </Item>
      <Item> 3 </Item>
    </PhraseList>

    <PhraseTopic label="chartlist" Scenario="Chartlisting" />
    <PhraseTopic label="artist" Scenario="Artist" />

  </CommandSet>
</VoiceCommands>

Then you need to initalize your VCD in the App.xaml.cs file:

using Windows.Phone.Speech.VoiceCommands;


private async void Application_Launching(object sender, 
  LaunchingEventArgs e)
{
  try 
  {
    await VoiceCommandService.InstallCommandSetsFromFileAsync(
      new Uri("ms-appx:///SuperMusicFinderVCD.xml"));
  }
  catch (Exception ex)
  {
    // Handle exception
  }
}

To handle the Voice Command simply do the following: If you say for example: "SuperMusicFinder show top songs by Pharell Williams" the query for this request would look similar to something like this: "/artistSong.xaml?voiceCommandName=topSongs&by=Pharell%20Williams&reco=show%20top%20songs%Pharell%20Williams"

private void artistSong_Loaded(object sender, RoutedEventArgs e)
{
  if (this.NavigationContext.QueryString != null
    && this.NavigationContext.QueryString.ContainsKey("voiceCommandName"))
  {
    // Page was launched by Voice Command
    string commandName =
      NavigationContext.QueryString["voiceCommandName"];
    string spokenNumber = "";
    if (commandName == "topSongs" &&
      this.NavigationContext.QueryString.TryGetValue("by", 
        out artist))
    {
     //do whatever you want to do
      }
    }
  }
}

You can find more information here - Note: All Code snippets were taken from that sample and edited to fit this question, not 100% sure if this works, you can get a sample code that works with "advanced" commands on 8.1 or simple commands on 8.0 from here

like image 186
Daniel Steiner Avatar answered Sep 19 '22 12:09

Daniel Steiner


No, WP8 Voice commands do not support Wildcards in the phrase list. Problem is, WP8 won't be able to perform local speech recognition on audio without a fixed phrase list. For wildcard phrases WP8 would have to perform speech-to-text in the cloud every time the user used WP8's voice commands and that's not a good UX.

Right now the maximum number of phrases that could be supported in voice commands is 2,000 phrases. That's across all commands for one single app. And that limit is in place to make disambiguation easier and provide the consumers with more accurate results. Overall, it's best to use as few phrases as possible to make disambiguation more accurate.

There's a recommanded workaround for a justified usecase that needs wildcard phrases in voice commands. Step one, have a "*" voice command that launches the app for the correct syntax. Once the app is open, use speech-to-text in the app (using SpeechRecognizer) by having the user repeat their specific command and that'll trigger speech-to-text in the cloud.

like image 41
JustinAngel Avatar answered Sep 17 '22 12:09

JustinAngel