- Quickstart
- Step-By-Step Guide
- Install/import Packages & Set API Key
- Audio Configuration & Global Variables
- Define Function to Find Blackhole Audio Device Index
- Websocket Event Handlers
- Open Websocket
- Handle Websocket Messages
- Close Websocket
- Websocket Error Handling
- Begin Streaming STT Transcription
- Troubleshooting
Transcribe System Audio in Real-Time (macOS)
This guide solves the challenge of transcribing system audio, which is can be used for transcribing media content or online calls. By using virtual audio devices, you’ll learn how to easily pipe system audio to AssemblyAI’s transcription API on both Mac and Windows.
The key to success lies in creating a virtual input device that captures your speaker output and converts it into an input stream. This approach allows you to bypass the limitations of direct system audio access.
For Mac Users: We recommend using BlackHole, a free open-source tool available through Homebrew. BlackHole creates a virtual audio device that can route your system audio to AssemblyAI’s API seamlessly.
For Windows Users: Virtual Audio Cable (VAC) is a popular option. While we don’t provide specific Windows instructions in this guide, VAC offers similar functionality to BlackHole for the Windows environment.
Quickstart
Step-By-Step Guide
Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up and get your API key from your dashboard.
Install/import Packages & Set API Key
Install the package pyaudio.
Import packages and set your API key.
Audio Configuration & Global Variables
Set all of your audio configurations and global variables. Make sure that you have the parameter format_turns set to True.
Define Function to Find Blackhole Audio Device Index
Define a function called get_blackhole_device_index, which retrieves the device index for your BlackHole virtual input device.
Websocket Event Handlers
Open Websocket
Handle Websocket Messages
Close Websocket
Websocket Error Handling
Begin Streaming STT Transcription
Make sure to find the Blackhole device index and to set it to the input_device_index.
You can press Ctrl+C to stop the transcription.
Troubleshooting
-
You need to select BlackHole as your system output device for the audio to be piped correctly
-
If you still need to hear the audio, you can create a multi-output device on Mac that sends audio to both BlackHole and your speakers/headphones Here’s how to set it up: Open “Audio MIDI Setup” (you can find this by searching in Spotlight). Click the ”+” button in the bottom left corner and choose “Create Multi-Output Device”. In the list on the right, check both your regular output (e.g., “MacBook Pro Speakers”) and “BlackHole 2ch”. Optionally, rename this new device to something like “BlackHole + Speakers”. You may need to modify your script to search for this new device.