I have found the way to send out my command to Blender internally with Python code… This will reduce the latency with my voice command and it open up more possibilities to anyone with more advanced Python script skill to develop more useful voice command too. This Blender addon is the key for this approach: Blender Command Port
This addon creates a Blender server on localhost at a desired port number (default value is 5000) which will accept a Python command sending through it as a string. I 've created a simple Vocola Extension (DLL file) to be put inside the extension folder for Vocola and its solely feature is just “send a string generated by my voice command to the localhost server at a specified port number”. So I can choose which port number to be use too in case I 'm running multiple server on multiple Blender instance…(I have tried with 2 servers and it was OK to do that).
Why I am doing this? : I found that many times when I use Blender, there are small things that I am too lazy to find or click or look for or whatever… they are part of the UI and all those small icons to toggle for my viewport : Gizmo, Overlay, Wireframe, Modifiers, Viewport Area Type,… bla bla bla…
So I came up with this solution: Use my voice to toggle all of those things on/off for a specific area under my mouse pointer or ALL areas in my active window so this can be dynamically defined and say out by Vocola voice command.
This is my example command:
gizmo (bigger='+='|smaller='-=') 2..10 = doCommandPort("bpy.context.preferences.view.gizmo_size" $1 "20*" $2,"","");
This will change my Gizmo size dynamically . If I say “gizmo bigger 3” my Vocola variable $1 will be “bigger” and variable $2 will be “3” then the values passing to my doComandPort() function will be “+=” and “20*3” or “60” respectively so Vocola will send this code to Blender:
bpy.context.preferences.view.gizmo_size+=60 at localhost IP 127.0.0.1 at port 5000.
I have made the function to be able to call with specified port number which is stored into Vocola session with Blender :
BlenderCom.SendBLCommand(Variable.Get(bpy) $command, Variable.Get(comPort)). The BlenderCom is my Extension namespace and SendBLCommand is its main function shouting to Blender Command Port addon.
The only limitation of Vocola by now is that it can only send 1 line of string to my extension, so I have to write Python code in the way that not easy to read… I think I can study more C# to re-write the code for my extension and create a new function to read my command string with the extra newline and whitespace character so it can send multiple lines of code to Blender easily in the future. For now… just forget that… this is getting too complex already…
Here is another example of the voice command:
overlay = doCommandPort("window = bpy.context.window;x = " getX() ";y = " getY() ";x = window.width+x if x < 0 else x;y = -1*y if y < 0 else window.height-y;area=next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D' and area.x < x and area.y < y and (area.width+area.x) > x and (area.height+area.y) > y);area.spaces.overlay.show_overlays = -1*(area.spaces.overlay.show_overlays -1)","",""); which is derived from:
import bpy window = bpy.context.window x = getX() y = getY() x = window.width+x if x < 0 else x y = -1*y if y < 0 else window.height-y area=next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D' and area.x < x and area.y < y and (area.width+area.x) > x and (area.height+area.y) > y) area.spaces.overlay.show_overlays = -1*(area.spaces.overlay.show_overlays -1)
Notice the part “import bpy” is missing from my vocola code because every commands will be include this part by another Vocola function in my VCL file before send them out also notice that the getX() and getY() are my Vocola function returning mouse’s coordinate x and y. Which is adapt from Vocola original function like this in my VCL code:
getX() := Eval(Replace(Split(Pointer.GetOffset(WindowInner),',',0),'(','')); getY() := Eval(Replace(Split(Pointer.GetOffset(WindowInner),',',1),')',''));
It requires this library to be included at the head of VCL code:
So basically the command above will toggle the “area.spaces.overlay.show_overlays” with True/False only for the 3DView area under my mouse cursor when I say this command.
Here is my video in action. Please be warned for my bad English… (I am not a good speaker)
To use my extension just call it like this from Vocola code:
Your Voice Command = BlenderCom.SendBLCommand(Command, PortNumber);
Note that you will have to include “import bpy;” in the string for this function to work.
I am still develop most of the code so I will share my VCL file once I fix all bugs and confliction in the commands…
Thanks for reading , I hope this is useful for someone ^ ^.
Also Thanks Paweł Kowalski for create the Blender Command Port…