Skip to content

pseudosavant/ps-audio-recorder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

One-Button Audio Recorder

Overview

Headless Raspberry Pi recorder triggered by a Bluetooth HID clicker (or any keyboard) and optionally indicating state via a TP-Link Kasa smart bulb. Audio is captured with arecord and encoded on-the-fly to MP3 using lame. Designed for fast, reliable single-action start/stop with clear visual feedback and easily accessible files (optionally via SMB share).

Designed and tested primarily on a Raspberry Pi Zero 2 W (sufficient CPU for real-time MP3 at preset extreme). It should run on any full-size Raspberry Pi. NOTE: The original Pi Zero W (v1) often cannot keep up with live MP3 encoding at the current quality setting.

Key Features

  • Bluetooth clicker / wireless keyboard toggle (no GPIO wiring)
  • MP3 pipeline: arecord -> lame --preset extreme
  • Auto USB audio capability probing
  • Kasa smart bulb tally (solid red while recording) with state restore
  • Auto-discovery of bulb named "Recording Light" (same subnet)
  • Safe timestamped filenames (audio-recorder-YYYY-MM-DD-HH-MM-SS.mp3)
  • Date-based folder organization (YYYY/MM by default)
  • Auto-stop on Bluetooth device reconnection
  • Systemd friendly, concise logging (/var/log/audio-recorder.log)
  • Tested with Kasa KL125 color bulb

Image

image

Setup (Quick)

git clone https://github.com/pseudosavant/ps-audio-recorder.git
cd ps-audio-recorder
chmod +x setup.sh upgrade.sh
sudo ./setup.sh

The script:

  • Installs required APT packages (ALSA, BlueZ, lame, etc.)
  • Installs/updates Python deps from ps-audio-recorder/requirements.txt
  • Creates /srv/recordings with group permissions
  • Touches/permissions the log file
  • Installs & enables the systemd service
  • Creates /etc/ps-audio-recorder/ps-audio-recorder.env for runtime config overrides (preserved on rerun)
  • Installs ReplayGain watcher service (mp3gain + inotify-tools) that monitors /srv/recordings

Upgrade

Recommended (one command from repo root):

./upgrade.sh

Equivalent manual flow:

git pull --ff-only
sudo ./setup.sh --upgrade

Upgrade mode refreshes Python dependencies and restarts managed services.

After running setup, pair your Bluetooth clicker (most show up as a HID keyboard). If pairing wasn’t done automatically inside the script, you can still use bluetoothctl manually; usually no config changes are needed if the remote emits key code 115 (F14). If not, set PS_AUDIO_TRIGGER_KEY_CODE in /etc/ps-audio-recorder/ps-audio-recorder.env and restart the service.

Bluetooth Clicker

A generic Bluetooth “selfie” / presentation clicker works (appears as a tiny keyboard). These are inexpensive (typically < $5). Example model used for testing: Amazon product link.
Most send a single key code (often 115) which the recorder treats as the toggle.

Kasa Smart Bulb

Automatically searches the local subnet for a TP-Link Kasa bulb whose alias matches Recording Light (Config.BULB_NAME). Tested with KL125. Other color Kasa models should work.

Usage

Manual run (same script systemd uses):

~/ps-audio-recorder/ps-audio-recorder/start-recorder.sh

This script loads /etc/ps-audio-recorder/ps-audio-recorder.env, creates/activates the virtual environment, and launches the recorder.

  • Press the Bluetooth remote button (mapped key code 115) or spacebar (if interactive TTY) to toggle recording.
  • MP3 files appear in /srv/recordings/YYYY/MM/ by default.

Systemd service (installed/enabled by setup.sh):

sudo systemctl status ps-audio-recorder
journalctl -u ps-audio-recorder -f

ReplayGain Auto-Processor

  • Service name: ps-replaygain
  • Watches: /srv/recordings (recursive)
  • Processes: .mp3 files only, skips temp/hidden
  • Tool: mp3gain (track mode, clipping protection, undo metadata)

Commands:

sudo systemctl status ps-replaygain
sudo journalctl -u ps-replaygain -f

Config file (optional): ~/ps-audio-recorder/replaygain-watcher.env See ps-audio-recorder/replaygain-watcher.env.example for fields:

  • WATCH_PATH (default /srv/recordings)
  • RECURSIVE (1)
  • LOG_LEVEL (info|debug|error)
  • PROCESS_MODE (track|album)
  • EXCLUDE_REGEX (temp/partial patterns)
  • NICE_LEVEL, IONICE_CLASS (resource knobs)

Enable verbose logs (optional)

echo 'LOG_LEVEL=debug' | sudo tee -a ~/ps-audio-recorder/replaygain-watcher.env
sudo systemctl restart ps-replaygain
sudo journalctl -u ps-replaygain -n 100 --no-pager

Configuration (/etc/ps-audio-recorder/ps-audio-recorder.env)

Adjust:

  • PS_AUDIO_SAMPLE_RATE / PS_AUDIO_AUDIO_FORMAT fallback
  • PS_AUDIO_TRIGGER_KEY_CODE (remote key)
  • PS_AUDIO_BULB_NAME (default Recording Light)
  • PS_AUDIO_RECORDING_EXTENSION (mp3)
  • PS_AUDIO_TIMESTAMP_FORMAT / PS_AUDIO_RECORDING_PREFIX
  • PS_AUDIO_RECORDING_SUBDIR_FORMAT (default %Y/%m)
  • PS_AUDIO_RECORDING_DIR / PS_AUDIO_LOG_FILE

Apply changes:

sudo systemctl restart ps-audio-recorder

Recording Details

Pipeline example:

arecord -r 48000 -t wav -f S32_LE -c 2 ... | lame --ignorelength --preset extreme --silent - file.mp3

Troubleshooting (Condensed)

  • Remote not toggling: run sudo evtest to confirm key code; update PS_AUDIO_TRIGGER_KEY_CODE in /etc/ps-audio-recorder/ps-audio-recorder.env and restart the service.
  • Audio device: arecord -l to verify card presence.
  • Empty/short MP3: check log for early arecord or lame exit.
  • Bulb not found: confirm alias, same subnet, run python -m kasa discover.
  • ReplayGain: ensure packages mp3gain and inotify-tools are installed; verify watch path exists and owned by pi.

Hardware / Performance Notes

  • Zero 2 W and larger Pis: OK at --preset extreme.
  • Original Zero W: likely too slow; lower quality (e.g. -V5) or record WAV then transcode offline.

License

MIT (see LICENSE).

Author

© John Paul Ellis (https://github.com/pseudosavant)

About

One-button Raspberry Pi audio recorder—Bluetooth clicker toggles live MP3 capture with optional smart-bulb recording indicator.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors