title: How to invoke python sound device package on Built-In Output
body: <p>I am trying to record computer's audio output (not input to the microphone, but input to the speakers - before it leaves the device) on Mac OS X 10.14.1 with python3 and sounddevice.</p>
  
  <p>As you can see from the following traceback, I have tried every sensible number of input channels and default number of input channels, with no luck. I have also looked at the source code, but haven't been able to determine my problem.</p>
  
  <p>Is there a way to record the audio output stream on my system?</p>
  
  <pre><code>Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) 
  [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import sounddevice as sd
  &gt;&gt;&gt; sd.query_devices()
  &gt; 0 Built-in Microphone, Core Audio (2 in, 0 out)
  &lt; 1 Built-in Output, Core Audio (0 in, 2 out)
  &gt;&gt;&gt; sd.default.device = 1
  &gt;&gt;&gt; print("Channels should be 0 (number of input channels) or 2 (number of output channels)")
  Channels should be 0 (number of input channels) or 2 (number of output channels)
  &gt;&gt;&gt; duration = 10
  &gt;&gt;&gt; fs = 44100
  &gt;&gt;&gt; x = sd.rec(int(duration * fs), samplerate=fs, channels=2)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 224, in rec
      ctx.input_dtype, callback, blocking, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 2417, in start_stream
      **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 1301, in __init__
      **_remove_self(locals()))
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 780, in __init__
      'Error opening {0}'.format(self.__class__.__name__))
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 2572, in _check
      raise PortAudioError(errormsg, err)
  sounddevice.PortAudioError: Error opening InputStream: Invalid number of channels [PaErrorCode -9998]
  &gt;&gt;&gt; x = sd.rec(int(duration * fs), samplerate=fs, channels=0)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 224, in rec
      ctx.input_dtype, callback, blocking, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 2417, in start_stream
      **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 1301, in __init__
      **_remove_self(locals()))
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 780, in __init__
      'Error opening {0}'.format(self.__class__.__name__))
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 2572, in _check
      raise PortAudioError(errormsg, err)
  sounddevice.PortAudioError: Error opening InputStream: Invalid number of channels [PaErrorCode -9998]
  &gt;&gt;&gt; x = sd.rec(int(duration * fs), samplerate=fs)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 215, in rec
      ctx.frames = ctx.check_out(out, frames, channels, dtype, mapping)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sounddevice.py", line 2351, in check_out
      'Unable to determine number of input channels')
  TypeError: Unable to determine number of input channels
  </code></pre>