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

 

 

 

 



 06/28/2020 03:01 PM
User is offline View Users Profile Print this message

Author Icon
NiptheZephyr
New Member

Posts: 5
Joined: 06/28/2020

Gaa, sorry for the formatting, don't know why it knocked out all the returns.
 06/28/2020 05:15 PM
User is offline View Users Profile Print this message

Author Icon
Ag
Top-Tier Member

Posts: 449
Joined: 07/08/2019

Originally posted by: NiptheZephyr Gaa, sorry for the formatting, don't know why it knocked out all the returns.

I find that in this web.forum I need to provide 2 newlines to get  paragraphs properly separated by a blank line.

 

 e.g. there is a completely blank "paragraph"  between this paragraph and the previous

 

 but between this paragraph and the next I will only do a single newline

 there is only a single newline, no blank paragraph, between this and the previous



-------------------------

DPG15.6 (also DPI 15.3) + KB, Sennheiser MB Pro 1 UC ML, BTD 800 dongle, Windows 10 Pro, MS Surface Book 3, Intel Core i7-1065G7 CPU @ 1.3/1.5GHz (4 cores, 8 logical, GPU=NVIDIA Quadro RTX 3000 with Max-Q Design.

 06/28/2020 05:30 PM
User is offline View Users Profile Print this message

Author Icon
NiptheZephyr
New Member

Posts: 5
Joined: 06/28/2020

Thanks Ag,

 

Will use it from now on!

 

*Fixed the above formatting.



 08/08/2020 04:59 PM
User is offline View Users Profile Print this message

Author Icon
Lunis Orcutt
Top-Tier Member

Posts: 37997
Joined: 10/01/2006

Originally posted by: Ag
Originally posted by: NiptheZephyr Gaa, sorry for the formatting, don't know why it knocked out all the returns.

 

I find that in this web.forum I need to provide 2 newlines to get  paragraphs properly separated by a blank line.

 

 

 

 e.g. there is a completely blank "paragraph"  between this paragraph and the previous

 

 

 

 but between this paragraph and the next I will only do a single newline

 

 there is only a single newline, no blank paragraph, between this and the previous

 



Tiger nailed it but you have an even faster solution: Place your cursor in the middle of your paragraph (to make it more difficult) and say Paragraph <this is special agent orange from the FBI>. This command will move your cursor to the end of the paragraph, press {Shift+Enter} twice (to create a real paragraph) and simultaneously type “this is special agent orange from the FBI”. Now you're cooking with jet fuel

 



-------------------------

Forum Mission Statement
Trial Downloads
Dragon/Sales@KnowBrainer.com 
(615) 884-4558 ext 1

 07/02/2020 03:05 AM
User is offline View Users Profile Print this message

Author Icon
Mav
Advanced Member

Posts: 198
Joined: 10/02/2008

Hi!

I've also tried invoking built-in commands of WSR (similar to what Dragon's "HeardWord" does), but to no avail.

I think the problem is that you can only emulate recognitions for your own Recognizer instance.

With WSR you can have many independent Recognizers, each with its own set of grammars. So far I haven't found a way to get to the "Desktop instance" grammars.

Basically, you have 2 options with WSR: Create your own recognizer in-process or use the "shared" out-of-process recognizer.

The first one can handle audio input independently for each instance.

The second one shows the UI and automatically handles default audio from the microphone, but apart from that you also get your own instance without any Grammars.

If you add a grammar to recognize "do something" and then call EmulateRecognition("do something"), then you'll get a recognized event from your own grammar, but that won't influence the instance running in the background.

I just found another difference between the in-process and the "shared" engine:

The in-process recognizer will fire SpeechRecognized events even for utterances colliding with built-in commands whereas the shared recognizer won't.

Regards,

mav

 07/25/2020 07:52 PM
User is offline View Users Profile Print this message

Author Icon
NiptheZephyr
New Member

Posts: 5
Joined: 06/28/2020

May,

Thanks for the info. Your info game me some things to play around with, but like you said, wasn't able to get it to work. I'm curious as to if creating one's own grammar, having some code activate WSRMacros, and then using an EmulateRecognition would do trigger any of the .WSRMacro files you have, but I myself don't understand what grammars are enough to do it.

It was a wonderful exercise in learning code and concepts, but I ended up calling it quits. Switched to AutoHotKey, since it still allowed a way to send inputs to activate certain coding and use part of what I type as a variable in the text. Pretty much using a HotString to recognize a typed number to run a loop however many times I specify.

Thanks again.
 08/08/2020 11:21 AM
User is offline View Users Profile Print this message

Author Icon
Tiger Feet
Top-Tier Member

Posts: 1902
Joined: 12/04/2009

Ag,

I see you have KnowBrainer. Instead of saying "New Line" or "New Paragraph," try saying, "Hard Line" or "Hard Paragraph," to get the correct line or paragraph spacing.

I also use these knowbrainer commands when composing a post in Microsoft Word before pasting it into the KnowBrainer forums. This will then give you the correct spaces between lines & paragraphs.

Cheers



-------------------------

Tiger Feet

| DPI 15.3 | KnowBrainer 2017 | Windows  10 Professional /64 Bit | Intel Core i7 Quad Core 3840QM (2.80GHz) 8MB | 16GB RAM. | 240GB Intel 520 Series SSD Boot Drive | 750GB 7200 rpm Secondary Drive  | Sennheiser D10-USB Wireless. |



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

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