4

I have a problem with my microphone connectivity using Pycharm. I ran the below code on Spyder and terminal and they were fine. However, on Pycharm, it seemed run without error but just without result as well. I see that both my terminal and Spyder have access to microphone (system preferences -> security & privacy). If anyone knows how to trigger the system to allow microphone connectivity using Pycharm, any answers will be appreciated. Thanks!

I also tried to record my voice using pyaudio and that worked fine with Spyder and terminal, but no audio was recorded if using Pycharm (though the file was created).

simple code:

import speech_recognition as sr
r = sr.Recognizer()

with sr.Microphone() as source:
    print("Speak")
    audio = r.listen(source)
    print("Stop")

try:
    print("You said " + r.recognize_google(audio))
except:
    pass
Matthew
  • 41
  • 2

2 Answers2

2

Even though it is an older question, I stumbled upon the same problem under MacOS. So maybe someone can find this useful:

Problem is that every App running on recent MacOS versions needs permissions for security relevant services, e.g. recording from the microphone. Unfortunately PyCharm did not request the needed permission, and it is not possible to set the permissions by hand. Every app you build and debug with PyCharm does not have those permissions either.

Maybe Jetbrains did already fix this, so be sure to use the latest version. For me, a little workaround did the trick: Just start Pycharm from Terminal, as long as Terminal has the microphone permissions, everything works fine. I did it with a small script:

#!/bin/sh
cd /Applications/PyCharm\ CE.app/Contents/MacOS/
./pycharm
dCb
  • 46
  • 3
0

Make sure that PyCharm also has access to microphones in the settings, and also run PyCharm as administrator when launching it.

ab123
  • 357
  • 4
  • 17