Skip to content

Instantly share code, notes, and snippets.

@PRosenb
Last active November 25, 2020 21:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PRosenb/2ce5159a334af203fca7ef06501775f0 to your computer and use it in GitHub Desktop.
Save PRosenb/2ce5159a334af203fca7ef06501775f0 to your computer and use it in GitHub Desktop.
Forward audio from BlackHole to the output device.
#!/usr/bin/env python
import sounddevice as sd
import sys
# Download the pkg file of BlackHole
# https://github.com/ExistentialAudio/BlackHole/releases
# Install BlackHole
#
# Install sounddevice
# pip install sounddevice --user
#
# Make file executable
# chmod +x ./forwardSound.py
#
# Click on Mac volume control (on top) and choose 'Output Device': 'BlackHole 16ch'
#
# Check with the following command what name the Built-in Output device has
# python -m sounddevice
sd.default.device = 'BlackHole 16ch', 'Built-in Output'
def callback(indata, outdata, frames, time, status):
if status:
print(status)
outdata[:] = indata
with sd.Stream(channels=2, callback=callback):
print('#' * 80)
print('press Return to quit')
print('#' * 80)
if sys.version_info[0] < 3:
raw_input()
else:
input()
@seabass9
Copy link

Hi, thank you for creating this. I'm testing this to see if I can get audio output to my speakers from the BH device like this:
sd.default.device = 'BlackHole 16ch', 'MacBook Pro Speakers'

I am sending output from DjayPro (but also tried Tidal) to the BH device.
but all I get is: "output underflow"

any ideas?

@PRosenb
Copy link
Author

PRosenb commented May 27, 2020

Mmmm.. Does it work when you use 'Built-in Output'?
Sometimes I also see "output underflow". Possibly it even works but is not loud enough?

@seabass9
Copy link

I've been playing with this a bit, also testing the wire.py example script. I'm sending audio from Tidal/DjayPro into the BH device. My goal would be to get that audio from BH output to the speakers. But still getting no audio at all so far.

@PRosenb
Copy link
Author

PRosenb commented May 27, 2020

Good luck mate. Please let us know if you get it to run.

@seabass9
Copy link

OK, couldn't get that to run, but was able to use GarageBand to get the BlackHole --> MacBook Pro Speakers working and that's enough for my needs at this time. Thank you!

@karlthorssen
Copy link

THANK YOU FOR THIS @PRosenb

@seabass9 and others trying to get it running - couple of things to check:

  • Need to have numpy installed, run the command python3 -m pip install numpy. Numpy is kind of a power tool we might not strictly need here, would be cool if somebody changed the code so it could run without numpy. Seems to be supported by sounddevice but I already had numpy so I didn't try it.
  • Make sure you are using the same python 3 install both to install packages and run the script. You can be sure by running it like,
         python3 -m pip install numpy sounddevice --user
         python3 ./forwardSound.py```
    

Also, I needed a little lower latency as I was using this to monitor myself playing keys while I stream online (ableton -> blackhole 1/2 for OBS, 3/4 for monitor) so I tweaked a few things that helped in my case: https://github.com/karlthorssen/monitor.py

@PRosenb
Copy link
Author

PRosenb commented Nov 25, 2020

In the meantime, there is a nice solution available if you like to control the volume of e.g. optical audio output.
For such cases, I recommend Proxy Audio Driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment