Author Topic: Store voice variable for later use?  (Read 5054 times)

JDsplice

  • Newbie
  • *
  • Posts: 20
Store voice variable for later use?
« on: December 14, 2016, 12:24:24 PM »
I use a MS word template constantly and the only thing that changes is the new file name I save under.

Can I have VA recognize a term like "Open Template 345d" (the 345d number would change on each use) and run the macro inputting 345d at the right time?

Any help is much appreciated

SIDE NOTE: When I say "345d", VA rec. as "345 D".  Is there a way to force VA to not put a space in between or cap the "D"?
« Last Edit: December 14, 2016, 02:26:06 PM by JDsplice »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Store voice variable for later use?
« Reply #1 on: December 14, 2016, 03:19:56 PM »
Not sure why your requirements have apparently changed, but I put together the following:
Dictate file name
Code: [Select]
Set small int (condition) [TextElements] value to 1
Marker: WaitForDictation
Start Dictation Mode (Clearing Dictation Buffer)
Start Loop While : [{DICTATION}] Equals ''
End Loop
Stop Dictation Mode
Begin Text Compare : [{DICTATION}] Equals 'Stop'
    Set Text [FileName] to ''
    Set small int (condition) [Element] value to 1
    Start Loop While : [Element] Does Not Equal [TextElements]
        Write '[Purple] {TXT:Element{SMALL:Element}}' to log
        Set Text [FileName] to '{TXTCONCAT:FileName:Element{SMALL:Element}}'
        Set small int (condition) [Element] value as incremented by 1
    End Loop
    Write '[Purple] {TXT:FileName}' to log
Else
    Begin Text Compare : [{DICTATION}] Starts With 'remove'
        Begin Small Integer Compare : [TextElements] Does Not Equal 0
            Set small int (condition) [TextElements] value as decremented by 1
            Set Text [Element{SMALL:TextElements}] to [Not Set]
            Jump to Marker: WaitForDictation
        Else
            Write '[Red] No text in buffer to remove' to log
        End Condition
    Else If Text Compare : [{EXP: {TXTNUM:"{DICTATION}"} >= 0}] Equals '1'
        Set Text [Element{SMALL:TextElements}] to '{TXTNUM:"{DICTATION}"}'
    Else If Text Compare : [{DICTATION}] Equals 'one'
        Set Text [Element{SMALL:TextElements}] to '1'
    Else If Text Compare : [{DICTATION}] Equals 'two'
        Set Text [Element{SMALL:TextElements}] to '2'
    Else If Text Compare : [{DICTATION}] Equals 'three'
        Set Text [Element{SMALL:TextElements}] to '3'
    Else If Text Compare : [{DICTATION}] Equals 'four'
        Set Text [Element{SMALL:TextElements}] to '4'
    Else If Text Compare : [{DICTATION}] Equals 'five'
        Set Text [Element{SMALL:TextElements}] to '5'
    Else If Text Compare : [{DICTATION}] Equals 'six'
        Set Text [Element{SMALL:TextElements}] to '6'
    Else If Text Compare : [{DICTATION}] Equals 'seven'
        Set Text [Element{SMALL:TextElements}] to '7'
    Else If Text Compare : [{DICTATION}] Equals 'eight'
        Set Text [Element{SMALL:TextElements}] to '8'
    Else If Text Compare : [{DICTATION}] Equals 'nine'
        Set Text [Element{SMALL:TextElements}] to '9'
    Else If Text Compare : [{DICTATION}] Equals 'zero'
        Set Text [Element{SMALL:TextElements}] to '0'
    Else
        Set Text [Element{SMALL:TextElements}] to '{TXTSUBSTR:"{DICTATION}":0:1}'
    End Condition
    Set small int (condition) [TextElements] value as incremented by 1
    Jump to Marker: WaitForDictation
End Condition

Usage example:
Quote
dictate file name
three
fortyfive
delta
oops
remove
stop
Will produce "345d".

