Tutorial: What the *bleep*?

in /var/log

Is that build you are fixing still failing? Can’t sudo your way into ssh-ing into the company mainframe? Frustrated and want to vent out over a Zoom call, but worried you can’t swear freely in front of co-workers?

Welcome, stranger, to this part of the internet, where I will be your guide in setting up a keyboard shortcut which will play a bleep sound over your voice so that your train of thought remains uninterrupted and your colleagues ears protected from foul language.

I'm here to help!
I'm here to help!

You will need

  • One computer running MacOS
  • Hammerspoon
  • A virtual audio in/out device
  • 5 minutes
  • (optional) An external microphone, because MacBook mics sound terrible

Step 1

You need a virtual audio device, there’s no way around that. For this example, we will use the BlackHole 2 channel. At the time of writing it is free of charge. Don’t worry, it works fine on both Intel and Apple Silicon macs. Just go to the page and follow the instructions to download and install the 2 channel virtual device (16 channel should work fine too).

Step 2

Launch Spotlight and type Audio MIDI Setup. Open the app and look in the bottom left corner for the + symbol. Hit that and then Create aggregate device.

Name that device whatever you want, the important part is that you select both your microphone and the virtual BlackHole 2ch device. Make sure Drift correction is checked for BlackHole 2ch.

Right-click on the newly created Aggregate Device in the sidebar and select Use This Device For Sound Input. You should see that device when you hold Option and click on the sound icon in the taskbar

Step 3

Get a bleep sound from the internet or download the one I use from my Hammerspoon config GitHub repo.

Step 4

Download and install Hammerspoon. It is a free and open source tool for automating Macs with Lua. Once you have it installed, fire up a terminal:

$ mkdir -p ~/.hammerspoon && touch ~/.hammerspoon/init.lua

Now open ~/.hammerspoon/init.lua with your favourite text editor and type this in:

-- Obviously, change the path to point to your local copy of the bleep sound
local bleep = hs.sound.getByFile("/Users/muxcmux/.hammerspoon/bleep.mp3")

bleep:volume(0.1)

-- This is the UID of my microphone. To find yours, open the Hammerspoon
-- console by clicking on the taskbar icon and then "Console..."
-- To get a list of all devices:
-- hs.audiodevice.allDevices()
-- To get the UID of the first one:
-- hs.audiodevice.allDevices()[1]:uid()
-- .. yes, Lua tables are 1-indexed, because *bleep* you
local mic = hs.audiodevice.findDeviceByUID("AppleUSBAudioEngine:CMEDIA:Q9-1:2222000:1")

-- This should be the same for you if you used the default installation
-- method for the BlackHole 2channel device from step 1, otherwise just
-- use the above mentioned method to obtain the virtual device uid
bleep:device("BlackHole2ch_UID")

local function censor_start()
  mic:setInputMuted(true)
  bleep:play()
end

local function censor_end()
  bleep:stop()
  mic:setInputMuted(false)
end

-- Use whatever shortcut you want, the bits between the squggly braces are
-- modifiers and "escape" is the key, so to map it to ctrl+alt+f for example:
-- hs.hotkey.bind({"ctr"}, "F", censor_start, censor_end)
hs.hotkey.bind({"ctrl", "shift", "alt"}, "escape", censor_start, censor_end)

From the hammer icon on the taskbar select “Reload config”. If you made errors, you’d get a Hammerspoon notification telling you so. To view the errors and correct them, open the console.

Test

Fire up QuickTime, File->New Movie Recording. Make sure to select the “Aggregate device” (or whatever name you gave it) from the drop-down list next to the red dot. If things worked out, you should be able to press and hold the shortcut for a bleep sound to mask your filthy speech.

The end

That was it. Credits to Mike for making me put a how-to online for other people to enjoy swearing with reduced chances of getting fired.

Note: You have to always select the Aggregate device as input from other apps, otherwise you risk your swear words being heard!

Note 2: Not all apps support aggregate devices, e.g. you need to use Zoom from a browser.