News:

HOT TIP! Enable the History Window in the main UI when trying to problem solve. It provides a handy log of what is happening. Roll over lines in the History to get more details.

Main Menu

Help to understand the python wiki

Started by Hellow, February 06, 2014, 08:04:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hellow

I have found:

void triggerEvent(string strEventName, List<string> payloads);
void callAction(string strActionType, string strParams, List<string> payloads);
void doWav(string strWavPath);
Evaluates an audio file and tries to recognize speech
object getObject(string strObject, string strSubObject);
more info
void log(string strLogText);
bool savePayloadFile(string strPath, Dictionary<string, string> payloadPairs, bool subsetMatching);
bool savePayloadListToXML(string strPath, List<xmlPayload> myxmlpayloads);
void setResultList(List<string> lstResults);

Would it be possible to add a explaination to each command and the python command. As i read it setResultList(List<string> lstResults); is it possible to use this one to make a list so you can use match on it?

Thanks in advance.

Hellow

jitterjames

Quote from: Hellow on February 06, 2014, 08:04:40 PM

void setResultList(List<string> lstResults);


This would store a list of results that VC could then access as {Match.1} {Match.2} etc.

Hellow

Quote from: jitterjames on February 06, 2014, 11:06:05 PM
This would store a list of results that VC could then access as {Match.1} {Match.2} etc.

Can i have a example on how to call this function from Python? I can't seem get the syntax right.

nime5ter

Sure. Here is an example of the python code:

from System.Collections.Generic import *
vc.setResultList(List[str](["this is match1","and this is match2"]))


Here are several ways of working with the list of matches in VoxCommando once they've been set:

<?xml version="1.0" encoding="utf-16"?>
<command id="635" name="setresultlist example" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <cmdString>py\setresulttest.py</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>Total matches: {#M}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <cmdString>{Match.{i}}</cmdString>
    <cmdRepeat>{#M}</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.MatchConcat</cmdType>
    <cmdString>{cr}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <cmdString>{LastResult}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>
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)

nime5ter

#4
It's worth plugging the above into your own VC command tree to get a better sense of what's happening.

If you look at the python code and compare it to the wiki page, you can see that the code is much the same as the example given on the wiki page for triggering an event (with slightly different parameters).



This same syntax applies to the other methods listed below the trigger event method.
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)

Hellow

Yeah, I understand now, what threw me off was list[str] I added the list there.  I got error that it wanted a str, so I tried to add a string there. I didn't know that you explicitly are saying this list contains string.

Thanks a lot!

jitterjames

string means string
bool means boolean
List<string> means a list of strings
List<int> means a list of integers
Dictionary<string, string> means a dictionary with a string for the key and a string for the value

List<xmlPayload> means a list of objects of type xmlPayload, but I'd rather not get into that one, and I have never even tried to use it from python.

Bear in mind that these are all the methods defined in C# which are made available to all plugins in VC.  The reason you need to write the syntax List[str] in front of your actual list is to help IronPython to serve the list up in a way that C# can understand that it is a list of strings, because python stores data differently than c#.  The line from System.Collections.Generic import * is also required for this reason.  Here python is importing from the C# namespace for things like Lists and Dictionaries.