Add UV package management and volume control feature

Features:
- Add pyproject.toml for UV package management
- Volume control with real-time slider (0-100%)
- Backend volume adjustment with numpy audio scaling
- Volume setting persists in config.json
- Debounced API calls for smooth slider interaction
- Enhanced audio playback with volume multiplier
- Update README with UV installation instructions
- Add volume control documentation

API Changes:
- GET /api/volume - Get current volume setting
- POST /api/volume - Set volume level

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-24 14:43:57 +07:00
parent 753b1bddfa
commit 1657a242fd
3 changed files with 211 additions and 21 deletions

View File

@@ -9,6 +9,7 @@ A Raspberry Pi-based rotary phone system for weddings and events. Guests can pic
- **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
- **HiFiBerry Support**: Optimized for HiFiBerry DAC+ADC Pro audio quality
@@ -43,7 +44,30 @@ git clone https://git.b4l.co.th/grabowski/wedding-phone.git
cd wedding-phone
```
### 2. Install Dependencies
### 2. Install UV (Recommended)
UV is a fast Python package installer and resolver. Install it:
```bash
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)
```bash
# 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
```bash
sudo apt-get update
@@ -51,7 +75,7 @@ sudo apt-get install -y python3-pip python3-pyaudio portaudio19-dev
pip3 install flask numpy RPi.GPIO
```
### 3. Configure HiFiBerry
### 4. Configure HiFiBerry
Run the automatic configuration script:
@@ -62,7 +86,7 @@ chmod +x configure_hifiberry.sh
Or follow the manual instructions in `AUDIO_FIX.md`.
### 4. Test Your Audio
### 5. Test Your Audio
```bash
python3 test_complete.py
@@ -73,7 +97,7 @@ This will test:
- Dial tone generation
- Microphone recording
### 5. Configure GPIO Pin
### 6. Configure GPIO Pin
Edit `rotary_phone_web.py` and set your hookswitch GPIO pin:
@@ -82,7 +106,7 @@ HOOK_PIN = 17 # Change to your GPIO pin number
HOOK_PRESSED = GPIO.LOW # Or GPIO.HIGH depending on your switch
```
### 6. Run the System
### 7. Run the System
```bash
python3 rotary_phone_web.py
@@ -96,21 +120,27 @@ The web interface will be available at:
### Web Interface
The web interface provides three main sections:
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. Greeting Messages
#### 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
- **Delete**: Remove unwanted greetings (cannot delete the active one)
- **Default Tone**: Generate a classic telephone dial tone
#### 3. Recordings
#### 4. Recordings
- **Play**: Listen to recordings directly in the browser
- **Download**: Save recordings to your computer
- **Delete**: Remove unwanted recordings
@@ -131,6 +161,7 @@ wedding-phone/
├── rotary_phone_web.py # Main application
├── test_complete.py # Audio testing script
├── configure_hifiberry.sh # HiFiBerry setup script
├── pyproject.toml # UV/pip package configuration
├── AUDIO_FIX.md # Audio configuration guide
├── README.md # This file
├── .gitignore # Git ignore rules
@@ -279,6 +310,8 @@ The system provides REST API endpoints:
- `GET /api/status` - Phone status JSON
- `GET /api/recordings` - List all recordings
- `GET /api/greetings` - List all greeting messages
- `GET /api/volume` - Get current volume setting
- `POST /api/volume` - Set volume level (0-100)
- `POST /upload_greeting` - Upload new greeting
- `POST /set_active_greeting` - Set active greeting
- `POST /delete_greeting/<filename>` - Delete greeting