422 lines
9.5 KiB
Bash
Executable File
422 lines
9.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Google AIY Voice Kit V1 - Installation Script
|
|
# Bilingual Voice Assistant (English/Mandarin)
|
|
#
|
|
# AI Now Inc - Del Mar Demo Unit
|
|
# Laboratory Assistant: Claw 🏭
|
|
#
|
|
|
|
set -e # Exit on error
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
INSTALL_DIR="$(dirname "$(readlink -f "$0")")"
|
|
MUSIC_DIR="$(dirname "$(readlink -f "$0")")/Music"
|
|
LOG_FILE="/var/log/voice-assistant-install.log"
|
|
PYTHON_VERSION="3.9"
|
|
|
|
echo -e "${BLUE}"
|
|
echo "=========================================="
|
|
echo " 🎤 Voice Assistant Installer"
|
|
echo " AI Now Inc - Del Mar Demo Unit"
|
|
echo "=========================================="
|
|
echo -e "${NC}"
|
|
|
|
# Logging function
|
|
log() {
|
|
echo -e "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
log_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
log_info() {
|
|
echo -e "${YELLOW}[INFO]${NC} $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
# Check if running as root
|
|
check_root() {
|
|
if [ "$EUID" -ne 0 ]; then
|
|
log_error "Please run as root (sudo ./install.sh)"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Check if running on Raspberry Pi
|
|
check_raspberry_pi() {
|
|
if ! grep -q "Raspberry Pi" /proc/cpuinfo 2>/dev/null; then
|
|
log_info "Not running on Raspberry Pi (this may still work)"
|
|
else
|
|
log_success "Raspberry Pi detected"
|
|
fi
|
|
}
|
|
|
|
# Update system packages
|
|
update_system() {
|
|
log_info "Updating system packages..."
|
|
apt-get update
|
|
apt-get upgrade -y
|
|
log_success "System updated"
|
|
}
|
|
|
|
# Install system dependencies
|
|
install_system_deps() {
|
|
log_info "Installing system dependencies..."
|
|
|
|
apt-get install -y \
|
|
python3 \
|
|
python3-pip \
|
|
python3-dev \
|
|
python3-venv \
|
|
portaudio19-dev \
|
|
libffi-dev \
|
|
libssl-dev \
|
|
libjpeg-dev \
|
|
zlib1g-dev \
|
|
libfreetype6-dev \
|
|
liblcms2-dev \
|
|
libopenjp2-7 \
|
|
libtiff6 \
|
|
libblas-dev \
|
|
liblapack-dev \
|
|
libatlas-base-dev \
|
|
libgfortran5 \
|
|
swig \
|
|
libasound2-dev \
|
|
alsa-utils \
|
|
wget \
|
|
git \
|
|
curl
|
|
|
|
log_success "System dependencies installed"
|
|
}
|
|
|
|
# Install Google AIY Voice Kit
|
|
install_aiy_voice() {
|
|
log_info "Installing Google AIY Voice Kit..."
|
|
|
|
# Check if AIY already installed
|
|
if [ -d "/usr/local/bin/aiy" ]; then
|
|
log_info "AIY Voice Kit already installed"
|
|
return
|
|
fi
|
|
|
|
# Install AIY packages
|
|
cd /tmp
|
|
wget https://dl.google.com/aiyprojects/raspbian/aiyvoice-buster-20230111.zip
|
|
unzip aiyvoice-buster-*.zip
|
|
cd aiyvoice-*
|
|
./install.sh
|
|
|
|
log_success "Google AIY Voice Kit installed"
|
|
}
|
|
|
|
# Create virtual environment
|
|
create_venv() {
|
|
log_info "Creating Python virtual environment..."
|
|
|
|
cd "$INSTALL_DIR"
|
|
python3 -m venv venv
|
|
|
|
log_success "Virtual environment created"
|
|
}
|
|
|
|
# Install Python dependencies
|
|
install_python_deps() {
|
|
log_info "Installing Python dependencies..."
|
|
|
|
cd "$INSTALL_DIR"
|
|
source venv/bin/activate
|
|
|
|
# Upgrade pip
|
|
pip install --upgrade pip
|
|
|
|
# Install requirements
|
|
pip install -r requirements.txt
|
|
|
|
# Install additional dependencies for hotword detection
|
|
pip install porcupine1
|
|
pip install webrtcvad
|
|
|
|
log_success "Python dependencies installed"
|
|
}
|
|
|
|
# Create music directory
|
|
create_music_dir() {
|
|
log_info "Creating music directory..."
|
|
|
|
if [ ! -d "$MUSIC_DIR" ]; then
|
|
mkdir -p "$MUSIC_DIR"
|
|
log_success "Music directory created: $MUSIC_DIR"
|
|
else
|
|
log_info "Music directory already exists"
|
|
fi
|
|
|
|
# Set permissions
|
|
chown $(whoami):$(whoami) "$MUSIC_DIR"
|
|
chmod 755 "$MUSIC_DIR"
|
|
}
|
|
|
|
# Configure audio
|
|
configure_audio() {
|
|
log_info "Configuring audio..."
|
|
|
|
# Create/update ALSA configuration
|
|
cat > /etc/asound.conf << 'EOF'
|
|
pcm.!default {
|
|
type plug
|
|
slave.pcm "hw:0,0"
|
|
}
|
|
|
|
ctl.!default {
|
|
type hw
|
|
card 0
|
|
}
|
|
EOF
|
|
|
|
log_success "Audio configured"
|
|
}
|
|
|
|
# Install systemd service
|
|
install_service() {
|
|
log_info "Installing systemd service..."
|
|
|
|
cat > /etc/systemd/system/voice-assistant.service << EOF
|
|
[Unit]
|
|
Description=Bilingual Voice Assistant
|
|
After=network.target sound.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=$(whoami)
|
|
WorkingDirectory=$INSTALL_DIR
|
|
ExecStart=$INSTALL_DIR/venv/bin/python3 $INSTALL_DIR/main.py --mode run
|
|
Restart=always
|
|
RestartSec=10
|
|
Environment=PYTHONUNBUFFERED=1
|
|
Environment=GOOGLE_APPLICATION_CREDENTIALS=/home/john/.credentials/google-credentials.json
|
|
|
|
# Logging
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
SyslogIdentifier=voice-assistant
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# Enable service
|
|
systemctl daemon-reload
|
|
systemctl enable voice-assistant.service
|
|
|
|
log_success "Systemd service installed and enabled"
|
|
}
|
|
|
|
# Configure hotword detection
|
|
configure_hotword() {
|
|
log_info "Configuring hotword detection..."
|
|
|
|
# Create hotword configuration
|
|
cat > "$INSTALL_DIR/hotword_config.json" << 'EOF'
|
|
{
|
|
"hotwords": [
|
|
{
|
|
"keyword": "hey osiris",
|
|
"keyword_zh": "你好 osiris",
|
|
"sensitivity": 0.5,
|
|
"library_path": "resources/porcupine"
|
|
}
|
|
],
|
|
"audio": {
|
|
"sample_rate": 16000,
|
|
"frame_length": 512
|
|
}
|
|
}
|
|
EOF
|
|
|
|
log_success "Hotword detection configured"
|
|
}
|
|
|
|
# Create sample music directory structure
|
|
create_sample_music_structure() {
|
|
log_info "Creating sample music structure..."
|
|
|
|
mkdir -p "$MUSIC_DIR/samples"
|
|
mkdir -p "$MUSIC_DIR/playlists"
|
|
|
|
# Create a README for music
|
|
cat > "$MUSIC_DIR/README.md" << 'EOF'
|
|
# Music Library
|
|
|
|
Place your MP3 files here. The assistant will automatically detect and index them.
|
|
|
|
## Supported Formats
|
|
- MP3
|
|
- WAV
|
|
- OGG
|
|
- FLAC
|
|
|
|
## Organization
|
|
You can organize music by:
|
|
- Artist/Album/Song.mp3
|
|
- Genre/Song.mp3
|
|
- Or flat structure: Song.mp3
|
|
|
|
## Voice Commands
|
|
- "Play [song name]" / "播放 [歌曲名]"
|
|
- "Pause" / "暂停"
|
|
- "Resume" / "继续"
|
|
- "Next" / "下一首"
|
|
- "Volume up/down" / "音量 大/小"
|
|
EOF
|
|
|
|
chown -R $(whoami):$(whoami) "$MUSIC_DIR"
|
|
|
|
log_success "Sample music structure created"
|
|
}
|
|
|
|
# Create startup script
|
|
create_startup_script() {
|
|
log_info "Creating startup script..."
|
|
|
|
cat > "$INSTALL_DIR/start.sh" << 'EOF'
|
|
#!/bin/bash
|
|
# Voice Assistant Startup Script
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
# Activate virtual environment
|
|
source venv/bin/activate
|
|
|
|
# Run the assistant
|
|
python3 main.py --mode run
|
|
EOF
|
|
|
|
chmod +x "$INSTALL_DIR/start.sh"
|
|
chown $(whoami):$(whoami) "$INSTALL_DIR/start.sh"
|
|
|
|
log_success "Startup script created"
|
|
}
|
|
|
|
# Create uninstall script
|
|
create_uninstall_script() {
|
|
log_info "Creating uninstall script..."
|
|
|
|
cat > "$INSTALL_DIR/uninstall.sh" << 'EOF'
|
|
#!/bin/bash
|
|
# Uninstall Voice Assistant
|
|
|
|
echo "Uninstalling Voice Assistant..."
|
|
|
|
# Stop service
|
|
sudo systemctl stop voice-assistant
|
|
sudo systemctl disable voice-assistant
|
|
sudo rm /etc/systemd/system/voice-assistant.service
|
|
|
|
# Remove installation
|
|
sudo rm -rf /home/john/voice-assistant
|
|
|
|
# Remove music directory (optional)
|
|
# sudo rm -rf $(dirname "$(readlink -f "$0")")/Music
|
|
|
|
echo "Uninstall complete!"
|
|
EOF
|
|
|
|
chmod +x "$INSTALL_DIR/uninstall.sh"
|
|
|
|
log_success "Uninstall script created"
|
|
}
|
|
|
|
# Final configuration
|
|
final_configuration() {
|
|
log_info "Running final configuration..."
|
|
|
|
# Copy config if not exists
|
|
if [ ! -f "$INSTALL_DIR/config.local.json" ]; then
|
|
cp "$INSTALL_DIR/config.json" "$INSTALL_DIR/config.local.json"
|
|
log_info "Created local configuration: config.local.json"
|
|
fi
|
|
|
|
# Set permissions
|
|
chown -R $(whoami):$(whoami) "$INSTALL_DIR"
|
|
chmod -R 755 "$INSTALL_DIR"
|
|
|
|
log_success "Final configuration complete"
|
|
}
|
|
|
|
# Print next steps
|
|
print_next_steps() {
|
|
echo ""
|
|
echo -e "${GREEN}=========================================="
|
|
echo " Installation Complete! 🎉"
|
|
echo "==========================================${NC}"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Edit configuration:"
|
|
echo " nano $INSTALL_DIR/config.local.json"
|
|
echo ""
|
|
echo "2. Add your MP3 files to: $MUSIC_DIR"
|
|
echo ""
|
|
echo "3. Test the assistant:"
|
|
echo " cd $INSTALL_DIR"
|
|
echo " ./start.sh"
|
|
echo ""
|
|
echo "4. Or run in demo mode:"
|
|
echo " $INSTALL_DIR/venv/bin/python3 $INSTALL_DIR/main.py --mode demo"
|
|
echo ""
|
|
echo "5. Start the service:"
|
|
echo " sudo systemctl start voice-assistant"
|
|
echo ""
|
|
echo "6. View logs:"
|
|
echo " sudo journalctl -u voice-assistant -f"
|
|
echo ""
|
|
echo "Voice commands:"
|
|
echo " - 'Hey Osiris' / '你好 Osiris' (hotword)"
|
|
echo " - 'Hello' / '你好'"
|
|
echo " - 'Play music' / '播放音乐'"
|
|
echo " - 'What time is it?' / '现在几点?'"
|
|
echo ""
|
|
echo -e "${YELLOW}Note: Make sure your microphone is connected and working!${NC}"
|
|
echo ""
|
|
}
|
|
|
|
# Main installation
|
|
main() {
|
|
log "Starting installation..."
|
|
|
|
check_root
|
|
check_raspberry_pi
|
|
update_system
|
|
install_system_deps
|
|
# install_aiy_voice # Commented out - install manually if needed
|
|
create_venv
|
|
install_python_deps
|
|
create_music_dir
|
|
configure_audio
|
|
install_service
|
|
configure_hotword
|
|
create_sample_music_structure
|
|
create_startup_script
|
|
create_uninstall_script
|
|
final_configuration
|
|
print_next_steps
|
|
|
|
log_success "Installation completed successfully!"
|
|
}
|
|
|
|
# Run main
|
|
main "$@"
|