BIA (AI) Vocal Assistant (2/3 : BIA on Raspberry PI)

24640

Intro: BIA (AI) Vocal Assistant (2/3 : BIA on Raspberry PI)

Hello

Hi there :) My nickname is TylerMaker, I live in France and am happy to share with you the lines below. This Instructables is the second in a serie of three.

What is BIA (AI) ?

BIA is an AI vocal assistant.. all in one software : ChatGPT, voice command, YouTube, Netflix, TV, Radio and web navigation. BIA is multi language, ... and BIA also provides AI to the educational Otto robot:)

Example of what you can do with it :

  • Chat with ChatGPT
  • Ask Bia to open a web page, YouTube, a radio, a TV channel or Netflix
  • Ask Bia to take a picture
  • Ask complex instruction with a If This Then That logic
  • Save complex instructions as a macro
  • Ask Otto the robot to dance, sing, walk, ...
  • And some more

The brain of Bia is the Python module biaspeech. I developed the the package and made it available for download. This instructable explains how to install the module, customize it and use it on a Raspberry PI.

STEP 1: The Concept

Concept

double layer IA mechanism provide fast and accurate answers :

First layer

The first layer is powered by OpenAI (chatGPT), ittakes care of answering the questions

Second layer

The second layer is processed by a native AI, it takes care of :

  • Cache management : questions and answers are cached in a local database. The goal of it is to get rid of the network latencies whenever possible (requests to chatGPT are network dependent, requests to the cache are not). The goal of it is ensuring faster answers
  • Categorization : the input is categorized with a NLP (Natural Language Processing) technique into categories like question, feedback, action, etc
  • Paraphrases : if for example you ask "how are you", and then later "how are you doing" both questions will be considered similar and the same answer will be picked up from the cache
  • Emotions : the user input is scored on several axis (positive, negative, neutral). Based on the emotion the previous answer will get promoted or deprecated in the cache
  • Scoring : each prompt/interaction is scored, in this way only the best answer is given
  • Smart actions (complex requests), like If This Then That requests, instructions to Otto Robot, etc

STEP 2: Install the Python Dependencies

All the steps below have been done via SSH. Please check the web on how to connect to Raspberry with SSH :)

Prerequesites :

Download the nltk ressources :

pip install nltk 
python3
>> import nltk
>> nltk.download('punkt')
>> nltk.download('vader_lexicon')

Install one by one the libraries : 

sudo apt-get install libjpeg8-dev
sudo apt install espeak
sudo apt install python3-opencv
sudo apt-get install flac
pip install openai
pip install websockets
pip install argostranslate
pip install py3langid
pip install pyautogui
pip install pyaudio
pip install speechrecognition
pip install pyttsx3
pip install parrot
pip install customtkinter
pip install pyduinocli
pip install pyserial
pip install sounddevice

Install the languages :

argospm install translate-de_en
argospm install translate-en_de
etc with all the languages needed
Check the microphone configuration : https://www.pofilo.fr/post/2018/12/16-mic-raspberry-pi/

STEP 3: Install the Arduino Client

Programs to manage the Arduino of the robot

Install arduino-cli and arduino avr. Important : the Arduino-cli file must be in the bin folder

<<python package>>/bin/.

The command to install arduino-cli and arduino avr are :

curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
./arduino-cli core install arduino:avr

STEP 4: Install the Python Package Biaspeech

# --------------------------
# Main folder
#
# run definition
# --------------------------

import os
os.environ['OPENAI_API_KEY'] = "xxxx" # openAI API key.. replace xxxx with your own key :)
os.environ['OS'] = "raspberry"
os.environ['ARDUINO'] = ""

from biaspeech import biaspeech
biaspeech()

STEP 5: Play With It

Basic usage of BIA, app mode :
  • Open a terminal, then type : 
python3 run.py
  • The BIA app will open, just push the button and ask a question. BIA will answer ... Enjoy :)
Advanced usage of BIA, command line mode :
  • Open a terminal, then type : 
python3 run.py "what can I do a friday afternoon in Paris?"
python3 run.py -help
python3 run.py -version
  • BIA will answer ... Enjoy :)
Developer usage of BIA, keyboard mode :
  • Open a terminal, then type : 
python3 run.py
  • Write a question. BIA will answer ... Enjoy :)

Note : the UI parameter under the [main] section must be set to "keyboard".

The config file can be found under :

<<python package>>/utils/config.cfg
Developer usage of BIA, voice mode :
  • Open a terminal, then type : 
python3 run.py
  • Ask a question. BIA will answer ... Enjoy :)

Note : the UI parameter under the [main] section must be set to "voice".

Example of some prompt :
  • Quelle est la capitale de la France?
  • How are you today?

STEP 6: Play With It, Other Options

Advanced prompts :
  • I do not like this answer => a negative prompt will decrease the scoring of the latest answer, it will go down in the cache
  • I like this answer very much => a positive prompt will increase the scoring of the latest answer, it will stays up in the cache
Skills. The special prompts are the following :
  • camera : take a picture => Example : Camera now
  • macro : save the last command as a keyword => Example : Macro salsa
  • netflix : run netflix and search for a movie => Example : Netflix breaking bad
  • python : run a combination of prompts => Example : Python if the capital of France is Paris then Arduino walk one meter
  • radio : open the web radio site and search for a station => Example : Radio deutschlandfunk
  • tv : open molotov tv => Example : TV m6
  • web : open a website => Example : Web google.com
  • youtube : open youtube and search for some => Example : Youtube dire straits
  • arduino or robot : ask the otto robot to do something
The predefined keywords for the robot are : walk, back, left, right, stop, happy, sad, surprise, moonwalkerleft, moonwalkerright, sing
A predefined keyword means that the Arduino code for the keyword/action is preloaded in Arduino. For others than those 11 predefined actions, a live request to chapGPT will dynamically build the Arduino code.
=> Example : "robot walk" .. the keyword walk is predefined... the Arduino code for it is preloaded
=> Example : "robot dance the salsa" .. this is a new action, chatGPT will generate live the Arduino code
Remote control

You can remote control BIA with VNC, this is explained in the next Instructables.

Update the paraphrases

Run the command below to update the paraphrases. Paraphrases are synonyms sentences stored in the local database. The cache will use those sentences to speedup the answers.

python3 run.py -update

STEP 7: Next Steps

Check those instructables

STEP 8: Annexes

Small donations matter : you can buy me a coffee :)

BIA(AI) © 2024 by Nicolas CHRISTOPHE is licensed under CC BY-NC-ND 4.0. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/

The python package is available on PyPi : https://pypi.org/project/biaspeech/