21
Fonctions vocales sous Windows Phone : intégrez votre application à Cortana ! Caroline Constantin Microsoft - Senior Program Manager @caroc Jean-Sébastien Dupuy Microsoft – Developer Evangelist @dupuyjs

Fonctions vocales sous Windows Phone : intégrez votre application à Cortana !

Embed Size (px)

Citation preview

Fonctions vocales sous Windows Phone : intégrez votre application à Cortana !

Caroline ConstantinMicrosoft - Senior Program Manager

@caroc

Jean-Sébastien DupuyMicrosoft – Developer Evangelist

@dupuyjs

tech.days 2015#mstechdays

Intégration Cortana

Reconnaissance vocale

Synthèse vocale

Cortana

Dr. Catherine Elizabeth Halsey

tech.days 2015#mstechdays

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

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);

// 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 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;

}

}

tech.days 2015#mstechdays

tech.days 2015#mstechdays

Collaboration entre Bing, Google, Yahoo! et Yandex

Effort commun pour structurer les données (et faire l’objet de traitement automatisés)

Disponible aux formats microdata, JSON-LD et RDFa

Exemples: Events, Reviews, Recipes, Package Tracking

// 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

// 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

tech.days 2015#mstechdays

© 2015 Microsoft Corporation. All rights reserved.

tech days•

2015

#mstechdays techdays.microsoft.fr