Add Voice Control and Local LLM to Pomodoro Bot

by CodersCafeTech in Circuits > Raspberry Pi

306 Views, 6 Favorites, 0 Comments

Add Voice Control and Local LLM to Pomodoro Bot

pomo_v2_cover.jpg

The Pomodoro Bot V2 is a significant upgrade from its predecessor, featuring smart voice interaction, enhanced design, and streamlined hardware. This version goes beyond just tracking focus sessions—it can now respond to voice commands and provide real-time feedback. With LLM integration, the bot operates completely hands-free, eliminating the need for physical buttons.

To complement these advancements, we have redesigned the bot with a more compact form factor, custom PCB, and an adorable new look with ears.

The first iteration of the Pomodoro Bot featured a simple display for tracking focus sessions and physical buttons for manual control. While it served its purpose well, we aimed to take productivity to the next level with a more intelligent and interactive experience.

If you haven't seen V1 in action, you can check out the V1 documentation here.

Let's dive in and see what's new in V2

Supplies

What's New in V2?

  1. Voice Control - No buttons needed! Interact using natural speech
  2. LLM Integration - Local AI processing with Deepseek R1 or any other LLMs of your choice
  3. Audio System - Built-in microphone and amplified speaker
  4. New Design - Adorable ears + compact PCB design
  5. Custom PCB - Streamlined sensor connections

Watch the Video

Before getting into the build, let's start by seeing our Pomodoro Bot V2 in action!

Audio System

One of the most significant upgrades in Pomodoro Bot v2 is the audio system, enabling natural voice interaction. We focused on compact and efficient components for both audio input and output, ensuring seamless integration into the design with minimal modifications.

Audio Input: USB Microphone

For voice commands and interaction, we selected a small USB microphone that fits perfectly with just a minor tweak to the 3D model. This allows for clear voice detection without requiring additional circuitry.

USB Microphone

Audio Output: Speaker & Amplifier

For audio feedback, we chose a compact 4Ω, 2.5W speaker, powered by a PAM8403 amplifier module, ensuring clear and crisp sound.

4Ω, 2.5W Speaker

PAM8403 Amplifier

Audio Routing: A Creative Solution

Since the Raspberry Pi 5 lacks a built-in audio output, we needed an alternative approach:

  1. Instead of using an external sound card, we routed the audio signal through the display's 3.5mm jack.
  2. This signal was fed into the PAM8403 amplifier, which then powered the speaker.

Power & Noise Reduction

  1. To prevent noise interference, the Raspberry Pi and PAM8403 amplifier were powered separately.
  2. A USB breakout board was used to power the amplifier conveniently.

Testing the Audio System

To verify functionality, we ran basic recording and playback tests using the following commands:

# Record audio
arecord -D plughw:1,0 -f cd -d 5 test.wav
# Play recorded audio
aplay test.wav

With these adjustments, Pomodoro Bot v2 now has a voice, making interactions more natural and engaging!

Integrating LLM for Voice Interactions

With the audio setup complete, the next step is integrating VIAM and Local LLM to enable real-time voice interactions. This allows the Pomodoro Bot to process speech, understand queries, and respond intelligently.

Adding Local LLM to the Bot

VIAM's Local-LLM module enables running offline AI models without relying on the cloud. It supports TinyLlama, Deepseek R1, and other models using llama.cpp.

Steps to Integrate Local LLM

  1. Navigate to the CONFIGURE tab in VIAM.
  2. Search for LOCAL-LLM under services and add it to the bot.
  3. To use a custom model, you'll need:
  4. LLM-File: The actual model file in GGUF format.
  5. LLM-Repo: The repository ID containing the model.

Using Deepseek R1 Model

  1. Search for Deepseek R1 GGUF on Hugging Face.

HF Search

  1. Download the GGUF file to the Raspberry Pi (this is the LLM-File).

GGUF Download

  1. Note down the repository ID (this is the LLM-Repo).

GGUF Repository ID

  1. Back in VIAM's CONFIGURE tab, set:
  2. LLM-File: Path to the downloaded GGUF file.
  3. LLM-Repo: Repository ID of the model.

