Voice commands

moancapableΤεχνίτη Νοημοσύνη και Ρομποτική

17 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

68 εμφανίσεις


<?
xml

version
=
"
1.0
"

encoding
=
"
utf
-
8
"
?>

<
VoiceCommands

xmlns
=
"
http://schemas.microsoft.com/
voicecommands
/1.0
"
>


<
CommandSet

xml:lang
=
"
en
-
us
"
Name
=
"
MagicMemoEnu
"
>


<
CommandPrefix
>
Magic Memo
</
CommandPrefix
>


<
Command

Name
=
"
showMemos
"
>


<
Example
>
Show memo number 2
</
Example
>
<!
--

ListenFor

elements for all ways to say the same command
--
>


<
ListenFor
>
Show [me] memo [number] {
num
}
</
ListenFor
>


<
ListenFor
>
Display memo [number] {
num
}
</
ListenFor
>


<
Feedback
>
Showing memo {
num
}
</
Feedback
>


<
Navigate

Target
=
"
/
ViewMemos.xaml
"
/>


</
Command
>


<!
--

Add Command elements for other pages
--
>


</
CommandSet
>



<
PhraseList

Label
=
"
num
"
>


<
Item
>

1
</
Item
>


<
Item
>

2
</
Item
>


<
Item
>

3
</
Item
>


</
PhraseList
>



</
CommandSet

xml:lang
=
"
jp
-
JA
"
Name
=
"
MagicMemoJp
"
>


<!


Add
CommandSets

for other languages
--
>


</
CommandSet
>

</
VoiceCommands
>

Recognizes:

Magic Memo, show me memo number
three.

Magic Memo, show memo
one.

Magic Memo, display memo number
two.

Magic Memo, display memo
two.


using

Windows.Phone.Speech.VoiceCommands
;

// ...

// Load the
VoiceCommandDefinition

file, usually on first run in
App.xaml.cs

private
async

void

Application_Launching
(
object

sender,
LaunchingEventArgs

e)

{


try



{


// Path to Voice Command Definition (VCD) file in application install path



Uri

uri

=
new

Uri
(
"
ms
-
appx
:///MagicMemoVCD.xml"
);


await

VoiceCommandService
.InstallCommandSetsFromFileAsync
(
uri
);



}



catch

(
Exception

ex)



{



// Handle Exception


}

}

private void
object
RoutedEventArgs
// Other code omitted ...


// Was the page launched by voice commands?
if
this.
"
voiceCommandName
"
string
this.
"
voiceCommandName
"
switch
case
"
showMemos
"
string
this.
"
num
"
// Display requested memo


break
// cases for other commands
default
// No match

break
//
Get
VoiceCommandSet

object

VoiceCommandSet
VoiceCommandService
"
MagicMemoEnu
"
// Update
PhraseList

for use in commands

(any time)

"
num
"
new
string
"1"
"2"
"3"
"4"
"5"
async

private
void
object
RoutedEventArgs
SpeechSynthesizer
new
SpeechSynthesizer
await
"You have a meeting with Peter in 15 minutes."
async

private
void
object
RoutedEventArgs
SpeechRecognizer
new
SpeechRecognizer
// Use the default short message dictation grammar
SpeechRecognitionResult
// Do something with the recognition result
MessageBox
string
"You said {0}."
async

private

void

InitializeSpeech
()

{


commandReco

=
new

SpeechRecognizerUI
();
// Instantiate speech recognizer



commandReco.Settings.ListenText

=
"Say a button name or select number"
;
// Prompt spoken to user


commandReco.Settings.ExampleText

=
"Ex. 'Clear three' or 'Select two'"
;
// Displayed as examples



// SRGS grammar to recognize button names and numbers


Uri

grammarFileUri

=
new

Uri
(
"
ms
-
appx
:///
ViewMemos.grxml
"
);




// Add grammar for later loading


commandReco.Recognizer.Grammars.AddGrammarFromUri
(
"
srgsCommands
"
,
grammarFileUri
);



await

commandReco.Recognizer.PreloadGrammarsAsync
();
// Preload grammar to reduce latency (optional)

}


async

private

void

MicImage_Tap
(
object

sender,
GestureEventArgs

e)

{


var

commandResult

=
await

commandReco.RecognizeWithUIAsync
();
// Start speech recognition


if

(
commandResult.ResultStatus

==
SpeechRecognitionUIStatus
.Succeeded
)


{
// Execute command spoken by user

}

}

SpeechRecognizerUI

SpeechRecognizer

object

Settings object:

timeout
values etc
.

Grammars collection

indexed by

grammar name

AddGrammar

Methods:

Predefined from
list

SRGS grammar
from URI

Methods:

PreLoadGrammarsAsync

Get/Set Recognizer

RecognizeAsync


UI
Settings object:

UI
text, Booleans
to
disable
features


Recognition Method:

RecognizeWithUIAsync

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