Add audio resampling utility and scipy dependency

- Created resample_audio.py utility script
  - Automatically reads target sample rate from config.json
  - Resamples all WAV files in sounds directory
  - Creates .backup files before modifying originals
  - Handles both mono and stereo audio
  - Uses scipy.signal.resample for high-quality resampling

- Added scipy>=1.7.0 dependency to pyproject.toml
- Updated Makefile sync command to include scipy
- Updated README.md with sample rate troubleshooting section
- Updated config example in README to show 48kHz default
- Added beep_sound configuration to README system section

This resolves sample rate mismatch errors when audio files
don't match the configured rate in config.json.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-27 13:02:39 +07:00
parent 52b8348a03
commit 30ac7e89e9
4 changed files with 190 additions and 2 deletions

View File

@@ -97,6 +97,7 @@ Web interface available at: `http://<raspberry-pi-ip>:8080`
- pyaudio>=0.2.13
- RPi.GPIO>=0.7.1
- waitress>=2.1.0 (production WSGI server)
- scipy>=1.7.0 (audio resampling utility)
## Installation
@@ -506,7 +507,7 @@ The `config.json` file contains all system settings:
"chunk_size": 1024, // Audio buffer size
"format": "paInt16", // Audio format (16-bit)
"channels": 1, // Mono audio
"sample_rate": 44100, // 44.1kHz sample rate
"sample_rate": 48000, // 48kHz sample rate
"max_record_seconds": 300 // Max recording time (5 minutes)
},
"paths": {
@@ -527,6 +528,8 @@ The `config.json` file contains all system settings:
"system": {
"active_greeting": "dialtone.wav", // Default greeting
"extra_button_sound": "button_sound.wav", // Default button sound
"beep_sound": "beep.wav", // Recording start beep
"beep_enabled": true, // Enable beep before recording
"greeting_delay_seconds": 0, // Delay before greeting plays (0-10)
"volume": 70 // Default volume (0-100)
}
@@ -597,6 +600,39 @@ Look for your HiFiBerry device and note its index number, then set it in `config
4. Check IP address: `hostname -I`
5. Try localhost: `http://127.0.0.1:8080`
### Audio Sample Rate Mismatch
If you see errors like `Expression 'paInvalidSampleRate' failed` or warnings about sample rate mismatches:
1. **Check your config.json sample rate** (default is 48000Hz):
```json
"audio": {
"sample_rate": 48000
}
```
2. **Resample your audio files** to match the configured rate:
```bash
# Using the provided resampling script
python3 resample_audio.py
# Or manually with ffmpeg
ffmpeg -i input.wav -ar 48000 output.wav
```
3. **Delete default sounds** to regenerate at correct rate:
```bash
rm rotary_phone_data/sounds/dialtone.wav
rm rotary_phone_data/sounds/beep.wav
# These will be regenerated at startup
```
The `resample_audio.py` utility will:
- Automatically detect the target sample rate from `config.json`
- Create `.backup` files before modifying originals
- Resample all WAV files in the sounds directory
- Preserve stereo/mono and bit depth
### Configuration Errors
If the script won't start: