Create your own Virtual Personal Assistant

Voice-unlock-coming-with-Microsofts-always-on-virtual-assistant-Cortana1.jpg

Sophie_LMR.zip (6745Bytes)

Well it has been quite a while since I've put something here mostly because of college stuff, so let me just get to it. The embedded video is me talking to my little quadbot which inspired me to create a virtual assistant. I created this assistant on Windows 7, so there might be some discrepancies if you are working on other OSs. 
Objective:
To create your own virtual personal assistant which can be modified to do a variety of different tasks like gather weather data, tell a joke or even place an order for your favorite sandwich.

Softwares Used:
Required:
  • BitVoicer - Speech Recognition (this is where the $5 comes in)
  • Python 2.7 - Coding language
  • Eclipse, Geany or your prefered interface for coding on Python
  • Virtual COM Port

Optional:

  • Ivona Voices - More natural sounding text-to-speech voices for Windows


Procedure:

First download Python (for this tutorial I am going to use version 2.7.3) which can be downloaded from https://www.python.org/download/releases/2.7.3 

Install it into C:\Python27 for convinience sake.

Next thing you need to do is download and install eclipse which is an interface for writing your code via Python. You can download it from http://www.eclipse.org/downloads/

Install it into C:\eclipse

If you get this error while running it...

java_error.png

Go to the first answer in http://stackoverflow.com/questions/2030434/eclipse-no-java-jre-jdk-no-virtual-machine

www.stackoverflow.com is the best place to find help for any issues in python

Use this tutorial to install python into eclipse.

Alternatively use this tutorial to install python into Geany.

There are something called 'libraries' that you will need to access the different functionalities of python. This case we want a way for the computer to speak (text-to-speech). This is done using a library called pyttsx. Now lets go ahead and install this library. For those of you who already know how to install libraries just go ahead to the code.

Installing pyttsx (use the hyper link for documentation)

The first thing pyttsx needs is a pywin32 windows package which should be downloaded from here.

Next, install pip which is a command line installer for python (don't worry about it now). Download pip from here and paste it to your Python27 directory.

Now go to C: drive and while holding Shift key right click on the "Python27" folder. And choose 'Open command window here'

Next type 'python get-pip.py' and you should get something like this:

pip_install.png

Now in C:\Python27 open command line as before, open command line for the folder "Scripts" and enter "pip install pyttsx"

If everything installed correctly, you should be able to make your computer speak. Let's now try this.

Create a new file called myVPA.py or anything that you prefer. Don't forget the '.py' at the end, because that is what makes Eclipse recoginize it as a python file.

Type this in it, turn your volume up and click on Run (accept any dialogue boxes that follow):


 

import pyttsx   # text-to-speech library

engine = pyttsx.init()   # initiates speech engine

engine.say('Hello World') # loads text into engine

engine.runAndWait()   # THIS LINE IS IMPORTANT, runs the speech engine

 


 

If you hear your computer say "Hello World", then wohla we are a third of the way there.

Once you are done having fun making your computer (which I am going to call Sophie) say all sorts of stuff, let us move to actually being able to have a conversation with her.

This is where we will have to buy and setup BitVoicer, yeah you just have to trust me with your $5 on this. Until I can find an alternative to a free speech-to-text software, I'm just gonna suggest BitVoicer. You could alternatively use BitVoicer to command your arduino like I have shown in the video.

Once you finish installing BitVoicer, we need to use a Virtual Serial Port Emulator. 
Why? Because BitVoicer was originally created to be used in conjuction with Arduino communicating over the Serial Port and we will have to make BitVoicer 'think' that it is still talking to an arduino over the serial port.

For now we can use this one: http://www.eltima.com/products/vspdxp/

Once you have installed this (trial version will do for now), open it and do the following.

Virtual_COM_Port.png

Click on Add Pair (make sure you are not using there COM ports prior to this, you can check this by going to Device Manager and clicking on ports)

Next, like before we need to install another library to Python that lets it communicate with Serial/COM ports.

Type this: pip install pyserial

pip_install_pyserial.png

 

Lets setup BitVoicer now.

Go to File >> Preferences and put in the following values:

I think this is a good place to say that you could install additional languages or accents by going to File >> Additional Languages to better suit your voice. I changed mine to English - India just to make the speech recognition more accurate. Create a new Voice Schema (File >> New).

Then “Add New Sentence” twice and set it up EXACTLY like this:

bitvoicer_new_sentence.png

If this picture is not legible, the command for “Who are you” is ‘who’ and “Do you like cookies” is ‘lik’ respectively.

Now we are ready to code on Python and get this thing working.

In your myVPA.py file write the following lines of code:


 

import pyttsx # text-to-speech library

 

import serial # serial communication library

 

while True: # creates a loop so that you can keep talking

    ser = serial.Serial(‘COM8’,9600) # opens COM port 8 with baud rate of 9600

    raw_data = ser.read(7)      # reads the first 7 characters coming from the port

    msg = str(raw_data[3:6])        # extracts 3rd to 6th characters from the array 


    # Note: The first three characters coming from BitVoicer are junk values

    #    for some reason I cannot understand, hence I just use values

    #    starting from the third character, you can increase the range of values

    #    as per your liking, but for the first time, just stick to this code

    

    print msg   # debugging line to check input

    ser.close() # closes the serial port so as to reset the input commands

    

    if(msg == ‘who’):

        engine = pyttsx.init()

        engine.say(‘Hi there. I am Sophie, your own Virtual Personal Assistant’)

        engine.runAndWait()

    

    if(msg == ‘lik’):

        engine = pyttsx.init()

        engine.say(‘Ofcourse I do! What do you think I am? A computer?’)

        engine.runAndWait()

 


 

Now go to BitVoicer and hit Start and only then go to your python script and click Run.

 

Now when you speak “Who are are?” clearly enough, your computer should respond with “Hi there. I am Sophie, your own Virtual Personal Assistant” or if you say “Do you like cookies?”, she should say "Ofcourse I do…"

Note: You can check the console of python to see what commands and being received and alternatively you can check the ‘Activity’ box to see what commands are being sent from BitVoicer

If this worked well, congrats!!! You have made it through this tutorial and are well on your way to upgrade Sophie or whatever you would choose to call it and make it do what ever you want.

An optional thing you can do here is install a voice pack from Ivona (use the trial version for now, install the voice you think suits you (I like to switch between Salli and Raveena).

You can change voices by going to Start >> ‘Change text to speech settings’ and doing this:

Apply changes and try your code again. Always remember, in python, terminate the current program before coding and executing your program.

The uploaded files needs to be used with each other but you will need to install the corresponding libaries by yourself, and also check the COM port settings.


 

The reason I wrote this tutorial is because I loved the AI in the movie "Her", but to be able to make an AI as powerful and efficient as that, there would require a lot of research and thousands of lines of code. I just wanted to motivate you to be one of those people to create a breakthrough in this field of an Artificial Personal Assistant. 


 

If you have any questions or suggestions or even your own cool updates, just post it as a comment and I will try to get back to you ASAP.

by Adith Jagadish Boloor

https://www.youtube.com/watch?v=xs0MVZD1LsI

@ 6677 and Ladvien, I just

@ 6677 and Ladvien, I just recently taught myself to use python, and the first tutorial showed Eclipse. I will check out Genny and if I like it and have enough time will update this guide with it.

Cool

An excellent write-up, thanks for taking the time with the details.

error in the program!!

i was following each and eevery step but by when i type in the first code which should result in the pc saying hello world, my eclipse software shows error as ImportError: No module named ‘engine’. please help me?? m new to this.

awesome

thank you for sharing :slight_smile:

of the pyton and bitvoicer,
Can be made into a single application that is ready to use,
like windows speech recognition macro?
I think could be made the object on the desktop computer, as a form of sophie.

Not a programming smart, but

Not a programming smart, but I find this project amazing. The concept is fascinating. One can actually build a human-like bust and have him/her in the room talk and beahve like a friend sitting around. Sky is the limit for this post, among which is fake attendant in your house to prevent burglers. Many many thanks.

i am using windows 10 does i

i am using windows 10 does i have use all the stuff in latest version

 

You don’t have to use virtual serial ports!

Hello, I know this post is a bit old, but I’ve been working on something similar and was annoyed about having to pay for the virtual serial ports program. So, I decided to make use of the TCP/IP option in BitVoicer to implement it over the internets.

This is useful, because it makes it so that you don’t have to pay $150 for the virtual serial port program once your free trial runs out. Also, you could use this to make it so whatever machine is reading the input from a microphone doesn’t have to be connected to your PC.

I’ve used a very basic implementation of Sockets and threads to make this work. You may not need to multithread your program for it to work, but I’ve done it here, just because it feels cleaner and I was already using threading for the GUI I made with TKInter.

You can check out my code here.