Using FreeSWITCH to add Google Voice to Asterisk

Michigan Telephone and I have been discussing using FreeSWITCH as an on-box adjunct to Asterisk to enable cutting-edge features, such as Google Voice integration, without having to use development-level Asterisk code. Here’s how to set up a very minimal FreeSWITCH on the same server as Asterisk for this very purpose.

References, at the top of the post to suggest that you read these first:

The steps:

FreeSWITCH

  1. Follow the installation guide to retrieve the development version of FreeSWITCH from the git repository. Warning! The Subversion repository is old, and so is the tarball, which claims to be a nightly snapshot. It is not. Only git will get you the current code.
  2. Build:
    • ./bootstrap.sh
    • Edit modules.conf in the source directory and uncomment endpoints/mod_dingaling. Later, once you see the minimal installation we’re producing, you may want to comment out other unused modules to save some build time.
    • ./configure, make, and make install. My Asterisk box already had most of the required libraries; only libtiff-devel was missing (needed for the spandsp module). I was able to retrieve libraries and headers with yum (yum install libtiff-devel for example). The make process will alert you of anything missing. Just install the requirements and then make again, and it will pick up where it left off.
  3. FreeSWITCH will now be installed in /usr/local/freeswitch and is contained within this directory and subdirectories. I noticed that it builds its own copy of iksemel, which I already have installed elsewhere for Asterisk’s use, but the custom libs are in /usr/local/freeswitch/lib so there is no interference.
  4. Delete the contents of /usr/local/freeswitch/conf. You can get them back later if you want by doing make samples from your FreeSWITCH source directory, but for this minimal installation, we can put all of the configuration in a single file and be sure nothing else is loading.
  5. I spent some time trying to optimize the FreeSWITCH config so that it contains just enough to act as a gateway between Asterisk (using SIP) and Google Voice. My freeswitch.xml config, appended to this post, should work for anyone following these steps. Copy it to the /usr/local/freeswitch/conf directory, editing the lines related to GMail login.

Asterisk

  1. If you’re set up for NAT, you may not (probably don’t) have the loopback network configured in your sip.conf as a local (non-NAT) network. Add localnet = 127.0.0.0/255.255.255.0 to [general] in sip.conf or the sip_nat.file if you’re using FreePBX. Otherwise, Asterisk will try to use NAT-traversal methods for the Asterisk-FreeSWITCH on-box trunk.
  2. Set up a new SIP trunk. In FreePBX, name the peer “freeswitch” and use these trunk details:

    host=127.0.0.1
    port=5050
    qualify=30000
    type=friend

    (FreePBX now sets up contexts appropriately within from-trunk, so the context line can be omitted here unless you wish to specify one.) The non-FreePBX method would be to create a [freeswitch] block in sip.conf with the aforementioned details and an appropriate context= line. That’s it. No registration, no usernames, nothing–we are authenticating by IP address and port only.

  3. Set up appropriate inbound and outbound routes in FreePBX or in your extensions.conf dialplan. This is outside the scope of this how-to.

Firewall

FreeSWITCH and/or the GTalk/Jingle protocol use more RTP ports than what I had previously configured in my router-firewall for Asterisk. So I updated my firewall to include UDP ports 10000-65000.

Google Voice and GMail

  1. Log into the GMail account with an associated Google Voice number, bring up the chat window and enable voice calling. Call a number and see that it works through your browser.
  2. Log into Google Voice and instruct it to route calls to Google Chat. According to the FreeSWITCH wiki, the FreeSWITCH integration only works when call screening is turned on. (Why?) So turn it on. Call your Google Voice number from any phone and see that it rings through to your browser. Then sign out of chat.

Get it started

With these settings in place, Asterisk should be listening to FreeSWITCH on 127.0.0.1 port 5060, and FreeSWITCH should be listening to Asterisk on 127.0.0.1 port 5050. Furthermore, FreeSWITCH should be able to navigate a NAT and talk to the Google Talk server and, using the latest FreeSWITCH code, send and receive calls on the Google Voice number.

Start FreeSWITCH. /usr/local/freeswitch/bin/freeswitch -c will give you a console and once you have worked out the bugs, you can run it in the background with -nc instead.

Does it work?

Let me know if you have followed these instructions and achieved success. I was able to send and receive calls with Google Voice, with working DTMF and mostly acceptable audio quality. 

Place test calls with dl_debug on in the FreeSWITCH console to see the XMPP messages. I spent a lot of time examining these and Wireshark captures to find RTP issues (solved in the config and with the firewall adjustments).

I was disappointed that the audio was sometimes jittery, which I never see with the Gizmo5 or PSTN Google Voice transports. I don’t know if it was from the Internet or from the server itself, but I can say that FreeSWITCH in this very minimal mode seems to add very little additional memory or CPU usage.

Appendix: the config 
My single-config-file freeswitch.xml. Cut, paste and use. Replace YOURUSERNAME, YOURPASSWORD, and YOURDID with your settings. A veteran FreeSWITCH user could help me optimize this even more.

