1

I have a NSMenu coming down under a NSStatusItem. I also have a NSSpeechRecognizer. When the NSMenu is open, the speech recognizer does not function properly. It will constantly show that it's receiving sound, until I close the menu. I need it to detect sound properly even while the menu is open.

How can I make the speech recognizer detect sound even while the menu is open? Does it need to become a "first responder" and take precedence over the menu?

I tried setting [speechRecognizer setListensInForegroundOnly: NO] and it still won't work.

If you don't understand, I am more than happy to provide clarification.

Here are some similar situations, but I don't yet fully understand.

Community
  • 1
  • 1
Hope4You
  • 1,927
  • 4
  • 21
  • 45

1 Answers1

2

The problem is most likely that the menu is running a modal run loop as long as it is open (for the purposes of tracking the mouse, etc...) and this is blocking the NSSpeechRecognizer's ability to function normally.

You can confirm this by bringing up the menu and then pausing into the debugger. You'll likely see two run loops; the outer, normal, one and one deeper down the stack that is running the modal loop.

In general, this is kind of an odd thing to do from a user interaction perspective. The whole point of a pop-up menu is to offer the user some commands that will be done after the corresponding menu item is selected.

If you really need "click this thing and recognize voice", I'd recommend a button that, maybe, pops up a bit of UI and then interacts with the speech recognizer without using a menu?

bbum
  • 162,346
  • 23
  • 271
  • 359
  • Is there any way to place the `NSSpeechRecognizer` onto a separate thread so that its delegate does not become blocked while waiting for the menu to close? Or is there any way so that the menu doesn't block the main thread? – Hope4You Nov 05 '12 at 18:33
  • Not unless the API is documented as allowing exactly that. Same goes for NSMenu; it is an implementation detail of the menu because it really isn't intended to be used as you are using it. – bbum Nov 05 '12 at 19:00
  • Thank you for this helpful information. I've decided to use an `NSPopover` instead of a menu to solve this problem. – Hope4You Nov 06 '12 at 22:51