Positive Response Chatbot

by 陳亮 in Circuits > Arduino

384 Views, 1 Favorites, 0 Comments

Positive Response Chatbot

IMG_7760.jpeg
Positive Response Chatbot Demo 2

This Instructables show how to build a simple chatbot pet.

It is motion responsive and gives positive message responses while chatting.

You'd be willing to chat with it for half an hour. Or you can leave it standby near you, sometimes it will give you some positive message responses while you chat with others.

Supplies

  • Arduino Nano RP2040 Connect dev board
  • JR6001 voice module
  • Motor Driver module
  • Electronic Pet bird, dancing robot or all other moving robot

What Should Chatbot Pets Do?

Mobile Suit Gundam Seed Lacus Voice Comparison Stephanie Sheh & Chantal Strand English FUNi/Ocean
I Love Fraw!!
Epic Anime Scenes: Lockon Stratos Indiscriminate Firing HD
Haro understand berry much

Many times, chatbot pets just need companionship rather than answering your questions intelligently. One of a good example is Haro in Gundum Anime. It can give random positive message response is already very good enough.

Designs & Requirements

  • Arduino IDE compatible
  • Speedy speech recognition, offline engine preferred
  • Voice output
  • positive message response
  • motion response

Note:

Arduino IDE just my personal preference, if you choose other platform like micro-python, then the hardware selection and software design may be very different.

Arduino Speech Recognition Engine

螢幕截圖 2024-01-14 上午11.54.51.png

If you browse the Arduino Official Store, you can find a Speech Recognition Engine for their dev board. It is a pre-trained offline engine so it can help to development a chatbot quickly.

There are various pre-trained speech recognition engine in the market but seldom support Cantonese language. So this time I will use this engine with Cantonese as a demo.

The engine can support Nano 33 BLE Sense Rev2, Portenta H7, Nicla Vision and Nano RP2040 Connect. I picked Nano RP2040 Connect in this project.

Ref.:

https://store-usa.arduino.cc/products/speech-recognition-engine

Trial Mode

螢幕截圖 2024-01-14 下午10.10.35.png
螢幕截圖 2024-01-14 上午11.58.06.png
螢幕截圖 2024-01-14 上午11.59.46.png
螢幕截圖 2024-01-14 下午10.16.36.png
Arduino Speech Recognition Engine - first test

The Arduino Speech Recognition Engine can run in trial mode before any payment.

Here are the steps to try it:

  1. Install DSpotterSDK_Maker_RP2040 Library in Arduino IDE Library Manager
  2. Follow the steps to get the dev board serial number: https://tool.cyberon.com.tw/ArduinoDSpotterAuth/DocHowToGetBoardSerialNumber.php
  3. Start the trial at: https://tool.cyberon.com.tw/ArduinoDSpotterAuth/CTMain.php
  4. Fill the email, serial number and select desired language
  5. Decide a Trigger words, this is the hint you start the conversation, just like "Hey Siri" or "Hello Google"
  6. This engine can recognize at most 20 Commands, you can treat it as 20 keywords in your conversation that the chatbot will response
  7. Confirm filled details and wait the reply email
  8. Open example in Arduino IDE File Menu -> Examples -> DSpotterSDK_Maker_RP2040 -> Voice Recognition
  9. Save the example
  10. Copy the email attachment to the example folder
  11. Change follow 2 #include line to the new file names
#include "CybLicense.h"

and

#include "Model_L0.h"             // The packed level zero model file.


Then upload the program to test. As show in the above video, trial mode requires wait 20 seconds in the middle.

Voice Output

earlephilhower/arduino-pico example - PWMAudio

After speech recognition, we need voice output response.

The RP2040 dev board can develop with 2 board cores.

The earlephilpower's arduino-pico board core support PWMAudio and I2S output. However, Arduino Speech Recognition Engine requires Arduino official Mbed OS board core.

So we need another way for voice output.

Voice Module

螢幕截圖 2024-01-15 下午9.17.29.png

Direct playing voice with MCU may not the best option. Decoding and playing voice use up the processing power, and the voice clip use up the limited storage easily. Better alternative is offload the job to a voice module. The voice clips, in MP3 format, preloaded in the voice module so you don't need to concern the storage and how to decode it. And it also built-in amplifier, simply connect it to a speaker and send a command will play the voice loudly.

Note:

I am using voice module JR6001, if you are using another voice module please follow the data sheet modify the send message function accordingly.

Motion Response

Most robot toy use a DC motor emulate bionic motions. Simply use a motor driver module can reproduce a motion response easily.

Wire Connection

DSCN1056.JPG
NANO RP2040 CONNECT.png

Since Arduino Nano RP2040 Connect is highly integrated many feature in one dev board. The wire connection in this project is relatively simple. Just few wires connect to 2 modules.

Here are the connection summary:

RP2040    Voice Module    Motor Module
====== ============ ============
GND -> GND -> GND
3V3 -> VCC
GPIO15 -> BUSY
TX -> RX
RX -> TX
SPK+/SPK- -> Speaker
GPIO28 -> IN2
GPIO29 -> IN1
VIN -> VCC
OUT1/OUT2 -> Motor

Sample Code

I have uploaded my sample code to the Github:

https://github.com/moononournation/PositiveResponseChatbot.git

However, the engine model needs to match the dev board serial number. You need import your own trial or release license and generated model files before using it.

Positive Message Response Map

螢幕截圖 2024-01-15 下午9.28.59.png

This is the most important step in this project. I would like to have positive message response for each keyword, or called command in this engine. To avoid message repeat too much in the conversation, each keyword can have multiple response and appear randomly. At the same time some message can reuse in multiple keywords. All relationship managed in the responseMap.h.

Here are some response example:

  • "Good Morning" will reply "Good Morning"
  • "Hello" will say back "Hello", "How are you?" or "Let's play together!"
  • "It's great!" will echo "great!" or "I think so."
  • "I am cold" will considerate "wear more clothes"
  • "It taste good" will reply "I wanna taste it"

Making Voice Clips

After decided the response message map, it's time to make voice clips. You can record clips one by one with recorder app. Or you can generate it by TTS engine.

I invited a little girl help me record it and use Audacity tune to a higher pitch. Then export all voice clips in MP3 format and name it in number according to the response map. At last copy all files to the voice module.

Note:

JR6001 requires all voice clips name in 2 digits number and place into the ZH folder.

If you are using Mac OS, you need to double check with Terminal no any "." leading files in the folder:

ls -la ZH

Test Run

Arduino Speech Recognition Engine + MP3 module

Off the Shelf Robot

IMG_7757.jpeg
Electronic Pet Birds
DSCN1057.JPG

The electronic part and the software are ready, but we still need a robot look. There are many off the shelf robot toy in the market, simply buy one or reuse one in your hand can do the job ;P

Demo

Arduino Speech Recognition Engine + MP3 module + Electronic Pet Birds

What's Next?

IMG_7751.jpeg
  • Battery powered
  • Attach it to the shoulder
  • Refine the response map
  • and more...