Head Bot Example and Starting Code
So Box Head and DRHead are done and fun but how does it all happen? It’s really simple when you look at it. The PC runs some simple voice recognition stuff in VB.net and the Arduino listens for commands from the PC and responds or does it’s own thing like blinking, etc.
Here’s how I’m doing this at least but I’m sure there are many other ways of doing the same thing. i think I left enough examples in the code to see how it works and how to add your own options. the code should allow for sending commands to the microcontroller, getting text and RSS info from the web, and just making general conversation… albeit very limited conversation.
Sorry I tried to make this short and sweet but if you already know how most of this works just get the code and build your bot. If not there are a few steps that may or may not be helpful here.
The PC Side
Get VB.net 2008 installed
The PC side is a VB.net Visual Studio 2008 (remember Box Head and DRHead are running on old XP laptops) and your normal Arduino stuff. It will work on Win7 by uncommenting a few things or re-commenting a few things in the enable area. It’s pretty obvious that Microsoft wants to get people to move along off the old development, and other old products, and on to the new but I’m still an old hack BASIC coder so I like the old VB.net 2008 version. You cannot find the download on the main MS site anymore and if you find a small “setup” program it would work for me as if the main download MS server is gone.
You may well be able to load this up and use it in a new version for VB Express, I just haven’t tried so far. BUT I DID find this ISO link and used it to download and burn a VB.net 2008 instllation disc. Actually Visual Studio 2008 but we only need VB.net to run this. https://go.microsoft.com/fwlink/?LinkId=104679 should give you an approximate 800mb download for the ISO. Burn it to an install disc and install the VB portion. This should be a setup file under the VBExpress folder. I do NOT want to help MS with the “experience” … especially since there is no experience left for this product so I uncheck that box. I also uncheck the MSDN Express Library and the Microsoft SQL Server 2005 Express install… not needed. Let the install run and keep reading… The install takes a while at least on my old machines.
Get the SAPI 5.x
I THINK you will need this but you might try it without the install. I do not think it will hurt anything one way or another but I know it’s needed on Win XP systems. This appears to still be found on the MS sites located here: https://www.microsoft.com/en-us/download/details.aspx?id=10121 – Click the DOWNLOAD button to get the options. You really only need the “SpeechSDK51.exe” and maybe the “msttss22l.exe” files I think unless you may want other languages but I haven’t messed with that.
eSpeak Install (Optional)
If you want to use or play with the eSpeak option then download and install eSpeak. I default the VB code to use eSpeak in the C:\eSpeak folder so either create that and copy the files in the /command_line folder in the eSpeak install or change the starting point in the speaking subroutine. you can actually switch between the MS and eSpeak voice options using voice commands if you want.
Getting the Code Into VB
Create you a new VB project as a Windows Form Application, give it a name at the bottom and click on through. Get into the Form1 design area by double clicking the Form1 and copy/paste the code here for the VB side. You’ll have some errors if you try to run (debug) but add the form fields and button like the image shows here to get past them and just work them one at a time. Any errors should be limited to the form fields as the code works for me with the right fields on the form. (No I’m not good a standardized labeling so if you want to fix that you can do that now too.)
You will also need to add the System.Speech .net object and maybe the Microsoft Speech Object Library COM reference from my experience and what I’ve seen online so add that under the Project / Add Reference menu items. Make sure the .NET tab is selected and scroll down to the System.Speech item and click OK. Then if you want add the Speech Object Library under the COM tab.
Now go back to the Form1 design and add the following fields from the image. They should be TextHeard multiline textbox, LastSaid multiline textbox, LastCommandSent multiline textbox, lblStatus label, lblVoiceStatus label, cmbPorts combo box, cmbBitRate combo box, and Button1 button. You can update the text on the button to Open, OpenCom, Connect, Screw It, or whatever you want.
Remember you DO have to have a microphone or some type of audio input device to use voice recognition. Seems silly BUT I was stumped for a bit when I tested on a new machine without a mic instead of a laptop with built in mic before. Yeah, I’m stupid. Also make sure you run through the basic speech recog mic setup in the Control panel to make sure things are working. The Win7+ speech recog stuff has to work before this will work. You will yell less at your robot if you do this, I promise.
Also make sure you have at least ONE Serial COM port to test the code as it doesn’t expect a machine with nothing in it as you are already writing code for microcontrollers so you have COM ports.. right?
There are a few variables you can use once the code is runnable including the Robot’s name, what you want he/she/it to call you when you wake it up if you leave that in, which COM port you want to default open, etc. Read the comments and it should make sense. The code defaults to the Microsoft voices but you can change that to eSpeak by flipping that variable in the DIM area. Or use the “Please use the eSpeak voice” command.
You should be able to turn OFF the GetComResponse flag and run the code WITHOUT a microcontroller hooked up. That just polls the micro for a response after sending a command. If you are getting slow choppy responses you are likely waiting for the com data timeout and not sending a blip back to the VB app.
The Arduino Side
I am not going to discuss much here, it’s Arduino so if you’re using an Arduino as your animation driver then you need to know a bit about it already. The basic code is included that should work with the VB code and allow basic left/right and up/down head movement, eye blinking using RGB or single LEDs, and driving a jaw animation either by servo or by LED… or both if you so desire… That would actually be kind of cool but I haven’t done that. Put an LED inside the mouth so it blinks as the jaw opens… hmmm…
If you change up the pin layout, which may be a good idea, make sure you make the changes to the Arduino code to adjust for it. Otherwise just read through the code and find all my bugs for me, fix them, and republish please. 🙂
Setting default Microsoft voices
You can setup the default MS voice to use in the Control Panel / Speech area. Windows 7 is limited to the Anna voice for the most part I believe. One may be able to parse the SAPI5 voices and make a selection in the code for them. I’ve done that in an old VB6 app but never looked at the option here since I’ve only really run this under XP.
Limitations and Information
Remember, as this is designed so you have to use the pretty much the exact words to get the command recognized. You also have to have the ExACt case in the IF statement as is in the grammar array or it generally won’t work. I could have UCASED things etc or made the process better but I didn’t.
Also remember everything is hard coded here so you can’t really add commands on the fly. A well written app would have a front end to add the phrase, command to send to the micro, field for what we are supposed to do such as RSS, URL, Speak, or multiple variations thereof, and so on. For my purposes I just run it all in “debug” mode as I’m always tweaking something one way or another.
Also be nice, I’m a hack coder that have somehow made an IT career spanning from PDP 11/34’s through today’s virtual everything and do code web, script and automation at the gov I work for. Just saying you are not going to see super nice, structured, professional code. But I have fun anyhow. 🙂
Visual Studio 2008 ISO Download https://go.microsoft.com/fwlink/?LinkId=104679
eSpeak text to speech http://espeak.sourceforge.net/
VB.Net Code – HeadBotBaseCode2VB.txt – Copy / past into your VB Project form code to use
Arduino Code – HeadBotBaseCodeArduino.txt – Renamed to .ino to use in Arduino IDE
This software works for me. It may or may not work on your PC, setup, configuration, version, etc. Please do not ask for help making it work. I barely can get things to work on my own stuff, much less someone else’s.