Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
11.96k stars 579 forks source link

noises feature stopped working in mojave? #2011

Closed Madd0g closed 5 years ago

Madd0g commented 5 years ago

The noises feature doesn't work for me anymore in Mojave. This is the gist of what I'm doing in my code, it used to work in 10.11 but I upgraded to 10.14 and the callbacks no longer fire.

local noiseCallback = {
    [1] = function() hs.alert.show("start!") end,
    [2] = function() hs.alert.show("finish!") end,
    [3] = function() hs.alert.show("you did it!") end,
}

noisesListener = hs.noises.new(function(noiseType)
    noiseCallback[noiseType]()
end)

local mod = {}

function mod.start()
    noisesListener:start()
end

function mod.stop()
    noisesListener:stop()
end

hs.hotkey.bind(cah, "y", function()
    hs.alert.show("listening")
    noisesListener:start()
end)

Thanks

latenitefilms commented 5 years ago

Maybe this is something @trishume can help with?

trishume commented 5 years ago

Darn. I haven't upgraded to Mojave yet but I will soon and then I might be able to reproduce this and possibly fix.

Madd0g commented 5 years ago

When I first tried this feature, I thought it wasn't very useful, I could only produce the 'sssss' sound, so how useful could it be if I could only trigger one thing with it?

But then I realized since there's a start and end event, I could track the duration and do something useful with it. So I started building a morse code thingy where longer hissing meant a different event and you could associate a hissing pattern to an action.

So I built most of the initial logic for my idea and then sadly upgraded to mojave so I never finished the actual thing I imagined. Recently I got that itch again, so I gave it a UI that I'm triggering with a modifier key.

I'm patient, but I really want to try hissing at this UI. I've been dreaming about this for a year.

asmagill commented 5 years ago

Huh, I used to use that module some a couple of machines ago, but hadn't really used it recently... I can confirm that it no longer seems to work in Mojave.

Taking a quick look at the Security and Privacy settings panel, I'm going to guess that Hammerspoon needs to be given access to the microphone, but I don't see a way to add it manually, so we'd need to find a way to trigger the request... @cmsj or @latenitefilms, any thoughts? @trishume did you ever get a chance to try it out in Mojave?

latenitefilms commented 5 years ago

I've never actually tried hs.noises, but...

In theory, macOS should automatically prompt the user for access if Hammerspoon requires microphone access. It's possible that if you've updated your machine from High Sierra to Mojave, that something could have gone funky with permissions? You could try resetting your microphone permissions by triggering tccutil reset Microphone from Terminal.

If you're running Hammerspoon from Xcode, I believe you must have the NSMicrophoneUsageDescription key in the Info.plist for the notification to actually trigger. I've added a pull request here: #2172

It might also be worth adding a function for requestAccessForMediaType:completionHandler: to hs.sound?

latenitefilms commented 5 years ago

When executing the following code with the #2172 pull request code, I get the attached notification.

noises = hs.noises.new(function(result) 
    print(string.format("Result: %s", result))
end):start()
Screen Shot 2019-09-08 at 8 32 08 pm

...which seems to fix the issue:

2019-09-08 20:30:39: Welcome to the Hammerspoon Console!
You can run any Lua code in here.

2019-09-08 20:30:42: -- Lazy extension loading enabled
2019-09-08 20:30:42: -- Loading ~/.hammerspoon/init.lua
2019-09-08 20:30:42: init.lua loaded
2019-09-08 20:30:42: -- Done.

> noises = hs.noises.new(function(result) 
    print(string.format("Result: %s", result))
end):start()
2019-09-08 20:32:03: -- Loading extension: noises

2019-09-08 20:33:04: Result: 1
2019-09-08 20:33:04: Result: 2
2019-09-08 20:33:39: Result: 1
2019-09-08 20:33:40: Result: 2
2019-09-08 20:33:40: Result: 1
2019-09-08 20:33:40: Result: 2
2019-09-08 20:33:41: Result: 1
2019-09-08 20:33:41: Result: 2
trishume commented 5 years ago

You can also check out https://talonvoice.com/ which is a scriptable input system which I worked with to integrate my noise recognizers, and then the author of Talon optimized them to use Accelerate.framework SIMD functions so it uses even less CPU.

Madd0g commented 5 years ago

@trishume - I am actually very interested in the idea of voice coding. I recently remembered that 2013 pycon video and I just did a couple of days research about what's available these days. I really liked the idea of connecting it to HS and doing all the automation in lua, but it seems like all these systems have their own scripting engines.

talonvoice looks cool, I love the idea of combining the hisses with regular voice commands. I'll check it out. I wonder how usable it is without dragon.

Thanks

Madd0g commented 5 years ago

I tried talonvoice, it's an amazing tool.

I managed to send the hiss events back to hammerspoon from talonvoice. It's a bit awkward because it communicates via hammerspoon:// urls which feels a bit slow, but it works.

trishume commented 5 years ago

I recommend trying to do everything within Talon, it's very powerful and all the hot reloading and things will work better and quicker that way. Talon can do basically everything Hammerspoon can, although it may not be documented and you have to look at examples or ask in the Talon Slack.

Madd0g commented 5 years ago

Talon can do basically everything Hammerspoon can

I am too invested in HS, it's not even funny how reliant I am on it. I can't imagine going back and rewriting everything in python.

Most of the things I need are not time sensitive, so I can accept some slowness due to talon>HS communication. I wonder if an applescript API in HS would have been better than hammerspoon:// urls for communication.

Madd0g commented 5 years ago

can confirm that 0.9.76 fixes the problem, thanks!

muescha commented 1 year ago

@Madd0g I have seen your screencast. very interesting. Is your hammerspoon config somewhere public available? I would like to look also into your hs.noises morse code setup

Madd0g commented 1 year ago

@muescha - for the only other person in the world who thinks it's cool - I took the time and created a gist

You can attach any function to a sequence of hisses, it of course has limitations (cannot redefine the same partial pattern), but there's still lots of freedom with combinations of SHORT-MEDIUM-LONG hiss patterns.

I cleaned up a little and removed dependencies on my other code, I was careful but cannot guarantee I didn't forget to remove something, I did not test it, but should work (fingers crossed).

PLEASE if you get it to work, provide some feedback! I only showed it to like 3 people in the entire world, with not enough appreciation in my opinion 🤣 It's hard to find the right cross section of people that can appreciate something like that lol

Sorry if it's not nice lua. I'm only a hobbyist with lua, only ever used it for hammerspoon, nothing else

EDIT: Also, I'm not afraid to admit that I can hiss but can't do the other "pop" sound (that is a whole extra feature), so my morse code thingy only supports hissing, but if you can manage the pop sound that's a cool feature to add that is currently unsupported! Support is partially there, for me the pop just alerted "you did it!"... but I could never do it.

muescha commented 1 year ago

@Madd0g thx a lot