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.

2 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.

4 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.