Difficulty: βββββ | Duration: 45 minutes | Gain: Mastering the complete setup of an embedded AI voice assistant
Today, we're diving into something hardcoreβusing a Raspberry Pi to create a voice-interactive AI assistant.
Press a button, ask your question, and the AI's response will stream live on the LCD screen. If you want it to speak, you can also enable TTS voice broadcasting.
This is pizero-openclaw, an open-source voice AI assistant running on a Raspberry Pi. We'll walk through getting it up and running step by step.
Target Audience
- Developers with 1-5 years of experience interested in embedded systems and AI
- Hobbyists looking to build AI hardware
- Students with a basic understanding of Linux command line
TIP
If you haven't encountered OpenClaw yet, it's recommended to check the official documentation to understand the basic concepts, but we'll aim to make this content self-contained.
Core Dependencies and Environment
Before starting, make sure you have the following:
| Category | Requirement | Description |
|---|---|---|
| Development Board | Raspberry Pi Zero 2 W / Pi Zero W | ARM v6/v7 architecture |
| Voice Board | PiSugar WhisPlay | 1.54" LCD, buttons, microphone, speaker |
| Operating System | Raspberry Pi OS Bookworm+ | Python 3.11+ |
| Network | Network environment with access to OpenAI API | For speech-to-text and TTS |
| OpenClaw | Gateway running in an accessible location | Local or cloud-based |
WARNING
The Raspberry Pi Zero series has limited performance and is not recommended for running overly complex tasks. Its strength lies in lightweight interactions in embedded scenarios.
Project Structure
pizero-openclaw/
βββ main.py # Entry file, main loop
βββ display.py # LCD rendering (status, replies, clock)
βββ openclaw_client.py # OpenClaw gateway HTTP client
βββ transcribe_openai.py # Speech-to-text (OpenAI)
βββ tts_openai.py # Text-to-speech (OpenAI)
βββ record_audio.py # Audio recording (ALSA)
βββ button_ptt.py # Button state machine (press to record, release to send)
βββ config.py # Configuration management (.env loading)
βββ sync.sh # Deployment script (rsync + systemd)
βββ .env.example # Configuration example
βββ requirements.txt # Python dependencies
Hardware Preparation
Let's gather all the necessary hardware.
Essential Hardware
| Hardware | Model | Notes |
|---|---|---|
| Development Board | Raspberry Pi Zero 2 W / Pi Zero W | Recommended Zero 2 W for better performance |
| Voice Board | PiSugar WhisPlay | Includes 240x240 LCD, buttons, microphone, and speaker |
| Storage Card | 16GB+ TF card | For flashing the Raspberry Pi system |
| Power Supply | 5V 2A micro USB | Stable power supply is crucial |
Optional Hardware
- PiSugar Battery β Lithium battery module for use without power
- Enclosure β 3D printed or acrylic cut
TIP
PiSugar WhisPlay is a voice AI expansion board specifically designed for the Raspberry Pi Zero series, available for purchase on Taobao/Xianyu.
System Flashing and Initialization
Flashing Raspberry Pi OS
- Download Raspberry Pi Imager
- Choose Raspberry Pi OS (Bookworm) 32-bit or 64-bit
- In advanced settings, enable:
- SSH
- Configure Wi-Fi SSID and password
- Set username
piand password
WARNING
Pi Zero W / Zero 2 W runs on a 32-bit system, it's recommended to use a 32-bit image for better compatibility.
Once the flashing is complete, insert the TF card into the Raspberry Pi and power it on.
First Connection
# Find Raspberry Pi IP on your computer
arp -a | grep raspberry
# SSH connection (default password is raspberry)
ssh [email protected]
After your first login, it's recommended to update the system:
sudo raspi-config
Configure the following options:
- Extend the file system to the entire TF card
- Set the timezone (Localization β Timezone)
- Enable the SPI interface (Interface Options β SPI)
Install Dependencies
Confirm Python Environment
# Check Python version
python3 --version
# Output should be Python 3.11+
# If the version is too low, upgrade it
sudo apt update
sudo apt install python3.11 python3.11-venv
Install System Dependencies
sudo apt install python3-numpy python3-pil python3-pip
Install Python Packages
# Clone the project
git clone https://github.com/your-repo/pizero-openclaw.git
cd pizero-openclaw
# Install dependencies
pip install -r requirements.txt
requirements.txt should look something like this:
requests
python-dotenv
numpy
Pillow
Install WhisPlay Drivers
This step is crucial as the LCD and buttons require drivers to function.
Install the drivers according to the official PiSugar documentation:
# The driver should be installed in /home/pi/Whisplay/Driver/
# For detailed steps, refer to: https://github.com/PiSugar/whisplay-ai-chatbot
After installation, test if the LCD displays correctly:
cd /home/pi/Whisplay/Driver/
python3 test_display.py
If the screen lights up and displays content, the driver installation is successful.
TIP
Different batches of WhisPlay drivers may vary slightly, refer to the official documentation. If there are issues with the driver, you can search for similar problems in GitHub Issues.
Configure Environment Variables
Copy Configuration Template
cd ~/pizero-openclaw
cp .env.example .env
nano .env
Fill in Necessary Configurations
# Required: OpenAI API Key (for speech-to-text and TTS)
export OPENAI_API_KEY="sk-your-openai-api-key"
# Required: OpenClaw Gateway Token
export OPENCLAW_TOKEN="your-openclaw-gateway-token"
# Optional: OpenClaw Gateway Address
export OPENCLAW_BASE_URL="http://192.168.1.100:18789"
Other Common Configurations
| Variable | Default Value | Description |
|---|---|---|
ENABLE_TTS | false | Whether to enable voice broadcasting |
OPENAI_TTS_VOICE | alloy | TTS voice (alloy, echo, fable, onyx, nova, shimmer) |
OPENAI_TTS_SPEED | 2.0 | TTS speed (0.25-4.0) |
CONVERSATION_HISTORY_LENGTH | 5 | Length of conversation context |
SILENCE_RMS_THRESHOLD | 200 | Silence threshold, values below this will be ignored |
LCD_BACKLIGHT | 70 | Screen brightness (0-100) |
Set Up OpenClaw Gateway
The voice assistant needs to connect to the OpenClaw gateway for AI interaction.
Run the Gateway on Raspberry Pi (Recommended)
# Install OpenClaw
npm install -g openclaw@latest
openclaw onboard --install-daemon
Run Gateway on Another Machine
If the performance of your other machine running the Raspberry Pi is limited, you can run the gateway on another computer:
# Run on Mac/server
npm install -g openclaw@latest
openclaw onboard --install-daemon
Configure the Gateway
Edit ~/.openclaw/openclaw.json:
{
"gateway": {
"bind": "0.0.0.0",
"port": 18789,
"auth": {
"mode": "token",
"token": "your-token"
}
}
}
# Restart the gateway
openclaw gateway restart
# Get Token
openclaw config get gateway.auth.token
Fill the obtained Token into the previously configured .env file.
Test Run
Local Start
With everything configured, it's time to test:
cd ~/pizero-openclaw
python3 main.py
Under normal circumstances, you should see:
- LCD displaying time, date, battery level, WiFi status
- The screen shows βReadyβ waiting for commands
Voice Interaction Test
- Long press the button on WhisPlay β start recording
- Release the button β send the recording
- Wait a few seconds, the screen will display:
- Recognized text
- AI's streaming response
- If TTS is enabled, you'll also hear the voice broadcasting
TIP
Itβs advisable to start with simple test phrases, like