A lightweight Python-based monitoring tool that continuously checks audio input levels and sends email alerts if silence is detected.
Designed for production or remote environments where reliable audio monitoring is essential.
- Detects audio silence and audio restoration in real time.
- Sends email alerts and reminder emails (with log attachments).
- Detects current city and country automatically through geolocation.
- Refreshes location every 12 hours or on application restart.
- Automatically retries email sending up to three times on connection errors.
- Works with any audio input recognized by
sounddevice. - Includes log rotation and optional attachment of recent log data.
AudioLossMonitor/ │ ├── monitor_audio.py # Main monitoring script ├── audio_utils.py # Core helper functions (RMS, email, geolocation, etc.) ├── config.py # Centralized configuration and environment loading ├── .env # Environment variables (email credentials, etc.) ├── audio_monitor.log # Generated runtime log └── test_audio_utils.py # Optional tests
EMAIL_FROM=you@example.com EMAIL_TO=primary@example.com,backup@example.com SMTP_SERVER=smtp.gmail.com SMTP_PORT=587 EMAIL_USER=you@example.com EMAIL_PASS=your_app_password
- List devices:
python monitor_audio.py --list-devices - Run monitor:
python monitor_audio.py --device <index> - Calibrate thresholds:
python monitor_audio.py --device <index> --calibrate 5 - Start Monitoring
python monitor_audio.py --device 1 --silence-threshold-db -36 --clear-threshold-db -20
- Example:
- [City, Country] [Microphone (USB Audio Device)] Audio Loss Alert
[City, Country] [Microphone (USB Audio Device)] Audio Restored
- Clone the repo:
git clone https://github.com/deemamahmud/Audio.git cd AudioLossMonitor - Create and activate a virtual environment:
python -m venv venv venv\Scripts\activate # Windows - Install dependencies:
pip install -r requirements.txt - Configure environment:
- Copy
.env.exampleto.envand fill in your email credentials and settings. - Edit
config.pyfor thresholds and options if needed.
- Copy
- Use app-specific passwords or OAuth2 for email.
- Never commit
.envwith real credentials to public repos.
- Check status:
git status - Add changes:
git add . - Commit:
git commit -m "Add docstrings and README" - Push:
git push origin main
- If email is not sent, check logs in
audio_monitor.log. - If audio device errors occur, use
--list-devicesto select a valid device.
MIT