Home » Technology » Audio » Tweaking Asterisk for Free Google Voice Calling

The Most Versatile VoIP Provider: FREE PORTING

Tweaking Asterisk for Free Google Voice Calling

Lips from Google Now that the Asterisk® and Google Voice marriage is finally underway, we wanted to step back today and revise the original methodology a bit to take advantage of some of the terrific comments which were offered in response to our last article. First, the good news. U.S. calls through Google Voice using Asterisk work! They sound great, and they're free. The not so good news was that the MeetMe conferencing trick to join your outbound call with the Google Voice click-to-dial return call from your destination worked great so long as a real person answered the phone. But, if an answering machine picked up or no one answered the call at all, there were problems because these calls already had been transferred to the MeetMe conference and there was no simple way to disconnect them. And the need for two DIDs to support a single Google Voice interface just seemed a bit wasteful.

9/1/2010 Update: A good bit has changed with Google Voice since this article was first published. For the definitive guide and installation procedure, we highly recommend The Incredible PBX and accompanying article which can be found at this link. Google Voice (and much more) already is included in our new PBX which is literally Plug-and-Play. If you prefer to roll your own, be sure to also have a look at this excellent update on the Michigan Telephone Blog.

Today we want to try to eliminate these two quirks while stiill providing a seamless interface between Google Voice and Asterisk. We also appreciate that thousands of you already have implemented the previous approach. So we want your transition to the new way of doing things to be as painless as possible. On the other hand, for frequent readers, we hope you'll bear with us as we repeat some of what already has been covered in previous articles so new visitors don't have to jump around between articles to get the complete picture of what we're trying to accomplish.

The objective remains the same. We want a methodology that lets us make outbound calls from any Asterisk phone using the Google Voice service to take advantage of free calling in the United States and Canada. And we want calls to our Google Voice number delivered to our Asterisk system for transparent call processing. Yes, SIP is still on our wish list for both outbound and inbound calls with Google Voice, but we'll make do with PSTN calls particularly while Google is footing the bill for all of the calls.

Update: There's now a turnkey Asterisk solution that implements Google Voice calling without getting your hands dirty. Check out our new Orgasmatron V.

Tweaked Design. Here's the new design. You obviously still need a free Google Voice account. If you don't have one, you can request an invite here. At last report, it's only taking a few days from application to invite which is really great news. Don't use a space in your Google Voice password! Once you have a Google Voice account and phone number (Google has reserved a million of them so... not to worry!), then you'll need a DID that provides unlimited, free incoming calls. Once you get your DID set up on your Asterisk system, we'll set up a forwarding phone number for this DID in your Google Voice account so that Google Voice calls can be connected to your Asterisk server.

For outbound calls, we'll combine a little dialplan voodoo with pygooglevoice to instruct Asterisk to place a click-to-dial call using your Google Voice forwarding number. Then we'll stuff in the destination U.S. phone number. When you dial GV-678-1234567 from any of your Asterisk phones, Asterisk will park your initial call in a reserved parking lot slot and then join the called party to the originally parked call. The entire procedure is virtually transparent both to the caller and the callee. And, unlike the MeetMe conference, the parking lot fades out of the picture as soon as the call is connected. Thus, if either party hangs up, the active channel for the call is terminated on your Asterisk server.

For inbound calls from your Google Voice number, we'll tweak the dialplan so that it can distinguish between a RingBack call that Google Voice initiated and a true inbound call. We'll peel off the real inbound calls and route them to a separate Inbound Route in FreePBX for processing in any way you desire.

Finally, for those that implemented the methodology in our previous article, we'll walk you through the steps to revise your existing setup to take advantage of these new tweaks. You can skip over the initial installation process if you already have gone through the Google Voice setup from our earlier article. Just skip down to Tweaking Previous Setups.

Special Thanks. At the outset, we again want to express our sincere appreciation to Jacob Feisley and Paul Marks for their pioneering work on a Python interface to Google Voice. We also stumbled upon another Python development project, Google Voice for Python. While we originally had planned to rely upon Jacob and Paul's script, we ultimately decided to implement pygooglevoice because of the additional flexibility it provided for down the road. With pygooglevoice, you not only can make Google Voice calls, but you also can send SMS messages with no muss or fuss. Jacob Feisley has now joined that project as well. So, our special tip of the hat goes to the entire Google Voice for Python development team. It's a terrific product as you will see.

Prerequisites. Today's setup requires a CentOS-based Asterisk aggregation with a current version of FreePBX. Be aware that today's solution requires Python 2.4 or higher and reportedly will not work with Python 2.3 found in some Linux distributions. We've tested everything with PBX in a Flash and, on that platform, you're good to go. The install script should work equally well with the other CentOS-based Asterisk aggregations, but we haven't tested them. Be our guest, and let us know if you encounter any problems. Finally, a word of caution. We don't ordinarily distribute solutions using development tools we don't use. Our knowledge of Python wouldn't fill a thimble. We've made an exception today because of the extraordinary interest in Google Voice by the Asterisk community. But, if something comes unglued, we can't fix it. So have a backup plan in place just in case. 🙂

Today's Drill. To get everything working today, there are six steps: (1) obtaining and configuring a DID to manage calls between Google Voice and Asterisk, (2) configuring a Google Voice forwarding number for this DID to manage your outbound and inbound calls, (3) configuring FreePBX to route all outbound calls with a GV prefix to your special Google Voice dialplan context, (4) configuring an inbound route to manage incoming calls from your Google Voice number, (5) setting up a series of Parked Call extensions, one of which will be used to manage your outbound Google Voice calls, and (6) running our install script which adds the dialplan code for Google Voice calling with your credentials and puts the Python application into place on your server. It sounds more complicated than it is. So hang on to your hat. Here we go!

Dedicated DID. Before you can use Google Voice with Asterisk, you'll need a DID that can be dedicated to your Google Voice interface to Asterisk. We'd recommend a free IPkall or SIPgate DID. To get started, use one of the links above to obtain and configure the DID. Temporarily point the DID to an extension on your Asterisk system that can be used to verify your requests for the number. Since all of these calls are free, the area code of the DID really doesn't matter because you're never going to publish the fact that it exists.

The easiest method for setting up the DID is to first create a SIP URI for the DID on your Asterisk system. Next route the SIP URI to an Inbound Route in FreePBX where you can manage the destination for calls to that DID. Initially, you want the destination to be an extension on your Asterisk system that you can answer to verify both the DID setup and the GV setup below. Finally, point the DID you obtained to the SIP URI defined above.

HINT: The entry in extensions_override_freepbx.conf would look something like this for a SIP URI called ipkall-1:

exten => ipkall-1,1,Goto(from-trunk,${DID},1)

Then you would create an inbound route named ipkall-1 using FreePBX and designate some existing extension on your server as the destination for these inbound calls.

When you set up the SIP forwarding for the DID at ipkall.com, you'd specify the SIP URI as:


We've previously covered in detail how to do this so read the article if you need a refresher course. To reiterate, the area code of this DID really doesn't matter because you're never going to give out the number. So use one of the free sources and save yourself some money. The real trick is you want to use a DID with unlimited, free inbound calls. Both IPkall and SIPgate provide that functionality at no cost.

Google Voice Setup. Log into your Google Voice account and click Settings, Phones, Add Another Phone. Add the area code and phone number of your DID. Be sure the DID is pointed to an extension on your PBX that you can answer since you have to go through Google's confirmation drill to successfully register the number. After the DID is confirmed, be sure there's a check mark beside this Google Voice destination so that incoming calls to your GV number will be routed to your Asterisk server.

While you're still in the Google Voice Setup, click on the General tab. Uncheck Enable Call Screening. Turn Call Presentation Off. And set CallerID to Display Caller's Number. Be aware that IPkall DIDs only forward your IPkall number as the CallerID number while SIPgate DIDs reportedly forward the actual number of the person calling you. If this matters to you, then you may prefer the SIPgate DID option. Finally, uncheck Do Not Disturb. Now click the Save Changes button.

Integrating Google Voice into Asterisk with FreePBX. Open FreePBX with a web browser and choose Setup, Trunks, Add Custom Trunk. Insert your GV number in the Outbound CallerID field and add the following Custom Dial String on the form and Submit Changes and reload the dialplan:


Next, choose Setup, Outbound Routes, Add Route and fill in the following entries on the form:

Route Name: GoogleVoice
Dial Pattern: 48|NXXNXXXXXX
Trunk Seq: local/$OUTNUM$@custom-gv

Inbound Routes. Next, we need two Inbound Routes to get everything working. In setting up your DID with IPkall or SIPgate, you already should have created one inbound route for that provider. It already should be routing calls to an extension on your PBX. Now we need to create a Custom Destination for this inbound route and then reroute these calls there. In that way, your RingBack calls will be routed to some special dialplan code that drops these calls into a custom parking lot where the RingBack call is married up to the extension from which you placed the original call. Then we need to create another inbound route to manage normal incoming calls that are forwarded to your PBX whenever someone dials your Google Voice number.

To begin, choose Tools, Custom Destinations, Add Custom Destination and add an entry like this and then click the Submit Changes button:

Custom Destination: custom-park,s,1
Description: Custom GV-Park

Next choose Setup, Inbound Route and click on the inbound route you created previously for IPkall or SIPgate. Change the destination for these calls to Custom Destination: Custom GV-Park.

Now click on Add Incoming Route and create a new route for your incoming Google Voice calls. Give it any description you like but, for the DID number, it must be gv-incoming. You can leave most of the other defaults. Just be sure you set a destination for your incoming calls from Google Voice. It could be an extension, ring group, IVR, or whatever best meets your needs. The important entry here is gv-incoming for the DID number. Click the Submit button to save your entries. Ignore the warning that you've entered an oddball DID. We know what we're doing. 🙂

Setting Up the Parking Lot. While still in FreePBX, we need to create or adjust your existing settings in Setup, Parking Lot. The parking lot is used by FreePBX to simulate old key telephones where you could place a call on hold and then someone else in the office could pick up the call by clicking on the blinking key on their phone. The Asterisk equivalent is to press the flash hook and dial your Parking Lot Extension which then places the call in a Parking Lot space and tells you what the space number is. Someone else then can dial the number of that space to pick up the call. Our little trick today works like this. When you place an outbound call through Google Voice, your extension will be dumped into a reserved parking lot space. When Google Voice initiates the RingBack call before connecting the destination number you've dialed, that call will be sent to the same reserved parking lot space. The two calls then are joined, and you'll hear the parking lot number followed by ring tones as your call is connected by GV to its final destination. Our special thanks to Richard Bateman for his comment on the previous article and this terrific tip! He wins an Atomic Flash installer from Nerd Vittles. In addition, A. Godong wins an Atomic Flash installer for his tip on consolidating two DIDs into a single DID to manage both inbound and outbound GV calls. Just send us your addresses.

Now, where were we? Most FreePBX systems have a default setup for the Parking Lot. What we need to do is be sure you have reserved one more space in the parking lot than you actually need for day to day operation of your PBX. We'll use the last parking lot space number to manage outbound calling through Google Voice. Our entries look like the following:

Enable Parking Lot Feature: checked
Parking Lot Extension: 70
Number of Slots: 5
Parking Timeout: 30 seconds
Parking Lot Context: parkedcalls

Destination for Orphaned Calls: Terminate Call: Hangup

If you use our setup above, the Magic Number is 75 which is the fifth slot in the Parking Lot. If you use a different Parking Lot extension or number of slots, here's how to calculate the Magic Number. Start counting the slots beginning with one more than the Parking Lot Extension. When you get to the last slot in the number of slots you've specified, that's your Parking Lot Magic Number. Write it down. You'll need it in a second when you run our GV installation script.

Save your entries and reload the Asterisk dialplan when prompted.

Integrating pygooglevoice. Now we're ready to complete the setup by running our revised script which loads pygooglevoice and sets up your dialplan in extensions_custom.conf. You'll need 5 pieces of information to run the script so write them down before you begin:

1. Your 10-digit Google Voice phone number
2. Your Google Voice email address
3. Your Google Voice password (no spaces!)
4. Your 11-digit RingBack DID (16781234567)
5. Your Parking Lot Magic Number

A word of caution: If you used a gMail address to set up your Google Voice account, it's possible to have different gMail and Google Voice passwords. For this to work, you'll need to enter your gMail password, not your Google Voice password (assuming they're different).

Now log into your Asterisk server as root and issue the following commands:

cd /root
wget http://bestof.nerdvittles.com/applications/gv/install-gv-new
chmod +x install-gv-new

Google Voice Speed Dials. For frequently called numbers, you can add speed dials by inserting entries in the [from-internal-custom] context of extensions_custom.conf that look like the example below where 333 is the speed dial number and 6781234567 is the area code and number to call. Be sure to reload your Asterisk dialplan to activate them.

exten => 333,1,Dial(local/6781234567@custom-gv,300)

Congratulations! You now have what we hope will be flawless and free U.S. calling on your Asterisk system using Google Voice. No gimmicks, no strings, no cost. Enjoy!

Finally, one additional word of caution. Both Google Voice and this call design are set up for a single call at a time. There are no safeguards to prevent multiple calls, but that may violate the Google Voice terms of service.

Asterisk 1.6 Solution. Several readers now have documented the procedure for implementing the Asterisk 1.6 bridge technology to make outbound Google Voice calls. You can read all about it here.

Tweaking Previous Setups. If you installed pygooglevoice using our previous tutorial, here's what you need to do. First, log into your Asterisk server as root and issue the following commands:

cd /etc/asterisk
nano -w extensions_custom.conf

Scroll to the bottom of the file by pressing Ctrl-W then Ctrl-V. Move up the file using up arrow until you reach [custom-gv]. Press Ctrl-K repeatedly to delete all of the lines in the [custom-gv] context. If you get to another line that starts with a label in brackets like [this], STOP deleting. Once you've deleted all of the lines in the [custom-gv] context, save the file: Ctrl-X, Y, and press Enter.

Now continue reading this article by jumping up to the Google Voice Setup topic. The Custom Trunk entry and the GoogleVoice outbound route will already be in your FreePBX system so there's no need to repeat those two steps. You will need to perform the remaining FreePBX steps beginning at the Inbound Routes topic and continuing on with Setting Up the Parking Lot. Finally, when you run the new installation script, it will detect that pygooglevoice is already on your system and will skip that step but will install the new custom contexts in extensions_custom.conf using your new settings. Enjoy!

Thought for the Day. Which is more arbitrary: (1) Apple snubs Google Voice or (2) Google Voice snubs SIP? Pays to look in the mirror occasionally.

Best Read of the Week. Memo to Steve Jobs and Apple: Stop Being A Jerk!

Need help with Asterisk? Visit the PBX in a Flash Forum.
Or Try the New, Free PBX in a Flash Conference Bridge.

whos.amung.us If you're wondering what your fellow man is reading on Nerd Vittles these days, wonder no more. Visit our new whos.amung.us statistical web site and check out what's happening. It's a terrific resource both for us and for you.


Special Thanks to Our Generous Sponsors

FULL DISCLOSURE: ClearlyIP, Skyetel, Vitelity, DigitalOcean, Vultr, VoIP.ms, 3CX, Sangoma, TelecomsXchange and VitalPBX have provided financial support to Nerd Vittles and our open source projects through advertising, referral revenue, and/or merchandise. As an Amazon Associate and Best Buy Affiliate, we also earn from qualifying purchases. We’ve chosen these providers not the other way around. Our decisions are based upon their corporate reputation and the quality of their offerings and pricing. Our recommendations regarding technology are reached without regard to financial compensation except in situations in which comparable products at comparable pricing are available from multiple sources. In this limited case, we support our sponsors because our sponsors support us.

BOGO Bonaza: Enjoy state-of-the-art VoIP service with a $10 credit and half-price SIP service on up to $500 of Skyetel trunking with free number porting when you fund your Skyetel account. No limits on number of simultaneous calls. Quadruple data center redundancy. $25 monthly minimum spend required. Tutorial and sign up details are here.

The lynchpin of Incredible PBX 2020 and beyond is ClearlyIP components which bring management of FreePBX modules and SIP phone integration to a level never before available with any other Asterisk distribution. And now you can configure and reconfigure your new Incredible PBX phones from the convenience of the Incredible PBX GUI.

VitalPBX is perhaps the fastest-growing PBX offering based upon Asterisk with an installed presence in more than 100 countries worldwide. VitalPBX has generously provided a customized White Label version of Incredible PBX tailored for use with all Incredible PBX and VitalPBX custom applications. Follow this link for a free test drive!

Special Thanks to Vitelity. Vitelity is now Voyant Communications and has halted new registrations for the time being. Our special thanks to Vitelity for their unwavering financial support over many years and to the many Nerd Vittles readers who continue to enjoy the benefits of their service offerings. We will keep everyone posted on further developments.

Some Recent Nerd Vittles Articles of Interest...


  1. Here’s the fix. First, you’ll need to find voice.py in your existing server. It should be in /root/pygooglevoice/googlevoice or /root/pygooglevoice/googlevoice.

    Once you find the directory, cd to that directory and…

    Be sure to cd to proper directory
    mv voice.py voice.py.old
    wget http://pbxinaflash.net/source/gv/voice.zip
    unzip voice.zip
    rm voice.zip
    cd ..
    python setup.py install

  2. Is there a way to change the GV account details (Phone number and/or google account credentials) once the python script has been setup? I have changed my account password and wanted to update it in the python script.

    [WM: You’ll find the entries at the end of the extensions_custom.conf file in /etc/asterisk.]

  3. For some reason my setup has stopped working. I have not changed anything on my side (Not even the google account settings). I just get the parked call message and then music on hold without the call ever connecting.

    I see that there is a new release of the Pygooglevoice script on google code. How do i upgrade to it?

    [WM: See the last 10 comments on this Nerd Vittles article for some tips.]

  4. There needs to be an update script, so when this thing breaks, u just type python setup.py update, and it wgets a script file that wgets everything else, and removes whatever files, and everything by itself, and then python setup.py installs again by itself, so people dont have to keep coming here and being like, its broken, wtf, they can just type setup.py fix, and it checks for a fix, oh, a new fix as of this date, would u like to apply… or something like that.

    [WM: Right you are. Not quite that easy, but here are the steps.]

    1. Visit http://pygooglevoice.googlecode.com and discern the name of the latest update.

    2. Log into your server as root and issue the following commands using the new filename:

    cd /root
    wget http://pygooglevoice.googlecode.com/files/pygooglevoice-0.5.tar.gz
    tar zxvf pygooglevoice*
    cd pygooglevoice-0.5 #<– Use latest filename here, too!
    python setup.py install

  5. If you are using a free IPkall number that doesn’t pass the correct caller ID through, when running the script enter your 10 digit IPkall number, not your Google Voice number.

    If you’ve already done it and wonder why the RingBack call is ringing on another extension rather than magically joining up with your outgoing call in the parking lot, you can change this detail in extensions_custom.conf and it should work.

  6. For anyone trying to set this up that can’t get it to work, here are a few pointers:

    1) Make sure you have the latest pygooglevoice version – see arandomperson’s post about three entries above this one.

    2) Try a call from the command line. Note that the number you are calling must be entered WITH a 1+area code (11 digits altogether), whereas the number you are directing the call to must be one of the destinations registered as a destination on your Google Voice account and is specified using only 10 digits. Further, you might need to leave an additional space and specify the type of number you are directing the call to. Permissible phone types are 1-Home, 2-Mobile, 3-Work, or 7-Gizmo. So lets say you are directing a call to a Gizmo5 number (ten digits starting with 747), here is what your entry from the command prompt should look like:

    gvoice -e myemail@gmail.com -p myGVpassword call 12345551234 7470000000 7

    3) If that works then you know you have to add the call type variable to the call in extensions_custom.conf. You can either add a variable for the type, or you can do what I did and eliminate the extraneous variables and hardcode everything but the extension number:

    exten => _X.,n,System(gvoice -e myemail@gmail.com -p myGVpassword call ${EXTEN} 7470000000 7)

    Remember, the type must match the number before it. I suspect this may be only necessary in some cases (such as when the destination is a Gizmo5 number).

    4) After doing the command line test above, check the CLI or your call records to see what Caller ID was used. If this doesn’t exactly match what’s in your [custom-park] context it won’t work. By the way, it is possible to do away with custom-park altogether, but it’s rather convoluted. You have to create a Misc. Destination pointing to your parking lot code, then you create an Announcement to kill a few seconds (have it play pls-wait-connect-call) and make its destination the Misc. Destination, then you can create an inbound route with the proper DID and Caller ID (exactly as it comes in on a callback from GV) and send it to the Announcement. The inbound route then detects the DID/CID combination, sends the call to the announcement to burn a few seconds while the caller is being transferred to the parking lot, then the call goes to the parking lot slot via the Misc. Destination. As I say it’s convoluted but if you like to stay within FreePBX as much as possible, that’s one way to do it.

    5) Take a few minutes reading the other comments above, there are some good hints there (like how to keep Allison from saying a couple of digits
    before the call connects through).

    6) Finally, on my system I set this up as a custom trunk, so I could route calls to it that are dialed in the normal manner, using the outbound route capability of FreePBX. To do that, create a new CUSTOM trunk, set Maximum Channels to 1, set dial rules to
    if you want to convert 10 and 7 digit numbers to the proper format (change aaa to your area code, or just leave that line out if you don’t have 7 digit calls in your area or take care of this elsewhere in your dial plan), and then in the Custom Dial String textbox put this:

    One other advantage of making it a trunk is that you can this make it first in the list of preferred trunks, and if you ever have a problem with it you can simply come back to the trunk page and check the Disable Trunk checkbox until you figure out what the problem is, and your calls will fall through to the next preferred trunk. Also, with a bit more effort you can restrict that trunk (and the route(s) that use it) to particular extensions, if you use either of the third party FreePBX modules that let you do that (Custom Contexts or Outbound Route Permissions – I happen to like the second one better, but either would work for that purpose).

  7. A couple more pointers found after I posted my previous message:

    First, you can get into the parking lot a bit faster by not waiting around for the system call to gvoice to finish executing. You do this by adding a space and ampersand just before the final parenthesis (compare the following to the similar line in item 3 of my previous post):

    exten => _X.,n,System(gvoice -e myemail@gmail.com -p myGVpassword call ${EXTEN} 7470000000 7 &)

    If you do this then you can probably eliminate the delay in sending the incoming call to the parking lot – in my case I was able to take out the time-wasting announcement that I inserted in step 4 (of my previous message) and go right from the inbound route to my Misc. Destination (the parking lot extension). As far as I can tell, the only reason that delay was needed is because if the incoming call from Google Voice tries to connect to the parking lot slot before your original call has been parked, everything fails. By not waiting around for the gvoice command to finish executing and going straight on to the parking lot, you avoid this possibility and your call connects faster.

    Finally, if you don’t like it playing a few seconds of the default music on hold, you can change the music on hold category that is used by inserting this line in your custom-gv context just before you transfer the call to the Parking Lot:

    exten => _X.,n,SetMusicOnHold(connect-gv)

    Either create a music on hold category called connect-gv and upload whatever sound file you want played, or change connect-gv in the above line to the name of one of your existing music-on-hold categories. Remember that at most you’re only going to hear three or four seconds of this before the call connects through (if all is working as it should), so don’t spend a lot of time on this because more than likely nobody’s ever going to hear more than the first four or five notes. And yes, you could use a few seconds of silence, or even some old-time sounds like the phone switches used to make while completing calls back in the 70’s or earlier (that ought to freak out anyone who uses your phone and is old enough to remember those). 🙂

  8. The bigger question now that Gmail has free phone calls in it is when is somebody gonna figure out how to make it dial all the way through Google without any phone lines? I’m assuming Google hasn’t provided a SIP interface yet?

    [WM: Funny you’d mention that. See this thread.]

  9. WM: Yeah I’ve been through that thread and it seems that freeswitch has it going on but I can’t really tell what the Asterisk solution is. Everything out there is still talking about Google Voice and other SIP and DID services- not the new Gmail calling.

    If you know how to do this or if I’m just missing something I’d surely love to know!


  10. How do you configure 1000 GV accounts with the Asterisk Server? Does anyone know how to do this?

    That’s what consultants are for. 🙂 ]

  11. Hi Everyone, I’m new at the world of PBX in general. I have read lots of documentation but no good leads.
    I’m looking for information on how to set up two did’s to use only one number.
    I’m currently using GVoice to make calls out and vitelity to receive.
    I want the number from vitelity to display everytime I make a call from GVoice.
    Please let me know if this is possible and if you can can you please share the setup or link for the guide so that I can follow it. Thanks so much.

    I’m using PBX in a Flash Purple.
    Piaf ver
    FreePbx Ver
    Dahdi ver 2.6.1
    CentOS 6.2

    Vitelity DID to receive calls
    Gvoice to Make calls.

  12. Now that’s ipkall phasingout the IAX2 in Nov, 20th

    what is the replacement to keep using GV

    [WM: SIP connection works exactly the same way.]

Comments are closed.