Installation
pip install tjpybot
Import TJBot library
from tjbot import *
Instantiate a TJBot object
bot = TJBot("IP ADDRESS")
Set arm angle
arm(angle)
Moves the TJBot's arm to a specified angle.
-
angle
-
The integer angle to set the arm servo motor.
Example:
for i in range(5):
bot.arm(90)
time.sleep(1)
bot.arm(180)
time.sleep(1)
Set LED color
led(color)
Turns on the LED with the specified color.
-
color
-
Must be a string english word like "red", "green" or "yellow" (use "black" to turn off the LED).
Example:
colors = ["red", "green", "blue", "yellow", "purple", "orange", "black"]
for i in range(10):
for color in colors:
bot.led(color)
time.sleep(1)
Conversation (Watson Assistant)
converse(user_input, workspace)
-
user_input
-
The input message for the "dialog flow" of the Watson Assistant conversation.
-
workspace
-
The ID of the workspace you want to converse with.
Example:
user_input = ""
response = ""
workspace = "1272c7d4-3048-4dac-b1fb-9cd7ffdcf4f0"
while True:
response = bot.converse(user_input, workspace))
print(response)
user_input = input("Write here: \n")
Text to Speech
speak(text, voice="default", wait="true")
-
text
-
The text to be synthesized.
-
voice
-
The voice to use for the speech synthesis. It must be written like: "it-IT_FrancescaVoice", "fr-FR_ReneeVoice", "en-US_AllisonVoice",
etc. The full list of voices can be found in the "settings" page of the TJBot.
-
wait
-
Whether or not the program should wait for the end of the speech before moving forward.
Example:
voice = "fr-FR_ReneeVoice"
bot.speak("Bonjour!", voice)
text = input("Que devrais-je dire? \n")
bot.speak(text, voice)
Speech to Text
listen(language="default")
Records sounds until it hears 2 seconds of silence and write it to an audio file. Then it sends the audio file to the Speech to Text Watson service and waits for an answer.
-
language
-
The language that Watson should use to understand the words in the audio file ("it", "en", "fr", "es", "jp", etc).
Example:
print("Say something!")
user_input = bot.listen("it")
print("I understood: " + user_input)
Visual Recognition
recognize(classifier="default", threshold="0.6")
Takes a picture and sends it to Watson.
-
classifier
-
The specific classifier that will be used to analyze the picture.
You can create custom classifiers using the Watson Visual Recognition tool.
-
threshold
-
A float number between 0 and 1. A higher threshold means less results but it's more accurate.
Example:
target = bot.recognize("robots_1670531342", 0.6)
print("I recognize... " + target)
Language Translator
translate(text, source, target)
Example: