Hammerspoon / hammerspoon

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

hs.speech.listener does not seem to ever execute callback function #888

Closed Korolen closed 7 years ago

Korolen commented 8 years ago

Hi,

I'm very excited to try and get hs.speech.listener working and migrate my commands from Dragon, but I can't get it to actually operate. This is my test code, and the callback function never seems to be executed:

`hs.logger.setGlobalLogLevel(5) log = hs.logger.new("speech", "verbose") require('hs.speech.listener')

listener = hs.speech.listener.new()

-- hs.speech included because looking at the code for listener non-string, non-number value should produce a warning; but it doesn't seem to listener:commands({"test", hs.speech, "cat"}) listener:blocksOtherRecognizers(true)

listener:setCallback(function(l, s) log.i('callback executed', l, s) end)

log.i('starting listener') listener:start() hs.logger.setGlobalLogLevel(5)`

I'm able to get the command window to show, with "test" and "cat" in it. The microphone meter shows the microphone is picking up sound. 'starting listener' shows up in the console.

But 'callback executed:' never does show up. Also strange, the hs.speech value included in the list of commands does not produce a warning, as expected.

Any ideas? @asmagill, do you have any thoughts? Happy to perform any diagnostics that might be useful.

Thanks, –Tom

asmagill commented 8 years ago

Are you running the latest release or a locally built version of Hammerspoon? When I try the above in my console, I get the following:

> hs.logger.setGlobalLogLevel(5)
log = hs.logger.new("speech", "verbose")
require('hs.speech.listener')

listener = hs.speech.listener.new()

-- hs.speech included because looking at the code for listener non-string, non-number value should produce a warning; but it doesn't seem to
listener:commands({"test", hs.speech, "cat"})
listener:blocksOtherRecognizers(true)

listener:setCallback(function(l, s)
log.i('callback executed', l, s)
end)

log.i('starting listener')
listener:start()
hs.logger.setGlobalLogLevel(5)
-- Loading extension: logger
-- Loading extension: speech
20:51:07 ** Warning:   LuaSkin: not a string or number value, skipping
             speech: starting listener

20:51:10     speech: callback executed hs.speech.listener: (null) (0x7fedfbe66d90) test
20:51:12     speech: callback executed hs.speech.listener: (null) (0x7fedfbe66d90) cat

> listener:stop()
hs.speech.listener: (null) (0x7fedfbe66d90)

Which appears to be working...

I sort of recall reading something about having Enhanced Dictation enabled in the Speech and Dictation preferences panel helps... can't find the reference now, and it wasn't in the Apple docs for the NSSpeechRecognizer class, so YMMV or I may be remembering wrong... It is enabled on my setup, so you might check as shown in this picture and also try adjusting the microphone's input volume under the Sound preferences panel.

screen shot 2016-04-28 at 8 59 23 pm

Background noise also makes a huge difference in how effective it is.

I'll take a closer look at the code later and see if we can enable additional logging or if any other ideas come to mind.

asmagill commented 8 years ago

@korolen, is this still an issue for you? If we need to update the docs to include the "Use Enhanced Dictation" field, I'm happy to do so, if that fixed it for you.

cmsj commented 7 years ago

(closing due to no response. please re-open if you disagree :)