LLM Config

  1. Save the configuration, and the bot is now powered by an offline LLM!

With LLM integration, the Pomodoro Bot can now listen, understand, and respond in real time, making it a truly hands-free experience.

Integrating a Wake Word Detector

To enable hands-free interaction, we're integrating a wake word detector into the Pomodoro bot using PicoVoice Porcupine Wake Word Engine. Porcupine is:

  1. Fast and efficient
  2. Works entirely offline
  3. Optimized for low-power devices like the Raspberry Pi

Setting Up the Wake Word


Access PicoVoice Console

  1. Go to the PicoVoice Console.

PicoVoice Console

  1. If you don't have an account, sign up first, then log in.
  2. Navigate to the Porcupine section.

Porcupine Home

Choosing or Creating a Wake Word

  1. You can select a default wake word like "Hey Google" or "Alexa".
  2. To create a custom wake word, follow these steps:
  3. Click "Create Wake Word".

Create WakeWord

  1. Enter your desired phrase (e.g., "Hey Pomo").

WakeWord

  1. PicoVoice will generate a PPN model file for your wake word.

Downloading the Wake Word Model

  1. Once the model is ready, download the PPN file.

Download PPN

  1. Save it in an easily accessible location on your device.

Getting the PicoVoice API Key

  1. Navigate to the API Access Key section in the PicoVoice Console.
  2. Copy the access key and store it securely.

Access Key

  1. This key is required in our code to authenticate with the Porcupine engine.

Next, we'll configure the wake word engine in our code. Here's a sample code to test whether your wake word detection is working fine or not.


#wake_word_test.py

import pvporcupine
import pyaudio
import struct

# Replace with your actual access key and wake word model file path
ACCESS_KEY = "YOUR_ACCESS_KEY"
WAKE_WORD_MODEL = "path/to/your_wakeword.ppn"

# Initialize Porcupine wake word engine
porcupine = pvporcupine.create(access_key=ACCESS_KEY, keyword_paths=[WAKE_WORD_MODEL])

# Configure audio stream
pa = pyaudio.PyAudio()
stream = pa.open( rate=porcupine.sample_rate, channels=1, format=pyaudio.paInt16, input=True, frames_per_buffer=porcupine.frame_length
)

print("Listening for wake word...")

try: while True: pcm = stream.read(porcupine.frame_length, exception_on_overflow=False) pcm = struct.unpack_from("h" * porcupine.frame_length, pcm) result = porcupine.process(pcm) if result >= 0: print("Wake word detected! Activating voice interaction...")
except KeyboardInterrupt: print("Stopping wake word detection...")
finally: stream.stop_stream() stream.close() pa.terminate() porcupine.delete()

To run the above code install the required libraries using following commands


sudo apt-get install portaudio19-dev
pip install pvporcupine pyaudio

Now run the code as

python3 wake_word_test.py

And just like that, our Pomodoro bot is now intelligent, interactive, and fully voice-enabled!

Custom PCB Design

To maintain a neat and clutter-free assembly, we designed a custom two-layer PCB using EasyEDA. The PCB layout was optimized to facilitate seamless connections between components, ensuring a compact and efficient design.

Features

  1. JST Connectors: Used for attaching sensors, speakers, and the audio jack for easy and secure connections.
  2. Direct Integration: The PAM8403 amplifier module and ADS1115 ADC module are directly mounted onto the PCB, reducing additional wiring and improving reliability.

PCB 2D View

Design Process

  1. Designed the PCB using EasyEDA. PCB Design
  2. Exported Gerber files for manufacturing. Export As Gerber

After the fabrication process was completed, we received our custom PCBs, precisely manufactured according to our design specifications.

Fabricated PCBs

This custom PCB simplifies the wiring process, enhances durability, and improves the overall aesthetics of the Pomodoro bot. You can get your own PCBs using this Gerber File.

3D Design and Fabrication

In addition to designing the custom PCB, we also gave the Pomodoro bot's case a complete makeover. The updated design enhances both aesthetics and functionality, creating a more charming and efficient look.

