News:

There is a soft-mute function which we use with the commands like "What song is this?" There is one for system volume, one for each of: MediaMonkey, XBMC, iTunes, MediaPortal.

Main Menu

Need HelppppppppppP!!!!!

Started by Haddood, October 26, 2014, 09:36:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haddood

ok this is driving me  :bonk :bonk

I am working on improved "what can I say" command,  which scrape the info from voicecommand.xml directly instead of relying on the help html.

after isolating the group code ... I am applying regex to isolate the commands within the group (after this I am supposed to extract the phrases)

I am applying regex.single using
<command\sid=.*?>(.*?)</command>
on the attached xml ... I get back 18 matches instead of 5

what is the missing part ????

When Voice command gets tough, use hand gestures

nime5ter

Based on just the info you've provided, I think the problem is happening before this step, when you're trying to isolate the group-level xml.

If you look at the group.xml file that you've posted, there are repeated commands there.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Haddood

Quote from: nime5ter on October 26, 2014, 11:18:04 AM
Based on just the info you've provided, I think the problem is happening before this step, when you're trying to isolate the group-level xml.

If you look at the group.xml file that you've posted, there are repeated commands there.
I will verify that again....
However before I posted I checked many times, I opened the attached xml in notpad++ and the commands nodes collapse to 5 commands only ...
When Voice command gets tough, use hand gestures

jitterjames

Don't collapse the nodes.  The group.xml you posted is not valid xml.

There are 4 copies of each command but they are not nested correctly.  A new command tag appears in the middle of a param element.

In order to help we would need to see a copy of the actions you are using to isolate the group xml and also the original xml that you are working with.

Haddood

This is the regex.single I am using to isolate groups

<commandGroup.*?name="{Var.CommandGroup}".*?>(.*?)</commandGroup>

I am applying it against voicecommands.xml ( I belive if it has wrong nested commands, VC Will object with an error)
When Voice command gets tough, use hand gestures

nime5ter

#5
It's not the voicecommands.xml that has nesting errors -- it's the xml file that you attached to your post that has nesting errors.

We need the command xml you used to generate those results in order to try to help, if you're still looking for assistance, not your regular expression.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Haddood

Will post all as soon as I get home.... Thanks a lot for all
When Voice command gets tough, use hand gestures

nime5ter

#7
Maybe this will help:
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.0.7-->
<command id="305" name="Beware of scraping/capturing last result variable" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
 <action>
   <cmdType>File.Read</cmdType>
   <params>
     <param>test document.txt</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>OSD.ShowText</cmdType>
   <params>
     <param>{LastResult}</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
</command>


Download the attached file to your VC directory. It contains one simple line of text:
QuoteHere is the > {LastResult} < There was the last result.

Then execute the above command to see what happens ...
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Haddood

thanks nime5ter will look into it and post back.

you guys give awesome support ... really appreciate it.
When Voice command gets tough, use hand gestures

Haddood

Hi

here is the command I am using ... and a sample group ... if I put Montreal in payload 1, the command return 18 matches instead of 5

