Friday, May 24, 2013

Using the Google Voice C++ API

First of all, this obviously isn't an official Google API. I wrote it because I wanted one in C++ and couldn't find one that worked.

That being said, the code is on github here (in the TextCommand folder) and is available under GPLv3 for anyone to use.
I know this could (maybe even should) have its own github project but since I use it for my home automation projects, its included in the PiAUISuite. That being said, the current gvapi binary is also compiled for the Pi. So you will need to run make gvapi if you want to use it on any other linux machine.

To include the C++ code in your own project, you just need to include gvoice.h in your file and then you should be able to access the GoogleVoice class. An excellent example to look at is gvapi.cpp since it shows how to interact with it. You should need only to call Init and Login, then you should be able to do any of the Google voice functions.

If you only to use gtextcommand to send commands to your pi, see here. If you want to send or check SMS without having to include the source in your code/project, just use the gvapi program. It can get contacts, send, receive, and delete SMS. It also comes in with built in spoof protection (this is included in GoogleVoice::CheckSMS).

Here's a quick video demo as an example of the kinds of things you can do with gvapi


Using the gvapi program is fairly simple and it's man page is below:


gvapi


gvapi - Use of Google voice API in order to send and receive SMS  

SYNOPSIS

gvapi [OPTIONS]...  

DESCRIPTION

gvapi was compiled for use with home automation on the Raspberry Pi but will work on any linux system with an internet connection. It uses curl and boost regex in order to login and stores the cookie in /dev/shm. It only logs in once every 24 hours to save time. It supports a multitude of different options and parameters. For help/comments/questions, feel free to e-mail me at help@stevenhickson.com. I answer sporadically but do eventually respond.
 

OPTIONS

-?
Same as -h
-c
Checks your incoming text messages to see if you have anything unread. It will mark it whatever it outputs as read unless you also use the -r flag. If you include a number with the -n flag, you can specify it to only check messages received from that number. You can also use the -k flag to specify that the message must start with a certain keyword.
-d
Sets debug mode on. You can also specify debug mode from 1 - 3, where 3 is the most verbose.
Ex: gvapi -c -d2
-h
Asks for some quick general use help for gvapi.
-i
Outputs the contacts of your google voice account in the form name==number
-k KEYWORD
Sets a keyword that has to be in the beginning of the text message for it to be returned. This is useful as a password for parsing only certain messages.
-m MESSAGE
Sends the message you specify. This should be in quotes if it contains special characters or a space. The number also has to be specified otherwise it won't have a message to send
Ex: gvapi -n +15551234 -m Hello
-n NUMBER
Can be used with the -c flag to check messages from a certain number or the -m flag to send a message. Can be in a format without the country code, with just the country code, or with a plus sign and the country code. If the formost, it interprets it as a US number.
Ex: gvapi -n 5551234 -c
-p PASSWORD
Can be used with the -u flag to log in manually. If not specified, the program uses the default username and password specified in ~/.gv
-r
Receives and deletes SMS messges. Can be used with the -c flag or without. It is the same as the -c flag but instead of just marking the messages as read. It deletes them.
-u USERNAME
Can be used with the -p flag to log in manually. See the -p flag for more details. Cannot be used without the -p flag.
-v
Outputs version and creater information

AUTHOR

Steven Hickson (help@stevenhickson.com)  

BUGS

No known bugs. To report bugs, send a clear description to help@stevenhickson.com Since this program is fairly crude, user typos could cause crashes/failed responses. Please read the man page thoroughly before submitting a bug.  

COPYRIGHT

Copyright © 2013 Steven Hickson. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it as long as you give credit to the author and include this license. There is NO WARRANTY, to the extent permitted by law.  

HISTORY

This is the second major version of this program  

SEE ALSO

http://stevenhickson.blogspot.com/

Consider donating to further my tinkering.


Places you can find me

Monday, May 13, 2013

Voice Command v2.0 for the Raspberry Pi

Voice Command 2.0 differences

Note: Updated version here
http://stevenhickson.blogspot.com/2013/06/voice-command-v30-for-raspberry-pi.html

I've made some big changes since my last post with voice control with the Raspberry Pi.
You can now verify the keyword, change the keyword, change the response, put it in quiet mode to not talk to you, and put it in ignore mode to not try to answer questions not in your config file.
The config file format has also been changed from voice=command to voice==command, comments have been allowed in the config file by starting a line with #, and special settings can be done by starting a line with !.
I've updated the TTS from espeak to Google's API since it sounds a lot better.
Finally, I've made an update script in the Install folder, that way you don't have to reinstall every time new changes get pushed out to github. All of the source code is at:
https://github.com/StevenHickson/PiAUISuite

