Skip to content

Instantly share code, notes, and snippets.

@PRosenb
Last active November 25, 2020 21:15
Show Gist options
  • 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()
@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