Transcript
Page 1: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

www.AgeofMobility.com

Page 2: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

http://www.bigbaldapps.com

www.AgeofMobility.com

@ActiveNick 2005-2014

Page 3: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Computer Speech is the Dream

Page 4: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Mobile Speech is a Responsibility

Page 5: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

AccessibilityMedical

Conditions

Hands &

Eyes Free

Driving Apps

& Games

Learning &

Therapy

Travel Apps

with

Translation

Page 6: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 7: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Speech SDK

Features for DevsWindows Phone Windows Store

iOS

(iPhone/iPad)

Android

(Phone/Tablet)

Built-in Personal

Assistant with

Speech

Cortana* N/A Siri* Google Now

Launcher*

Personal Assistant

Extensions in third-

party apps using

Voice Commands

Yes N/A No

(first-party apps

only)

No

(first-party apps

only)

Speech Synthesis

SDK for Devs

(Text-to-Speech)

Yes Yes Yes Yes

In-app Speech

Recognition SDK

for Devs

Yes Yes* No* Yes

Page 8: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 9: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 10: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 11: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 12: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 13: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

Page 14: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<CommandPrefix>MSDN</CommandPrefix>

Page 15: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Example>How do I add Voice Commands to my application</Example>

Page 16: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

/Command>

Page 17: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Example>Find Install Voice Command Sets</Example>

Page 18: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor>

Page 19: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Feedback>Search on MSDN</Feedback>

Page 20: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Navigate Target="MainPage.xaml" />

Page 21: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

Page 22: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>Find Voice Commands</Example>