<?xml version=”1.0″?>
<document type=”freeswitch/xml”>
        
  <include>
    <!– this is a good place to pre-define globals if you want –>
    <X-PRE-PROCESS cmd=”set” data=”global_codec_prefs=G7221@32000h,G7221@16000h,G722,PCMU,PCMA,GSM”/>
  </include>
  <section name=”configuration” description=”Various Configuration”>
      
    <configuration name=”modules.conf” description=”Modules”>
      <modules>
        <load module=”mod_console”/>
        <load module=”mod_logfile”/>
        <load module=”mod_sofia”/>
        <load module=”mod_dingaling”/>
        <load module=”mod_commands”/>
        <load module=”mod_dptools”/>
        <load module=”mod_dialplan_xml”/>
      </modules>
    </configuration>
            
    <configuration name=”console.conf” description=”Console Logger”>
      <mappings>
        <map name=”all” value=”console,debug,info,notice,warning,err,crit,alert”/>
      </mappings>
      <settings>
        <param name=”colorize” value=”true”/>
        <param name=”loglevel” value=”info”/>
      </settings>
    </configuration>
      
    <configuration name=”switch.conf” description=”Core Configuration”>
      <cli-keybindings>
        <key name=”1″ value=”help”/>
        <key name=”2″ value=”status”/>
        <key name=”3″ value=”show channels”/>
        <key name=”4″ value=”show calls”/>
        <key name=”5″ value=”sofia status”/>
        <key name=”6″ value=”dingaling status”/>
        <key name=”7″ value=”reloadxml”/>
      </cli-keybindings> 
              
      <settings>
        <param name=”colorize-console” value=”true”/>
        <param name=”max-sessions” value=”1000″/>
        <param name=”sessions-per-second” value=”30″/>
        <param name=”loglevel” value=”debug”/>
        <param name=”dump-cores” value=”yes”/>
        <param name=”rtp-enable-zrtp” value=”false”/>
      </settings>
    </configuration>
    <configuration name=”logfile.conf” description=”File Logging”>
      <settings>
        <param name=”rotate-on-hup” value=”true”/>
      </settings>
      <profiles>
        <profile name=”default”>
          <settings>
            <param name=”rollover” value=”10485760″/>
          </settings>
          <mappings>
            <map name=”all” value=”debug,info,notice,warning,err,crit,alert”/>
          </mappings>
        </profile>
      </profiles>
    </configuration>
    <configuration name=”sofia.conf” description=”sofia Endpoint”>
      <global_settings>
        <param name=”log-level” value=”0″/>
        <param name=”debug-presence” value=”0″/>
      </global_settings>
      <profiles>
        <profile name=”freeswitch-sip”>
          <gateways>
            <gateway name=”asterisk-local”>
              <param name=”username” value=”freeswitch”/>
              <param name=”password” value=”0″/>
              <param name=”proxy” value=”127.0.0.1:5060″/>
              <param name=”register” value=”false”/>
              <param name=”retry-seconds” value=”30″/>
              <param name=”caller-id-in-from” value=”true”/>
            </gateway>
          </gateways>
          <domains>
            <domain name=”all” alias=”true” parse=”false”/>
          </domains>
          
          <settings>
            <param name=”debug” value=”0″/>
            <param name=”sip-trace” value=”no”/>
            <param name=”log-auth-failures” value=”false”/>
            <param name=”forward-unsolicited-mwi-notify” value=”false”/>
            <param name=”context” value=”asterisk”/>
            <param name=”rfc2833-pt” value=”101″/>
            <param name=”sip-port” value=”5050″/>
            <param name=”dialplan” value=”XML”/>
            <param name=”dtmf-type” value=”info”/>
            <param name=”inbound-codec-prefs” value=”$${global_codec_prefs}”/>
            <param name=”outbound-codec-prefs” value=”$${global_codec_prefs}”/>
            <param name=”use-rtp-timer” value=”true”/>
            <param name=”rtp-timer-name” value=”soft”/>
            <param name=”vad” value=”none”/>
            <param name=”rtp-ip” value=”127.0.0.1″/>
            <param name=”sip-ip” value=”127.0.0.1″/>
            <param name=”inbound-codec-negotiation” value=”generous”/>
            <param name=”tls” value=”false”/>
            <param name=”nonce-ttl” value=”60″/>
            <!–<param name=”disable-transcoding” value=”true”/>–>
            <param name=”auth-calls” value=”false”/>
            <param name=”auth-all-packets” value=”false”/>
            
            <param name=”ext-rtp-ip” value=”127.0.0.1″/>
            <param name=”ext-sip-ip” value=”127.0.0.1″/>
        
            <param name=”rtp-timeout-sec” value=”300″/>
            <param name=”rtp-hold-timeout-sec” value=”1800″/>
        
            <param name=”challenge-realm” value=”auto_from”/>
          </settings>
        </profile>
      </profiles>
    </configuration>
            
    <configuration name=”dingaling.conf” description=”XMPP Jingle Endpoint”>
      <settings>
        <param name=”debug” value=”0″/>
        <param name=”codec-prefs” value=”PCMU”/>
      </settings>
              
      <profile type=”client”>
        <param name=”name” value=”gtalk”/>
        <param name=”login” value=”YOURUSERNAME@gmail.com/freeswitch”/>
        <param name=”password” value=”YOURPASSWORD”/>
        <param name=”dialplan” value=”XML”/>
        <param name=”context” value=”gtalk”/>
        <param name=”message” value=”This is FreeSWITCH”/>
        <param name=”auto-reply” value=”This is an automated system for audio calls only. Please do not chat.”/>
        <param name=”rtp-ip” value=”auto”/>
        <param name=”candidate-acl” value=”wan.auto”/>
        <param name=”local-network-acl” value=”localnet.auto”/>
        <param name=”ext-rtp-ip” value=”stun:stun.freeswitch.org”/>
        <param name=”auto-login” value=”true”/>
        <param name=”sasl” value=”plain”/>
        <param name=”server” value=”talk.google.com”/>
        <param name=”tls” value=”true”/>
        <!– disable to trade async for more calls –>
        <param name=”use-rtp-timer” value=”false”/>
        <!– default extension (if one cannot be determined) –>
        <param name=”exten” value=”gtalk-in”/>
      </profile>
    </configuration>
    <configuration name=”post_load_modules.conf” description=”Post-load modules” />
  </section>
  <section name=”dialplan” description=”Regex/XML Dialplan”>
    <context name=”asterisk”>
      <extension name=”asterisk-outbound”>
        <condition field=”destination_number” expression=”^(.*)$”>
          <action application=”ring_ready” />
          <action application=”set” data=”hangup_after_bridge=true”/>
          <action application=”set” data=”bridge_generate_comfort_noise=true”/>
          <action application=”bridge” data=”dingaling/gtalk/+$1@voice.google.com”/>
        </condition>
      </extension>
    </context>
    <context name=”gtalk”>
      <extension name=”gtalk-in”>
        <condition field=”destination_number” expression=”^(.*)$”>
          <action application=”set” data=”hangup_after_bridge=true”/>
          <action application=”set” data=”effective_caller_id_name=${caller_id_number}”/>
          <action application=”set” data=”execute_on_answer=send_dtmf 1″/>
          <action application=”set” data=”bridge_generate_comfort_noise=true”/>
          <!– <action application=”answer” /> Add this to answer the call before bridge to * –>
          <!– <action application=”ring_ready” /> Or GV Voicemail will get it if you don’t ans. –>
          <!– <action application=”set” data=”ringback=%(2000, 4000, 440.0, 480.0)” /> –>
          <action application=”bridge” data=”sofia/gateway/asterisk-local/YOURDID” />
        </condition>
      </extension>
    </context>
  </section>
</document>

47 thoughts on “Using FreeSWITCH to add Google Voice to Asterisk”

  1. Strike that last comment. I was able to get this going fine with “Make Current.” The glitch probably had to do with my being signed into the Google account with my Android tablet. One thing I can say is that trying to use Google Voice this way can be pretty squirrelly.

  2. I used this solution for a while and gave up on it for a few months because of intermittent unreliability – mainly the problem was that FreeSwitch would occasionally (once every few days) disconnect from Google Voice (perhaps due to a router hiccup?), and, when I’d make an outgoing call, I would just hear ringing and no indication that the call wasn’t being connected. I’d either have to restart FreeSwitch, or the act of trying to make a call would reconnect it (for the next call).

    I came back to this installation out of curiosity, and did “Make Current” on my FreeSwitch installation to see if there were any changes, and I now find that I can make outgoing calls OK (and I see FreeSwitch showing up on Google Chat), but FreeSwitch doesn’t register incoming calls. I restored to the old version (from late last year, I believe), and things worked fine again, but another “Make Current” gave me the same incoming call failure.

  3. First, to answer Jrey’s comment, I suspect most of us are not using “raw” Asterisk as you appear to be. When you write your own dialplans, as you must when you don’t use any sort of configuration tool, then you are pretty much on your own. FreeSWTCH appears to Asterisk just as any other trunk would appear (assuming you use the trunk configuration shown above) and it’s pretty much up to you to route calls to and from that trunk.

    (And, I might add, if you are going to go through all the trouble of writing your own dialplans, why not just use FreeSWITCH all the way? I don’t know offhand how hard it would be to get it to work on a Debian dockstar but it might be worth a try, since FreeSWITCH seems to be a more stable product, whereas the Asterisk developers have a nasty habit of breaking existing functionality with each new release.)

    Now, I also have a question. I’m not real good with regular expressions, otherwise I might be able to figure this out myself. But I have one user that’s connecting to our server using Sipdroid, which is a VoIP application for the Android operating system. He has the ability to cut and paste numbers into Sipdroid and apparently it will send whatever is pasted. So he pasted in a number of the form xxx-xxx-xxxx and it sent it, hyphens and all, and of course the call failed.

    In the configuration there is a line like this:

    <condition field=”destination_number” expression=”^(.*)$”>

    The page at explains the .* pattern like this: “The dot matches any character, and the star allows the dot to be repeated any number of times, including zero.” The problem is that if the user pastes in a number with the pattern xxx-xxx-xxxx or (xxx) xxx xxxx or anything with non-numeric characters, it will still (if I understand correctly) get passed to Google Voice and Google Voice will reject it.

    What I’d like to know is whether that regex could be modified to strip out all non-numeric characters before passing the call to Google Voice. Note I’m not trying to block a call that looks like xxx-xxx-xxxx or (xxx) xxx-xxxx, but I want to strip out anything that’s not a number (hyphens, parens, spaces, and any other stray non-numeric character), so that either of those would get passed to Google Voice as xxxxxxxxxx (actually +1xxxxxxxxxx after we add the +1 in the line that bridges the call). Seems like there ought to be an easy way to do that in the regex but if there is, I don’t know what it is.

    I also find it strange that Asterisk apparently totally ignores hyphens in pattern matches, but that’s another issue.

  4. Can someone show an example of sip.conf and extensions.conf in Asterisk? I am a newbie and don’t quite understand what to do with the comment:
    “3. Set up appropriate inbound and outbound routes in FreePBX or in your extensions.conf dialplan. This is outside the scope of this how-to.”

    I have install Asterisk1.8 and Freeswitch on a debian dockstar and use an unlocked sunlocket for ATA.

    Any help would be very appreciated. Thanks.

  5. I’ve been working with this setup for over a year now, GREAT work guys! I’m using Asterisk 1.4 and this freeswitch + google voice integration is seamless and lightweight. I do however, have a couple of issues that perhaps the community is already aware of, but I haven’t seen any threads on it. First thing, when making many calls, google servers stop taking your call requests for about 5-10 minutes. I’m guessing google has a limit on how many outgoing calls you can place. I have 6 gvoice accounts authorized in dingaling. Second, as of late, the dingaling mod shows my accounts as “unconnected” for a long while after i start the freeswitch server. I have to wait, perhaps attempt to make a call, before I see that 5 of 6 accounts have been “authorized.” What may be causing the delay?

  6. Outbound calls have all work 100%. The same was true for Asterisk when I used that. Only inbound calls have an issue.

    It seem if I introduce a delay in answering, as mentioned above on Feb 1st, does seem to make things work for a *short* while. Ultimately though the same problem comes back. I’ve tried this:
    http://pbxinaflash.com/forum/showthread.php?t=12377. It too soon to say for sure since I just install freeswitch today but it appears to help.

  7. Does this still work? Trying this myself I am seeing exactly the same sort issues I had with Asterisk’s built in functionality. Incoming calls will ring my phones for a few seconds only. If I answer them I get silence. Regardless what happens the caller hears ringing until the call ultimately goes to google voicemail. At least with Asterisk direct a few calls would make it through. With freeswitch this happens 100% of the time. Outgoing calls work fine with either.

    If it makes any difference I’m using Asterisk 1.8.7 (rpmfusion) with FreePBX. My asterisk system is behind a firewall.

  8. Greg, I haven’t seen the 5-second disconnect issue, but suspect it has to do with NAT and Asterisk believing FreeSWITCH is not on your network. Check your Asterisk SIP/NAT settings and make sure that 127.0.0.1 is configured as a “localnet”. (See the Asterisk section above.)

  9. Doc,

    Yes, that’s my gateway running Yate. I haven’t tried Yate and Asterisk on the same server yet. It would not be hard to do, and the procedure would be much the same as we are doing here with FreeSWITCH: set Yate to listen on a different SIP port, configure the Google Voice account on Yate and a “trunk” between Yate and Asterisk on localhost. Add some simple routing rules and you have a gateway.

    Yate is actually simpler to configure and it starts up bare-bones. You add what you want. FreeSWITCH’s default has a bunch of things to remove if all you want is a proxy/gateway. A big difference is that Yate uses several config files, whereas you can configure FreeSWITCH in a single file, as I’ve done here. So a blog post describing a Yate gateway setup might need more instructions even though I am claiming here that it is simpler.

    I don’t know whether Yate or FreeSWITCH is better. I have come to like Yate more, just because. As to how well it scales… just between you and me and the rest of the Internet, the Yate/GV gateway test server has over 250 GV accounts logged in at this time. It’s basically idle, because XMPP connectivity doesn’t cost much in terms of server resources. With any VoIP server your resource usage will be tied to media streams (call legs, multipoint conferencing/mixing).

    PS: I am not sure whether our blog service does comment notification. I’ll check on it. If you use a news reader, you can subscribe with RSS to this blog’s comments feed using the link on the right side of the page.

  10. Bill,

    THANK you for responding. I don’t know if I was supposed to be notified – but I wasn’t. I just happen to come across your thread/article again continuing my search for this endeavor.

    If I am correct – you are the same Bill that has the info online about the YATE/Google Voice Gateway? (and you even have a test server up and running for that, correct?)

    With the experience that you have both using FreeSwtich and YATE (as gateways to Asterisk allowing use of the Google Voice service) – which one is better, and why?

    If you are going to have multiple Google Accounts (say like anywhere from 3 or 4 or even up to 10) – then would you change your position on which Gateway method is better?

    Thanks again for responding!

  11. I can confirm that the FreeSwitch integration will work with Asterisk 1.4.

    Try a pay-as-you-go SIP provider like CallCentric (www.callcentric.com) for more certain results with your call center testing. You can get a test number with a bunch of inbound and outbound minutes for under $10. Just my 2 cents.

  12. Thanks for all the work on this!

    I don’t have the time nor inclination to try and even think I’m going to learn this stuff. (I’m a computer born and raised kid, but chose to go financial services!)

    I am looking for an arrangement for my small office 2 and 1/2 people – don’t ask! 🙂 using the newly (for me) found ViciDial open source call center solution.

    I believe I have seen enough to know I want to go with said solution – but I’d really like to take it for a test drive on the shoestring budget I have. And that includes setting up carriers.

    I’m at the point where I’m ready to hire a freelancer or something just to get the server I got up and running to have some valid SIP trunks working so I can actually experience live in and outbound calls from the ViciDial software.

    So since ViciDial uses Asterisk 1.4 (older version) – and everything I’ve read on Asterisk supporting Google Voice (not going to happen!) – I wondered if I could use your set up here to get a couple Google Voice SIP trunks as carrier lines for my ViciDial solution?

    Any help is appreciated. As stated – I’m burning myself out trying to learn about what’s available for a shoe string budget (and am completely humbled with awe as to the power of the open source stuff available) – but with everything I’m trying to do to keep my kiddies from starving – I’m unable to commit much more brain power in trying to tinker with these things myself. So unless there was some straight forward guide – I’d really just like to know if I actually put a few dollars out of pocket for a professional to set this up – will it have success in actually getting a live working SIP carrier phone line working with ViciDial?

    Your help is GREATLY appreciated!

  13. I have the config in place without all the additional configs that were suggested. I am having a issue where the call gets disconnected after about 5 seconds of talking. Have any of you had this issue, and if not, do you know what could be causing it?

    thanks,

  14. I have read through all the comments and guides, and have a general idea of all the changes and updates, is it possible to get a copy of the working configuration being used with all the changes implemented that we should try?

  15. Starting last night I saw a couple cases where incoming calls did not seem to receive the touch-tone “1” sent by FreeSWITCH, so although the called extension rang, the called party heard only silence while the caller heard ringing and then GV’s voicemail. I think this might be old issue of Google Voice not wanting to be answered IMMEDIATELY after it puts the call through. If you have uncommented the three commented-out lines in the “gtalk” context and experience this issue, then just before

    <action application=”answer” />

    you can try adding

    <action application=”sleep” data=”1000″ />

    That will cause it to delay one second after the call arrives before answering. You could possibly (probably) get by with a bit less than that, or you may need a bit more, but I just used 1000 (milliseconds) and so far it has seemed to fix that issue, in a very limited number of attempts.

  16. I hadn’t intended to send another comment (I hate to monopolize Bill’s comments section) but I had to add a couple additional things to get multiple accounts to work, so here’s a quick summary of what I did. You do have to use multiple client blocks (one for each Google Voice account) and each one should look like this:

      <profile type=”client”>
        <param name=”name” value=”gtalk-YOURCALLERID”/>
        <param name=”login” value=”YOURUSERNAME@gmail.com/freeswitch”/>
        <param name=”password” value=”YOURPASSWORD”/>
        <param name=”dialplan” value=”XML”/>
        <param name=”context” value=”gtalk”/>
        <param name=”message” value=”This is FreeSWITCH”/>
        <param name=”auto-reply” value=”This is an automated system for audio calls only. Please do not chat.”/>
        <param name=”rtp-ip” value=”auto”/>
        <param name=”candidate-acl” value=”wan.auto”/>
        <param name=”local-network-acl” value=”localnet.auto”/>
        <param name=”ext-rtp-ip” value=”stun:stun.freeswitch.org”/>
        <param name=”auto-login” value=”true”/>
        <param name=”sasl” value=”plain”/>
        <param name=”server” value=”talk.google.com”/>
        <param name=”tls” value=”true”/>
        <!– disable to trade async for more calls –>
        <param name=”use-rtp-timer” value=”false”/>
        <!– default extension (if one cannot be determined) –>
        <param name=”exten” value=”YOURDID”/>
      </profile>

    Some notes on the above: YOURCALLERID is, for all intents and purposes, the Caller ID number you send on outgoing calls (it can be your Google Voice number, but doesn’t have to be), and in FreePBX it’s found in each extension’s Outbound CID setting (just the number, not the name). So the idea here is that each extension can have its own Google Voice account, or you can have multiple extensions share an account by putting the same number in each one’s Outbound CID setting. Note that whatever you put in the Outbound CID setting will be ignored by Google Voice (though it may be used by other providers if you have any other trunks that will accept it) so if you are using ONLY Google Voice for outgoing, you could put any reasonable number in the Outbound CID field and then also use that in the above context to select the correct GV account on outgoing calls.

    YOURUSERNAME and YOURPASSWORD are, of course, your login credentials for your Google Voice account.

    YOURDID again will usually be your Google Voice number, but doesn’t have to be. It’s the number that the Inbound Routes will see in FreePBX, so you could use any number here as long as you have an inbound route that matches it.

    Next, in the “asterisk” context (which handles outgoing calls) the last three “action application” lines should be:

          <action application=”set” data=”bridge_generate_comfort_noise=true”/>
          <action application=”set” data=”execute_on_answer=start_dtmf_generate”/>
          <action application=”bridge” data=”dingaling/gtalk-${sip_from_user_stripped}/+$1@voice.google.com”/>

    The first line is unchanged from the original and is only shown as a place marker. The second is the line that mostly fixes the outgoing DTMF issues – omit it if you don’t need it. The third line is changed to effectively append the Caller ID (in the variable ${sip_from_user_stripped}) to “gtalk-” so that the correct account will be selected – I could have used any of several variables (that all contain the same data at this point) here, but picked that one because I think it would probably strip off any “garbage” data. If you like a different one better, feel free to experiment.

    And finally, in the “gtalk” context (which handles incoming calls) I changed YOURDID to $1 as Bill suggested:

          <action application=”bridge” data=”sofia/gateway/asterisk-local/$1″ />

    I also uncommented the commented-out lines so that Google Voice could not snatch the call back to their voicemail. Note that if you wanted some extension to use Asterisk’s voicemail and others to use Google Voice’s voicemail, that could be accomplished by simply duplicating the entire “gtalk” context, renaming the context name for the copy, and then changing the line

        <param name=”context” value=”gtalk”/>

    to show the new duplicate context name in the Google Voice profiles you want to use that context. Of course you’d leave the commented-out lines commented out in only ONE of the two contexts (the original “gtalk” context or the renamed duplicate context).

    Note that the above may not handle some unique situations well (for example, a user that has two Google Voice accounts, and wants to use one account when making calls to certain area codes and a different account for calls to other areas) so there is probably room for even more improvement, but the above modifications will handle many situations pretty well. And again, I apologize to Bill for my verbosity, but I figured some folks might appreciate a little bit more detailed explanation.

  17. We have a winner!

    The correct statement to add is this:

    <action application=”set” data=”execute_on_answer=start_dtmf_generate”/>

    This goes just prior to the line:

    <action application=”bridge” data=”dingaling/gtalk/+$1@voice.google.com”/>

    According to Anthony Minessale of FreeSWITCH, the “nolocal:” in pianoquintet’s suggestion “means to push it to the b-leg when really you want to execute the app on the A leg.” I have no clue why that might have worked for pianoquintet. But taking out the “nolocal:” was the key. Anthony also suggested using execute_on_answer rather than execute_on_media. I figure he should know which is best. 🙂

    I will point out that you MAY need to go into the source directory and do MAKE CURRENT before this will work without throwing an error. If you didn’t do MAKE CURRENT as late as this afternoon (January 24, 2012), you may still have the version that throws the error. This, of course, assumes that you followed the instructions and used the git repository to get FreeSWITCH in the first place.

    Anthony also had another suggestion which did NOT work for me, but I’ll throw it out there anyway because it may work for someone with a different build. He suggested using:

    <action application=”start_dtmf_generate”/>
    <action application=”set” data=”ringback=${us-ring}”/>

    Where us-ring can be replaced by whatever ringback tone spec you want. Again, that did NOT work for me, but maybe it will help someone in a different situation.

    Thank you, Bill, for all your work on this, and I hope I’ve been able to contribute in some small way. And thank you to Anthony Minessale for his help as well.

  18. Interesting, and makes me wonder why FreeSWITCH’s ring_ready isn’t effective in sending the SIP 180 back to Asterisk to cause the ringing tone to be played. Did you ever happen to capture some SIP packets between FreeSWITCH and Asterisk to see what FS is sending back during the outbound call? Thanks for the continued feedback on this solution. Google Voice/PBX integration is a moving target.

  19. Well, I think I have found a hack that will fix both the Touch Tone issues and the lack of ringback, so you don’t have to accept one or the other. This is a real kludge and I don’t like it but unless someone comes up with a better idea it’s what I’ll be using.

    The first thing you have to do is use Zack’s suggestion:

    2. I couldn’t send touchtones successfully (e.g., to automated systems) over Google Voice. I fixed this by changing to inband DTMF by adding this line to the FreeSwitch dialplan you excellently provided above:
    <action application=”start_dtmf_generate”/>

    The above line goes just before the line that is or is similar to:

    <action application=”bridge” data=”dingaling/gtalk/+$1@voice.google.com”/>

    That will fix MOST of the outgoing touch tone issues although occasionally you may get doubled digits (that happens with Asterisk’s drivers also). Changing the dtmfmode on your extensions may or may not help; feel free to experiment.

    But the problem with the above is that your ringback tone disappears, so when you call someone you get dead silence until they answer. Now, the ringback that is generated for outgoing Google Voice calls is fake to begin with (it’s not coming from the destination phone company) so we don’t really care where it’s generated. So, my reasoning went, if FreeSWITCH won’t do it, maybe I can get Asterisk to do it.

    So I watched an outgoing call go through Asterisk on the Asterisk CLI and when the call was handed off to FreeSWITCH I saw something like this at the end of a line:

    Dial(“SIP/asteriskbox-00000028”, “SIP/FreeSWITCH/+12345678900,300,TW”) in new stack

    FreeSWITCH is the name of my trunk to FreeSWITCH, and TW is the Asterisk Outbound Dial command options that I have set in FreePBX’s General Settings — both of those may be different on your system. So I created a new CUSTOM trunk named FreeSWITCH-ringback, and for the Custom Dial String I put this:

    SIP/FreeSWITCH/$OUTNUM$,300,TWr

    Note the added “r” at the end of the line — that’s what tells Asterisk to generate the fake ringback tone from the time it hands the call off to FreeSWITCH until the time the call is answered. I then changed my outbound route to use the FreeSWITCH-ringback trunk rather than the original FreeSWITCH trunk.

    Now if you do that and watch a call go out on the CLI, you will see something like this (this is why I say it’s a kludge):

    Dial(“SIP/asteriskbox-0000002b”, “SIP/FreeSWITCH/+12345678900,300,TWr,300,TW”) in new stack

    And you will note that while your added arguments are preserved, FreePBX also insists on adding them again at the end of the line. But, at least in Asterisk 1.8, it appears that the extra added arguments are ignored, and the call goes through. The caller hears the fake ringback until the call is answered.

    There may be one drawback to this, and that is that I don’t know what happens if you call a busy number. I don’t know if you would ever actually hear the busy signal, or if all you would hear is ringing. That probably in part depends on how Google Voice, and the FreeSWITCH Google Voice channel driver handles that situation.

    There’s got to be a better way than this, but I don’t know what it might be offhand.

  20. Forgot to add one thing to my previous comment… if you are looking for a way to add a FreeSWITCH service so you can easily start FreeSWITCH at bootup, etc. there’s a real simple way to do it here:

    Just thought I might save others the trouble of looking for it!

  21. Thanks, Bill, that is a huge help! My only remaining issue is that I can’t get outgoing touch tones to work properly AND still get a ringback sound while the distant phone is ringing. As I noted previously I tried pianoquintet’s suggestion of <action application=”export” data=”nolocal:execute_on_media=start_dtmf_generate”/> and got the error message:

    [ERR] switch_ivr_async.c:2512 Can not install inband dtmf generate. Media not enabled on channel

    It appears that the code that generates that error is in the file switch_ivr_async.c and the trigger condition is:

    if (!switch_channel_media_ready(channel) || !switch_core_session_get_read_codec(session))

    However that means nothing to me and I don’t understand why I’m getting that error. pianoquintet’s syntax is correct, according to the page at http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_start_dtmf_generate so I’m at a loss on this one.

    If you don’t use any statement and try to send a touch tone, each time you press one or more tones the other party hears a single tone that lats about five or ten seconds. So single digit menu selections might actually work in some cases, but any multi-digit entries will not. I hope someone has found or will find a working solution for this. And if pianoquintet happens to read this, I’d like to know if he added anything to your configuration to get his fix to work (loaded any additional modules, for example).

  22. Connecting to FreeSWITCH:

    So you noticed that I eliminated the configuration necessary to connect to the running FreeSWITCH instance. 🙂 Indeed, this config is minimal. I figure no one will be touching it, just starting and stopping (freeswitch -stop). Here’s how to use the fs_cli command to connect to the console.

    Add to the <modules> section:

    <load module=”mod_event_socket”/>

    Then add a new configuration block to freeswitch.xml:

    <configuration name=”event_socket.conf” description=”Event socket”>
    <settings>
    <param name=”nat-map” value=”false”/>
    <param name=”listen-ip” value=”127.0.0.1″/>
    <param name=”listen-port” value=”8021″/>
    <param name=”password” value=”ClueCon”/>
    </settings>
    </configuration>

    Now when you start FreeSWITCH with -nc you can connect to it using the event socket interface (looks & works just like the console) by using the fs_cli command: fs_cli -p ClueCon (with the default ClueCon password, you can just use fs_cli with no parameters)

    Inside, type “help”.

    Multiple Google Voice accounts:

    Easier than you might think. Just define multiple profile type=”client” blocks, one for each of your Google Voice accounts, inside the dingaling.conf configuration block. Change the credentials and the “exten” param (use the DID for each GV account instead of exten=”gtalk-in” – I should go back and update that). Lastly, see in the dialplan section where you bridge the incoming Gtalk call to sofia/gateway/asterisk-local/ ? Change the explicitly defined “YOURDID” there to $1. Then the call will be sent to Asterisk with the right GV DID.

  23. Well, I figured out the reason for my #2 issue… this is running on a VMware server (the server is not mine so please no comments about VMware; I couldn’t change it if I wanted to) and there was a time fix directive in grub.conf (described in http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006427 ) that doesn’t need to be there with the current version of CentOS. Took that out and not only did the complaint go away but so did the minor audio problems (at least in very limited testing).

    I do have an additional question, though. As suggested above, I started FreeSWITCH using the -nc directive, so I can disconnect my bash session (it’s on a remote server and I don’t want to waste bandwidth). The specific invocation I used is:

    ulimit -s 240 ; /usr/local/freeswitch/bin/freeswitch -nc

    The first part of that addresses the complaint in my #1 point in my previous post. But now, I’m wondering how I can come in and view what’s happening in FreeSWITCH if I need to. Is there an easy way to connect to the running instance of FreeSWITCH so I can see what is happening in a console window?

    Still looking for a way to use this with multiple Google Voice accounts – that’s what will make this truly useful for me. 🙂

  24. Bill, thank you for this article. I have looked at it many times but I am just getting around to actually trying to make it work (yes, I am the world’s worst procrastinator). At the outset I am seeing a few issues:

    1) When I first bring up FreeSWITCH I get this:

    # /usr/local/freeswitch/bin/freeswitch -c
    Error: stacksize 4194303 is too large: run ulimit -s 240 from your shell before starting the application.
    auto-adjusting stack size for optimal performance…

    What are the implications of running that ulimit command? I’m not exactly a Linux geek and I’m not sure if I should just blindly follow that advice, without knowing if it might adversely impact Asterisk.

    2) Also during startup I see:

    2012-01-22 14:05:52.990087 [INFO] switch_time.c:1035 Timezone loaded 0 definitions
    2012-01-22 14:05:52.990288 [CONSOLE] switch_time.c:1159 Calibrating timer, please wait…
    2012-01-22 14:05:53.516690 [CONSOLE] switch_time.c:240 Test: 1000 Average: 10518 Step: 50
    2012-01-22 14:05:53.516837 [WARNING] switch_time.c:244 Abnormally large timer gap 9518 detected!
    Do you have your kernel timer frequency set to lower than 1,000Hz? You may experience audio problems.
    2012-01-22 14:05:58.642295 [INFO] switch_time.c:423 Clock synchronized to system time.

    Well, I am experiencing audio problems, albeit not major ones. Mostly clicks and momentary dropouts. I have no idea how to check the “kernal timer frequency.” Any suggestions?

    3) I did have the outbound DTMF problem. When I tried to use pianoquintet’s last suggested fix…

    <action application=”export” data=”nolocal:execute_on_media=start_dtmf_generate”/>

    I got this error:

    2012-01-22 14:02:44.849067 [ERR] switch_ivr_async.c:2512 Can not install inband dtmf generate. Media not enabled on channel

    If I use the plain old <action application=”start_dtmf_generate”/> then it works, although occasionally it seems to get a doubled digit.

    On the plus side, I will note that outgoing calls seem to connect MUCH faster than when using Asterisk’s channel driver.

    Now the real question… what would need to be modified to allow this to service multiple Google Voice accounts (that is, to bridge more than one Google Voice account to and from Asterisk)? Is that even possible?

    And finally, to Bill: I understand that on your gateway that have put online is running under YATE. Do you find that works better, and if so, do you have any plans to publish an article such as this showing how we might interface YATE and Asterisk on our own systems?

  25. As a follow up to my earlier post, I was able to fix the ringtone issue created by

    <action application=start_dtmf_generate”/>

    by replacing it with

    <action application=”export” data=”nolocal:execute_on_media=start_dtmf_generate”/>

    This in effect causes the DTMF generation to start only when the call is connected, so it does not override ring_ready while the phone is still ringing.

  26. Interesting. I am not sure why you and Zack are seeing the DTMF problems. Thanks for posting your fixes here. I have not had to add the start_dtmf_generate to produce inband DTMF. My config matches the config posted here in this blog posting and still works. Puzzling!

  27. I had the same issue with sending DTMF signals out on Google Voice, which I was also able to fix by adding start_dtmf_generate right before the call is bridged out to Google Voice.

    This in turn caused another issue however: I no longer hear the ring tone while waiting for the called party to pick up. I played around with various ring_ready settings to try to fix this but without success.

    Any leads?

  28. So I’ve been happy with FreeSwitch except for two issues –
    1. FreeSwitch seems to be sensitive to Internet disruptions. I bought a new router and installed DD-WRT on it, and, though I really liked DD-WRT, I found that the router would crash and reboot every few days (whole other story, which I don’t really understand). The downtime would only be a few seconds, but this was enough to make FreeSwitch disconnect from Google Voice, and, as far as I could tell, it wouldn’t automatically reconnect. Since changing back to stock firmware, the router is stable, and I haven’t had disconnection problems with FreeSwitch.

    2. I couldn’t send touchtones successfully (e.g., to automated systems) over Google Voice. I fixed this by changing to inband DTMF by adding this line to the FreeSwitch dialplan you excellently provided above:
    <action application=”start_dtmf_generate”/>
    I’ve seen warnings about using inband DTMF with certain compressed codecs, I haven’t found this to be a problem on extensions that use GSM.

    (Also, I still have had variable issues with “Dial-1” stuff on inbound calls and had to add an additional Dial-1 step in my Asterisk dialplan as I mentioned above in order to answer the phone reliably. Actually, for this and other reasons, I decided to use ipKall to Asterisk to route my inbound calls and Asterisk to FreeSwitch for outbound. FreeSwitch is better than native Asterisk for outbound on Google Voice because of the long delay in routing outbound calls through Google Voice via Asterisk. So complicated.)

  29. Zack, assuming no helpful information shows up in the freeswitch.log file, no idea. I have noticed that, on occasion, FreeSWITCH seems to “doze off” when no calls have come in for a while. Thus it misses the first call and GV voicemail picks it up, but it then answers the second and subsequent calls. I have no idea why.

  30. So FreeSwitch seems to drop its connection to my Google Voice line every day or so, and I have to restart it. FreeSwitch itself doesn’t crash. Any suggestions on how I can troubleshoot this?

  31. Nope, I definitely though intermittently get asked to dial 1 if I don’t put this in the Asterisk dialplan (I also inserted a 2-second pause). Seems like more of this Google uncertainty with GV and Jabber access.

  32. Interesting, Bill. I admit (embarrassed) that I didn’t read through the configuration file. However, when I was setting this up, I picked up the phone and was asked to dial 1. I then changed the Asterisk custom extension file to add the dial-1 stuff and made a few other changes, and it all works now. It’s true that sometimes (but only sometimes) when I make a test call I hear the DTMF tone on the caller’s side. I’ll mess with this some more.

  33. Thanks for the comments Zack. Re: comment #2, FreeSWITCH sends the DTMF 1 digit in this line of the posted config:

    <action application=”set” data=”execute_on_answer=send_dtmf 1″/>

    That’s why you don’t need to make Asterisk do it, also.

  34. This works great! Three comments:

    1. It took forever for me to “./configure” and “make” FreeSwitch, and it looked like it was in a loop. It was not, though. Just had to have patience.

    2. I believe you still need to put in the “dial 1” steps in a custom extension configuration; I don’t think you can just rely on FreePBX to treat this like any old extension. (That is, if you don’t have Asterisk do this for you, you’ll be asked to dial 1 when you pick up an incoming call.)

    3. With regard to this instruction: “Add localnet = 127.0.0.0/255.255.255.0 to [general] in sip.conf or the sip_nat.file if you’re using FreePBX.” I think you mean “sip_nat.conf” for FreePBX. However, I wouldn’t do it this way. If you put it alone in sip_nat.conf, it will override your existing local network settings and mess a lot of other stuff up. I think you either have to add it to sip_nat.conf and also add your existing settings, or (much better) just do it through the FreePBX web interface: Tools –> Asterisk SIP Settings –> Local Networks –> Add Local Network Field.

  35. Hi, Bill,

    Thanks for the help! It is a little weird as it seems it is only my problem.

    Yes, it worked when the freeswitch answered (by uncommenting three lines). Thanks!! While my personal preference is to use a GV mail due to some features (i.e. transcription etc.) over the asterisk voice mail, certainly, this would be useful as well.

    I’ve tried to set up a standalone freeswitch with GV only, and I am still seeing the same issue (interrupts after 10+ sec). It may be related to a module, mod_dingaling…not sure…

    Anyway, thanks for the help and the detailed guide! It was really helpful…

    Best

  36. Hi Jae, I have not seen that exact behavior, but I would suspect that it would go away if you add the “answer” application. Check out the gtalk context above, gtalk-in extension, and uncomment the three lines that are commented out with XML comment markings. See whether that solves the problem.

  37. Hi,

    Thanks for the detailed guide, and it works 🙂 In the mean time, I am wondering if you have seen a similar issue as mine:

    After all configurations, receiving a call with a GV number works. However, the call signaling process interrupts (in freeswitch/asterisk/phone) in about 10+ secs although the caller still hears ringing. Then, in about 25 secs (by default with GV), the GV mail starts. It turned out that I would have to take a call in about 10 secs…

    Any suggestions would be a great help…

    Best
    jae

  38. Great guide!

    This worked first time for me, which is wonderful, because I didn’t want to be forced to upgrade my working Asterisk system.

    My only issue is that ringing is not indicated, so I had to add the ‘r’ option to the Dial command in my * dialplan, but that’s a minor irritation.

    Thank you very much for enabling me to make and receive calls via GV with my VoIP system!

  39. Thanks for your comment and your quality VoIP server.

    While I would not say it was easy, it also was not terribly difficult to configure FreeSWITCH for the exact purpose I had in mind, even with no prior FS experience. Documentation could be more consistent.

    I’ll be spending more time investigating FreeSWITCH.

  40. You might even want to try doing more with it if you go to all the trouble to install it.
    Before you remove all your configs, turn it on and register a few phones with the extension range 1000-1019 and pass 1234

    The default config is a working mini-pbx.

Comments are closed.