sveinbjornt / hear

Command line speech recognition and transcription for macOS
https://sveinbjorn.org/hear
BSD 3-Clause "New" or "Revised" License
390 stars 24 forks source link

hear works on Terminal, but not on Alacritty: NSSpeechRecognitionUsageDescription key missing. #23

Open rflcrz opened 1 year ago

rflcrz commented 1 year ago

When I run 'hear' from Alacritty it does not ask access to speech recognition and return 'zsh: abort'.

Console.app:

ERROR: This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSSpeechRecognitionUsageDescription key with a string value explaining to the user how the app uses this data.

On the other hand, when I tried to run 'hear' using Terminal.app, it worked perfectly. Terminal asked for access to speech recognition and started outputting the transcribed text.

Apple documentation says that "You must include the NSSpeechRecognitionUsageDescription key in your app’s Info.plist file. If this key is not present, your app will crash when it attempts to request authorization or use the APIs of the Speech framework."(1) Because "This key is required if your app uses APIs that send user data to Apple’s speech recognition servers."(2)

I added to /Applications/Alacritty.app/Contents/Info.plist:

<key>NSSpeechRecognitionUsageDescription</key>
<string>An application in Alacritty would like to access speech recognition.</string>

Now 'hear' exit with:

Error: Speech recognition authorization not determined https://github.com/sveinbjornt/hear/blob/e3247563695cc38bc05953c706c909910fe242d3/src/Hear.m#L114

Does anyone know how to solve this issue? Or have any suggestion?

Thanks!

sveinbjornt commented 1 year ago

Strange issue. The hear binary does contain an embedded Info.plist: https://github.com/sveinbjornt/hear/blob/master/Info.plist

Screenshot 2023-04-25 at 13 15 57

This must be something specific to Alacritty, since everything runs just fine in iTerm and Terminal.app.

sveinbjornt commented 1 year ago

I tried adding NSSpeechRecognitionUsageDescription to Alacritty's Info.plist, and was able to reproduce your result. However, launching Alacritty from the command line in iTerm or Terminal.app works. It looks like subprocesses inherit the permissions of the parent process:

$ /Applications/Alacritty.app/Contents/MacOS/alacritty

At no point does Alacritty appear in this permissions list in Settings despite the changed Info.plist:

Screenshot 2023-04-25 at 13 42 25
hamidzr commented 1 year ago

I haven't figured out why but this lets me use hear directly Alacritty what I did is I launched skhd through alacritty and had it run a script that uses hear. that that point i was asked by the os (13.x) if I wanted to let Alacritty use the speech recognition and I did. Now I can directly call hear in Alacritty and it works fine.

AlienKevin commented 1 year ago

I encountered the same zsh abort issue when running hear in the vscode terminal. Similar to Alacritty, speech recognition permission doesn't list vscode but I don't have a way to request that permission.