How to Implement Voice Control/Triggers for KM Macros

I don't recall if this has been discussed before, so I'll mention it here. You can use your voice to trigger Keyboard Maestro macros. I do it every day to trigger some of my macros. Here's an example. I have a simple/free App Store game called Pool and I can trigger it by creating a small Automator script which is triggered by the macOS dictation assistant. Here's what the Automator script looks like:

(Actually I don't have a macro in KM called "Play Pool", I just typed this in as an example. Hopefully I made no typos.)

To make this work you have to have macOS dictation enabled, which is in the "System Preferences" and looks like this:

From there if you click on "Dictation Commands" make sure you have the checkbox called "Enable Advanced Commands" checked. I am omitting that screenshot from this message but you can easily find it.

As you can see able, you have to say "Computer" before you speak, but if you uncheck that box you can even avoid saying that word. (a macOS voice recognition popup box stays on the screen then, which I find annoying, so I say the keyword "Computer" instead.)

Another relevant window to get this to work is the System Preferences / Keyboard / Dictation window. As shown here:

I turned on the Enhanced Dictation (which downloads a huge file from Apple in order to do voice recognition locally. I'm not sure if it's a requirement for all this to work. I downloaded it years ago and haven't gone back.)

About once a day macOS gets quite badly stuck on voice recognition and it seems to require a reboot. Sometimes it can be resolved by turning dictation off and on, but sometimes a reboot is required. There are discussions about this issue online but I don't think anyone has a perfect solution for this yet. I could give tips on this problem in a follow up post if anyone is interested.

The macOS voice recognition is good quality, but not as good as SIRI. I'd estimate it interprets me correctly about 95% of the time.

Naturally I'm hoping that some future version of KM can hook into macOS so a voice command can be used to trigger a KM macro. This might be difficult for Peter to implement, but it seems in keeping with the philosophy of KM to make simple ways to trigger sophisticated macros, like the recently implemented trackpad gesture triggers.

3 Likes

That would be way cool. How 'bout it Peter @peternlewis? Can you put this on our wish list?

It is on the todo list already.

5 Likes

I use Alexa to trigger an IFTTT, which creates a OneDrive file in a folder my KM macro watches. It takes a couple of seconds, but I can trigger it from any room. I mostly use it to control iTunes and the AirPlay speakers.

That's cool. I, too, use files in folders to trigger KM (including the timestamp on the file to pass information). There is some commercial software I've bought that creates an audio file whenever it hears sound above a certain threshold. And I have KM monitoring that folder for files. In this way KM is triggered whenever the volume is above a certain level in my house. Basically I'm simulating a volume trigger, eg, "If volume is above X decibels then activate this macro."

That is very interesting. I like to adjust the volume, depending on various situations, such as working from home, listening to Audiobooks, softly in background, loud when I'm in the mood, etc. I've set up AppleScripts to adjust the volume and disbursement of the AirPlay speakers. The KB macros call the AppleScripts. Some of them are set by day of the week or time of the day or other circumstances. I can also trigger them with Alexa voice commands.

My speakers are HomePods so I don't think I need to use your approach since (with my Apple Music subscription) I can ask SIRI directly for music actions like Play, Pause, go back, etc. I can even interrupt a song playing with questions like "Hey Siri, who plays the guitar in this song?" or "Hey Siri, when was this song released?" Apple has an API called SIRIkit which applications like KM (hint, hint) can interface with to perform actions within an application. I'm not sure if customers of KM want to be able to say things like "Trigger the Macro: Play Pool" but that's the sort of thing SIRIkit can do. Personally I'd even like the KM web interface to be SIRIkit enabled to allow me to use voice control to control KM from outside my home, but I really don't sense that Peter would do that - maybe in KM version 11.

I want to be able to click my middle mouse button instead of saying "Computer." Is this possible? I can use Logitech Options to map my middle mouse button to a keystroke (or to various other actions). The problem is that when I set it up to say "Computer" before issuing a command, the command works reliably. But when I don't say "Computer" and only enable dictation (by pressing Fn twice, for example) then I have to say the command three or four times before the Mac recognizes it. So the ideal would be to press the mouse middle button and have Logitech Options press a keystroke that makes Keyboard Maestro say "Computer" to the computer. Is that possible?
P.S. Keyboard Maestro's "Speak Text" action doesn't seem to work. I guess the computer doesn't listen to itself when it speaks.

As for your "P.S. comment", I'll test that myself. It's a good idea. As for your main comments, my first suggestion is "reboot". As I said in my original post, voice recognition can get corrupted. Reboots can fix that. My gut tells me that you can't achieve what you are trying, but I'll give it some thought. I never tested the Fn Fn trigger.

Sleepy, Have you tested my "P.S. comment"?

Here is another example @Sleepy & @bburd how to use Siri for KM macros. But then from the iPhone or iPad. Because they are 99% within my call range... no problem for me :wink:

Sorry for the slow response. My house has HomePods and iPhones which DO respond to commands from the "Speak Text" action. Perhaps that helps you out a bit. However you appear to be right, I can't get the Accessibility mode to recognize sound from the Mac itself. It seems to ignore its own sound output. That's a very good idea you had, and I wish I had thought of it myself.

So I thought I'd try to trick it by going to the Preferences and changing the output of my computer to be my HomePod, with my accessibility/dictation feature still enabled. Guess what, something odd happens. When I issue the KM Action to "Speak Text" the action starts speaking (correctly through my HomePod) but then cuts out. I have a feeling that this isn't really a bug in KM, although at first glance it looks that way. I think there's something deeper going on here that KM can't fix. But then when I disable Accessibility/Dictation then KM works fine.

I think it's a legit question to ask PeterNLewis, why the Speak Text action fails to speak more than one second of text when Dictation is enabled in macOS. But I think KM is not at fault here. It's probably built-in to macOS as a feature. I'm not sure if that feature can be disabled. That would take someone a lot smarter than me to answer.

I would like KM to be enhanced to be able to activate macros by voice from KM. The reason I want this is because I am a high-level quadriplegic. I have no use of my limbs. I operate my computer completely hands-free using Dragon Professional Individual (DPI) for Mac. DPI for Mac was discontinued in October 2018. I have been able to continue to use DPI for Mac up until Catalina. I used DPI for Mac through macOS Big Sur beta. Unfortunately when macOS Big Sur release came out DPI for Mac became unstable. Because of this I am trying to move to macOS Voice Control. When I connect to work using XenDesktop, where I control my work computer using Dragon Professional Individual for Windows, I need to disable macOS Voice Control which I could do using macOS Voice Control. The problem is once Voice Control is off I need to somehow enable it again when I leave my work computer. Unfortunately there's no way to do this at the moment hands-free. If KM was modified to activate macros by voice I could have KM enable macOS Voice Control.

Hopefully this makes sense. If not, I will be happy to try to explain it again.

Greetings

I agree that having this built-in to KM would be ideal

But right now you can activate KM macros by voice - I just gave it a try.

Create a custom voice command using the instructions on this page https://support.apple.com/en-mt/guide/mac-help/mchl3eb7b79a/mac . Then have the action be to open a URL. Then set up your KM macro to be triggered by URL and make that the URL executed by your voice command. It works well.

image

@rkaplan I have already created a macOS Voice Control command to trigger a KM macro. But I need a way of being able to turn on macOS Voice Control by voice. That's why I'm requesting KM to add a new activation type for by voice. Then I can use KM to turn our macOS Voice Control. Sorry if that was not clear in my original post.

Doesn't Accessibility voice control stay on once turned on?

@rkaplan please reread my original post to understand my use-case.

OK I see the issue now

Two suggestions:

(1) There are a number of ideas in this thread on how to turn voice control on/off on the Mac. It can be done via an Applescript; you can save the Applescript as an App.

Could you write one Applescript which turns on your Dragon dictation and turns off Mac dictation. Then another one which turns on Mac dictation and turns off Dragon dictation?

(2) Do you have an iPhone or iPad with accessibility features turned on, i.e. the Grid to control the iPhone/iPad by voice? If so then you could use the iOS version of Keyboard Maestro. With it you could use voice control on the iPhone or iPad to execute any Macro currently on Keyboard Maestro on your Mac. I suspect this is the most fail-proof solution. One of the macros you execute by voice on iOs could even be an Applescript to turn Mac voice recognition on or off.

@rkaplan thanks for the suggestions. I do have an iPhone and an iPad that have Voice Control enabled. I did not know there was a way to use KM on iOS to execute KM macros on a Mac. If you have a link that documents the setup please share it with me. I would like to give it a try.

By the way "Hey Siri" can enable/disable Voice Control if you simply say "Hey Siri turn on voice control" or "Hey Siri turn off voice control". The unfortunate thing about this is the mac mini doesn't support "Hey Siri" and you cannot invoke "Hey Siri" on a laptop when the lid is fully closed. 2 more of my use-cases and the reason I'm looking for a KM solution.

It is a regular app available for iPhone or iPad

1 Like