Cortana: Integrating Your App into the Windows Phone Speech

<?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>
<?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>
<CommandPrefix>MSDN</CommandPrefix>
<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>
<?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>
<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>
<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>
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
<ListenFor>Find</ListenFor>
<ListenFor>Find
{dictatedSearchTerms}</ListenFor>
<CommandSet xml:lang="en-us"
Name="englishCommands">
<Feedback>Search on MSDN</Feedback>
<CommandPrefix>MSDN</CommandPrefix>
<Navigate
Target="MainPage.xaml"
<Example>How do I add
Voice Commands
to my application</Example>/>
</Command>
<Command Name="FindText">
<Example>Find Install Voice Command Sets</Example>
<ListenFor>Search</ListenFor>
<Command Name="nlpCommand">
<ListenFor>Search for {dictatedSearchTerms}</ListenFor>
<Example>How do I add Voice Commands to my application</Example>
<ListenFor>Find</ListenFor>
<ListenFor>{dictatedVoiceCommandText}</ListenFor>
<ListenFor>Find {dictatedSearchTerms}</ListenFor>
<Feedback>Search <Feedback>Starting
on MSDN</Feedback>
MSDN...</Feedback>
<Navigate Target="MainPage.xaml" />
<Navigate Target="MainPage.xaml" />
</Command>
/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>
<?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>
<Example>Find Install Voice Command Sets</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>
<PhraseTopic Label="dictatedSearchTerms" Scenario="Search">
<Subject>MSDN</Subject>
</PhraseTopic>
</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="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>
<ListenFor>Search</ListenFor>
<ListenFor>Search for {dictatedSearchTerms}</ListenFor>
<ListenFor>Find</ListenFor>
<ListenFor>Find {dictatedSearchTerms}</ListenFor>
<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>
<?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>
<Feedback>Search on MSDN</Feedback>
<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>
<?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>
<Navigate Target="MainPage.xaml" />
<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>
<?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>
<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation">
<Command Name="FindText">
<Subject>MSDN</Subject>
<Example>Find Install
Voice Command Sets</Example>
<ListenFor>Search</ListenFor>
</PhraseTopic>
<ListenFor>Search for {dictatedSearchTerms}</ListenFor>
<ListenFor>Find</ListenFor>
<ListenFor>Find
{dictatedSearchTerms}</ListenFor>
<PhraseTopic
Label="dictatedSearchTerms"
<Feedback>Search on MSDN</Feedback>
<Subject>MSDN</Subject>
<Navigate Target="MainPage.xaml"
/>
</Command>
</PhraseTopic>
<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>
Scenario="Search">
Windows Phone 8.0
<?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>
Windows Phone 8.1
<?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>
</VoiceCommands>
Simple Scenarios, Limited Accuracy
More Powerful, Easier, More Accurate
Windows Phone 8.0
<?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>
Windows Phone 8.1
<?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>
</CommandSet>
</VoiceCommands>
Simple Scenarios, Limited Accuracy
… and enables Natural Language
<?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>
Windows Phone Silverlight Apps on Windows Phone 8.1
private async void
// SHOULD BE PERFORMED UNDER TRY/CATCH
Uri
new
ms-appx:///vcd.xml
await
UriKind.Absolute
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);
❶
❷
// 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)
{
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);
// Windows Phone Silverlight App, in MainPage.xaml.cs
string voiceCommandName = null; // Which command was recognized in the VCD.XML file? e.g. "FindText"
NavigationContext.QueryString.TryGetValue("voiceCommandName",
out voiceCommandName);
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs
e)
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
// What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"
string recoText
= null;
Silverlight
App, in MainPage.xaml.cs
NavigationContext.QueryString.TryGetValue("reco", out recoText);
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Which command was recognized in the VCD.XML file?
base.OnNavigatedTo(e);
if
{
e.g. "FindText"
string voiceCommandName = null;
(e.NavigationMode
== System.Windows.Navigation.NavigationMode.New)
NavigationContext.QueryString.TryGetValue("voiceCommandName",
out voiceCommandName);
string recoText = null; // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"
// What did the user say, forout
named
phrase topic or list "slots"?
NavigationContext.QueryString.TryGetValue("reco",
recoText);
e.g. "Windows
Phone Voice Commands"
string voiceCommandName
= null; // Which
command was recognized in the VCD.XML file? e.g. "FindText"
string searchTerms
= null;
NavigationContext.QueryString.TryGetValue("voiceCommandName", out voiceCommandName);
NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", out searchTerms);
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?
{
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
case "FindText":
{
base.OnNavigatedTo(e);
HandleFindText(searchTerms);
break;
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
// Windows Phone Silverlight App, in MainPage.xaml.cs
{
string recoText = null; // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"
case "nlpCommand":
NavigationContext.QueryString.TryGetValue("reco", out recoText);
HandleNlpCommand(recoText);
break;
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 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)
{
VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;
// Windows Runtime App on Windows Phone 8.1, inside OnActivated override
string voiceCommandName
= vcArgs.Result.RulePath.First(); // What command launched the app?
// in App class
switch (voiceCommandName)
// Navigate
to right page for the voice command
if (args.Kind ==
ActivationKind.VoiceCommand)
{
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)
VoiceCommandActivatedEventArgs
vcArgs = (VoiceCommandActivatedEventArgs)args;
{
VoiceCommandActivatedEventArgs
vcArgs
// What command launched the
app?= (VoiceCommandActivatedEventArgs)args;
string voiceCommandName = vcArgs.Result.RulePath.First();
string voiceCommandName = vcArgs.Result.RulePath.First(); // What command launched the app?
// Navigate to right page for the voice command
switch
// Navigate to right page for the voice command
switch(voiceCommandName)
(voiceCommandName)
{
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
// Windows Runtime
App(voiceCommandName)
on Windows Phone 8.1, inside OnActivated override in App class
switch
{
if (args.Kind == ActivationKind.VoiceCommand)
case "FindText": // User said "find" or "search"
{
rootFrame.Navigate(typeof(MSDN.FindText), vcArgs.Result);
VoiceCommandActivatedEventArgs
vcArgs = (VoiceCommandActivatedEventArgs)args;
break;
string voiceCommandName
= vcArgs.Result.RulePath.First();
// What
case "nlpCommand":
// User said something
elsecommand launched the app?
rootFrame.Navigate(typeof(MSDN.NlpCommand), vcArgs.Result);
switch (voiceCommandName)
break; // 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 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.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Windows Runtime App //
on Windows
Phone 8.1, inside
OnNavigatedTo
In FindText.xaml.cs
Get recognition
result
from parameter
passed in frame.Navigate call
protected override voidSpeechRecognitionResult
OnNavigatedTo(NavigationEventArgs
e)
vcResult
= e.Parameter as SpeechRecognitionResult;
{
// Get recognition result from parameter passed in frame.Navigate call
if (vcResult!=null)
SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;
{
// What did the user say? e.g. MSDN, "Find Windows
if (vcResult!=null)
{
string recoText = vcResult.Text;
// What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"
string recoText = vcResult.Text;
// Store the semantics dictionary for later use
Phone Voice Commands"
IReadOnlyDictionary<string,IReadOnlyList<string>> semantics =
// Store the semantics dictionary for later use
vcResult.SemanticInterpretation.Properties;
IReadOnlyDictionary<string,IReadOnlyList<string>>
semantics = vcResult.SemanticInterpretation.Properties;
string
voiceCommandName =
string voiceCommandName
= vcResult.RulePath.First();
}
}
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")
// Windows Runtime{ App on Windows Phone 8.1, inside OnNavigatedTo In FindText.xaml.cs
protected override void//
OnNavigatedTo(NavigationEventArgs
e) named phrase topic or list "slots"?
What did the user say, for
{
// e.g. "Windows Phone Voice Commands"
// Get recognition result from parameter passed in frame.Navigate call
if (semantics.ContainsKey("dictatedSearchTerms"))
SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;
{
HandleFindTextWithSearchTerms(semantics["dictatedSearchTerms"][0]);
if (vcResult!=null)
{
}
// What did theelse
user say? e.g. MSDN, "Find Windows Phone Voice Commands"
string recoText{= vcResult.Text;
// Store the semantics dictionary for later use
HandleNoSearchTerms();
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 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, inside OnNavigatedTo In NlpCommand.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Windows Runtime App on Windows Phone 8.1, in OnNavigatedTo in NlpCommand.xaml.cs
base.OnNavigatedTo(e);
protected override void OnNavigatedTo(NavigationEventArgs e)
// Get recognition result from parameter passed in frame.Navigate call
{
SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;
// Get recognition result from parameter passed in frame.Navigate call
// Check for null!
SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;
string commandMode
= vcResult.SemanticInterpretation.Properties["commandMode"][0];
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?
{
// Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo In NlpCommand.xaml.cs
SpeakText(audioPlayer, String.Format("MSDN voice heard you say {0}", vcResult.Text));
protected override void OnNavigatedTo(NavigationEventArgs e)
{
HandleNlpCommand(vcResult);
base.OnNavigatedTo(e);
}
else if(commandMode=="text")
// Get recognition result from parameter passed in frame.Navigate call
{
SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;
msgTextBox.Text= string.Format("Working on your request \"{0}\"", vcResult.Text);
// Check for null!
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 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);
}
}
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":
// ...
private void HandleNlpCommand(string recoText, bool actSilently)
{
string action = null;
string navigateTo = null;
string searchFor = null;
if (recoText.Contains("go to ") || recoText.Contains("goto ") ||
recoText.Contains("find ") || recoText.Contains("search ") ||
recoText.Contains("show me "))
recoText = {
recoText.ToLower();
action
if (recoText.Contains("go
to ")=|| "navigate";
recoText.Contains("goto ") ||
recoText.Contains("find ") || recoText.Contains("search ") ||
if (recoText.Contains("windows phone dev center"))
recoText.Contains("show me "))
{
{
action = "navigate";
navigateTo
"http://dev.windowsphone.com";
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":
// ...
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;
}
else if (recoText.Contains("learn how to "))
{
action = "find";
searchFor = recoText.Substring(recoText.IndexOf("learn how to ") + 13);
}
switch (action)
{
case "find":
// ...
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;
}
else
{
action = "find";
searchFor = recoText;
}
switch (action)
{
case "find":
// ...
// 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
// Windows Phone Silverlight App
// Synthesis
private async void SpeakText(string textToSpeak)
{
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
await synthesizer.SpeakTextAsync(textToSpeak);
// Synthesis
}
private async void SpeakText(string textToSpeak)
// Recognition {
private async Task<SpeechRecognitionUIResult>
SpeechSynthesizerRecognizeSpeech()
synthesizer = new SpeechSynthesizer();
{
synthesizer.SpeakTextAsync(textToSpeak);
SpeechRecognizerUIawait
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
// Silverlight
RecognitionApp
// Windows Phone
// Synthesis private async Task<SpeechRecognitionUIResult> RecognizeSpeech()
private async {void SpeakText(string textToSpeak)
{
SpeechRecognizerUI recognizer = new SpeechRecognizerUI();
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
await synthesizer.SpeakTextAsync(textToSpeak);
// One of three Grammar types available
}
recognizer.Recognizer.Grammars.AddGrammarFromPredefinedType(
"key1", SpeechPredefinedGrammar.WebSearch);
// Recognition
private async Task<SpeechRecognitionUIResult> RecognizeSpeech()
// Optional but recommended
{
SpeechRecognizerUI
= new SpeechRecognizerUI();
awaitrecognizer
recognizer.Recognizer.PreloadGrammarsAsync();
// 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
// Windows Phone Silverlight App
// Synthesis
private async void SpeakText(string textToSpeak)
{
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
await synthesizer.SpeakTextAsync(textToSpeak);
}
// Put up UI and recognize user's
utterance
// Recognition SpeechRecognitionUIResult result
private async Task<SpeechRecognitionUIResult>
RecognizeSpeech()
= await recognizer.RecognizeWithUIAsync();
{
SpeechRecognizerUI recognizer = new SpeechRecognizerUI();
return result;
// 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
// 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"
}
// Windows Phone Store App
// Synthesis
<!--MediaElement in xaml file-->
<MediaElement Name="audioPlayer" AutoPlay="True" .../>
// Synthesis
// C# code behind
// Function to <!--MediaElement
speak a text string in xaml file-->
private async void
SpeakText(MediaElement
audioPlayer, string
textToSpeak)
<MediaElement
Name="audioPlayer"
AutoPlay="True"
{
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 string
private async void SpeakText(MediaElement audioPlayer, string textToSpeak)
{
// Windows Phone Store App
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
// Synthesis
<!--MediaElement
in xaml file--> ttsStream
SpeechSynthesisStream
<MediaElement Name="audioPlayer" AutoPlay="True" .../>
= await synthesizer.SynthesizeTextToStreamAsync(textToSpeak);
// C# code behind
audioPlayer.SetSource(ttsStream,
"");
// Function
to speak a text string
// async
Thisvoid
starts
the player because
AutoPlay="True"
private
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"
}
// 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();
// Windows Phone Store App
// One of three Constraint types available
// Recognition
topicConstraint
private async SpeechRecognitionTopicConstraint
Task<SpeechRecognitionResult> RecognizeSpeech()
= new SpeechRecognitionTopicConstraint(
{
SpeechRecognizer recognizer
= new SpeechRecognizer();
SpeechRecognitionScenario.WebSearch,
"MSDN");
// One of three Constraint types available
recognizer.Constraints.Add(topicConstraint);
SpeechRecognitionTopicConstraint topicConstraint
= new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebSearch, "MSDN");
await recognizer.CompileConstraintsAsync(); // Required
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
// Windows Phone Store App
// Put up UI and recognize user's utterance
// Recognition
SpeechRecognitionResult
result
private async Task<SpeechRecognitionResult>
RecognizeSpeech()
= await recognizer.RecognizeWithUIAsync();
{
SpeechRecognizer recognizer = new SpeechRecognizer();
return result;
// One of }three Constraint types available
SpeechRecognitionTopicConstraint topicConstraint
// Calling code uses result.RecognitionResult.Text or
= new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebSearch, "MSDN");
// result.RecognitionResult.SemanticInterpretation
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
❶
❷
❶
❷
❸
❹
❺
❻
❶
❷
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