bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
689 stars 70 forks source link

No Input on OS X #39

Closed nmagerko closed 5 years ago

nmagerko commented 5 years ago

I have the following code that I'm trying to run on OS X 10.14.1 (Mojave) via Python 3.7.0. It is essentially taken from the tutorial:

import soundcard as sc

mic = sc.default_microphone()
data = mic.record(samplerate=48000, numframes=48000)

When I inspect data, it's an array of all -0.'s, and this is true for other sample rates too. I've checked the microphone being used and it is the built-in microphone as expected, and the built-in microphone seems to be picking up my voice when I speak into it from the OS X System Preferences menu.

Any ideas about what's going wrong? I have restarted my machine and tried the pysoundcard library as well, but the same thing is happening. I can provide debug information as needed.

bastibe commented 5 years ago

This is probably related to #36. Apparently, Apple changed something in Mojave that broke SoundCard. It is good to know that this affects PySoundCard (and therefore, pulseaudio), too, though. I'll see if the portaudio guys know a solution.

nmagerko commented 5 years ago

As it turns out, the issue is not this library at all. The actual issue is the terminal application I was using (iTerm).

OS X requires that applications receive user approval before granting them access to hardware like the microphone. Unfortunately, iTerm doesn't request access (even though the underlying script it's running needs access to it), and so things fail silently.

Luckily the built-in Terminal application handles this correctly. When I ran the code I wrote in there, I was prompted to allow access to my microphone and everything worked out. Sorry for the confusion!