macOS Menu Bar App to Control Transcription
This guide explains how to create a macOS menu bar application using Python that:
- Lists available audio input devices such as BlackHole or built-in microphones.
- Allows device selection from the menu bar.
- Launches a transcription script using the selected device.
- Opens a window to show live transcribed text.
Prerequisites
- Python 3.8 or newer
- macOS
- Install dependencies:
pip install pyobjc sounddevice
File Structure
menu_app.py
: macOS menu bar app using PyObjC.transcribe.py
: Your transcription script. It must accept--device
argument and output transcription text to stdout.
Instructions
-
Set Up the Menu Bar App
Use
NSStatusBar
from PyObjC to create a status item in the macOS menu bar. -
List Input Devices
Use
sounddevice.query_devices()
to get available audio input devices. Filter for devices withmax_input_channels > 0
. -
Generate a Menu for Devices
For each input device, create a menu item. When clicked, this sets the selected device.
-
Start Transcription
Use
subprocess.Popen
to run the transcription script with the selected device passed as--device
. Capture stdout for real-time transcription. -
Open Transcription Window
Create a
NSWindow
with aNSTextView
wrapped in aNSScrollView
. Display transcription output here. -
Stop Transcription
Terminate the subprocess and close the transcription window.
-
Quit App
Add a Quit menu item that terminates the app and subprocess if running.
Running the App
Launch the app using:
python menu_app.py
Look for the “Transcribe” menu in the macOS menu bar. Select an input device, start transcription, and see the output in a separate window.
Notes
- Ensure
transcribe.py
prints transcribed text to stdout. - The menu bar item must have a title or icon to be visible.
- Use read-only
NSTextView
inside a scroll view for clean text display.