Author Topic: Is it possible to use the wildcard from the acitvation phrase of the command?  (Read 2576 times)

E.M.P

  • Newbie
  • *
  • Posts: 7
  • Languages: German, English
So I recently thought of a command which would allow me to change my system volume by saying the activation phrase "volume" and immediately after that the volume number I would like to set it to.

The activation phrase for that would be "volume *". So if I want to set the volume to 50% I would say "volume 50".

Shortly after preparing my command I figured out that there was a tiny problem.
The wildcard in the activation phrase could not be used in the actual command sequence.

As a result of this discovery I had to redesign my command to work properly. (see first attachment).
I am now using the activation phrase "volume" to activate the command and then wait for a spoken response from the user, which is allowed to be a number between 0 and 100 and store it in a variable called "volume".

After that I convert the text/string variable into a 32bit integer called "int32vol" and set the system audio volume by inserting the integer variable (see second attachment).


My question is therefore:
Is there any way to reference the wildcard from the activation phrase inside of the command sequence?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
There are a number of ways to get the text that was recognized when using a wildcard:

You could use the "{CMD}" token, which gets the entire spoken phrase, or the "{CMD_BEFORE}" or "{CMD_AFTER}" tokens to get the text before the static section of your command, or the text after that static section, respectively.

Given that this wildcard feature is dictation-based (meaning the speech recognition engine has to interpret what it hears without context, which is part of why it is noted to be "somewhat unsupported"), other, non-numeric text may get recognized along with any numeric characters.
Because of that, you'd want to use the "{TXTNUM:}" token to filter those out.

In addition, the Microsoft speech recognition engine writes out single-digit numbers, rather than transcribing them as digits, E.G. "one" is transcribed as "one" rather than "1", whereas "ten" is transcribed as "10".
The "{TXTWORDTONUM:}" token is designed to work around this by replacing the written-out single digits with their numeric counterparts, so you'd want to use that as well, before passing the result to the "{TXTNUM:}" token.

E.G.
Code: [Select]
Set system audio volume to [{TXTNUM:"{TXTWORDTONUM:"{CMD_AFTER}"}"}]

Notes on your original command:
The "When I say" field, as well as the "Wait For Spoken Response" action, allow a shorthand for numeric ranges, rather than having to specify each individual number, E.G. "[1..100]" would automatically insert every number from 1 to 100 (note two periods, not three). It also support a multiplier, E.G. "[1..10, 10]" would insert the equivalent of "1;10;20;30;40;50;60;70;80;90;100"

The conversion to an Integer variable is redundant, given that the "Wait For Spoken Response" action, unless you set it up to time out or "Continue on any Speech", would only return a numeric character you defined, so converting to an integer would not be necessary to ensure a valid number was spoken, and arguably there are better ways of doing so as if the conversion fails, the command would not stop, but only generate error messages in the log on the main window
As the "Level" field of the "Set Audio Level" action takes literal text that represents a number, you could have used "{TXT:volume}", which would have been replaced by the text recognized by the "Wait For Spoken Response" action

Even if the conversion were not redundant, as you are using the "{INT:}" token to get the value of the variable, and tokens always, without exception, are replaced by text, you are converting text that represents a number into an actual number, then back to text that represents that number, which the "Set Audio Level" then internally needs to convert back to an actual number again.
If the conversion were necessary, you could use the name of that integer variable in the "Level" field directly, and the action will then retrieve the value of that variable for itself.


Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, which contains information on these and other VoiceAttack features.

These topics may also be of use:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up

E.M.P

  • Newbie
  • *
  • Posts: 7
  • Languages: German, English
Thank you for the quick answer.
I tried it out immediatly and it works pretty good  ;D :D

ErikderFreak

  • Newbie
  • *
  • Posts: 14
Oh that's so great!
Was wondering this too.