Video:

Here's a video demonstrating the new changes:


Special Options


The default special options are as follows:
!keyword==pi
!verify==1
!continuous==1
!quiet==0
!ignore==0
!filler==1
!thresh=0.7
!response=Yes sir?

response and keyword can be any string.
verify, continuous, quiet, filler, and ignore can be 1 or 0 (true or false respectively).
thresh can be any floating point number to set the appropriate volume.

Install Instructions

(this requires git)

sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh


Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh


Consider donating to further my tinkering



I've also created a man page fore voicecommand. You can access it with man voicecommand. It is shown below:

voicecommand

Section: voicecommand man page (8)
Updated: 13 May 2013
Index  

NAME

voicecommand - Listen to user defined strings and run the corresponding command  

SYNOPSIS

voicecommand [OPTIONS]...  

DESCRIPTION

voicecommand was developed for the Raspberry Pi but will work on any linux system with a microphone attached. It is a crude program, which uses basic comparisons to determine if your voicecommand fits a format specified in a config file; it it does, it runs the corresponding linux command. It supports auto-completion and variables as well as command verification, a continuous mode, and other options. For help/comments/questions, feel free to e-mail me at me@stevenhickson.com. I answer sporadically but do eventually respond.
 

OPTIONS

-?
Same as -h
-b
Turns off the FILL audio. The purpose of this was because the Raspbery Pi (or mine at least) cuts off the first few seconds of audio. This flag turns that feature off. You should only be concerned with this if you hear FILL before everything it says.
-c
Makes voicecommand run in continuous mode, where it will keep listening over and over again.
-e
Edits the voicecommand config file.
The format is voice==command
You can use any character except for newlines or ==
You can also put comments if the line starts with # and special options if the line starts with a !
Default options are shown as follows:
!keyword==pi,!verify==1,!continuous==1,!quiet==0,!ignore==0,!thresh=0.7,!response=Yes sir? keyword and response accept strings. verify, continuous, quiet, and ignore except 1 or 0 (true or false respectively). thresh excepts a floating point number. These allow you to set some of the flags as permanent options (though the flags can overwrite them temporarily).
-f /my-location/config-file

This allows you to load a different config file located in a different spot. The default one is in your home directory and is ~/.commands.conf
The config file must be formatted the same way.
-h

Shows this man page.
-i

Sets the ignore mode. When this flag is activated, if a command is not in the config file, nothing happens. The default behavior is to try to find an answer or response to that question and then speak it. This turns off that behavior.
-k word

Sets the keyword. The default is pi. If this flag is set, the verify and continuous flags are also set since this is only checked during those two modes.
      Ex. voicecommand -c -v -k Jarvis

-r word

Sets the response. The default is "Yes Sir?" (For version 1.0, it was Ready?. If this response is more than one word, it should be put in quotes, otherwise it doesn't need to be
      Ex. voicecommand -r Ready?

-t #

Sets the threshold for volume to determine if the keyword was spoken. This should be a floating point number. The default value is 0.7 which works well with the Logitech C310 camera/mic from about 6 feet away.
Ex. voicecommand -t 1.2
-q

Sets quiet mode on so that voicecommand never speaks through the audio output. It still prints everything but doesn't ever respond. This includes the keyword response.
-v

Makes voicecommand verify the keyword. This only happens in continuous mode so if this flag is set, the continuous flag will be set as well. The default mode is to not verify. When voicecommand hears any sound above the threshold, it says the response then listens for a command. The default keyword is pi. When the verify flag is set, after the threshold is met, voicecommand verifies that the keyword was spoken.

AUTHOR

Steven Hickson (me@stevenhickson.com)  

BUGS

No known bugs. To report bugs, send a clear description to me@stevenhickson.com Since this program is fairly crude, user typos could cause crashes/failed responses. Please read the man page thoroughly before submitting a bug.  

COPYRIGHT

Copyright © 2013 Steven Hickson. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it as long as you give credit to the author and include this license. There is NO WARRANTY, to the extent permitted by law.  

HISTORY

This is the second major version of this program  

SEE ALSO

http://stevenhickson.blogspot.com/



Consider donating to further my tinkering