Polly is a voice assistant that processes speech and generate responses. It's designed to run on a Raspberry Pi with a button and microphone.
- Button-triggered audio recording
- WebSocket communication with a web app for audio processing
- Audio playback of responses
- Configurable settings via environment variables or command line arguments
- Health monitoring of system components
- Structured logging with operation tracking
- Graceful error handling and recovery
- Mock implementations for development without hardware
- Raspberry Pi (tested on Raspberry Pi 4)
- USB microphone or USB audio interface
- Speaker connected to the headphone jack or USB audio interface
- Push button connected to GPIO pin 17
- LED connected to GPIO pin 27 (optional)
- Raspberry Pi OS (Bullseye or newer)
- Python 3.7+
- Required Python packages (see requirements.txt)
-
Clone the repository:
git clone https://github.com/yourusername/polly.git cd polly -
Install dependencies:
pip install -r requirements.txt -
Create a
.envfile with your configuration (optional):POLLY_HOST=localhost POLLY_PORT=8765 POLLY_BUTTON_PIN=17 POLLY_RECORDING_TIME=5
Run Polly with default settings:
python main.py
python main.py --host localhost --port 8765 --button-pin 17 --debug
Available options:
--host: WebSocket server host (default: localhost)--port: WebSocket server port (default: 8765)--button-pin: GPIO pin for the button (default: 17)--debug: Enable debug logging
All settings can be configured via environment variables:
POLLY_HOST: WebSocket server hostPOLLY_PORT: WebSocket server portPOLLY_BUTTON_PIN: GPIO pin for the buttonPOLLY_AUDIO_CHANNELS: Number of audio channelsPOLLY_AUDIO_RATE: Audio sample ratePOLLY_AUDIO_CHUNK: Audio chunk sizePOLLY_RECORDING_TIME: Recording duration in secondsPOLLY_SOUNDS_DIR: Directory for sound filesPOLLY_STATUS_FILE: Path to status filePOLLY_LOG_FILE: Path to log filePOLLY_LOG_LEVEL: Logging level
main.py: Main application entry pointconfig.py: Configuration managementutils/: Utility moduleslogging_utils.py: Enhanced logging functionalityhealth_monitor.py: System health monitoring
sounds/: Directory for sound filesstart_recording.wav: Sound played when recording startsstop_recording.wav: Sound played when recording stops
The application includes mock implementations for hardware components, allowing development and testing without a Raspberry Pi, button, or audio devices.
Place WAV files in the sounds directory:
start_recording.wav: Played when recording startsstop_recording.wav: Played when recording stops
The application includes a health monitoring system that tracks the status of various components. The status is saved to a JSON file (polly_status.json by default) and can be used to monitor the application's health.
Logs are written to both the console and a log file (polly.log by default). The logging level can be configured via the POLLY_LOG_LEVEL environment variable or the --debug command line option.
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for Whisper and ChatGPT APIs
- Eleven Labs for text-to-speech API
- The Raspberry Pi community