<Command Name="FindText"><Example>Find Windows Phone</Example><ListenFor>Search</ListenFor><ListenFor>Search {*}</ListenFor><ListenFor>Search for {listSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {*}</ListenFor><ListenFor>Find {listSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseList Label="listSearchTerms" Disambiguate="false"><Item>Voice Commands</Item><Item>Windows Phone</Item>

</PhraseList>

</CommandSet>

</VoiceCommands>

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

Windows Phone 8.0 Windows Phone 8.1

Simple Scenarios, Limited Accuracy More Powerful, Easier, More Accurate

Page 23: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>Find Voice Commands</Example>

<Command Name="FindText"><Example>Find Windows Phone</Example><ListenFor>Search</ListenFor><ListenFor>Search {*}</ListenFor><ListenFor>Search for {listSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {*}</ListenFor><ListenFor>Find {listSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseList Label="listSearchTerms" Disambiguate="false"><Item>Voice Commands</Item><Item>Windows Phone</Item>

</PhraseList>

</CommandSet>

</VoiceCommands>

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

Windows Phone 8.0 Windows Phone 8.1

Simple Scenarios, Limited Accuracy … and enables Natural Language

Page 24: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">

<CommandSet xml:lang="en-us" Name="englishCommands">

<CommandPrefix>MSDN</CommandPrefix><Example>How do I add Voice Commands to my application</Example>

<Command Name="FindText"><Example>Find Install Voice Command Sets</Example><ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor><Feedback>Search on MSDN</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<Command Name="nlpCommand"><Example>How do I add Voice Commands to my application</Example><ListenFor>{dictatedVoiceCommandText}</ListenFor><Feedback>Starting MSDN...</Feedback><Navigate Target="MainPage.xaml" />

</Command>

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"><Subject>MSDN</Subject>

</PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"><Subject>MSDN</Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

Page 25: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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.1

private async void

// SHOULD BE PERFORMED UNDER TRY/CATCH

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

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uriVoiceCommands);

await VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file);

Page 26: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Page 27: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

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

{

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

NavigationContext.QueryString.TryGetValue("reco", out recoText);

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

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

string searchTerms = null; // What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voice Commands"

NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", out searchTerms);

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

{

case "FindText":

HandleFindText(searchTerms);

break;

case "nlpCommand":

HandleNlpCommand(recoText);

break;

}

}

}

Page 28: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

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

{

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

NavigationContext.QueryString.TryGetValue("reco", out recoText);

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

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

string searchTerms = null; // What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voice Commands"

NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", out searchTerms);

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

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

Page 29: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

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

{

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

NavigationContext.QueryString.TryGetValue("reco", out recoText);

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

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

string searchTerms = null; // What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voice Commands"

NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", out searchTerms);

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 Commands"string recoText = null;NavigationContext.QueryString.TryGetValue("reco", out recoText);

// Which command was recognized in the VCD.XML file? e.g. "FindText"string voiceCommandName = null; NavigationContext.QueryString.TryGetValue("voiceCommandName", out voiceCommandName);

// What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voice Commands"string searchTerms = null;NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", out searchTerms);

Page 30: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

{

base.OnNavigatedTo(e);

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

{

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

NavigationContext.QueryString.TryGetValue("reco", out recoText);

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

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

string searchTerms = null; // What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voice Commands"

NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", out searchTerms);

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;

}

Page 31: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Page 32: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

if (args.Kind == ActivationKind.VoiceCommand)

{

VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

string voiceCommandName = vcArgs.Result.RulePath.First(); // What command launched the app?

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;

}

}

Page 33: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

if (args.Kind == ActivationKind.VoiceCommand)

{

VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

string voiceCommandName = vcArgs.Result.RulePath.First(); // What command launched the app?

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 OnActivated override// in App class

if (args.Kind == ActivationKind.VoiceCommand)

Page 34: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

if (args.Kind == ActivationKind.VoiceCommand)

{

VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

string voiceCommandName = vcArgs.Result.RulePath.First(); // What command launched the app?

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;

}

}

VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

// What command launched the app?string voiceCommandName = vcArgs.Result.RulePath.First();

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

Page 35: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

if (args.Kind == ActivationKind.VoiceCommand)

{

VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

string voiceCommandName = vcArgs.Result.RulePath.First(); // What command launched the app?

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 command switch (voiceCommandName) {

case "FindText": // User said "find" or "search"rootFrame.Navigate(typeof(MSDN.FindText), vcArgs.Result);break;

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

}

Page 36: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(NavigationEventArgs e)

{

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

SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

if (vcResult!=null)

{

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

string recoText = vcResult.Text;

// Store the semantics dictionary for later use

IReadOnlyDictionary<string,IReadOnlyList<string>> semantics = vcResult.SemanticInterpretation.Properties;

string voiceCommandName = vcResult.RulePath.First();

if (voiceCommandName == "FindText")

{

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

if (semantics.ContainsKey("dictatedSearchTerms"))

{

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

}

else

{

HandleNoSearchTerms();

}

}

// Else handle other voice commands

} navigationHelper.OnNavigatedTo(e)

}

Page 37: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(NavigationEventArgs e)

{

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

SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

if (vcResult!=null)

{

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

string recoText = vcResult.Text;

// Store the semantics dictionary for later use

IReadOnlyDictionary<string,IReadOnlyList<string>> semantics = vcResult.SemanticInterpretation.Properties;

string voiceCommandName = vcResult.RulePath.First();

if (voiceCommandName == "FindText")

{

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

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.csprotected override void OnNavigatedTo(NavigationEventArgs e){

// Get recognition result from parameter passed in frame.Navigate callSpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

if (vcResult!=null){

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

// Store the semantics dictionary for later useIReadOnlyDictionary<string,IReadOnlyList<string>> semantics =

vcResult.SemanticInterpretation.Properties;

string voiceCommandName = vcResult.RulePath.First();

Page 38: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(NavigationEventArgs e)

{

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

SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

if (vcResult!=null)

{

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

string recoText = vcResult.Text;

// Store the semantics dictionary for later use

IReadOnlyDictionary<string,IReadOnlyList<string>> semantics = vcResult.SemanticInterpretation.Properties;

string voiceCommandName = vcResult.RulePath.First();

if (voiceCommandName == "FindText")

{

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

if (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 "slots"?// e.g. "Windows Phone Voice Commands"if (semantics.ContainsKey("dictatedSearchTerms")){

HandleFindTextWithSearchTerms(semantics["dictatedSearchTerms"][0]);}else{

HandleNoSearchTerms();}

}

Page 39: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(NavigationEventArgs e)

{

base.OnNavigatedTo(e);

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

SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

// Check for null!

string commandMode = vcResult.SemanticInterpretation.Properties["commandMode"][0];

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

{

SpeakText(audioPlayer, String.Format("MSDN app heard you say {0}", vcResult.Text));

HandleNlpCommand(vcResult);

}

else if(commandMode=="text")

{

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

HandleNlpCommand(vcResult);

}

}

Page 40: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(NavigationEventArgs e)

{

base.OnNavigatedTo(e);

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

SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

// Check for null!

string commandMode = vcResult.SemanticInterpretation.Properties["commandMode"][0];

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

{

SpeakText(audioPlayer, String.Format("MSDN app heard you say {0}", vcResult.Text));

HandleNlpCommand(vcResult);

}

else if(commandMode=="text")

{

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

HandleNlpCommand(vcResult);

}

}

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

protected override void OnNavigatedTo(NavigationEventArgs e)

{

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

SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

string commandMode = vcResult.SemanticInterpretation.Properties["commandMode"][0];

Page 41: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

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

protected override void OnNavigatedTo(NavigationEventArgs e)

{

base.OnNavigatedTo(e);

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

SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

// Check for null!

string commandMode = vcResult.SemanticInterpretation.Properties["commandMode"][0];

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

{

SpeakText(audioPlayer, String.Format("MSDN app heard you say {0}", vcResult.Text));

HandleNlpCommand(vcResult);

}

else if(commandMode=="text")

{

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

HandleNlpCommand(vcResult);

}

}

string commandMode = vcResult.SemanticInterpretation.Properties["commandMode"][0];

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

{

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

HandleNlpCommand(vcResult);

}

else if(commandMode=="text")

{

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

HandleNlpCommand(vcResult);

}

Page 42: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 43: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

private void HandleNlpCommand(string recoText, bool actSilently)

{

string action = null;

string navigateTo = null;

string searchFor = 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";

}

}

else if (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":

// ...

Page 44: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

private void HandleNlpCommand(string recoText, bool actSilently)

{

string action = null;

string navigateTo = null;

string searchFor = 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";

}

}

else if (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("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";}

}

Page 45: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

private void HandleNlpCommand(string recoText, bool actSilently)

{

string action = null;

string navigateTo = null;

string searchFor = 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";

}

}

else if (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 if (recoText.Contains("learn how to ")){

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

}

Page 46: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

private void HandleNlpCommand(string recoText, bool actSilently)

{

string action = null;

string navigateTo = null;

string searchFor = 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";

}

}

else if (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;

}

Page 47: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 48: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Silverlight App

// Synthesis

private async void SpeakText(string textToSpeak)

{

SpeechSynthesizer synthesizer = new SpeechSynthesizer();

await synthesizer.SpeakTextAsync(textToSpeak);

}

// Recognition

private async Task<SpeechRecognitionUIResult> RecognizeSpeech()

{

SpeechRecognizerUI recognizer = new SpeechRecognizerUI();

// One of three Grammar types available

recognizer.Recognizer.Grammars.AddGrammarFromPredefinedType(

"key1", SpeechPredefinedGrammar.WebSearch);

await recognizer.Recognizer.PreloadGrammarsAsync(); // Optional but recommended

// Put up UI and recognize user's utterance

SpeechRecognitionUIResult result = await recognizer.RecognizeWithUIAsync();

return result;

}

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

Page 49: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Silverlight App

// Synthesis

private async void SpeakText(string textToSpeak)

{

SpeechSynthesizer synthesizer = new SpeechSynthesizer();

await synthesizer.SpeakTextAsync(textToSpeak);

}

// Recognition

private async Task<SpeechRecognitionUIResult> RecognizeSpeech()

{

SpeechRecognizerUI recognizer = new SpeechRecognizerUI();

// One of three Grammar types available

recognizer.Recognizer.Grammars.AddGrammarFromPredefinedType(

"key1", SpeechPredefinedGrammar.WebSearch);

await recognizer.Recognizer.PreloadGrammarsAsync(); // Optional but recommended

// Put up UI and recognize user's utterance

SpeechRecognitionUIResult result = await recognizer.RecognizeWithUIAsync();

return result;

}

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

// Synthesisprivate async void SpeakText(string textToSpeak){

SpeechSynthesizer synthesizer = new SpeechSynthesizer();await synthesizer.SpeakTextAsync(textToSpeak);

}

Page 50: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Silverlight App// Synthesisprivate async void SpeakText(string textToSpeak){

SpeechSynthesizer synthesizer = new SpeechSynthesizer();await synthesizer.SpeakTextAsync(textToSpeak);

}

// Recognitionprivate async Task<SpeechRecognitionUIResult> RecognizeSpeech(){

SpeechRecognizerUI recognizer = new SpeechRecognizerUI();

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

"key1", SpeechPredefinedGrammar.WebSearch);

await recognizer.Recognizer.PreloadGrammarsAsync(); // Optional but recommended

// Put up UI and recognize user's utteranceSpeechRecognitionUIResult result = await recognizer.RecognizeWithUIAsync();

return result;}// Calling code uses result.RecognitionResult.Text or result.RecognitionResult.Semantics

// Recognitionprivate async Task<SpeechRecognitionUIResult> RecognizeSpeech(){

SpeechRecognizerUI recognizer = new SpeechRecognizerUI();

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

"key1", SpeechPredefinedGrammar.WebSearch);

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

Page 51: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Silverlight App

// Synthesis

private async void SpeakText(string textToSpeak)

{

SpeechSynthesizer synthesizer = new SpeechSynthesizer();

await synthesizer.SpeakTextAsync(textToSpeak);

}

// Recognition

private async Task<SpeechRecognitionUIResult> RecognizeSpeech()

{

SpeechRecognizerUI recognizer = new SpeechRecognizerUI();

// One of three Grammar types available

recognizer.Recognizer.Grammars.AddGrammarFromPredefinedType(

"key1", SpeechPredefinedGrammar.WebSearch);

await recognizer.Recognizer.PreloadGrammarsAsync(); // Optional but recommended

// Put up UI and recognize user's utterance

SpeechRecognitionUIResult result = await recognizer.RecognizeWithUIAsync();

return result;

}

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

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

= await recognizer.RecognizeWithUIAsync();

return result;

Page 52: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Store App

// Synthesis

<!--MediaElement in xaml file-->

<MediaElement Name="audioPlayer" AutoPlay="True" .../>

// C# code behind

// Function to speak a text string

private async void SpeakText(MediaElement audioPlayer, string textToSpeak)

{

SpeechSynthesizer synthesizer = new SpeechSynthesizer();

SpeechSynthesisStream ttsStream = await synthesizer.SynthesizeTextToStreamAsync(textToSpeak);

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

}

Page 53: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Store App

// Synthesis

<!--MediaElement in xaml file-->

<MediaElement Name="audioPlayer" AutoPlay="True" .../>

// C# code behind

// Function to speak a text string

private async void SpeakText(MediaElement audioPlayer, string textToSpeak)

{

SpeechSynthesizer synthesizer = new SpeechSynthesizer();

SpeechSynthesisStream ttsStream = await synthesizer.SynthesizeTextToStreamAsync(textToSpeak);

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

}

// Synthesis<!--MediaElement in xaml file--><MediaElement Name="audioPlayer" AutoPlay="True" .../>

Page 54: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Store App

// Synthesis

<!--MediaElement in xaml file-->

<MediaElement Name="audioPlayer" AutoPlay="True" .../>

// C# code behind

// Function to speak a text string

private async void SpeakText(MediaElement audioPlayer, string textToSpeak)

{

SpeechSynthesizer synthesizer = new SpeechSynthesizer();

SpeechSynthesisStream ttsStream = await synthesizer.SynthesizeTextToStreamAsync(textToSpeak);

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

}

// C# code behind// Function to speak a text stringprivate async void SpeakText(MediaElement audioPlayer, string textToSpeak){

SpeechSynthesizer synthesizer = new SpeechSynthesizer();

SpeechSynthesisStream ttsStream= await synthesizer.SynthesizeTextToStreamAsync(textToSpeak);

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

}

Page 55: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Store App

// Recognition

private async Task<SpeechRecognitionResult> RecognizeSpeech()

{

SpeechRecognizer recognizer = new SpeechRecognizer();

// One of three Constraint types available

SpeechRecognitionTopicConstraint topicConstraint

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

recognizer.Constraints.Add(topicConstraint);

await recognizer.CompileConstraintsAsync(); // Required

// Put up UI and recognize user's utterance

SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync();

return result;

}

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

Page 56: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Store App

// Recognition

private async Task<SpeechRecognitionResult> RecognizeSpeech()

{

SpeechRecognizer recognizer = new SpeechRecognizer();

// One of three Constraint types available

SpeechRecognitionTopicConstraint topicConstraint

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

recognizer.Constraints.Add(topicConstraint);

await recognizer.CompileConstraintsAsync(); // Required

// Put up UI and recognize user's utterance

SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync();

return result;

}

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

SpeechRecognizer recognizer = new SpeechRecognizer();

// One of three Constraint types availableSpeechRecognitionTopicConstraint topicConstraint

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

recognizer.Constraints.Add(topicConstraint);

await recognizer.CompileConstraintsAsync(); // Required

Page 57: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

// Windows Phone Store App

// Recognition

private async Task<SpeechRecognitionResult> RecognizeSpeech()

{

SpeechRecognizer recognizer = new SpeechRecognizer();

// One of three Constraint types available

SpeechRecognitionTopicConstraint topicConstraint

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

recognizer.Constraints.Add(topicConstraint);

await recognizer.CompileConstraintsAsync(); // Required

// Put up UI and recognize user's utterance

SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync();

return result;

}

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

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

= await recognizer.RecognizeWithUIAsync();

return result;}// Calling code uses result.RecognitionResult.Text or// result.RecognitionResult.SemanticInterpretation

Page 58: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Page 59: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Page 60: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Page 61: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps
Page 62: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

http://aka.ms/CortanaDev

http://channel9.msdn.com/Events/Build/2014/2-530

http://www.bing.com/blogs/site_blogs/b/search/archive/2014/04/14/integrating-store-apps-with-cortana-in-windows-phone-8-1.aspx

http://www.bing.com/dev/en-us/speech

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

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

Page 63: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

http://www.windowsphone.com/en-us/store/app/msdn-voice-search/aed09797-b424-4030-a04d-5ec8ec63847f

http://code.msdn.microsoft.com/wpapps/MSDN-Voice-Search-for-95c16d92

https://voicecommands.codeplex.com

http://code.msdn.microsoft.com/wpapps/Voice-Commands-for-Windows-2f808ac6

http://code.msdn.microsoft.com/windowsapps/Speech-synthesis-sample-6e07b218

http://code.msdn.microsoft.com/windowsapps/Bing-Speech-Recognition-210c8978

http://code.msdn.microsoft.com/windowsapps/Speech-Recognition-19c452b4

Page 64: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

https://developer.apple.com/technologies/ios/accessibility.html

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVSpeechSynthesizer_Ref/Reference/Reference.html

http://nshipster.com/avspeechsynthesizer

DEVFRIGHT Blog Post: http://www.devfright.com/quick-look-avspeechsynthesizer-class/

Page 65: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

https://play.google.com/store/apps/details?id=com.google.android.launcher

http://developer.android.com/reference/android/speech/package-summary.html

http://developer.android.com/reference/android/speech/tts/package-summary.html

Page 66: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

http://channel9.msdn.com/Events/Build/2014/

Page 67: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

http://channel9.msdn.com/Events/Build/2014

Page 68: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Get Ready to Become a Windows Phone Developerdev.windowsphone.com

Learn More About Windows Phone Dev via Official Microsoft Videoshttp://aka.ms/wp81js

http://aka.ms/wp81devbegin

Check Out Additional Learning Resourceswww.pluralsight.com/training/Courses#windows-phone

www.developer.nokia.com

Download Additional Resources & Become an Expertphone.codeplex.com

http://bit.ly/nokiadevoffers

68

1

2

3

4

Page 69: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

www.AgeofMobility.com

dev.windowsphone.com

dev.windows.com

blogs.windows.com/windows_phone/b/wpdev

blogs.windows.com/windows_phone/b/windowsphone

http://developer.nokia.com

http://bit.ly/godvlup

http://conversations.nokia.com

http://appstudio.windows.com

http://flip.it/95YFG

www.geekchamp.com

www.wpcentral.com

Page 70: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Thank You!Slides will be posted on my Slideshare account.

Slideshare: www.slideshare.net/ActiveNick

Blog: www.AgeofMobility.com

Twitter: @ActiveNick

Mobile Apps: www.bigbaldapps.com

LinkedIn: www.linkedin.com/in/activenick

Website: www.AgeofMobility.com

Email: [email protected]

Page 71: Beyond Cortana & Siri: Using Speech Recognition & Speech Synthesis for the Next Generation of Mobile Apps

Top Related