Sox now has some brains in him! I have managed to used Patrick Loeber's pytorch-chatbot github code to give Sox a basic chatbot which is already better than the default chatbots many websites are using to "help" new users. This was achieved by following the instructions in github, but I will go highlight the main components and what I changed to make it go from a general chatbot to Sox.
Once the package was downloaded into Sox, pytorch and NLTK were installed using pip. Once these were in, it was ready to become unique to Sox.
Opening up intents.json shows all of the viable inputs and intents that can arise. For Sox, the intents that I have are greeting, status, wikipedia, goodbye, thanks, alarm, timer, weather, and internet. Each one of these has multiple preprogrammed sentences that are suggestions for what should fire this type of intent. For example, "what does mean?", "Can you search for", "What is a ", "Who is ", "When is", "Describe for me", "Describe" are all vailid sentences for Sox to scan wikipedia (more on that later) but Sox is not limited to these exact phrases to fire the intent. The weather intent has the sentence "what is the weather", while the wiki intent could state "what is weather". Due to the simple neural net that Patrick Loeber made, Sox can determine thedifference between these 2 intents based on word weight and sentence structure.
Once trained, the file "data.pth" is generated, which is the save file for the neural net combined with the intents file. This is then accessible by the built in chat.py program to read text input and determine intent. I created my own copy of the chat.py file and modified it to be able to call wikipedia using the wikipedia library in python, which only needs to be imported to connect to all of Wikipedia. Currently, Sox will print out the first sentence of Wikipedia when asked, and state "According to Wikipedia..." before. He will also catch if the search is ambiguous and list out the page options, and if there is no page, he will say so as well.
I also added an OnInternet check so that Sox can see if he has internet access before running Wikipedia or any other internet based scripts.This is done by opening a socket to 8.8.8.8 and trying to connect within 3 seconds. 8.8.8.8 is Google's DNS server, which if that goes down, a good chunk of the internet won't be able to be resolved so is a good check for outbound connectivity checks.
I do plan on having Sox communicate with Home Assistant eventually, through the API, but that is another article in the future.
Sox's vocal training is ongoing nightly on my main computer as it could not train on the raspberry pi directly. I am now using Rhasspy's Piper, which was developed to run on Raspberry Pis so it should be small and powerful. It is currently at 2300 out of 10 000 iterations and should be ready in the next month. I listened to it at 1000 iterations, and it sounds like Sox recorded through a 20 year old dollar store microphone, but it is better than cursed cat sounds from Coqui.
Comments
Log in to add a comment.