Author Topic: Help to understand the python wiki  (Read 2361 times)

0 Members and 1 Guest are viewing this topic.

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Help to understand the python wiki
« on: February 06, 2014, 08:04:40 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Help to understand the python wiki
« Reply #1 on: February 06, 2014, 11:06:05 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

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Help to understand the python wiki
« Reply #2 on: February 07, 2014, 01:58:54 AM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Help to understand the python wiki
« Reply #3 on: February 07, 2014, 08:14:05 AM »
Sure. Here is an example of the python code:

Code: [Select]
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:

Code: [Select]
<?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

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Help to understand the python wiki
« Reply #4 on: February 07, 2014, 08:22:15 AM »
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.
« Last Edit: February 07, 2014, 08:25:53 AM by nime5ter »
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

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Help to understand the python wiki
« Reply #5 on: February 07, 2014, 09:42:34 AM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Help to understand the python wiki
« Reply #6 on: February 07, 2014, 10:27:34 AM »
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
Code: [Select]
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.