Features: - Configurable extra button on any GPIO pin - Upload and select custom sound for button press - Non-blocking button operation (separate thread) - Debounced to prevent double-triggers (0.5s) - Works independently from phone handset - Can be pressed anytime, even during recording Configuration: - gpio.extra_button_enabled: Enable/disable feature - gpio.extra_button_pin: GPIO pin number (default: 27) - gpio.extra_button_pressed_state: "LOW" or "HIGH" - system.extra_button_sound: Default sound file Web Interface: - Display active button sound in alert - "🔘 Set Button" action on greeting items - Visual indicator (🔘) for active button sound - Upload any WAV file and assign to button - Play/preview button sounds in browser Backend: - RotaryPhone.play_extra_button_sound() method - RotaryPhone.set_extra_button_sound() method - Thread-based playback to not block main loop - /set_extra_button_sound API endpoint - Extra button sound tracked in user_config.json Documentation: - Extra button setup in README - Configuration examples - GPIO pin configuration - Operation workflow Use Cases: - Play special message on button press - Sound effects for wedding games - Multiple interaction points - Custom audio triggers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Wedding Phone - Vintage Rotary Phone Audio System
A Raspberry Pi-based rotary phone system for weddings and events. Guests can pick up the handset to hear custom greeting messages and leave voice recordings. Features a modern web interface for managing messages and recordings.
Features
- Vintage Phone Integration: Uses a real rotary phone with GPIO hook detection
- Custom Greeting Messages: Upload multiple greeting messages and select which one plays
- Voice Recording: Automatically records guest messages after the greeting
- Web Interface: Beautiful, responsive web UI for managing the system
- Audio Playback: Play recordings and greetings directly in the browser
- Volume Control: Adjust playback volume with real-time slider (0-100%)
- Multiple Message Support: Upload and manage multiple greeting messages
- Active Message Selector: Choose which greeting plays when the phone is picked up
- Extra Button Support: Optional GPIO button to play custom sounds on demand
- HiFiBerry Support: Optimized for HiFiBerry DAC+ADC Pro audio quality
- Real-time Status: Monitor phone status (on-hook/off-hook/recording)
- Auto-refresh: Status updates every 5 seconds
Hardware Requirements
- Raspberry Pi (3/4/5 or Zero 2 W)
- HiFiBerry DAC+ADC Pro (or similar audio interface)
- Vintage rotary phone with hookswitch
- Speaker (connected to HiFiBerry output)
- Microphone (connected to HiFiBerry input, or use phone handset mic)
Software Requirements
- Raspberry Pi OS (Bullseye or newer)
- Python 3.7+
- Required Python packages:
- pyaudio
- flask
- numpy
- RPi.GPIO
- wave (built-in)
Installation
1. Clone the Repository
git clone https://git.b4l.co.th/grabowski/wedding-phone.git
cd wedding-phone
2. Install UV (Recommended)
UV is a fast Python package installer and resolver. Install it:
curl -LsSf https://astral.sh/uv/install.sh | sh
# Or on Raspberry Pi with pip:
pip3 install uv
3. Install Dependencies
Option A: Using UV (Recommended)
# Install system dependencies
sudo apt-get update
sudo apt-get install -y python3-pyaudio portaudio19-dev
# Install Python dependencies with UV
uv pip install -e .
Option B: Using pip
sudo apt-get update
sudo apt-get install -y python3-pip python3-pyaudio portaudio19-dev
pip3 install flask numpy RPi.GPIO
4. Configure HiFiBerry
Run the automatic configuration script:
chmod +x configure_hifiberry.sh
./configure_hifiberry.sh
Or follow the manual instructions in AUDIO_FIX.md.
5. Create Configuration File
Copy the example configuration and customize it:
cp config.example.json config.json
nano config.json # or use your preferred editor
Important settings to configure:
{
"gpio": {
"hook_pin": 17, // GPIO pin for hookswitch
"hook_pressed_state": "LOW", // "LOW" or "HIGH"
"extra_button_enabled": true, // Enable extra button feature
"extra_button_pin": 27, // GPIO pin for extra button
"extra_button_pressed_state": "LOW" // "LOW" or "HIGH"
},
"audio": {
"device_index": 1, // HiFiBerry device index
"sample_rate": 44100
},
"paths": {
"base_dir": "./rotary_phone_data" // Relative or absolute path
},
"web": {
"port": 8080
}
}
Finding your audio device index:
python3 -c "import pyaudio; p=pyaudio.PyAudio(); [print(f'{i}: {p.get_device_info_by_index(i)[\"name\"]}') for i in range(p.get_device_count())]"
6. Test Your Audio
python3 test_complete.py
This will test:
- Speaker playback
- Dial tone generation
- Microphone recording
7. Run the System
python3 rotary_phone_web.py
The web interface will be available at:
http://localhost:8080http://<raspberry-pi-ip>:8080
Usage
Web Interface
The web interface provides four main sections:
1. Phone Status
- Shows current phone state (on-hook/off-hook/recording)
- Displays active recording filename
- Auto-refreshes every 5 seconds
2. Volume Control
- Adjust Volume: Drag slider to set playback volume (0-100%)
- Real-time visual feedback with percentage display
- Changes apply immediately to greeting playback
- Volume setting persists across restarts
3. Greeting Messages
- Upload: Click "Choose WAV File(s)" to upload one or multiple greeting messages
- Play: Click "▶️ Play" to preview any greeting in your browser
- Set Active: Click "⭐ Set Active" to select which greeting plays when the phone is picked up
- Set Button: Click "🔘 Set Button" to assign sound to extra button (if enabled)
- Delete: Remove unwanted greetings (cannot delete the active one)
- Default Tone: Generate a classic telephone dial tone
4. Recordings
- Play: Listen to recordings directly in the browser
- Download: Save recordings to your computer
- Delete: Remove unwanted recordings
- Statistics: View total recordings, storage used, and total duration
Phone Operation
- Guest picks up phone: System detects via GPIO
- Greeting plays: Active greeting message plays through speaker
- Recording starts: After greeting, system records guest message
- Guest hangs up: Recording stops and saves automatically
- Ready for next call: System returns to waiting state
Extra Button Operation (Optional)
If enabled in config.json:
- Guest presses button: System detects GPIO signal
- Sound plays: Configured button sound plays through speaker
- Non-blocking: Button can be pressed anytime, even during recording
- Debounced: 0.5s delay prevents accidental double-presses
File Structure
wedding-phone/
├── rotary_phone_web.py # Main application
├── test_complete.py # Audio testing script
├── configure_hifiberry.sh # HiFiBerry setup script
├── config.example.json # Example configuration (copy to config.json)
├── pyproject.toml # UV/pip package configuration
├── AUDIO_FIX.md # Audio configuration guide
├── README.md # This file
├── .gitignore # Git ignore rules
└── templates/ # Auto-generated on first run
└── index.html # Web interface (embedded in script)
Runtime Data (Auto-created)
rotary_phone_data/ # Default location (configurable)
├── recordings/ # Voice recordings from guests
├── sounds/ # Greeting message WAV files
└── user_config.json # Runtime settings (volume, active greeting)
Configuration
All configuration is done via the config.json file. No need to edit Python code!
Configuration File Structure
The config.json file contains all system settings:
{
"gpio": {
"hook_pin": 17, // GPIO pin number for hookswitch
"hook_pressed_state": "LOW", // "LOW" or "HIGH" depending on switch
"extra_button_enabled": true, // Enable optional extra button
"extra_button_pin": 27, // GPIO pin for extra button
"extra_button_pressed_state": "LOW" // Button pressed state
},
"audio": {
"device_index": 1, // Audio device index (run test to find)
"chunk_size": 1024, // Audio buffer size
"format": "paInt16", // Audio format (16-bit)
"channels": 1, // Mono audio
"sample_rate": 44100, // 44.1kHz sample rate
"max_record_seconds": 300 // Max recording time (5 minutes)
},
"paths": {
"base_dir": "./rotary_phone_data", // Data directory (relative or absolute)
"recordings_dir": "recordings", // Subdirectory for recordings
"sounds_dir": "sounds" // Subdirectory for greeting sounds
},
"web": {
"port": 8080, // Web interface port
"max_upload_size_mb": 50 // Max upload file size
},
"system": {
"active_greeting": "dialtone.wav", // Default greeting
"extra_button_sound": "button_sound.wav", // Default button sound
"volume": 70 // Default volume (0-100)
}
}
Finding Your Audio Device
To find your HiFiBerry or other audio device index:
python3 -c "import pyaudio; p=pyaudio.PyAudio(); [print(f'{i}: {p.get_device_info_by_index(i)[\"name\"]}') for i in range(p.get_device_count())]"
Look for your HiFiBerry device and note its index number, then set it in config.json.
Troubleshooting
No Sound from Speaker
-
Check HiFiBerry configuration:
aplay -l # List audio devices amixer -c 3 sset Digital 100% # Set volume (adjust card number) -
Test speaker directly:
speaker-test -D plughw:3,0 -c 1 -t wav -
Run the complete test:
python3 test_complete.py
Microphone Not Recording
- Check microphone is connected to HiFiBerry input
- Adjust input gain:
alsamixer -c 3 - Test recording:
arecord -D plughw:3,0 -f cd test.wav -d 5 aplay test.wav
GPIO Not Detecting Hookswitch
- Verify GPIO pin number in
config.json - Check if switch is normally open or closed
- Update
hook_pressed_stateinconfig.json("LOW" or "HIGH") - Test with a simple script:
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) print(GPIO.input(17)) # Should change when switch toggles
Web Interface Not Accessible
- Check if Flask is running:
ps aux | grep python - Verify port in
config.jsonmatches URL - Check firewall:
sudo ufw allow 8080(or your configured port) - Check IP address:
hostname -I - Try localhost:
http://127.0.0.1:8080
Configuration Errors
If the script won't start:
- Ensure
config.jsonexists (copy fromconfig.example.json) - Validate JSON syntax:
python3 -m json.tool config.json - Check all paths exist or can be created
- Verify audio device index is correct
Auto-start on Boot
Create a systemd service:
sudo nano /etc/systemd/system/wedding-phone.service
Add (replace /path/to/wedding-phone with your actual path):
[Unit]
Description=Wedding Phone Service
After=network.target sound.target
[Service]
Type=simple
User=pi
WorkingDirectory=/path/to/wedding-phone
ExecStart=/usr/bin/python3 /path/to/wedding-phone/rotary_phone_web.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable wedding-phone.service
sudo systemctl start wedding-phone.service
sudo systemctl status wedding-phone.service
API Endpoints
The system provides REST API endpoints:
GET /- Web interfaceGET /api/status- Phone status JSONGET /api/recordings- List all recordingsGET /api/greetings- List all greeting messagesGET /api/volume- Get current volume settingPOST /api/volume- Set volume level (0-100)POST /upload_greeting- Upload new greetingPOST /set_active_greeting- Set active greetingPOST /delete_greeting/<filename>- Delete greetingGET /play_audio/<type>/<filename>- Stream audio fileGET /download/<filename>- Download recordingPOST /delete/<filename>- Delete recordingPOST /restore_default_sound- Generate default dial tone
Contributing
Feel free to open issues or submit pull requests for improvements.
License
This project is open source and available for personal and commercial use.
Credits
Created for wedding events to capture guest messages in a unique, nostalgic way.
Support
For issues or questions, please open an issue on the repository.