Broca is a foundational project for developing a local chatbot designed to interact onboard social robots like Pepper or iCub. This project focuses on integrating local Speech-to-Text, a Large Language Model (LLM), and Text-to-Speech to enable fully offline conversational capabilities without relying on cloud services.
-
Local Speech Recognition: Integrates an offline speech-to-text module using
arecordand the Hugging Face Transformersopenai/whisper-basemodel. -
Local LLM Integration: Utilises Hugging Face's
transformerslibrary to run a local LLM (e.g.,HuggingFaceTB/SmolLM2-360M-Instruct). -
Local Text-to-Speech (TTS): Provides verbal responses using local models. Includes a high-quality, balanced engine (Microsoft SpeechT5) and an expressive engine (Parler-TTS).
-
GPU Memory Management: Implements a "workbench" strategy to shuttle models on and off the GPU, allowing multiple large models to run on a single, memory-constrained device.
-
Configurable Personality: The chatbot's personality and rules can be easily customised via a system prompt.
-
Modular Design: Separates concerns into
llm_handler.py,speech_recognition.py, variousttsmodules, andmain.pyfor orchestration. -
Component Control: Command-line arguments allow for granular control over speech recognition, LLM processing, and the choice of TTS engine.
-
Expressive Status Display: Provides real-time visual feedback on the bot's state (idle, listening, thinking, speaking, error) directly in the terminal using animated, color-coded faces.
State Face Animation Frames Color Idle [ -_- ](Static)Grey Listening [ o.o ](Static)Blue Thinking [ o_O ]<->[ O_o ]Yellow Speaking [ ^o^ ]<->[ ^-^ ]Green Error [ x.! ]<->[ !.x ]Red
These instructions will get you a copy of the project up and running on your local machine.
- Python 3.11: This version is recommended for best compatibility with the required machine learning libraries.
- A Linux Environment: Required for the
arecordutility used in speech recognition. For Debian/Ubuntu, install withsudo apt-get install alsa-utils. - NVIDIA GPU with CUDA: Highly recommended for acceptable performance.
pipandvenv(Python package and environment managers).
- Clone the repository:
git clone [https://github.com/jwgcurrie/Broca.git](https://github.com/jwgcurrie/Broca.git) cd Broca - Create a virtual environment:
python3.11 -m venv venv
- Activate the virtual environment:
- On Linux/macOS:
source venv/bin/activate - On Windows:
.\venv\Scripts\activate
- On Linux/macOS:
- Install dependencies:
The required packages are listed in the
requirements.txtfile included in the repository. Run:pip install -r requirements.txt
To run the chatbot, activate your virtual environment and execute main.py from the src directory.
python3 src/main.py [OPTIONS]--no-speech: Disables voice recognition, requiring you to type your input manually.--no-llm: Disables the language model. The application will simply echo your input back as its "response".--use-local-tts: Enables the text-to-speech engine to speak responses aloud. Without this, responses are printed to the console.--tts-engine <engine>: Selects which TTS engine to use. Your choices arespeecht5(the default) orparler.--no-pepper: Legacy flag to disable direct robot interaction. This is now the default behaviour.--verbose: Enable verbose output for debugging.
- Run with default settings (Speech Input, LLM, SpeechT5 TTS Output):
python3 src/main.py --use-local-tts
- Run with the alternative Parler TTS engine:
python3 src/main.py --use-local-tts --tts-engine parler
- Run with text input and SpeechT5 output:
python3 src/main.py --no-speech --use-local-tts
The default LLM can be changed in src/llm_handler.py by modifying the model_id parameter. Be mindful of your VRAM limitations when choosing a larger model.
The chatbot's personality is defined by the system_prompt string in src/main.py. You can edit this to customise its behaviour and conversational style.
arecord: command not found: Thearecordutility is missing. Install it on Debian/Ubuntu systems withsudo apt-get install alsa-utils.- Dependency Errors during
pip install: This project is tested on Python 3.11. If you encounter installation errors, ensure you are using a compatible Python version. - CUDA / GPU Errors: Ensure your NVIDIA drivers and CUDA toolkit are installed correctly. If you have GPU issues, you can try running the models on the CPU by modifying the
devicevariables in the respective module files, though performance will be significantly slower.