Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac Mic Stream only giving indata as 0's #267

Closed
vineyugave opened this issue Jul 27, 2020 · 7 comments
Closed

Mac Mic Stream only giving indata as 0's #267

vineyugave opened this issue Jul 27, 2020 · 7 comments

Comments

@vineyugave
Copy link

I am using a streamer like this

self.audio_streamer = sd.Stream(device=self.input_device, channels=self.channels,
                                        samplerate=self.sampling_rate, dtype='int16',
                                        callback=self.update_audio_feed, blocksize=self.audio_block_size,
                                        latency='low')



def update_audio_feed(self, indata, outdata, frames, time, status):
        print("update_audio_feed")
        if status:
            print(status, file=sys.stderr)

        print(indata)
        outdata.fill(0)


Output :

The indata is an array with 0's always from the callback.
update_audio_feed
[[0]
 [0]
 [0]
 ...
 [0]
 [0]
 [0]]

Sounddevice is detectingt the mic fine but not getting the signal :
Device Info: {'name': 'MacBook Pro Microphone', 'hostapi': 0, 'max_input_channels': 1, 'max_output_channels': 0, 'default_low_input_latency': 0.04852607709750567, 'default_low_output_latency': 0.01, 'default_high_input_latency': 0.05868480725623583, 'default_high_output_latency': 0.1, 'default_samplerate': 44100.0}
Sampling rate: 44100.0 

Any ideas what is going on ? I checked that PortAudio is installed fine ..

@mgeier
Copy link
Member

mgeier commented Jul 27, 2020

I'm not a macOS user myself, but I've heard about problems with the microphone permissions on macOS.

Maybe this helps: https://www.reddit.com/r/MacOS/comments/9lwyz0/mojave_not_privacy_settings_blocking_all_mic/

@mgeier
Copy link
Member

mgeier commented Jul 27, 2020

Same question on SO: https://stackoverflow.com/q/63109391/

@mattgwwalker
Copy link
Contributor

Hi,

I'm no expert, but I've been using sounddevice without major issues on a number of Macs for a few months now, and I've not touched anything to do with permissions in my code (my users have however clicked "yes" when asked on, for example, OSX10.15).

Firstly, have you tried the wire.py example? That works out of the box for me.

Two things that I noticed in your code:

  • I haven't tried specifying the blocksize. I have only used the default value of 0. I could well believe that may be causing you issues.
  • You've specified a "low" latency Stream. At the very least on OSX10.13 this produces very unstable audio (lots of input underflows). If stable audio is important to you, I would recommend you consider latency options higher than "high". For reference, Audacity uses 100ms and obtains stable audio.

Hope that helps,

Matthew

@mattgwwalker
Copy link
Contributor

(Oh, and input underflows often produce input with all zeros.)

@mattgwwalker
Copy link
Contributor

@vineyugave I think I may just have reproduced the same issue as you had.

I have not had a problem at all with sounddevice until I attempted to code-sign my application. Now, on Catalina (OSX 10.15.6), I too am getting nothing from the microphone. The code works fine on OSX10.13.6, but even after adding the com.apple.security.device.microphone entitlement, I am not getting anything from the mic.

Is this the same scenario as you were having? Did you find a solution?

@mattgwwalker
Copy link
Contributor

mattgwwalker commented Aug 3, 2020

However, I was able to get the microphone to work when I gave my app the com.apple.security.device.audio-input entitlement. I haven't yet tried it in the Sandbox.

It also required the com.apple.security.cs.allow-unsigned-executable-memory because of the use of old-school callbacks in sounddevice (see #270).

@vineyugave
Copy link
Author

Issue on my Mac was a permission / security issue .. when I ran the python script throught Visual Studio Code console it did not work .. But when I ran it through mac Terminal it prompted for mic access and it started working ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants