VoxCommando

Help and Support (Using VoxCommando) => Python Scripting => Topic started by: xtermin8r on April 22, 2014, 01:47:31 PM

Title: Python TTS.SpeakSync lastresult help
Post by: xtermin8r on April 22, 2014, 01:47:31 PM
Hi
vc.callAction("TTS.SpeakSync",lastresult, None) = not working (https://voxcommando.com/forum/proxy.php?request=http%3A%2F%2Fwww.freesmileys.org%2Fsmileys%2Fsmiley-angry015.gif&hash=fd73a522480b28b6ccf52ba2aba587b5b32ac9cd) (http://www.freesmileys.org/smileys.php)

What is the correct syntax ?
thanks.
Title: Re: Python TTS.SpeakSync lastresult help
Post by: nime5ter on April 22, 2014, 02:00:59 PM
per the wiki: void callAction(string strActionType, string strParams, List<string> payloads)

... doesn't look as though you've defined lastresult as a string?
Title: Re: Python TTS.SpeakSync lastresult help
Post by: jitterjames on April 22, 2014, 02:07:58 PM
There are examples and explanations for python here:

http://voxcommando.com/mediawiki/index.php?title=Python

Your second parameter should be a string, but as Nime5ter points out, you probably did not define a string variable named lastresult.  There is no way to know since you only showed us one line of your code.

One of the examples on the page I linked to above is this:
Code: [Select]
print vc.getObject("LastResult","")
so you could adapt this to grab the lastresult from vc and store it in your variable:
Code: [Select]
myLastResult = vc.getObject("LastResult","")
vc.callAction("TTS.SpeakSync", myLastResult, None)
Title: Re: Python TTS.SpeakSync lastresult help
Post by: xtermin8r on April 22, 2014, 02:48:09 PM
this is what I was trying to do

Code: [Select]
vc.callAction("Weather.TWN.1","gbxx0037",None)
myLastResult = vc.getObject("LastResult","")
vc.callAction("TTS.SpeakSync", myLastResult, None)

working fine now, thanx for the xplanation.

but why doesn't this work ?

Code: [Select]
myTime = vc.getObject("ShortTime","")
vc.callAction("TTS.SpeakSync", myTime, None)

I get that ShortTime is not a strObject, so what is the correct format ?
Title: Re: Python TTS.SpeakSync lastresult help
Post by: jitterjames on April 22, 2014, 02:59:11 PM

but why doesn't this work ?

Code: [Select]
myTime = vc.getObject("ShortTime","")
...

Please see the reference material that I linked to.  That doesn't work for the same reason that the following code does not work:
Code: [Select]
myBalance = vc.getObject("HowMuchMoneyIsInMyBank","")
You can't just make up object names.  The objects are listed on the page I linked to.  More specifically they can be found here:
http://voxcommando.com/mediawiki/index.php?title=Python#getObject


I should probably point out that if you were calling a python function from within a VC macro (instead of just running python code) then you could do something like this:

Code: [Select]
py.execstring    myFunc({ShortTime})
This is because actions will look at anything in {} to see if it can be replaced with a payload, variable, map value etc. but this does not apply to python code.  And before you ask, no that isn't going to change.  However, I could probably add a new method to accept a string and do these substitutions, and return a string with the substituted values in place.

Title: Re: Python TTS.SpeakSync lastresult help
Post by: nime5ter on April 22, 2014, 03:01:39 PM
To code in Python, why not use Python methods?

The following returns a "short time" string in Python speak:
Code: [Select]
import time
myTime= time.localtime(time.time())
print time.strftime("%H:%M", myTime)
Title: Re: Python TTS.SpeakSync lastresult help
Post by: xtermin8r on April 22, 2014, 03:16:14 PM
It makes total sense now thank you both.