<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.0.7-->
<command id="378" name="--- Commands in a Topic uner Dev. scrape xml directly" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="{1} Group Name">
  <action>
    <cmdType>VcAdvanced.Log</cmdType>
    <params>
      <param>------------------------------- Start: list Commands in {1} -------------------------------</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params>
      <param>{1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.Replace</cmdType>
    <params>
      <param><![CDATA[ ]]></param>
      <param>\s</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>CommandGroup</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>{Path.VC}\voicecommands.xml</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <params>
      <param>&lt;commandGroup.*?name="{Var.CommandGroup}".*?&gt;(.*?)&lt;/commandGroup&gt;</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params>
      <param>{Match.1.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <params>
      <param>&lt;command\sid=.*?(.*?)&lt;/command&gt;</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{#M}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.StopMacro</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>
When Voice command gets tough, use hand gestures

nime5ter

#10
Any time you are scraping the command xml, you'll need to find/replace the variables in the scraped document before doing anything with the result.

(Probably most important to get rid of "{LastResult}" and "{Match.x}", but might as well get rid of all of them in this particular context since you don't actually need any of the macro info.)

This holds true also at the first stage, when you're grabbing the content of particular groups.

Try:
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.0.7-->
<command id="378" name="--- Commands in a Topic uner Dev. scrape xml directly" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="{1} Group Name">
 <action>
   <cmdType>VcAdvanced.Log</cmdType>
   <params>
     <param>------------------------------- Start: list Commands in {1} -------------------------------</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.SetLastResult</cmdType>
   <params>
     <param>{1}</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.Replace</cmdType>
   <params>
     <param><![CDATA[ ]]></param>
     <param>\s</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.SetVar</cmdType>
   <params>
     <param>CommandGroup</param>
     <param>{LastResult}</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Scrape</cmdType>
   <params>
     <param>{Path.VC}\voicecommands.xml</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.RegExReplace</cmdType>
   <params>
     <param>\{.*?\}</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.RegExSingle</cmdType>
   <params>
     <param>&lt;commandGroup.*?name="{Var.CommandGroup}".*?&gt;(.*?)&lt;/commandGroup&gt;</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.SetLastResult</cmdType>
   <params />
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.SetLastResult</cmdType>
   <params>
     <param>{Match.1.1}</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>Results.RegExSingle</cmdType>
   <params>
     <param>&lt;command\sid=.*?(.*?)&lt;/command&gt;</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>OSD.ShowText</cmdType>
   <params>
     <param>{#M}</param>
   </params>
   <cmdRepeat>1</cmdRepeat>
 </action>
 <action>
   <cmdType>VC.StopMacro</cmdType>
   <params />
   <cmdRepeat>1</cmdRepeat>
 </action>
</command>


I've added a Results.RegExReplace action directly after your scrape action. You'll want to do the same in your initial command where you are grabbing the groups.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Haddood

 :bonk :bonk :bonk :bonk :bonk :bonk :bonk :bonk :bonk :bonk :bonk :bonk

Now I understood even the post before ...

BTW: my significant other sends her gratitude to you for saving the few remaining hairs in my head ...  :biglaugh :biglaugh :biglaugh
When Voice command gets tough, use hand gestures

nime5ter

:) I hear shaved heads are all the rage nowadays anyhow.

Sorry if my post last night was too cryptic. I thought it would be more helpful to "show" than to "tell". Probably better to combine the two.

Believe me, it took me a while to figure out what the issue was. James (of course!) gave me the obvious, simple solution when I described the problem to him. Teamwork, eh.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

I think it is important to note that any time your parameter contains {sometext} it will try to replace {sometext} with a value (if it has one), before executing the action.  It will then try again to see if there is something inside what was replaced, that might also be of the form {sometext}.  It will keep doing it until it fails to do a replacement.

This is normally a good thing... but you need to be careful.

This behaviour is not limited to scrape, or regex, it applies to all actions.  In theory we could probably put an option on an action to instruct VC not do replacements on its params, but I'm not sure it is worth the trouble to implement, or worth complicating the UI, for such a special case.

nime5ter

#14
@Haddood, for this particular thing you're trying to build, you might find it worthwhile to learn how to use Python's ElementTree module: https://docs.python.org/2/library/xml.etree.elementtree.html

I think you'll find this xml parsing solution much neater and more efficient in the long run, and translatable to other things you may want to do.

Just as an introductory example, the following python script looks for enabled command groups, and creates a list of their names. It also creates a "vcGroups" payload xml file, and an OSD message listing all the enabled groups.

The same principles could be applied to write a function that retrieves all commands within a particular group (or all groups), finds the relevant phrase nodes etc.

import xml.etree.ElementTree as ET
tree = ET.parse('voicecommands.xml')
root = tree.getroot()

def getGroups():
   count=0
   groupList=[]#keep track of command groups in a list, in case it's useful later
   vc.callAction('PayloadXML.Clear','payloads\\vcGroups.xml',None)#clear/create payload xml in VC > payloads folder
   vc.callAction('OSD.ShowText','Command Groups:&&8000&&-10',None)#8 sec. OSD in VC

   for group in root.findall('commandGroup'):#finds all commandGroup nodes, iterates through them
       name = group.get('name')#gets name of each commandGroup
       count +=1
       group_status = group.get('enabled')#gets enabled status of each commandGroup      
           
       if group_status == 'True':#if group is enabled
           groupList.append(name)#add each enabled group to our groupList
           vc.callAction('OSD.AddText',str(count)+'. '+name,None)#add enumerated group to our OSD in VC
           vc.callAction('PayloadXML.AddPair','payloads\\vcGroups.xml&&%s&&%s&&True'%(name,name),None)#add group to payloadXML
       
   return str(groupList)#return list as string so VC can use it (see command xml example)


And some basic commands that use the above:
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.0.7-->
<commandGroup open="True" name="Get command info" enabled="True" prefix="" priority="0" requiredProcess="" description="">
 <command id="292" name="Name command groups" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
   <action>
     <cmdType>PY.ExecString</cmdType>
     <params>
       <param>result=getGroups()</param>
     </params>
     <cmdRepeat>1</cmdRepeat>
   </action>
   <action>
     <cmdType>TTS.Speak</cmdType>
     <params>
       <param>{LastResult}</param>
     </params>
     <cmdRepeat>1</cmdRepeat>
   </action>
   <phrase>Name command groups</phrase>
 </command>
 <command id="307" name="Commands in group {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
   <action>
     <cmdType>Help.ShowByName*</cmdType>
     <params>
       <param>{1}</param>
     </params>
     <cmdRepeat>1</cmdRepeat>
   </action>
   <phrase>Commands in group</phrase>
   <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\vcGroups.xml</payloadFromXML>
 </command>
</commandGroup>
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)