+ All Categories
Home > Software > Using the Power of Speech in Your Windows Phone Apps

Using the Power of Speech in Your Windows Phone Apps

Date post: 27-Jun-2015
Category:
Upload: lori-lalonde
View: 191 times
Download: 0 times
Share this document with a friend
Description:
The Windows Phone SDK provides APIs which make it easy for developers to incorporate speech recognition and voice commands within a Windows Phone app. In this session, you will learn how to incorporate speech synthesis, voice commands, and simple speech recognition within your own Windows Phone app to provide a truly engaging user experience.
Popular Tags:
27
Using the Power of Speech in your Windows Phone Apps Lori Lalonde Twitter: @loriblalonde Blog: geekswithblogs.net/ lorilalonde
Transcript
Page 1: Using the Power of Speech in Your Windows Phone Apps

Using the Power of Speech in your Windows Phone Apps

Lori LalondeTwitter: @loriblalonde

Blog: geekswithblogs.net/lori-lalonde

Page 2: Using the Power of Speech in Your Windows Phone Apps
Page 3: Using the Power of Speech in Your Windows Phone Apps

About Me

Twitter: @loriblalondeEmail: [email protected]

Blog: geekswithblogs.net/lorilalondeLinkedIn:

http://ca.linkedin.com/in/lorilalonde

CTTDNUG

Page 4: Using the Power of Speech in Your Windows Phone Apps

Why should I integrate speech in my mobile

app?

Page 5: Using the Power of Speech in Your Windows Phone Apps

Minimum RequirementsWindows Phone 8.1 Development

Windows 8.1 (x64)

Visual Studio 2013 Update 2 or later (Pro, Premium, or Ultimate)OR

Visual Studio 2013 Express for Windows Update 2 or later

*includes Windows Phone 8.1 SDK

*Windows Phone Emulators – require Professional edition of Windows, and a processor that supports Client Hyper-V and Second Level Address

Translation (SLAT)

Page 6: Using the Power of Speech in Your Windows Phone Apps

Speech for Windows Phone

Voice Commands

Speech Recognition

Text-To-Speech

Page 7: Using the Power of Speech in Your Windows Phone Apps

Voice Commands

Simply say something to launch (or navigate into) the app…

… instead of:

tap, tap, scroll, select, dang…go back…

tap, scroll…

oh geez forget it!

Page 8: Using the Power of Speech in Your Windows Phone Apps

Add Capabilities

Page 9: Using the Power of Speech in Your Windows Phone Apps

Add a Voice Command Definition File<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0"> <CommandSet xml:lang="en-US"> <CommandPrefix>Contoso Rodeo</CommandPrefix> <Example> play a new game </Example>

<Command Name="PlayGame"> <Example> play a new game </Example> <ListenFor> [and] play [a] new game </ListenFor> <ListenFor> [and] start [a] new game </ListenFor> <Feedback> Starting a new game... </Feedback> <Navigate /> </Command>

... </CommandSet></VoiceCommands>

Page 10: Using the Power of Speech in Your Windows Phone Apps

Phrase Lists

<Command Name="PlayLevel"> <Example> replay level two </Example> <ListenFor> replay level {number} </ListenFor> <Feedback> Going to level {number}... </Feedback> <Navigate /> </Command>

<PhraseList Label="number"> <Item> one </Item> <Item> two </Item> <Item> three </Item> </PhraseList>

Page 11: Using the Power of Speech in Your Windows Phone Apps

Register the VCD using Windows.Media.SpeechRecognition; using Windows.Storage; ... private async Task InitializeVoiceCommands() {

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

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(vcdUri);

await VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file); }

Installs the CommandSet whose specified language matches the device language setting

Page 12: Using the Power of Speech in Your Windows Phone Apps

Handle Navigation protected override void OnActivated(IActivatedEventArgs args) {

if (args.Kind == ActivationKind.VoiceCommand) {

Frame rootFrame = Window.Current.Content as Frame;VoiceCommandActivatedEventArgs vcArgs =

(VoiceCommandActivatedEventArgs)args;

//check for the command name that launched the appstring voiceCommandName = vcArgs.Result.RulePath.FirstOrDefault();

if (voiceCommandName == "ViewEntry") {

rootFrame.Navigate(typeof(ViewDiaryEntry), vcArgs.Result.Text);

} }

}