Stop ends dictation and concatenates all elements to a string.
Remove clears the last character.
Numbers are always accepted as numbers if they're higher than 9, otherwise you'll have to clearly speak a single digit.
Any text that isn't 0-9 will have the first character added to the name(I.E. if you say "Delta" but the speech engine recognizes "dealt with", "d" will still be added).
You can change "Equals" to "Contains" for any of the lookup table elements, but the risk of false positives will increase as expected.


When I say "345d", VA rec. as "345 D".  Is there a way to force VA to not put a space in between or cap the "D"?
To remove the space you can use the "{TXTREPLACEVAR:}" token:
Code: [Select]
{TXTREPLACEVAR:text:" ":""}

If you really need lowercase letters, you can run your text through the "{TXTLOWER:}" token:
Code: [Select]
{TXTLOWER:"{TXTREPLACEVAR:text:" ":""}"}Or, if you're using dictation, use the "LOWERCASE" parameter:
Code: [Select]
{TXTREPLACEVAR:"{DICTATION:LOWERCASE}":" ":""}
However, Windows filesystems are generally not case-sensitive, so you may find uppercase works fine.

JDsplice

  • Newbie
  • *
  • Posts: 20
Re: Store voice variable for later use?
« Reply #2 on: December 14, 2016, 03:41:18 PM »
Not sure why your requirements have apparently changed, but I put together the following:

I tried like a million different combinations and finally got the [wait for my dictation before continuing] part to work.
Here is my code:

Marker: Loop
Begin Text Compare: [{DICTATION}] Equals ''
   Jump to Marker: Loop
Else
   Stop Dictation Mode
   Quick Input, '{DICTATION}'
End Condition

Your code is vastly superior to mine and I don't think I understand it completely, but thank you for taking the time to hash it all out.  Do you see a way to incorporate the lowercase and no space code into my script?

BTW: Your avatar is hilariously distracting while trying to figure out ur code, LOL.
« Last Edit: December 14, 2016, 03:47:51 PM by JDsplice »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Store voice variable for later use?
« Reply #3 on: December 14, 2016, 03:44:48 PM »
Do you see a way to incorporate the lowercase and no space code into my script?
Code: [Select]
Marker: Loop
Begin Text Compare: [{DICTATION}] Equals ''
   Jump to Marker: Loop
Else
   Stop Dictation Mode
   Quick Input, '{TXTREPLACEVAR:"{DICTATION:LOWERCASE}":" ":""}'
End Condition

JDsplice

  • Newbie
  • *
  • Posts: 20
Re: Store voice variable for later use?
« Reply #4 on: December 14, 2016, 03:58:03 PM »
Thank you, that worked like a charm!!!

OK, for my next challenge...
Example file names:
345d
697
444m
A104a
C505g
B293

Cases make a difference. If the file name begins with a letter it's always uppercase. If it ends with a letter then it's always lower case.  Is there a simple code like the one u just provided that can handle this scenario?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Store voice variable for later use?
« Reply #5 on: December 14, 2016, 04:25:05 PM »

Code: [Select]
Marker: Loop
Begin Text Compare: [{DICTATION}] Equals ''
   Jump to Marker: Loop
Else
   Stop Dictation Mode
   Quick Input, '{TXTUPPER:"{TXTALPHA:"{TXTSUBSTR:"{TXTREPLACEVAR:"{DICTATION}":" ":""}":0:1}"}"}{TXTNUM:"{DICTATION}"}{TXTLOWER:"{TXTALPHA:"{TXTSUBSTR:"{TXTREPLACEVAR:"{DICTATION}":" ":""}":1:}"}"}'
End Condition

JDsplice

  • Newbie
  • *
  • Posts: 20
Re: Store voice variable for later use?
« Reply #6 on: December 14, 2016, 04:37:30 PM »
Your amazing!!  That worked perfectly as well.  Not sure how cuz I can't follow the code, but thanks so much!