HTML5 APPS ON WP8.1

download HTML5 APPS ON WP8.1

of 64

Transcript of HTML5 APPS ON WP8.1

  • 8/12/2019 HTML5 APPS ON WP8.1

    1/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    2/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    3/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    4/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    5/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    6/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    7/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    8/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    9/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    10/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    11/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application

    {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

  • 8/12/2019 HTML5 APPS ON WP8.1

    12/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application

    {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

    MSDN

    http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1
  • 8/12/2019 HTML5 APPS ON WP8.1

    13/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application

    {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

    How do I add Voice Commands to my applicat

    http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1
  • 8/12/2019 HTML5 APPS ON WP8.1

    14/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application

    {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application

    http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1
  • 8/12/2019 HTML5 APPS ON WP8.1

    15/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application

    {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

    Find Install Voice Command Sets

    http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1http://schemas.microsoft.com/voicecommands/1.1
  • 8/12/2019 HTML5 APPS ON WP8.1

    16/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

    SearchSearch for {dictatedSearchTerms}

  • 8/12/2019 HTML5 APPS ON WP8.1

    17/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

    Search on MSDN

    http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0
  • 8/12/2019 HTML5 APPS ON WP8.1

    18/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

    http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0
  • 8/12/2019 HTML5 APPS ON WP8.1

    19/64

    MSDN How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

  • 8/12/2019 HTML5 APPS ON WP8.1

    20/64

    MSDN

    Find Voice Commands

    Find Windows Phone Search Search {*} Search for {listSearchTerms} Find Find {*} Find {listSearchTerms} Search on MSDN

    Voice Commands Windows Phone

  • 8/12/2019 HTML5 APPS ON WP8.1

    21/64

    MSDNFind Voice Commands

    Find Windows PhoneSearchSearch {*}Search for {listSearchTerms}FindFind {*}Find {listSearchTerms}Search on MSDN

    Voice CommandsWindows Phone

  • 8/12/2019 HTML5 APPS ON WP8.1

    22/64

    MSDN

    How do I add Voice Commands to my application

    Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find {dictatedSearchTerms} Search on MSDN

    How do I add Voice Commands to my application {dictatedVoiceCommandText} Starting MSDN...

    MSDN

    MSDN

    http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0http://schemas.microsoft.com/voicecommands/1.0
  • 8/12/2019 HTML5 APPS ON WP8.1

    23/64

    private async void

    // SHOULD BE PERFORMED UNDER TRY/CATCH

    Uri new ms-appx:///vcd.xml UriKind.Absolute

    await

    Windows Phone Silverlight Apps on Windows Phone 8.1

    Windows Runtime Apps on Windows Phone 8.1private async void

    // SHOULD BE PERFORMED UNDER TRY/CATCH

    Uri uriVoiceCommands =newUri("ms-appx:///vcd.xml", UriKind.Absolute);

    StorageFile file =awaitStorageFile.GetFileFromApplicationUriAsync(uriVo

    awaitVoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file);

  • 8/12/2019 HTML5 APPS ON WP8.1

    24/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    25/64

    // Windows Phone Silverlight App, in MainPage.xaml.cs

    protectedoverridevoidOnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

    {

    base.OnNavigatedTo(e);

    if(e.NavigationMode ==System.Windows.Navigation.NavigationMode.New)

    {

    stringrecoText =null; // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"

    NavigationContext.QueryString.TryGetValue("reco", outrecoText);

    stringvoiceCommandName =null; // Which command was recognized in the VCD.XML file? e.g. "FindText"

    NavigationContext.QueryString.TryGetValue("voiceCommandName", outvoiceCommandName);

    stringsearchTerms =null;// What did the user say, for named phrase topic or list "slots"? e.g. "Wind

    NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", outsearchTerms);

    switch(voiceCommandName) // What command launched the app?

    {

    case"FindText":

    HandleFindText(searchTerms);

    break;

    case"nlpCommand":

    HandleNlpCommand(recoText);

    break;

    }

    }

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    26/64

    // Windows Phone Silverlight App, in MainPage.xaml.cs

    protectedoverridevoidOnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

    {

    base.OnNavigatedTo(e);

    if(e.NavigationMode ==System.Windows.Navigation.NavigationMode.New)

    {

    stringrecoText =null; // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"

    NavigationContext.QueryString.TryGetValue("reco", outrecoText);

    stringvoiceCommandName =null; // Which command was recognized in the VCD.XML file? e.g. "FindText"

    NavigationContext.QueryString.TryGetValue("voiceCommandName", outvoiceCommandName);

    stringsearchTerms =null;// What did the user say, for named phrase topic or list "slots"? e.g. "Wind

    NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", outsearchTerms);

    switch(voiceCommandName) // What command launched the app?

    {

    case"FindText":

    HandleFindText(searchTerms);

    break;

    case"nlpCommand":

    HandleNlpCommand(recoText);

    break;

    }

    }

    }

    // Windows Phone Silverlight App, in MainPage.xaml.cs

    protectedoverridevoidOnNavigatedTo(System.Windows.Navigation.Navig

  • 8/12/2019 HTML5 APPS ON WP8.1

    27/64

    // Windows Phone Silverlight App, in MainPage.xaml.cs

    protectedoverridevoidOnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

    {

    base.OnNavigatedTo(e);

    if(e.NavigationMode ==System.Windows.Navigation.NavigationMode.New)

    {

    stringrecoText =null; // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"

    NavigationContext.QueryString.TryGetValue("reco", outrecoText);

    stringvoiceCommandName =null; // Which command was recognized in the VCD.XML file? e.g. "FindText"

    NavigationContext.QueryString.TryGetValue("voiceCommandName", outvoiceCommandName);

    stringsearchTerms =null;// What did the user say, for named phrase topic or list "slots"? e.g. "Wind

    NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", outsearchTerms);

    switch(voiceCommandName) // What command launched the app?

    {

    case"FindText":

    HandleFindText(searchTerms);

    break;

    case"nlpCommand":

    HandleNlpCommand(recoText);

    break;

    }

    }

    }

    // What did the user say? e.g. MSDN, "Find Windows Phone Voice ComstringrecoText =null;NavigationContext.QueryString.TryGetValue("reco", outrecoText);

    // Which command was recognized in the VCD.XML file? e.g. "FindTex

    stringvoiceCommandName =null;NavigationContext.QueryString.TryGetValue("voiceCommandName", out

    // What did the user say, for named phrase topic or list "slots"? Phone Voice Commands"stringsearchTerms =null;NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", o

  • 8/12/2019 HTML5 APPS ON WP8.1

    28/64

    // Windows Phone Silverlight App, in MainPage.xaml.cs

    protectedoverridevoidOnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

    {

    base.OnNavigatedTo(e);

    if(e.NavigationMode ==System.Windows.Navigation.NavigationMode.New)

    {

    stringrecoText =null; // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"

    NavigationContext.QueryString.TryGetValue("reco", outrecoText);

    stringvoiceCommandName =null; // Which command was recognized in the VCD.XML file? e.g. "FindText"

    NavigationContext.QueryString.TryGetValue("voiceCommandName", outvoiceCommandName);

    stringsearchTerms =null;// What did the user say, for named phrase topic or list "slots"? e.g. "Wind

    NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", outsearchTerms);

    switch(voiceCommandName) // What command launched the app?

    {

    case"FindText":

    HandleFindText(searchTerms);

    break;

    case"nlpCommand":

    HandleNlpCommand(recoText);

    break;

    }

    }

    }

    switch(voiceCommandName) // What command launched the app{

    case"FindText":

    HandleFindText(searchTerms);break;

    case"nlpCommand":HandleNlpCommand(recoText);break;

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    29/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    30/64

    // Windows Runtime App on Windows Phone 8.1, inside OnActivated override in App

    if(args.Kind == ActivationKind.VoiceCommand)

    {VoiceCommandActivatedEventArgsvcArgs = (VoiceCommandActivatedEventArgs)arg

    stringvoiceCommandName = vcArgs.Result.RulePath.First(); // What command l

    switch(voiceCommandName) // Navigate to right page for the voice command

    {

    case"FindText": // User said "find" or "search"

    rootFrame.Navigate(typeof(MSDN.FindText), vcArgs.Result);

    break;

    case"nlpCommand": // User said something else

    rootFrame.Navigate(typeof(MSDN.NlpCommand), vcArgs.Result);

    break;

    }

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    31/64

    // Windows Runtime App on Windows Phone 8.1, inside OnActivated override in App

    if(args.Kind == ActivationKind.VoiceCommand)

    {VoiceCommandActivatedEventArgsvcArgs = (VoiceCommandActivatedEventArgs)arg

    stringvoiceCommandName = vcArgs.Result.RulePath.First(); // What command l

    switch(voiceCommandName) // Navigate to right page for the voice command

    {

    case"FindText": // User said "find" or "search"

    rootFrame.Navigate(typeof(MSDN.FindText), vcArgs.Result);

    break;

    case"nlpCommand": // User said something else

    rootFrame.Navigate(typeof(MSDN.NlpCommand), vcArgs.Result);

    break;

    }

    }

    // Windows Runtime App on Windows Phone 8.1, inside OnAct// in App class

    if(args.Kind == ActivationKind.VoiceCommand)

  • 8/12/2019 HTML5 APPS ON WP8.1

    32/64

    // Windows Runtime App on Windows Phone 8.1, inside OnActivated override in App

    if(args.Kind == ActivationKind.VoiceCommand)

    {VoiceCommandActivatedEventArgsvcArgs = (VoiceCommandActivatedEventArgs)arg

    stringvoiceCommandName = vcArgs.Result.RulePath.First(); // What command l

    switch(voiceCommandName) // Navigate to right page for the voice command

    {

    case"FindText": // User said "find" or "search"

    rootFrame.Navigate(typeof(MSDN.FindText), vcArgs.Result);

    break;

    case"nlpCommand": // User said something else

    rootFrame.Navigate(typeof(MSDN.NlpCommand), vcArgs.Result);

    break;

    }

    }

    VoiceCommandActivatedEventArgsvcArgs = (VoiceCommandActivatedEven

    // What command launched the app?

    stringvoiceCommandName = vcArgs.Result.RulePath.First();

    // Navigate to right page for the voice commandswitch(voiceCommandName)

  • 8/12/2019 HTML5 APPS ON WP8.1

    33/64

    // Windows Runtime App on Windows Phone 8.1, inside OnActivated override in App

    if(args.Kind == ActivationKind.VoiceCommand)

    { VoiceCommandActivatedEventArgsvcArgs = (VoiceCommandActivatedEventArgs)arg

    stringvoiceCommandName = vcArgs.Result.RulePath.First(); // What command l

    switch(voiceCommandName) // Navigate to right page for the voice command

    {

    case"FindText": // User said "find" or "search"

    rootFrame.Navigate(typeof(MSDN.FindText), vcArgs.Result);

    break;

    case"nlpCommand": // User said something else

    rootFrame.Navigate(typeof(MSDN.NlpCommand), vcArgs.Result);

    break;

    }

    }

    // Navigate to right page for the voice commandswitch(voiceCommandName){

    case"FindText": // User said "find" or "search"

    rootFrame.Navigate(typeof(MSDN.FindText), vcArgs.break;

    case"nlpCommand": // User said something elserootFrame.Navigate(typeof(MSDN.NlpCommand), vcArgbreak;

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    34/64

    // Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo in FindText.xaml.cs

    protectedoverridevoidOnNavigatedTo(NavigationEventArgse)

    {

    // Get recognition result from parameter passed in frame.Navigate call

    SpeechRecognitionResultvcResult = e.Parameter asSpeechRecognitionResult;

    if(vcResult!=null)

    {

    // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"

    stringrecoText = vcResult.Text;

    // Store the semantics dictionary for later use

    IReadOnlyDictionary semantics = vcResult.SemanticInterpretation

    stringvoiceCommandName = vcResult.RulePath.First();

    if(voiceCommandName == "FindText")

    {// What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voi

    if(semantics.ContainsKey("dictatedSearchTerms"))

    {

    HandleFindTextWithSearchTerms(semantics["dictatedSearchTerms"][0]);

    }

    else

    {

    HandleNoSearchTerms();

    }

    }

    // Else handle other voice commands

    } navigationHelper.OnNavigatedTo(e)

    // Windows Runtime App on Windows Phone 8 1 inside

  • 8/12/2019 HTML5 APPS ON WP8.1

    35/64

    // Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo In FindText.xaml.cs

    protectedoverridevoidOnNavigatedTo(NavigationEventArgse)

    {

    // Get recognition result from parameter passed in frame.Navigate call

    SpeechRecognitionResultvcResult = e.Parameter asSpeechRecognitionResult;

    if(vcResult!=null)

    {

    // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"

    stringrecoText = vcResult.Text;

    // Store the semantics dictionary for later use

    IReadOnlyDictionary semantics = vcResult.SemanticInterpretation

    stringvoiceCommandName = vcResult.RulePath.First();

    if(voiceCommandName == "FindText")

    {// What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voi

    if(semantics.ContainsKey("dictatedSearchTerms"))

    {

    HandleFindTextWithSearchTerms(semantics["dictatedSearchTerms"][0]);

    }

    else

    {

    HandleNoSearchTerms();

    }

    }

    // Else handle other voice commands

    } navigationHelper.OnNavigatedTo(e)

    // Windows Runtime App on Windows Phone 8.1, inside// OnNavigatedTo in FindText.xaml.csprotectedoverridevoidOnNavigatedTo(NavigationEventArgse){

    // Get recognition result from parameter passed in frame.NaviSpeechRecognitionResultvcResult = e.Parameter asSpeechRecog

    if(vcResult!=null){

    // What did the user say? e.g. MSDN, "Find Windows Phone stringrecoText = vcResult.Text;

    // Store the semantics dictionary for later useIReadOnlyDictionary semanti

    vcResult.SemanticInterpretation.Properties;

    stringvoiceCommandName = vcResult.RulePath.First();

  • 8/12/2019 HTML5 APPS ON WP8.1

    36/64

    // Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo In FindText.xaml.cs

    protectedoverridevoidOnNavigatedTo(NavigationEventArgse)

    {

    // Get recognition result from parameter passed in frame.Navigate call

    SpeechRecognitionResultvcResult = e.Parameter asSpeechRecognitionResult;

    if(vcResult!=null)

    {

    // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"

    stringrecoText = vcResult.Text;

    // Store the semantics dictionary for later use

    IReadOnlyDictionary semantics = vcResult.SemanticInterpretation

    stringvoiceCommandName = vcResult.RulePath.First();

    if(voiceCommandName == "FindText")

    {

    // What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voiif(semantics.ContainsKey("dictatedSearchTerms"))

    {

    HandleFindTextWithSearchTerms(semantics["dictatedSearchTerms"][0]);

    }

    else

    {

    HandleNoSearchTerms();

    }

    }

    // Else handle other voice commands

    } navigationHelper.OnNavigatedTo(e)

    }

    if(voiceCommandName == "FindText"){

    // What did the user say, for named phrase topic or list "slo// e.g. "Windows Phone Voice Commands"if(semantics.ContainsKey("dictatedSearchTerms")){

    HandleFindTextWithSearchTerms(semantics["dictatedSearchTe}else{

    HandleNoSearchTerms();}

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    37/64

    // Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo in NlpComman

    protectedoverridevoidOnNavigatedTo(NavigationEventArgse)

    {

    base.OnNavigatedTo(e);

    // Get recognition result from parameter passed in frame.Navigate call

    SpeechRecognitionResultvcResult = e.Parameter asSpeechRecognitionResult;

    // Check for null!

    stringcommandMode = vcResult.SemanticInterpretation.Properties["commandMo

    if(commandMode == "voice") // Did the user speak or type the command?

    {

    SpeakText(audioPlayer, String.Format("MSDN app heard you say {0}", vcRe

    HandleNlpCommand(vcResult);

    }

    elseif(commandMode=="text")

    {

    messageTextBox.Text = string.Format("Working on your request \"{0}\"",

    HandleNlpCommand(vcResult);

    }

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    38/64

    // Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo In NlpComman

    protectedoverridevoidOnNavigatedTo(NavigationEventArgse)

    {

    base.OnNavigatedTo(e);

    // Get recognition result from parameter passed in frame.Navigate call

    SpeechRecognitionResultvcResult = e.Parameter asSpeechRecognitionResult;

    // Check for null!

    stringcommandMode = vcResult.SemanticInterpretation.Properties["commandMo

    if(commandMode == "voice") // Did the user speak or type the command?

    {

    SpeakText(audioPlayer, String.Format("MSDN app heard you say {0}", vcRe

    HandleNlpCommand(vcResult);

    }

    elseif(commandMode=="text")

    {

    messageTextBox.Text = string.Format("Working on your request \"{0}\"",

    HandleNlpCommand(vcResult);

    }

    }

    // Windows Runtime App on Windows Phone 8.1, in OnNavigatedTo in NlpCo

    protectedoverridevoidOnNavigatedTo(NavigationEventArgse)

    {

    // Get recognition result from parameter passed in frame.Navigate

    SpeechRecognitionResultvcResult = e.Parameter asSpeechRecognitio

    stringcommandMode = vcResult.SemanticInterpretation.Properties["c

    stringcommandMode

    = vcResult.SemanticInterpretation.Properties["comman

  • 8/12/2019 HTML5 APPS ON WP8.1

    39/64

    // Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo In NlpComman

    protectedoverridevoidOnNavigatedTo(NavigationEventArgse)

    {

    base.OnNavigatedTo(e);

    // Get recognition result from parameter passed in frame.Navigate call

    SpeechRecognitionResultvcResult = e.Parameter asSpeechRecognitionResult;

    // Check for null!

    stringcommandMode = vcResult.SemanticInterpretation.Properties["commandMo

    if(commandMode == "voice")// Did the user speak or type the command?

    {

    SpeakText(audioPlayer, String.Format("MSDN app heard you say {0}", vcRe

    HandleNlpCommand(vcResult);

    }

    elseif(commandMode=="text")

    {

    messageTextBox.Text = string.Format("Working on your request \"{0}\"",

    HandleNlpCommand(vcResult);

    }

    }

    g p p [

    if(commandMode == "voice") // Did the user speak or type the command?

    {

    SpeakText(audioPlayer, String.Format("MSDN voice heard you say {0}"

    HandleNlpCommand(vcResult);

    }

    elseif(commandMode=="text"){

    msgTextBox.Text= string.Format("Working on your request \"{0}\"", v

    HandleNlpCommand(vcResult);

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    40/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    41/64

    privatevoidHandleNlpCommand(stringrecoText, boolactSilently)

    {

    stringaction = null;

    stringnavigateTo = null;

    stringsearchFor = null;

    recoText = recoText.ToLower();

    if(recoText.Contains("go to ") || recoText.Contains("goto ") ||

    recoText.Contains("find ") || recoText.Contains("search ") ||

    recoText.Contains("show me "))

    {

    action = "navigate";

    if(recoText.Contains("windows phone dev center"))

    {

    navigateTo = "http://dev.windowsphone.com" ;

    }

    }

    elseif(recoText.Contains("learn how to "))

    {action = "find";

    searchFor = recoText.Substring(recoText.IndexOf("learn how to ") + 13);

    }

    else

    {

    action = "find";

    searchFor = recoText;

    }

    switch(action)

    {

    case"find":

    // ...

  • 8/12/2019 HTML5 APPS ON WP8.1

    42/64

    privatevoidHandleNlpCommand(stringrecoText, boolactSilently)

    {

    stringaction = null;

    stringnavigateTo = null;

    stringsearchFor = null;

    recoText = recoText.ToLower();

    if(recoText.Contains("go to ") || recoText.Contains("goto ") ||

    recoText.Contains("find ") || recoText.Contains("search ") ||

    recoText.Contains("show me "))

    {

    action = "navigate";

    if(recoText.Contains("windows phone dev center"))

    {

    navigateTo = "http://dev.windowsphone.com" ;

    }

    }

    elseif(recoText.Contains("learn how to "))

    {action = "find";

    searchFor = recoText.Substring(recoText.IndexOf("learn how to ") + 13);

    }

    else

    {

    action = "find";

    searchFor = recoText;

    }

    switch(action)

    {

    case"find":

    // ...

    if(recoText.Contains("go to ") || recoText.Contains(recoText.Contains("find ") || recoText.Contains("recoText.Contains("show me "))

    {action = "navigate";if(recoText.Contains("windows phone dev center"){

    navigateTo = "http://dev.windowsphone.com";}

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    43/64

    privatevoidHandleNlpCommand(stringrecoText, boolactSilently)

    {

    stringaction = null;

    stringnavigateTo = null;

    stringsearchFor = null;

    recoText = recoText.ToLower();

    if(recoText.Contains("go to ") || recoText.Contains("goto ") ||

    recoText.Contains("find ") || recoText.Contains("search ") ||

    recoText.Contains("show me "))

    {

    action = "navigate";

    if(recoText.Contains("windows phone dev center"))

    {

    navigateTo = "http://dev.windowsphone.com" ;

    }

    }

    elseif(recoText.Contains("learn how to "))

    {action = "find";

    searchFor = recoText.Substring(recoText.IndexOf("learn how to ") + 13);

    }

    else

    {

    action = "find";

    searchFor = recoText;

    }

    switch(action)

    {

    case"find":

    // ...

    elseif(recoText.Contains("learn how to ")){

    action = "find";searchFor = recoText.Substring(recoText.IndexOf("learn h

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    44/64

    privatevoidHandleNlpCommand(stringrecoText, boolactSilently)

    {

    stringaction = null;

    stringnavigateTo = null;

    stringsearchFor = null;

    recoText = recoText.ToLower();

    if(recoText.Contains("go to ") || recoText.Contains("goto ") ||

    recoText.Contains("find ") || recoText.Contains("search ") ||

    recoText.Contains("show me "))

    {

    action = "navigate";

    if(recoText.Contains("windows phone dev center"))

    {

    navigateTo = "http://dev.windowsphone.com" ;

    }

    }

    elseif(recoText.Contains("learn how to "))

    {action = "find";

    searchFor = recoText.Substring(recoText.IndexOf("learn how to ") + 13);

    }

    else

    {

    action = "find";

    searchFor = recoText;

    }

    switch(action)

    {

    case"find":

    // ...

    else{

    action = "find";searchFor = recoText;

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    45/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    46/64

    // Windows Phone Silverlight App

    // Synthesis

    privateasyncvoidSpeakText(stringtextToSpeak)

    {

    SpeechSynthesizersynthesizer = newSpeechSynthesizer();

    awaitsynthesizer.SpeakTextAsync(textToSpeak);}

    // Recognition

    privateasyncTask RecognizeSpeech()

    {

    SpeechRecognizerUIrecognizer = newSpeechRecognizerUI();

    // One of three Grammar types available

    recognizer.Recognizer.Grammars.AddGrammarFromPredefinedType(

    "key1", SpeechPredefinedGrammar.WebSearch);

    awaitrecognizer.Recognizer.PreloadGrammarsAsync(); // Optional but recommended

    // Put up UI and recognize user's utterance

    SpeechRecognitionUIResultresult = awaitrecognizer.RecognizeWithUIAsync();

    returnresult;

    }

    // Calling code uses result.RecognitionResult.Text or result.RecognitionResult.Semantics

  • 8/12/2019 HTML5 APPS ON WP8.1

    47/64

    // Windows Phone Silverlight App

    // Synthesis

    privateasyncvoidSpeakText(stringtextToSpeak)

    {

    SpeechSynthesizersynthesizer = newSpeechSynthesizer();

    awaitsynthesizer.SpeakTextAsync(textToSpeak);}

    // Recognition

    privateasyncTask RecognizeSpeech()

    {

    SpeechRecognizerUIrecognizer = newSpeechRecognizerUI();

    // One of three Grammar types available

    recognizer.Recognizer.Grammars.AddGrammarFromPredefinedType(

    "key1", SpeechPredefinedGrammar.WebSearch);

    awaitrecognizer.Recognizer.PreloadGrammarsAsync(); // Optional but recommended

    // Put up UI and recognize user's utterance

    SpeechRecognitionUIResultresult = awaitrecognizer.RecognizeWithUIAsync();

    returnresult;

    }

    // Calling code uses result.RecognitionResult.Text or result.RecognitionResult.Semantics

    // SynthesisprivateasyncvoidSpeakText(stringtextToSpeak){

    SpeechSynthesizersynthesizer = newSpeechSynthawait synthesizer.SpeakTextAsync(textToSpeak);

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    48/64

    // Windows Phone Silverlight App// SynthesisprivateasyncvoidSpeakText(stringtextToSpeak){

    SpeechSynthesizersynthesizer = newSpeechSynthesizer();

    awaitsynthesizer.SpeakTextAsync(textToSpeak);}

    // RecognitionprivateasyncTask RecognizeSpeech(){

    SpeechRecognizerUIrecognizer = newSpeechRecognizerUI();

    // One of three Grammar types availablerecognizer.Recognizer.Grammars.AddGrammarFromPredefinedType(

    "key1", SpeechPredefinedGrammar.WebSearch);

    awaitrecognizer.Recognizer.PreloadGrammarsAsync(); // Optional but recomme

    // Put up UI and recognize user's utteranceSpeechRecognitionUIResultresult = awaitrecognizer.RecognizeWithUIAsync()

    returnresult;}// Calling code uses result.RecognitionResult.Text or result.RecognitionResult

    // RecognitionprivateasyncTask RecognizeSp{

    SpeechRecognizerUIrecognizer = newSpeechRecognizerUI

    // One of three Grammar types availablerecognizer.Recognizer.Grammars.AddGrammarFromPredefine

    "key1", SpeechPredefinedGrammar.WebSearch);

    // Optional but recommendedawait recognizer.Recognizer.PreloadGrammarsAsync();

  • 8/12/2019 HTML5 APPS ON WP8.1

    49/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    50/64

    // Windows Phone Store App

    // Synthesis

    // C# code behind

    // Function to speak a text string

    privateasyncvoidSpeakText(MediaElementaudioPlayer, stringtextToSpeak)

    {

    SpeechSynthesizersynthesizer = newSpeechSynthesizer();

    SpeechSynthesisStreamttsStream = awaitsynthesizer.SynthesizeTextToStreamA

    audioPlayer.SetSource(ttsStream, ""); // This starts the player because Aut}

  • 8/12/2019 HTML5 APPS ON WP8.1

    51/64

    // Windows Phone Store App

    // Synthesis

    // C# code behind

    // Function to speak a text string

    privateasyncvoidSpeakText(MediaElementaudioPlayer, stringtextToSpeak)

    {

    SpeechSynthesizersynthesizer = newSpeechSynthesizer();

    SpeechSynthesisStreamttsStream = awaitsynthesizer.SynthesizeTextToStreamA

    audioPlayer.SetSource(ttsStream, ""); // This starts the player because Aut}

    // Synthesis

  • 8/12/2019 HTML5 APPS ON WP8.1

    52/64

    // Windows Phone Store App

    // Synthesis

    // C# code behind

    // Function to speak a text string

    privateasyncvoidSpeakText(MediaElementaudioPlayer, stringtextToSpeak)

    {

    SpeechSynthesizersynthesizer = newSpeechSynthesizer();

    SpeechSynthesisStreamttsStream = awaitsynthesizer.SynthesizeTextToStreamA

    audioPlayer.SetSource(ttsStream, ""); // This starts the player because Aut}

    // p gprivateasyncvoidSpeakText(MediaElementaudioPlayer, string{

    SpeechSynthesizersynthesizer = newSpeechSynthesizer();

    SpeechSynthesisStreamttsStream

    = await synthesizer.SynthesizeTextToStreamAsync(textTo

    audioPlayer.SetSource(ttsStream, "");// This starts the player because AutoPlay="True"

    }

  • 8/12/2019 HTML5 APPS ON WP8.1

    53/64

    // Windows Phone Store App

    // Recognition

    privateasyncTask RecognizeSpeech()

    {

    SpeechRecognizerrecognizer = newSpeechRecognizer();

    // One of three Constraint types available

    SpeechRecognitionTopicConstrainttopicConstraint

    = newSpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebS

    recognizer.Constraints.Add(topicConstraint);

    awaitrecognizer.CompileConstraintsAsync(); // Required

    // Put up UI and recognize user's utterance

    SpeechRecognitionResult result = awaitrecognizer.RecognizeWithUIAsync();

    returnresult;

    }

    // Calling code uses result.RecognitionResult.Text or// result.RecognitionResult.SemanticInterpretation

  • 8/12/2019 HTML5 APPS ON WP8.1

    54/64

    // Windows Phone Store App

    // Recognition

    privateasyncTask RecognizeSpeech()

    {

    SpeechRecognizerrecognizer = newSpeechRecognizer();

    // One of three Constraint types available

    SpeechRecognitionTopicConstrainttopicConstraint

    = newSpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebS

    recognizer.Constraints.Add(topicConstraint);

    awaitrecognizer.CompileConstraintsAsync(); // Required

    // Put up UI and recognize user's utterance

    SpeechRecognitionResult result = awaitrecognizer.RecognizeWithUIAsync();

    returnresult;

    }

    // Calling code uses result.RecognitionResult.Text or// result.RecognitionResult.SemanticInterpretation

    SpeechRecognizerrecognizer = newSpeechRecognizer(

    // One of three Constraint types availableSpeechRecognitionTopicConstraint topicConstraint

    = new SpeechRecognitionTopicConstraint (SpeechRecognitionScenario.WebSearch, "MSDN");

    recognizer.Constraints.Add(topicConstraint);

    await recognizer.CompileConstraintsAsync(); // Requ

  • 8/12/2019 HTML5 APPS ON WP8.1

    55/64

    // Windows Phone Store App

    // Recognition

    privateasyncTask RecognizeSpeech()

    {

    SpeechRecognizerrecognizer = newSpeechRecognizer();

    // One of three Constraint types available

    SpeechRecognitionTopicConstrainttopicConstraint

    = newSpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebS

    recognizer.Constraints.Add(topicConstraint);

    awaitrecognizer.CompileConstraintsAsync(); // Required

    // Put up UI and recognize user's utterance

    SpeechRecognitionResult result = awaitrecognizer.RecognizeWithUIAsync();

    returnresult;

    }

    // Calling code uses result.RecognitionResult.Text or// result.RecognitionResult.SemanticInterpretation

    // Put up UI and recognize user's utteranceSpeechRecognitionResult result

    = await recognizer.RecognizeWithUIAsync();

    returnresult;}// Calling code uses result.RecognitionResult.Text // result.RecognitionResult.SemanticInterpretation

  • 8/12/2019 HTML5 APPS ON WP8.1

    56/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    57/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    58/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    59/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    60/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    61/64

    http://aka.ms/CortanaDev

    http://go.microsoft.com/fwlink/?LinkId=394067

    http://msdn.microsoft.com/en-us/magazine/jj721592.aspx

    http://blogs.msdn.com/b/robch

    http://aka.ms/CortanaDevhttp://go.microsoft.com/fwlink/?LinkId=394067http://msdn.microsoft.com/en-us/magazine/jj721592.aspxhttp://blogs.msdn.com/b/robchhttp://blogs.msdn.com/b/robchhttp://msdn.microsoft.com/en-us/magazine/jj721592.aspxhttp://msdn.microsoft.com/en-us/magazine/jj721592.aspxhttp://msdn.microsoft.com/en-us/magazine/jj721592.aspxhttp://go.microsoft.com/fwlink/?LinkId=394067http://aka.ms/CortanaDevhttp://aka.ms/CortanaDev
  • 8/12/2019 HTML5 APPS ON WP8.1

    62/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    63/64

  • 8/12/2019 HTML5 APPS ON WP8.1

    64/64