Skip to content

fiddling with the attributes

Kronk edited this page Aug 4, 2022 · 7 revisions

In this part i will talk about the attributes, yes both of them. We have the CommandAttribute and the ConfidenceAttribute. Both have their own use, first i will talk about the CommandAttribute.

CommandAttribute Explained

Okay, so the Command attribute is a by far the most handy thing i've made. you can in 1 line of code make a whole command.

    //this shows how:

    [Command("Hello")]
    public void Hello()
    {
        Paige.SpeakAsync("Hey there, How can i help you today?");
    }

    //This mean this method will be executed when the speech engine pick up the word "hello".
    //But that is not very handy because what if you also want it to react when you say "hi" and "hey".
    //Well i've though of that to, that's why you can do this:

    [Command("Hello", "hi", "hey")]
    public void Hello()
    {
        Paige.SpeakAsync("Hey there, How can i help you today?");
    }

    //How handy is that, and the beauty of it is that the command is already implemented in the speech recognizer. 
    //so you don't have to worry about 
    //anything :).

for more 'behind the scenes' explenation go to: fiddling with the attributes Extended


ConfidenceAttribute Explained

The System also includes a second attribute called the ConfidenceAttribute, it handles some less needed work, but is very handy none the less. You can add it to the same method as the CommandAttribute and it controls how confident the speech recognizion system has to be in order to allow it to execute certain code.

    //this shows how:

    [Command("Hello")]
    [Confidence(90)]
    public void Hello()
    {
        Paige.SpeakAsync("Hey there, How can i help you today?");
    }

    //It takes a number between 0 and 100 and that is how confident the speech recognizion system has to be.
    //If the output is 70 the command will not execute, if it is 91 it will because simple math 
    //91 < 90 = right 👍
    //70 < 90 = wrong 👎 

    //Good to know too is, that if you do not add the attribute, then the Confidence level has to be higher then 75
    //I found that a pretty good general confidence level.

CommandClassAttribute Explained

This attribute doesn't have any working parts, it is just there to tell the commandSystem that is there may be some commands in that class. To use it just add it to the top of a class and the rest is handled for you ;)

namespace PersonalAssistant
{
    [CommandClass]
    public class ExampleCommands
    {

That is everything you need to know about the attributes.

again for more 'behind the scenes' explenation go to: fiddling with the attributes Extended