Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - claymic

Pages: [1]
1
Python Scripting / We Need To Talk About Python - 1 Variables
« on: May 28, 2013, 09:16:19 AM »
OK, i decided to learn Python to use with Vox, i am more comfortable with Javascript and i really love it. Somethings in python let me crazy sometimes, so i decided to share here what i learn, when i get sometime free of course  ;D
Today i will try to explain how python treat Local and Global variables.
Dont worry about the previous explanations, the example will cover everything that you need.
- What is a Local Variable :
  Well, like the name suggest, "local variables" can only be used inside the function that was created.
- What is a Global Variables:
  You can call this variables from any place in the code.
Let see the examples and learn how we can change Global Variables inside a function.
Code: [Select]
#Global Variables
variable1 = "test1"
variable2 = "test2"
def changeVariables():
    variable1 = "change1"
    variable2 = "change2"
    #Local Variable
    variable3 = variable1+variable2
def changeVariablesGlobal():
    global variable1
    global variable2
    variable1 = "change1"
    variable2 = "change2"
Copy the code above and save in your "PY" folder, give the name TestVariables.py.
Now, see in the code that we have three variables. Two of them are declared outside the functions (variable1 and variable2), when we do that we are creating Global Variables and we can use this variables in any place of the code, see that i am using this variables in the function "changeVariables" to set the value of another variable.
The "variable3" otherwise its a Local Variable, was declared inside the function "changeVariables", so we can only use it inside this function, if you try to use this variable in the function "changeVariablesGlobal" you will get a error.
So far so good, but Python its a bad snake, we have to understand how to change the Global Variables now.
Lets put Vox to teach us. Copy the command bellow and paste in your VoxCommando, i think that you already now how to do that and i believe that you already put your script the folder PY, if you need change the path.
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="1791" name="variables" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <cmdString>PY\TestVariables.py</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <cmdString>changeVariables()</cmdString>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <cmdString>changeVariablesGlobal()</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <cmdString>result = variable1 + " " + variable2</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>{LastResult}&amp;&amp;3000</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>
So, now that you have the command we need to edit it to make some tests. Set your command like the picture bellow:

Ok, let understand the actions.
We will block the actions 2 and 3 (see the picture above) for this test.
Now, when we run the command, the action 1 will run the script file, everything that is outside a function will run, in our case we have only this outside the function:
Code: [Select]
variable1 = "test1"
variable2 = "test2"
So when Vox run the script this will set our global variables.
In the action 4 we will set our result to be equal to the variable1 and variable2, in the action 5 we show the result, so Vox will show this to you:

Nice...now we know how to set and use Global Variables in Vox.
To next test we will set the command like this:

Ok...see that now we enable the action 2. When we ask Vox to run the "PY.ExecString" we are saying to Vox to only run a small peace of code, in our case this means that we will run the function "changeVariables()", see:
Code: [Select]
def changeVariables():
    variable1 = "change1"
    variable2 = "change2"
    #Local Variable
    variable3 = "test3"
When we do that, the script will not run anything more, this means that the Global Variables will not be set again in our case.
What will be the result when we run the command in Vox ? Will be the same, the snake bite us ;D

In the function changeVariables() we are setting the values of the variable1 and the variable2, but when we do that we are not setting the value of the Global Variable, because Python will understand this like a Local Variable.
So, How we can change the value of a Global Variable ? Before  change the value of any Global Variable (if we are inside the function) we have to tell Python that it is a Global Variable. See the function changeVariablesGlobal()
Code: [Select]
def changeVariablesGlobal():
    global variable1
    global variable2
    variable1 = "change1"
    variable2 = "change2"
See ? We have to use the "global variable1", this will tell for Python that we will change the value of the Global Variable.
Now set your command in Vox like the picture bellow:

Run the command and now we will have a new result:

Ok...we can now use Global Variables in all our scripts, once we set the value of a Global Variable we can get this value from any place in our code, even in a different script.
Hope that help
Clayton

2
Python Scripting / File.Read
« on: May 27, 2013, 04:08:01 PM »
Hi James
Do you see anything wrong with this small code ? I am missing something
Code: [Select]
powerArCondition  = vc.callAction("File.Read","{Path.VC}\Devices\ArGree.txt",None)
doorSpeek = sensorControl["DOORSPEEK"]
doorSpeekFechado = sensorControl["DOORSPEEKFECHADO"]
def _doorOpen():
   if  powerArCondition == "Ligado" and doorSpeek == "True":
      variable = "True"
   else:
      variable = "False"
   return variable
The result is always "False", i dont know why. I check this showing a OSD in vox, to see if the variable are right. The OSD show the powerArCondition  = Ligado and the doorSpeek = True.
The strange is that when the OSD show up the value of the powerArCondition i get a error in the log , something like a NullReferenceException, is it because i am using File.Read ? This dont happens for the variable doorSpeek
Thanks