Page 13: Using the Power of Speech in Your Windows Phone Apps

DEMO!!!

Page 14: Using the Power of Speech in Your Windows Phone Apps

Speech Synthesis (Text-To-Speech)

Enable the app to read text to the user

The text can be:

A simple string

Speech Synthesis Markup Language (SSML) string

SSML file

Page 15: Using the Power of Speech in Your Windows Phone Apps

Speak! Part 1

using Windows.Media.SpeechSynthesis; ...

private SpeechSynthesizer synthesizer;

public async Task SpeakAsync(string textToSpeech) {

SpeechSynthesizer synthesizer = new SpeechSynthesizer();SpeechSynthesisStream synthesisStream =

await synthesizer.SynthesizeTextToStreamAsync(textToSpeech);

... }

Page 16: Using the Power of Speech in Your Windows Phone Apps

Speak! Part 2

public async Task SpeakAsync(string textToSpeech) {

SpeechSynthesizer synthesizer = new SpeechSynthesizer();SpeechSynthesisStream synthesisStream =

await synthesizer.SynthesizeTextToStreamAsync(textToSpeech);

if (synthesisStream != null) {

this.media.AutoPlay = true; this.media.SetSource(synthesisStream, synthesisStream.ContentType); this.media.Play();

} }

<MediaElement x:Name="media“ AutoPlay="False" />Add MediaElement to the view’s XAML

Set the media source to the stream and play

Page 17: Using the Power of Speech in Your Windows Phone Apps

DEMO!!!

Page 18: Using the Power of Speech in Your Windows Phone Apps

Enable the app to react when the user is speaking to it

Speech Recognition

Page 19: Using the Power of Speech in Your Windows Phone Apps

Built-In Speech Prompts/Confirmations

Heard You Say…

Unrecognized input

Did You Say…

Listening…

Page 20: Using the Power of Speech in Your Windows Phone Apps

using Windows.Media.SpeechRecognition; ... private SpeechRecognizer speechRecognizer; public async Task InitializeSpeechRecognizerAsync(string topicHint) {

speechRecognizer = new SpeechRecognizer();

//add web search grammar to the recognizer SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, topicHint);

speechRecognizer.Constraints.Add(topicConstraint);

await speechRecognizer.CompileConstraintsAsync(); }

Initialize SpeechRecognizer

A speech recognizer needs at least one constraint, and constraints must be compiled, before speech recognition can be performed.

Page 21: Using the Power of Speech in Your Windows Phone Apps

private SpeechRecognizer speechRecognizer; public async Task SpeakTextAsync() {

SpeechRecognitionResult recognitionResult = await speechRecognizer.RecognizeWithUIAsync();

... }

Using the Built-In UI

Page 22: Using the Power of Speech in Your Windows Phone Apps

private SpeechRecognizer speechRecognizer; public async Task SpeakTextAsync(string audiblePrompt, string exampleText) {

speechRecognizerUI.UIOptions.IsReadBackEnabled = true;speechRecognizerUI.UIOptions.ShowConfirmation = true;

speechRecognizer.UIOptions.AudiblePrompt = audiblePrompt;speechRecognizer.UIOptions.ExampleText = exampleText;

SpeechRecognitionResult recognitionResult = await speechRecognizer.RecognizeWithUIAsync();

... }

Setting UI Options

Page 23: Using the Power of Speech in Your Windows Phone Apps

DEMO!!!

Page 24: Using the Power of Speech in Your Windows Phone Apps

Questions

Page 26: Using the Power of Speech in Your Windows Phone Apps

apress.com

30% off Windows Phone 8 Recipes eBook

Discount Code: LORI14Expires: Dec 31, 2014

Page 27: Using the Power of Speech in Your Windows Phone Apps

Lori LalondeTwitter: @loriblalonde

Blog: geekswithblogs.net/lori-lalonde


Recommended