Custom Voice Commands with Parameters or Placeholder variables

Braina supports variables in custom commands since version 1.70. Custom voice commands with parameters or placeholder variables can be very useful and gives the freedom of powerful voice interaction with the system. In this article we will know how can we create custom commands with placeholder variables in Braina

You can use three placeholder variables <x>, <y> and <z> while creating custom commands. These placeholder variables can be used to capture a word or phrase that can be used as parameters for creating dynamic and personalized custom commands.

To create custom commands with place holder variables, simply use the variables within the custom command name and use the same variable inside the natural language command value to be executed. Please note that the variables must be specified in lower case. Using <X>, <Y> and <Z> will not work.

For example, we will create a custom command that will print the color name specified by the user in the same text color. If user speaks “I like Blue color”, the output should be You like Blue color. If user speaks “I like Orange color”, the output should be You like Orange color and so on.

Instead of creating hundreds of different custom commands for each different colors, we can simply create a single custom command with placeholder variable to achieve the needed goal. To do this, we simply place <x> variable between “I like ” and ” color” in the command name to capture the color name from the command that will be spoken/entered by the user and then we pass the value of the variable <x> (i.e the color name) to the echo command which is used to print output in Braina. The command echo supports HTML tags and we can use <font> HTML tag to format the text output in the specified color.

e.g. Command name: I like <x> color || I like <x> colour 
     Command value: echo <font color=<x>>You like <x> color

Note: In the command name above, we have specified multiple command names separated with || symbol. This will make sure that both UK or US English spelling version (color and colours) get matched. Support for many to one mappings for custom command and voice recognition aliases was added in the version 1.841

We have just used a single placeholder variable in the above example. Similarly, you can use <y> and <z> along with <x> placeholder variable to capture up to 3 values from user input.

Some rules to follow while using placeholder variables are as follows:

  1. Same placeholder variable cannot be used more than once in a single command name. However, you can use it multiple times in the script to be executed.
  2. <x>, <y> and <z> variables should appear in proper sequence in the command name. <y> cannot appear before <x> and <z> cannot appear before <y> or <x> in the command name. However, you can use the variables in any order in the script to be executed.
  3. The command name should at least have 4 characters when placeholder variable is used.

If you are using custom voice commands with parameters or placeholder variables for an interesting use-case, or if you have any queries regarding placeholder variable, please let us know in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *