1

How can I call a python function from an advanced scripting voice command in Dragon NaturallySpeaking?

I don't want to use a third-party application such as dragonfly or NatLink (paper).

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
  • 2
    Have you tried adding a reference to some Python DLL the MyCommands Editor? – user 99572 is fine May 26 '17 at 15:22
  • @user99572isfine No, any example is welcome. Or perhaps it could be easier if Dragon advanced scripting could execute some command as if it was executed in the terminal. – Franck Dernoncourt May 27 '17 at 01:01
  • 1
    I'd like to get direct references to py DLL. Could @user99572isfine explain more with examples? Examples using vbs should be somewhat close . . . – PGilm May 31 '17 at 20:29
  • 1
    Btw, why couldn't you execute it in a terminal? You can open one up, send it the keys and enter, etc. But again, the problem is getting the return value back in Dragon (which you could do if you could call the function itself). – PGilm May 31 '17 at 20:31
  • @PGilm yes as you said the terminal has some limitations – Franck Dernoncourt May 31 '17 at 20:45
  • @PGilm Q: Does Python, when installing on Windows, create a DLL file somewhere? Can't figure it out.Could you provide me with a file path? – user 99572 is fine May 31 '17 at 22:00
  • Hmmm. Closest I can find is called "`pythoncom27.dll`" -- perhaps exposes the COM? In the "`Python27\Lib\site-packages\pywin32_system32`" folder – PGilm May 31 '17 at 22:06
  • @PGilm I did collect what I know in an "answer". Please see if any of this is useful. – user 99572 is fine Jun 01 '17 at 09:32

2 Answers2

2

So, one way is to compile it. You can put a bunch of functions that do different things all into the same program and pass along appropriate arguments to select the function you want, and pass the parameters along. Returning the result can be tricky, though, but I usually use the Clipboard (so copy the py output to clip and read from clip in Dragon). Multi-word params need to have spaces escaped (%20) and process it inside your py.

Something like this:

 ShellExecute "path\program.exe myFunc myPar1, my%20Par%202", 6  ' 6 runs minimized
 Wait 1
 myVar = Clipboard

Hth,

PGilm
  • 2,262
  • 1
  • 14
  • 26
1

Warning: This is not an answer. I am not a programmer. I don't know any Python and have no way of testing it.

This is just a suggestion on how to solve this problem. I don't know where else to put this. I'd put it in a comment, but it allows no screenshots. Please edit and suggest as you wish.

  1. There is answer on SO that deals with calling Python from Excel, which is a similar concept: https://stackoverflow.com/a/3569988/2101890. I am trying to use that here but don't know how.

  2. When using commands in another programming language, you can sometimes add them by adding a reference in the MyCommands Editor. You can reference DLLs and other "stuff". Some references to libraries appear automatically. I've installed Python and hoped to find Python in the References, but no such luck:

enter image description here

There is no Python entry here that I can find. You may have better luck. If you do find something, check the box and see if you can add python commands without causing an error when saving the command.

enter image description here

Maybe you can browse to %localappdata%\Programs\Python\Python36\ and add some of the DLLs from there and call Python commands from there. Or try getting it to work in the way described under 1.

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501