Using voice command to send ANY Python code directly to Blender: Blender Command Port

Refer to the previous topic : https://blenderartists.org/t/my-voice-command-in-blender-which-maybe-useful-for-someone-with-disabilities-or-rsi-like-me/1150016

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[0].overlay.show_overlays = -1*(area.spaces[0].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[0].overlay.show_overlays = -1*(area.spaces[0].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:
$using Library.String;

So basically the command above will toggle the “area.spaces[0].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)
https://www.youtube.com/watch?v=czlMDC_OEhQ

If anyone want to try this then you can find my extension from this link:
BlenderComPort.dll
and get the command port addon from this link : https://github.com/p4vv37/blender_command_port

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…

2 Likes

This was an idea I had back in the days.

Having these two ideas combine perhaps will lead to something very useful.

Hi rootaman,

This is something i want to do for a long time since i was plague by RSI frequently in the past but i don’t understand how vocola work and there is no good tutorials on how to do this.

For non programmers people this seem way too complicated and it’s a shame since it can speed up modeling tremendously even for people without disability.

Well, you can start reading more about Vocola 3.1 from the Author’s website: http://vocola.net/v3/. It is well documented there and Vocola language is easy to write even for someone not a programmer like me (I am working as a graphic desinger.).

My tips is this: dont use normal microphone and onboard soundcard…
Your PC should have a decent sound card (onboard one is not recommended for speech recognition) + Good wired microphone (noice cancelling is a much preferable choice) OR a decent USB microphone (no need for sound card here)
I am using Andrea USB-SA soundcard (it is a portable USB one) with Audio Technica Pro8HE. This is the best microphone at the lowest price you can find. There are more comfortable one from another brand too if you look for speech recognition mic.

Another tip is: Edit your Windows Speech Recognition (WSR) dictionary words to prevent it from wrong recognition on your command. There is a section for adding a word to prevent it from being dictated (dictation is like typing each letter in the recognized word to the program we use but we need to activate the voice command not typing a text so in this case we need to prevent a word from dictation). I build up my WSR profile time by time and share it across my working PC at many places without any problem.

There is more detail on how to use Vocola with Blender since I got a consistent SHIFT key problem in Blender so I end up using AutoHotKey to solve it.

So you may need to read my instruction here before trying to test my VCL code
https://docs.google.com/presentation/d/1r8yvDUzqVJZsknqr0CdXrX5EvWdHxUovpPknLYHspDQ/edit?usp=sharing

You can get my sample (900 lines of code there) VCL commands from this Gumroad link. (Free)
https://gum.co/BlenderVCL it is a version without using the Command Port but all the information from this post should be enough for you to adapt them for Command Port.

1 Like

Those bunches of buttons may not suite me well (I am having RSI) ^ ^’ but thanks for another idea.

If you have RSI you might find other ways to minimize hand movement, especially moves with mouse that strain.

Voice commands might be one way to do.

Using a mid-size stylus, might be a good idea to replace mouse as much as possible. As for example doing simple photo editing or moving things around. Not quite precise though in comparison to a mouse, mouse feels like superior in control, but perhaps gives the idea of being a little more easy on the use.

However about anatomically correct mouse devices, trackballs, touchpads, touchscreens, would seem good choices, but is rather unavoidable to spend money and test them yourself first hand.

Using 3DAxis device for viewport navigation, though I haven’t used one yet, this is my top pick, considering most of the input actions are related to viewport navigation, only a few with really related to actual work on the canvas. Imagine how many movements you could save.

I 've been using mouse for over 10 years then I switched to trackball and some pen tablet. I used to have 3D mouse but found it not working well in Blender (laggy & not enough buttons or too expensive for the PRO one) so I tried with Sony PlayStation Move controller which can be held by one hand and I found it was the best control over the previous devices!
The good thing for this game controller is that I can reach all buttons without even the need to look at them and its layout is MORE hand-friendly to me.

1 Like