VoxCommando
Help and Support (Using VoxCommando) => Python Scripting => Topic started by: DHHJ on March 26, 2014, 05:22:03 PM
-
Is there a way I can "pass" a decimal number to a python script/file? Is there a VC Method that can be used?
I assume payload range is integer only? What is the upper range of the payload range- I don't think this is the way to go, just curious.
I'd like to build a VC calculator........building on this example http://voxcommando.com/forum/index.php?topic=73.msg385#msg385 (http://voxcommando.com/forum/index.php?topic=73.msg385#msg385) and adding some scientific functions, trig, etc.
-
A concrete example would help me to understand what you need. 5 is a decimal number, so payload range can give you a range of decimal numbers, that happen to be integers as well.
You can call a python function with a payload using PY.ExecString myFunc({1})
If your payload {1} = 10 then it will be treated as a number. Python will only treat it as a string if you put quotes around it like this:
myFunc("{1}")
If you want to be able to say any number with decimal points or fractional values then you are going to need to get pretty creative.
-
Yes, that's my question/issue. How can I do something like....
"Calculate 12% of 65.7" or "What's the square root of 78.9"
-
Can I ask, what is the ultimate goal? Do you want to then do something with the calculated values in subsequent commands, or do you just want to be able to have VC verbally give you answers to math problems?
-
"Calculate 12% of 65.7" or "What's the square root of 78.9"
You are not going to have much fun trying to come up with all the possible ways people can say numbers. I think it is a wasted effort, but you can try to use the Wolfram Alpha commands that we previously posted.
Wolfram Alpha does a pretty good job of converting words from free dictation to numbers when appropriate. So VC will understand you saying: "Wolfram, What's the square root of seventy eight point nine" and Wolfram will give you the answer.
-
Yes, that's my question/issue. Hjavascript:void(0);ow can I do something like....
"Calculate 12% of 65.7" or "What's the square root of 78.9"
The W\A commands work quite well for this sort of thing, as long as open dictation works decently for you. Here you can see it in action:
http://www.screencast.com/t/QTyDT3t4BlS (http://www.screencast.com/t/QTyDT3t4BlS)
We've already posted the xml for Wolfram Alpha commands a few times, but here is a version I re-created specifically for the video demo above. This particular xml requires VC2, because I'm using the new and improved regular expression syntax. It can be done as well the old way with little difficulty; it's just different.
<?xml version="1.0" encoding="utf-16"?>
<command id="625" name="wolfram" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
<action>
<cmdType>Scrape</cmdType>
<cmdString>http://api.wolframalpha.com/v2/query?appid=YOUR_API_KEY&input={1}&format=plaintext</cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Results.RegExSingle</cmdType>
<cmdString>Input.*?<plaintext>([^<].*?)</plaintext>.*?[Result|Definition|approximation].*?<plaintext>([^<].*?)</plaintext></cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
<if ifBlockDisabled="False" ifNot="False">
<ifType>LastActionSuccess</ifType>
<ifParams>&&</ifParams>
<then>
<action>
<cmdType>Results.SetLastResult</cmdType>
<cmdString>You asked for: {Match.1.1}. {Cr}The answer is: {Match.1.2}</cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Results.RegExReplace</cmdType>
<cmdString>sqrt\((.*?)\)&&square root of $1</cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Results.Replace</cmdType>
<cmdString> × && times </cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Results.Replace</cmdType>
<cmdString> | &&, </cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>OSD.ShowText</cmdType>
<cmdString>{LastResult}</cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>TTS.Speak</cmdType>
<cmdString>{LastResult}</cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
</then>
<else>
<action>
<cmdType>TTS.Speak</cmdType>
<cmdString>I'm sorry, I don't know the answer to: {1} Could you speak more clearly, or perhaps try to rephrase your question.</cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>OSD.ShowText</cmdType>
<cmdString>I'm sorry, I don't know the answer to: {CR}{1}{CR}Could you speak more clearly, or perhaps try to rephrase your question.</cmdString>
<cmdRepeat>1</cmdRepeat>
</action>
</else>
</if>
<phrase>Wolfram</phrase>
<payloadDictation>payloadDictation: Regular</payloadDictation>
</command>
-
With the above command, I also had good success with queries such as:
Convert x to y
What is [value]Fahrenheit in [value]Celsius (etc.)
What's the square root of x
How far is point A from point B
... And so on.
-
Thanks- that seems to meet the need. I'll play with it and let you know!