🤖 Python library for programming TJBot recipes!
TJBot is an open-source robot created by IBM for learning how to program artificial intelligence applications. This library provides a simple, high-level interface to control TJBot running on a Raspberry Pi.
TJBot's core capabilities are:
- Listen – Capture and transcribe speech with Speech-to-Text
- Look – Take photos with an integrated camera
- Shine – Control an RGB LED in various colors and effects
- Speak – Play audio and synthesize speech with Text-to-Speech
- Wave – Move its arm using a servo motor
This library supports both local AI backends (using sherpa-onnx for offline speech processing) and IBM Watson cloud services for more advanced capabilities.
Install the system camera package:
sudo apt-get install rpicam-apps-liteNote: This package is installed as part of TJBot's bootstrap script.
Install the library using pip:
pip install python-tjbotlibfrom tjbot import TJBotThis example initializes a NeoPixel LED and sets its color:
from tjbot import TJBot
# Initialize with NeoPixel LED enabled via override config
config = {
"hardware": {
"led_neopixel": True
}
}
tj = TJBot(override_config=config)
# Set LED to red
tj.shine('red')
# Set LED to a custom hex color
tj.shine('#00FF00')
# Pulse the LED
tj.pulse('blue')
print('LED demo complete!')This example uses the sherpa-onnx text-to-speech backend to speak text:
from tjbot import TJBot
# Initialize with speaker enabled
config = {
"hardware": {
"speaker": True
},
"speak": {
"backend": {"type": "local"}
}
}
tj = TJBot(override_config=config)
# Speak text using local TTS (sherpa-onnx)
# The TTS model is automatically downloaded on first use
tj.speak('Hello, I am TJBot!')
print('Speech demo complete!')TJBot automatically loads its configuration from the tjbot.toml file in your current working directory. Create this file to customize TJBot's behavior:
tjbot.toml:
[log]
level = 'debug'
[shine.neopixel]
gpioPin = 18Then use it in your code:
from tjbot import TJBot
# TJBot automatically loads tjbot.toml from the current directory
# Assuming tjbot.toml enables led_neopixel
tj = TJBot()
# Use the configured settings
tj.shine('cyan')
tj.speak('TJBot is ready!')TJBot uses TOML for configuration. By default, it looks for tjbot.toml in the current working directory. Create this file to override the default settings.
See tjbot.default.toml in the package for all available options.
For detailed API documentation, please refer to the source code or generated docs.
To contribute to the TJBot library:
-
Clone the repository:
git clone https://github.com/ibmtjbot/python-tjbotlib.git cd python-tjbotlib -
Install dependencies:
pip install -e .[dev]
-
Run tests:
pytest
-
Lint and format code:
ruff check . ruff format .
This project is licensed under the Apache License 2.0.