Google Voice on Asterisk with an Auto-attendant and free calls

I’ve heard about Asterisk for some time now since using VoIP services such as Google Voice, Gizmo5, Sipgate and Skype. Most of these services allow you to receive unlimited phone calls for free; you just need to register the service using a sip client, such as Ekiga on Linux, telephone on Mac OS X, sipdroid on an Android phone with unlimited data. The only “fancy” thing I did with these services was receive Google Voice calls on Gizmo5 and using the voicemail feature for parents in my local youth group to leave messages (so I don’t have to release my personal phone number or talk to them…I am a busy person).

Before I continue, I just want to say that I really like Google Voice as a service. You get a free phone number that you can forward to different phones, including the VoIP provider Gizmo5. The voicemail transcription is just awesome; I even set my personal cell phone to use GV as it’s default voicemail application over the network provider’s. If you use an Android phone, you get the GV app that let’s you read voicemails and text messages, send text messages and call using the GV phone number. Most recently, you can even receive and call any US number for free!

I recently wanted to set up an auto-attendant with GV so my youth group’s main phone number could be routed to the specified person when parents need to speak with us; I really don’t like to give out our personal phone numbers, not because we don’t want to talk to parents, but because they still call you (thinking you’re in charge) when other volunteers have taken over your position at the group.

Searching for “free auto-attendant” or the likes yielded a few services. I checked out Phonebooth but it didn’t really do what I wanted to or is very limited; either that or I didn’t know how to set it up. I remembered Asterisk and finally looked more into it.

According to Wikipedia), Asterisk is an open source PBX (Private Branch Exchange). It’s called Asterisk (*) because once the original author wrote a program to connect a computer to the telephone system, he realized anything could be done with the program. Hence asterisk meaning anything.

I will now outline how to set up Google Voice to receive and forward calls with Asterisk, along with playing messages for the caller to hear. This is what I want to have for my youth group. Note figuring out this entire process was hard because I am not familiar with phone systems and networking. The folks from #asterisk on freenode was very helpful. Before I start, let me mention that the free book on asterisk is the definitive guide on learning this stuff. Reading the Dialplan section is a must for learning how to handle calls (play message, forward, etc). Debugging is a must when seeking help in the irc channel, forum, or mailing list.

Install Asterisk on a Linux system

I will provide instructions for how to install the plain Asterisk version, not AsteriskNow or the many derived products. You can install it using apt-get on Debian/Ubuntu, but we’ll need version 1.8 to get Google Voice working with Asterisk without going through another VoIP provider. I’ll install it from the 1.8 branch of the svn version:

sudo apt-get install libiksemel-dev libssl-dev libncurses5 g++ libxml2-dev
svn co
cd 1.8
sudo make install
sudo make samples

This will install asterisk. Be default, Asterisk needs to be run under the root user. sudo asterisk would start it. sudo asterisk -r will connect to a CLI on the current machine with asterisk running. sudo asterisk -c will start Asterisk and go directly into the CLI.

Google Voice setup

Edit the following files in /etc/asterisk/.

jabber.conf and replace gmail.address with yours, and tnttspJabber with what you want to call this connection:


username=gmail.address/gmail ;; either will work
statusmessage="I am an asterisk server." ;required


;;context=default ;; you can specify here too

context=tnttsp ;; context in extensions.conf
connection=tnttspJabber ;; refer to the connection name in [ ] in jabber.conf

This will make asterisk connect to GV via the jabber protocol. It is as if you are logged into gtalk in gmail, where you can send and receive phone calls.

The dialplan, the configuration in extensions.conf, is what we tell asterisk to do when a call is received from a channel or what to do when digits are pressed in a call. Please read it in the book.

A basic hello world example and the ability to dial out in extensions.conf:


exten => s,1,Answer()
;;exten => s,n,Wait(10)
exten => s,n,Wait(1)
exten => s,n,SendDTMF(1) ;;needed for google voice; otherwise, only call to computer in gmail will work and not calls made to google voice
exten => s,n,Playback(hello-world)

;; call
exten => _1NXXNXXXXXX,1,Dial(Gtalk/tnttspJabber/+${EXTEN}

Some references for this setup are here, here (look in comments), here, and here (look in comments).

Note that to dial out, you need to use something like an AMI script or be in Asterisk. I have not yet figured out how to connect a sip client to asterisk to be able to dial out because I am not that savvy with networking. Sip client and asterisk needs to be directly connected to each other, and having the host and/or client behind firewalls make things complicated.

For wav files to be played using Playback() or Background(), make sure

  1. File paths do not include the extensions, such as .wav. For example, /home/username/sound/mysound not /home/username/sound/mysound.wav.
  2. Wav files need to be mono and 8000 Hz. Use the following script to convert them:
#! /bin/bash

for file in "$@"
mv $file ORG$file
sox ORG$file -r 8000 -c1 -s $file rate -ql

I have not tested mp3 files.

USB NAS and print server

I assume you have a compatible router with usb ports with the Teddy Bear mod Tomato firmware installed.

These instructions show that the USB NAS portion is quite easy. Once the hard drives are connected, they are automatically mounted in the router’s Linux OS. A computer on the same network can connect to the router’s hostname/ip via the samba protocol or ftp (if enabled).

Printserver was less obvious since I wasn’t familiar with it. Tomato uses p910nd printer daemon. By default, only 1 instance is running on Tomato on port 9100. If you plan on connecting multiple printers (eg, adding through a USB hub), then you will need to run additional instances of p910nd in the startup script of the Tomato firmware:

 <pre class="src src-sh">/usr/sbin/p910nd -b -f /dev/usb/lp1 1

Continue to add 2, 3, …, if more printers are required. Reboot the router, and another instance is added to port 9101, etc. Note: the ordering is based on the proximity of the USB ports. Check the USB page on the router config site to determine the ordering.

To add a printer on a Windows machine, you will have to add it MANUALLY (auto-detect of any kind will not work). Following copied in case those links die:


  • I installed the printer the same exact way I do most USB print servers
  • HOSTNAME/IP: Your_Router_IP (ex:, mine is different), PORT NAME: let it auto-populate
  • UNCHECK the “Query the printer…”
  • Detection should fail…
  • On bottom, DEVICE TYPE click on CUSTOM, then SETTINGS
  • Leave all default ports and settings and click OKAY
  • Finish everything and print a test page.

On my Ubuntu, searching the printer on the router’s hostname/ip works. However, on all machines, you will have to select the type of printer manually.