3
Other Plugins / Problem with TCP plugin and Global Cache
« on: May 27, 2013, 09:40:32 AM »
I install the new version over my old version of Vox today.
I created a new folder group
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="GC Itach 161" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="1515" name="Itach161Connect" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Tcp.Client.Connect</cmdType>
      <cmdString>ItachRs1&amp;&amp;192.168.0.161&amp;&amp;4999&amp;&amp;\x0A</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Itach161Connect</event>
  </command>
  <command id="1540" name="Itach161Desconnect" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TCP.Client.Disconnect</cmdType>
      <cmdString>ItachRs1</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Itach161Desconnect</event>
  </command>
  <command id="1531" name="Itach161SendCommandVariable" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Tcp.Client.Write</cmdType>
      <cmdString>ItachRs1&amp;&amp;{Var.SendItach161}&amp;&amp;4999&amp;&amp;\x0A</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Itach161SendCommandVariable</event>
  </command>
  <command id="1533" name="Itach161SendCommandPayload" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Tcp.Client.Write</cmdType>
      <cmdString>ItachRs1&amp;&amp;{1}&amp;&amp;4999&amp;&amp;\x0A</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Itach161SendCommandPayload</event>
  </command>
</commandGroup>
This group will manage my connections with a ITach.
Then i created a new Command to force vox (in the startup) to connect and send a null command to my ITach
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="1477" name="startup" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>VC.Off</cmdType>
    <cmdString />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <cmdString>{Path.VC}\PY\Startup.py</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.SetEventTimer</cmdType>
    <cmdString>4&amp;&amp;Itach161Connect</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.SetEventTimer</cmdType>
    <cmdString>5&amp;&amp;Itach161SendCommandPayload&amp;&amp;Null</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>VC.Loaded</event>
</command>
But when i run Vox i get this in the log

There is a loop running and sending the command 4x, but i dont put any loop in the command.
The second problem its that when i run a Command to send any data to any of my GlobalCache the command is sent instantaneously but Vox freeze for 7 seconds.
Clayton

4
Ok, before anyone say...i am not crazy :bonk...maybe just a little ;D
Smartplaylist its nice but when we generate a smartplaylist the xbmc dont insert the items in the playlist, since the smartplaylist its more like a filter then a true playlist.
I need to insert all the items from a smartplaylist in a playlist, in this way i can easy get this items and show in my ipad interface (to use without have to turn on the tv or play the files in another player like Dune...just an example).
For now i tried to modify the VoxTools to insert the smartplaylist in the playlist using Playlist.add, this works but the xbmc dont insert the items, it insert only the path for the smartplaylist. I tried with the Playlist.load too.
If anyone have a tip to help me with this i will appreciate.
Thanks

5
Feature Requests / Tcp Plugin
« on: January 15, 2013, 05:25:09 PM »
Hi James, maybe i missed this, but can i send tcp commands with vox ? For now i am using the EventGhost for do this, but will be awesome if i can send a tcp command directly using Vox.
In the EventGhost i am using the phyton code bellow:
Code: [Select]
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.0.160", 4998))
s.send('sendir,5:3,1,39000,1,1,230,46,46,46,23,22,23,22,23,45,23,22,23,22,23,45,23,45,23,1152,115,45,46,46,23,22,23,22,23,45,23,22,23,22,23,45,23,45,23,1152,115,45,46,46,23,22,23,22,23,45,23,22,23,22,23,45,23,45,23,780"+"\r\n')
s.close()
I just need to send some commands for the GlobalCache, will be nice can do this using Vox(maybe setting the ip and port for each command, since this will depend of the device)
Thanks
Clayton

6
VoxWav Free and VoxWav Pro / Training with Android
« on: January 13, 2013, 08:37:47 AM »
Hi
What is the best way to training our speech recognition using android ? I have to make the training of my computer again but my mic its very weird today. Maybe will be better make the training with my android device.
Thanks for the help
Clayton

7
Off Topic (not related to VC) / CAV1.0
« on: November 07, 2012, 09:28:41 AM »
YES! I AM ALIVE !
Little video showing my new automation control system using CommandFusion. Finally its almost done.





8
Hi
After the smart playlists this is my prefer command. I dont speak english but i will try to explain how this works.
Thanks James and Wanilton for all help with this.
We have to install a plugin in Xbmc, this plugin will generate a txt file everytime we send the command with vox, so we can get the info of ours songs, albuns, episodes, season, tv shows and movies. We can get all the infos without have to play the files. You can for exemple navigate over you movies and get the plot, rating, duration, etc.
For this work install the plugin and import the group for VoxCommando:

Quote
https://dl.dropbox.com/u/89557567/script.vcgetinfo.zip
https://dl.dropbox.com/u/89557567/VcGrp_XBMC%20script%20container.xml
You will better understand using then reading here.
You can use all this regex to get the infos :
<Container>(.*)</Container> This will get the info of the container who you are navigating. The match will depend where you are in xbmc. EX: Movie, TV Show, TV Show Episodes, TV Show Seasons, Music or Music Songs.
<Title>(.*)</Title> get the title of the songs, episodes or movies
<Rating>(.*)</Rating> get the rating of the movies or songs.
<OriginalTitle>(.*)</OriginalTitle> original title of the movie
<Plot>(.*)</Plot> plot of movies or episodes
<Year>(.*)</Year> year of the movie, album or tv show.
<Genre>(.*)</Genre>
<Director>(.*)</Director>
<Country>(.*)</Country>

<Tagline>(.*)</Tagline> for movies or tv shows
<Duration>(.*)</Duration> songs, movies or episodes
<FileExtension>(.*)</FileExtension> get the files extension of the movies or episodes
<TVShowTitle>(.*)</TVShowTitle> only for tv show
<ShowPlot>(.*)</ShowPlot> Only for tv show
<Season>(.*)</Season> will get the number of the season of a tv show
<TotalSeasons>(.*)</TotalSeasons> will get the total number of seasons of a tv show.
<Episode>(.*)</Episode> get the number of the episode
<TotalEpisodes>(.*)</TotalEpisodes> if you are over a tv show will return how much episodes the tv show have, if you are over a season will return the number of episodes in the season.
<WatchedEpisodes>(.*)</WatchedEpisodes> if you are over a tv show will return how many episodes you watched for this tv show, if you are over a season will return the number of episodes you watched in this season.
<UnWatchedEpisodes>(.*)</UnWatchedEpisodes> same thing, but for unwatched
<audioType>(.*)</audioType> the type of the audio file
<Artist>(.*)</Artist> name of the singer if you are navigation over a album or song
<Album>(.*)</Album>
<TrackNumber>(.*)</TrackNumber>
<Lyrics>(.*)</Lyrics> this will get the lyrics of the song, if the song have one.
<Path>(.*)</Path> you return the full path of a file
<FolderName>(.*)</FolderName> will return only the folder name of the file.

Now the only thing you need its imagination.
Import the group  "XBMC script container" and you see how you can manage all this regex without any problem. This group have only one phrase : "Read to Me" , try to navigate in xbmc (movies, musics, tv shows, episodes, etc) and say Read to Me, you will see how the VoxCommando group works using the regex for Container and a few events.
How the this group works :
You will se a command in this group named "Read to me" with a phrase "Read to me", see the picture
[attachment=1]
See the actions picture :
[attachment=2]
When you say the phrase Read to Me VoxCommando will tell for xbmc run the script, after that the script will generate a .txt file (infotemp.txt), you can open this txt file (will be in root of your VoxCommando) and see al the infos there.
After the VoxCommando read the file with can get and manage the infos with the regex, in this case i am geting the container informartion with the regex <Container>(.*)</Container>, so if you are navigating over your movies the {Match.1} will be Movies, lke i said before. In the next acdtion the VoxCommando will trigger a event Container.{Match.1} in this case Container.Movies, see now the pictrue bellow :
[attachment=3]
After the trigger Event the command Container.Movie will run.
[attachment=4]
All done. Off course we can get off the TTS.SetVoiceName, i am using because my movies have the title in Englisch but the plot is in portuguese.
Its the same thing for songs, tvShows, episodes, etc. All this have a event.
For people from Brasil the match from the Container regex its a little diferent for songs and tvshows, because sometimes we have in the same tvshow a plot in English and other in Portuguese. How solved that ? Well, the most of portugue plots have accents and "ç", so i put a little code in the script. If the episode (tv show, season) plot have accents or "ç" the script will return the container like "TV Show Brasil" this will trigger the event Container.Tv Shows Brasil and you can use the TTS.SetVoiceName to get the tts in portuguese.
For music i solved this with another trick. Every song have a genre, so if the genre its a brasilian genre like samba, mpb, sertanejo, rock nacional, reggee nacional, etc, the regex from the container will be "Container.Music Brasil" or "Container.Music Songs Brasil", again you can decide how tss voice you want to use. This can be make for others country songs too, like  german songs for our friend Kalle. I only need to know the name of the genrs of this country to put this in the script.
I think this is all. Works very well for me and i thik works for James and Wanilton, i am not sure.
I am sorry for my bad english, i will explain this better in the portuguese section very soon. Now i am trying to put vox to control the PopCorn Hour and Dune HD Max, like we make with XBMC, i think will be possible to navigate, ask for musics and movies, maybe even pick up the feedback from PopCorn Hour.
Clayton

Pages: [1]