Skip to content

tjbot-ce/python-tjbotlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TJBot Library (Python)

Python Version Raspberry Pi Support License

🤖 Python library for programming TJBot recipes!

What is TJBot?

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.

What Can TJBot Do?

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.

System Dependencies

Install the system camera package:

sudo apt-get install rpicam-apps-lite

Note: This package is installed as part of TJBot's bootstrap script.

Installation

Install the library using pip:

pip install python-tjbotlib

Quick Start

Importing TJBot

from tjbot import TJBot

Example 1: Control an LED

This 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!')

Example 2: Speak Text Using On-Device Text-to-Speech (TTS)

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!')

Example 3: Change TJBot's Configuration

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 = 18

Then 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!')

Configuration Reference

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.

API Documentation

For detailed API documentation, please refer to the source code or generated docs.

Development

Setting Up a Development Environment

To contribute to the TJBot library:

  1. Clone the repository:

    git clone https://github.com/ibmtjbot/python-tjbotlib.git
    cd python-tjbotlib
  2. Install dependencies:

    pip install -e .[dev]
  3. Run tests:

    pytest
  4. Lint and format code:

    ruff check .
    ruff format .

License

This project is licensed under the Apache License 2.0.

About

Python library for programming TJBot Community Edition

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages