KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Activating WSRMacro voice commands via Keyboard Shortcut
Topic Summary: Does anyone have coding for using a .vbs to EmulateRecognition a WSRMacro?
Created On: 06/28/2020 03:00 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Activating WSRMacro voice commands via Keyboard Shortcut   - NiptheZephyr - 06/28/2020 03:00 PM  
 Activating WSRMacro voice commands via Keyboard Shortcut   - NiptheZephyr - 06/28/2020 03:01 PM  
 Activating WSRMacro voice commands via Keyboard Shortcut   - Ag - 06/28/2020 05:15 PM  
 Activating WSRMacro voice commands via Keyboard Shortcut   - NiptheZephyr - 06/28/2020 05:30 PM  
 Activating WSRMacro voice commands via Keyboard Shortcut   - Lunis Orcutt - 08/08/2020 04:59 PM  
 Activating WSRMacro voice commands via Keyboard Shortcut   - Mav - 07/02/2020 03:05 AM  
 Activating WSRMacro voice commands via Keyboard Shortcut   - NiptheZephyr - 07/25/2020 07:52 PM  
 Activating WSRMacro voice commands via Keyboard Shortcut   - Tiger Feet - 08/08/2020 11:21 AM  
Keyword
 06/28/2020 03:00 PM
User is offline View Users Profile Print this message

Author Icon
NiptheZephyr
New Member

Posts: 5
Joined: 06/28/2020

TL;DR

 

My goal is to run a .vbs file with code that will send a text string to WSR to be recognized as speech input. I know it's a bass-ackwards thing to do, but I'm trying to play around w/ WSRMacros in my freetime at home, and looking for a quiet/silent way to test out my scripting without distracting my wife when we are talking or waking her up if it's late at night.

 

Full Story:

 

First off, I want to say that this is my frist post to the KnowBrainer forums, and I want to say thank you to everyone on here. I've been creeping on here for a few years, and have found the communities knowledgebase incredible, and everyone very helpful and friendly in their posts. Also, if there is a clearer way to post the below code in the forum, please let me know.

 

I started off using DNS Medical just for dictation a few years ago, got into it's advanced scripting to develop efficient macros for our old EMR, and then tried to find something similar to do for repetitive tasks at home. This past year I've picked up a bit of VBScript, using Notepad ++ to code and desktop shortcuts assigned to keyboard combinations to run it.  I recently started to use WSR and WSRMacros to create similar, voice activated macros, but as I noted up in the TL;DR, I can't casually test my scripts without being rude to the people I'm around if we are just hanging out together, and so I wanted to pick your (know)brains. I'm trying to craft a vbscript that will use EmulateRecognition to send a string, interpreted as speech, to WSR/WSRMacros, so I can set it as a keyboard shortcut.

 

I know one can access the SAPI as an object to use it's methods, based upon the below:

 

Set Sapi = Wscript.CreateObject("sapi.SpVoice")
i = 1
do
Sapi.speak i
i=i+1
loop while (i<=5)

 

Based off of this link: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms723609(v=vs.85)

 

It looks like there are a few more methods under SpVoice that one can call, but I'm not seeing those as any viable options for putting text as speech into the system. Higher up on the contents section on the left, it looks like SpVoice falls under the Automation heading. Looking through all the other Objects, the ISpeechRecognizer contains the method EmulateRecognition. ISpeechRecognizer is not described as an Object, but the coding higher on the page shows it being created as one. So, I tried the following:

 

Set Sapi = Wscript.CreateObject("SAPI.SpSharedRecognizer")
Sapi.EmulateRecognition("Start Listening")

 

Which doesn't give me any errors, but won't activate the WSR to start listening. This site: https://www.autohotkey.com/boards/viewtopic.php?t=8389, states that it only runs within the application using the EmulateRecognition command, which in this case would be Notepad++. I've tried numerous other iterations, with the same result. I took them from the docs.microsoft.com corresponding pages and their code snippets. For example:

 

1. Set Sappy = Wscript.CreateObject("Sapi.SpSharedRecoContext")
re"> Set myGrammar = Sappy.CreateGrammar
re"> myGrammar.DictationSetState SGDSActive
re"> Sappy.Recognizer.EmulateRecognition ("Blip Blue")

 

I've tried confirming that the stuff is actually running with the below codes, but given my limited coding knowledge am unsure if it's actually checking the state, or I'm just setting a variable to be something that returns as true:

 

1. Set Sapi = Wscript.CreateObject("Sapi.SpSharedRecognizer")
Set Sappy = Wscript.CreateObject("Sapi.SpSharedRecoContext")
    Set myGrammar = Sappy.CreateGrammar
    myGrammar.DictationSetState SGDSActive
Sapi.EmulateRecognition ("start listening")
    If Sappy.State = SRSActive Then
MsgBox "Is Active"
Else
MsgBox "Is Not Active"
End If
'Returns "Is Not Active"

 

2.Set Sapi = Wscript.CreateObject("Sapi.SpSharedRecognizer")
Set Sappy = Wscript.CreateObject("Sapi.SpSharedRecoContext")
    Set myGrammar = Sappy.CreateGrammar
    myGrammar.DictationSetState SGDSActive
Sapi.EmulateRecognition ("start listening")
Sappy.State = SRSActive
    If Sappy.State = SRSActive Then
MsgBox "Is Active"
Else
MsgBox "Is Not Active"
End If
'Returns "Is Active"

 

 

I also used Microsoft Office's VBA editor's Object Browser to try to find some other Objects/methods to try. My computer apparently has a SapiCS 1.0 Library in it's references, which appears to belong to the WSRMacros program, however trying to CreateObject those is a complete failure, with the following error:

 

"Could not locate automation class named "xxx"

 

Where xxx has been:

 

1. "SapiCS.CSpApplication" used with 

 

Set Sapi = Wscript.CreateObject("SapiCS.CSpApplication")
Sapi.MsgBox("Blip Blue")

 

Where SapiCS was the library and CSpApplication was the class.

 

2. "SapiCS.ISpRecognizer" used with 

 

Set Sapi = Wscript.CreateObject("SapiCS.ISpRecognizer")
Sapi.MsgBox("Blip Blue")

 

Where SapiCS was the library and ISpRecognizer was the class.

 

3. "SAPI.CSpApplication" used with

 

Set Sapi = Wscript.CreateObject("SAPI.CSpApplication")
Sapi.MsgBox("Blip Blue")

 

Where SapiCS was the library and CSpApplication was the class, in my jenky version of playing around with the library.

 

So there you have it. It's broke me, I have to admit I've hit a wall, and has finally caused me to create an account to ask the forums instead of just searching through it for bits of knowledge. Any guidance anyone can provide would be much appreciated. If it's just "this is impossible", fair enough, but an explanation of why would be nice to help grow my knowledge base. Sorry for the incredibly long post, just wanted to walk you through what I've already explored. 

 

V/r,

 

NiptheZephyr

 

 

 

 



Statistics
32000 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 2 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 563 guests browsing this forum, which makes a total of 565 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2021 FuseTalk™ Inc. All rights reserved.