3D Design

Below are the key features of the redesigned case:

  1. Personality Touch: The case now includes cute little ears, adding a fun and endearing element to the bot's appearance.
  2. Component Space: A dedicated space was integrated for the USB microphone and other essential components, ensuring easy access and proper placement.
  3. Compact and Organized Layout: The new layout is both visually appealing and efficient, optimizing space while improving the overall look and feel of the bot.

3D Printing the New Design

Once the redesign was finalized, we moved on to preparing the 3D printing files and began printing the individual parts. The choice of materials and colors was carefully considered to complement the bot's appearance:

  1. Body: The bot's body was printed using white filament, providing a clean and sleek finish.

3D Printing Body

  1. Front Ring & Ears: The front ring and ears were printed separately using purple filament. This allows them to be attached easily and customized, adding a personal touch to each Pomodoro bot.

3D Printing Ears

This redesign elevates the bot's functionality and personality, creating a more cohesive and delightful user experience.

3D Printed Parts

Find the 3D Files here.

Assembly

Front Portion Assembly

  1. Speaker Installation
  2. Place the speakers onto the speaker grill and ensure proper alignment.

Speakers

Speakers Assembled

  1. PCB Assembly
  2. Solder all necessary components onto the PCB. PCB Soldering
  3. Use female headers for the ADS1115 module to allow easy replacement. ADS1115
  4. Directly solder the PAM8403 module for a secure connection. Assembled PCB
  5. Mounting the PCB on the Raspberry Pi
  6. Attach the 3.5mm audio jack to the PCB. 3.5 MM Jack To RPI
  7. Stack the assembled PCB onto the Raspberry Pi. PCB On RPI
  8. Insert the entire unit into the front portion of the case. PCB In Case
  9. Connect the speakers to the PCB. Speakers To PCB

Back Portion Assembly

  1. Sensor and USB Module Installation
  2. Solder JST connectors to both sensors. JST To Sensors
  3. Attach the sensors and USB module to the back side of the case. Back Portion
  4. Final Wiring
  5. Connect the wiring between the back portion and the front portion, completing the internal assembly. Back To Body

Final Assembly

  1. Securing the Outer Case
  2. Glue the front ring and ear portions to the Pomodoro bot's body.

Ears

Front Ring

Assembled Pomo

Assembly process fully completed! The Pomodoro Bot is now ready for use.

Giving Life to Our Pomodoro Bot

1. Power Up the Raspberry Pi

Once the assembly process is complete, power up your Raspberry Pi. You can do this by connecting the power supply to the Raspberry Pi's power jack.

2. Verify Functionality

After powering up, take a moment to verify that everything is functioning as expected. This may involve checking the Raspberry Pi's LED indicators and ensuring the Waveshare display turns on.

3. Download Source Code

The next step is to download the source code for the Pomodoro Bot application on to your Raspberry Pi. You can download the code from the following GitHub repository:

  1. https://github.com/CodersCafeTech/PomodoroBot-V2

4. Edit the Source Code (main.py)

  1. Open the downloaded source code and navigate to the Code directory. Locate the file named main.py.
  2. Within main.py, you will need to replace the following placeholders with your own values:
  3. API Key: Locate the section where the API key is stored and replace it with your own API key.
  4. API Key ID: Similarly, find the section where the API Key ID is stored and replace it with your unique ID.
  5. Robot Address: Replace the address with Machine Address in the CONNECT tab.
  6. Porcupine Access Key: Find the section containing the Porcupine Access Key and replace it with your own.
  7. Component Names (Optional): If you have used different component names during configuration, you may need to modify the corresponding names within the code.

5. Run the Pomodoro Bot Code

  1. Once you've made the necessary edits to main.py, save the changes.
  2. Install the necessary python packages using the following command
pip install -r requirements.txt
  1. Run the python code from the terminal using
python3 main.py

6. See Your Pomodoro Bot Alive!

If everything is configured correctly, the Pomodoro Bot application should launch and your Raspberry Pi will transform into a functional Pomodoro Bot, ready to help you manage your work sessions and boost your productivity.

Assembled Product