Archive for the ‘Asterisk’ Category

Q&A with Mark Spencer at ETel

Saturday, March 3rd, 2007

At the O’Reilly Emerging Telephony conference, Mark Spencer spoke for 15 minutes on the future of Asterisk, with questions at the end. The audience, packed into a ballroom at the San Francisco Airport Marriott, actually left time on the table at the end, reflecting how Asterisk has become the community platform for innovation.

Somebody asked a question about integrating speech recognition into Asterisk. In 1.4, Digium is selling the proprietary LumenVox speech interface. There is also the option to use the free Sphinx engine, but Mark’s experience is that it is challenging to build a multi-channel Asterisk system with the performance characteristics necessary to run Sphinx.

Somebody asked about the fate of the “Asterisk device” that was announced at last year’s VON conference. Mark said that the appliance is available now as a developer kit, but doesn’t know when it will be available as a customer product.

There was a question about the GUI; somebody wanted to know if it would be web based. It will be. The whole GUI sounds cool, since all Digium is doing is providing a framework to build a GUI with. Any changes made on the GUI will be reflected in the configuration files, and changes to the configuration files will be available to any GUIs built with the framework. Mark spoke of two goals for the fundamental design: (1) it should be easy to add additional commands in to the management interface, and (2) management should be possible over HTTP. I’m particularly pleased with the second point. I’ve experimented with the Asterisk manager, and while it’s nice, it’s hard to use across the network. Tunneling management over HTTP will enable use of an existing security framework. Using the manager will also enable GUIs to start or terminate calls.

The Q&A came to a close with a couple of questions on voicemail. Mark began his presentation with an apology for voicemail and queuing, and said that they would be changing. Somebody (Jim van Meggelen, I think!) asked if they would break apart into lots of smaller functions. Mark said that the functionality of voicemail wasn’t bad, but the code has grown to be unmaintainable. He would like to be able to add “personalities” to the system and enable more administrative configuration. He and Kevin differ slightly as maintainers of the code; he believes that the idea that voice mail must be configured properly to work is not appealing. Separately, one of the problems with implementing voicemail personalities (to make Asterisk sound like a Nortel or Avaya PBX) is that recording all the prompts and getting different control flows is hard to do.

In terms of queues, the fundamental problem is that the time that queues were developed there was nothing that reported state changes. The queue manager can only poll for status, but it doesn’t get events. While this works adequately when all agents are readily available, it breaks down a bit for remote agents because presence informamtion may not be handy.

Separately, I got a chance to talk to Mark. Jay Phillips introduced us once he realized that we’d both contributed to the March 2007 issue of Linux Journal. (Thanks, Jay!) Aside from the overwhelming smartitude, the thing that struck me most about Mark was his genuine interest in what everybody was doing with Asterisk.

Truncated e-mail attachments of recordings with the Asterisk Gateway Interface

Saturday, February 24th, 2007

I recently wrote what I’m referring to as a “private podcast” service for Asterisk. My friends are widely distributed throughout the world. While there are some who are quite convenient to call, like those who are on the West Coast with me, others are much farther away. It’s really not that convenient to arrange times to talk to people in London or Singapore when you are in Califoria.

My “pseudopodcast” is an extension on Asterisk that prompts to record a sound file, plays it back, and then e-mails the sound file to a receipient specified by the extension. It’s implemented as an AGI script that takes arguments for the sender and receiver. The dialplan has a two-digit receiver extension that specifies the recipient. Caller ID provides the sender identification.

It’s a neat idea, and it has helped me stay in touch with several of my friends. The only problem was that I initially was sending out e-mail with the recording truncated. It would sound fine, but it would only be a few hundred kilobytes. It wasn’t a big problem because I had the original and I could mail in the traditional manner, but it was a bit annoying to have written all this automation that didn’t work.

The first thing I checked was that the file was being recorded OK. That allowed me to trace the problem to the delivery of the e-mail. After reading the documentation for Perl’s MIME::Lite module, which I used to create the message with its attachment, I discovered that MIME::Lite doesn’t do the encoding on attached files until it’s necessary. My first troubleshooting step was to write out the e-mail message that I meant to send to disk. By checking the message on disk, I could see that it looked fine. However, receivers still told me about truncated messages.

As a next step, I sent the e-mail message on to my ISP’s mail server. (I only run sSMTP on my Asterisk server because I don’t need to receive mail from the Internet.) Even that seemed to work, which validated the SMTP route between my Asterisk server and at least one Internet e-mail host. So, the problem wasn’t my ISP arbitrarily truncating the attachment.

What I realized when sending the the message “by hand” from the command prompt is that it takes a long time to send more than a megabyte through base64 encoding and SMTP. The problem was in how my AGI script was implemented. I had assumed that when I called MIME::Lite’s $message->send() operation, it would fork a copy of sSMTP and deliver the message. Almost, but not quite. When I hung up, the AGI script would be hung up, and that would kill its child processes. The reason all the attachments were about 500 kB is that was about the limit of my patience.

There’s a two-fold fix. One was to have the script call Asterisk’s Playtones() application to give me an audio indication that it was still working on sending. The second, and more important part, is to have the AGI script ignore HUP until it’s done sending the message. Problem solved!

Perl POE programs (for the Asterisk manager?) hang Linux

Thursday, February 8th, 2007

I have recently been experimenting with the Perl Object Environment. It’s a neat event-driven framework that builds on top of Perl. I started using it for the Perl Asterisk manager interface.

I started using the Asterisk manager as a way to get information out of Asterisk and to display on the LCD on my system. The POE component is much easier than coding up something in Expect, and it’s a wondeful standardized layer for catching events. I’ve been experimenting with a POE program that displays the number of waiting voicemails on the LCD panel. Here’s the core of the program, which essentially says that when the manager indicates a new waiting voicemail, call the voicemail_state_handler procedure, and when there is a voicemail status report, call the voicemail_status_state_handler procedure.

Alias => ‘vm-monitor’,
Username => ‘user’, # not real!
Password => ‘secret’, # also not real!
CallBacks => {
input => ‘:all’,
voicemail => {
‘Event’ => ‘MessageWaiting’,
voicemail_status => {
‘Response’ => ‘Success’,
‘Message’ => ‘Mailbox Message Count’,
inline_states => {
input => \&input_state_handler,
voicemail => \&voicemail_state_handler,
voicemail_status => \&voicemail_status_state_handler,


I’ve also experimented with programs that report other Asterisk data, or even programs that tick off a clock for display on an LCD. What they all have in common is that eventually, the system will lock up. Hard. Nothing responds, not even the attached monitor. I haven’t done any detailed diagnosis, but I can’t figure out what might cause the computer to just hang hard. The best I have for a working theory at this point is that the POE loop isn’t correctly freeing objects and is exhausting system memory to the point where a critical system task is interrupted, but that’s just a working theory.

Ignoring SIP redirect messages from the Cisco 7912

Saturday, January 27th, 2007

A few months ago, I started using a Cisco 7912 with my home Asterisk system. It’s a much nicer phone than most analog sets you can buy. Furthermore, it is a pure IP phone and therefore doesn’t have the same echo problems as my analog phones hanging off ATAs.

However, there is one frustration. The phone attempts to be smart, and will redirect calls to voice mail after four rings if the voice mail number has been configured. Generally, it’s a nice feature, but it can be quite annoying when I have the Asterisk-powered doorbell ring the 7912. The procedure goes something like this:

  1. Somebody presses the Doorbell Fon, which creates a call into an FXO port on my Asterisk server.
  2. Asterisk handles the call, either by ringing a group of extensions directly, as in Dial(SIP/cisco7912&SIP/others), or by ringing all extensions in a queue.
  3. All the phones that are targets in the queue or Dial application ring. On the fourth ring, the 7912 gets smart and decides to send the call to voice mail.
  4. Upon receipt of the SIP redirect message, Asterisk sends the call to the voice mail extension. However, without knowing what mailbox to send to, Asterisk prompts the user. On a Doorbell Fon, there is only one button and no way to interact with the phone.

While redirection to voicemail may generally be a useful feature, four rings doesn’t make sense for a doorbell, especially if the 7912 causes the call to be sent to voice mail and prevents other extensions from answering it. What I would really like Asterisk to do is to ignore SIP redirect messages. (I can think of many applications where you’d want Asterisk to do the call processing without regard to what client devices tell you to do, especially if you might be liable for the resulting toll charges.)

It turns out that there’s an experimental flag to do this in the Dial application. In Asterisk trunk, there’s a small bit of code that allows you to pass the “i” option to Dial to instruct Asterisk to ignore SIP redirects. I’m still running the 1.2 release, so I don’t have this option just yet. I suppose it is just another reason why I am looking forward to my upgrade from Asterisk 1.2.

Robo-caller, meet Asterisk. And then go to a special circle of hell.

Monday, November 6th, 2006

Clearly, for people who use automatic robot callers to send you recorded messages deserve to go to hell. If somebody with the right connections is reading, I’d like to propose construction of an extra-special circle of hell for people who use mis-programmed auto-dialers. The Barrington Courier-Review (Illinois) is reporting that some political telemarketing machines will call you right back if you don’t listen to the whole message.

The campaign caught making repeated phone calls has blamed the telemarketing contractor, saying that it was obviously a mis-configured computer. Well, those campaigns can retain their mis-configured computer, because my correctly configured Asterisk machine will handle the calls appropriately. I’ll make my voting decision in peace, by reviewing sources of information I trust. (Hint to campaign managers: this probably is not you.) Please, make as many calls as you want. My computer is happy to listen to you spew your message, and it will deliver it to me if it is appropriate. I have programmed my computer with an algorithm that is working quite well so far, namely, that all telemarketing calls should be discarded.

However, there’s clearly a reason why these calls get made. Somebody has to believe that they work, which means that they’re either effective or cheap. Thudfactor says that a robo-call is only five cents per call, though I’ve also heard figures between one and two cents per call. No wonder they’re so depressingly common. The Center for Information and Research on Civic Learning and Engagement (CIRCLE) says that

[t]he most effective way of getting a new voter is the in-person door knock by a peer; the least effective is an automated phone call. Canvassing costs $11 to $14 per new vote, followed closely by phone banks at $10 to $25 per new vote. Robocalls mobilize so few voters that they cost $275 per new vote. (These costs are figured per vote that would not be cast without the mobilizing effort.)

(The figures cited are a study of the youth vote, which may not necessarily be representative of the whole voting population.)

Defeating telemarketers with Asterisk

Tuesday, October 31st, 2006

One of the reasons I initially started using Asterisk at home is that I was tired of telemarketers. Most telemarketers have been deterred by the national (U.S.) do not call list. However, the do not call list has two important exceptions for political organizations and charities (see question 29 on the FTC’s Q&A).

The exception for politics is a huge hole in California. In addition to all the candidates for public office, we typically are faced with a slew of ballot propositions. In this election cycle, there are thirteen state measures and eleven city measures in San Francisco, to say nothing of the actual people running for office. I think a majority of the money and effort is spent on the referendum side of the ballot, since text inserted into the state constitution, city charter, or California legal code never develops an annoying conscience and turns on its financiers.

Now that it’s the final push in the electoral season here in California, I’m sure the calls are flying furiously. However, I sit in blissful silence at home with a phone that’s not ringing. When you call my house, Asterisk picks up and asks you to enter an extension number or use the dial-by-name directory. If you don’t do either of those tasks, you can’t make the internal extensions ring.

Initially, I had expected that guarding the phone was going to be hard. I thought it would require validating caller ID, checking it for correctness somehow, and possibly even doing a “liveness” proof that generated a random string of digits for the caller and requested that the caller enter them back to you. It turns out that there’s a much simpler and easier way. Most mass-dialing operations use predictive dialers or robot dialers. Neither type of device is capable of understanding and reacting to speech appropriately. All I needed to do was to pick up the phone, read out an extension number (“hello, you’ve reached this phone number, dial extension 123 to talk to person #1“), and wait for a response. Most computer dialers are not able to intelligently process the voice, so Asterisk hangs up on them.

Here’s the essence of the code I use:
mainmenu => {
NoOp(Received Caller ID is => ${CALLERID(all)});

// Caller ID checks and Iotum processing left out for clarity
// Friends and family menu check goes here

// My voice menu — default for most callers

So far, that simple voice menu does the trick. I haven’t needed to modify the code yet so that when it detects a telemarketing computer, it plays the “disconnected number” tones with the Zapateller application.

Initial investigations on hooking up Skype to SIP with Asterisk: NCH Uplink, ChanSkype, and PSGw

Monday, October 30th, 2006

I’ve been playing around for the past couple of weeks with Skype-to-SIP adapters so that I could set up a Skype trunk with my home Asterisk server. No matter what your feelings on the proprietary Skype approach, it does deal with NAT quite well, and that may be important if you are on a single dynamic IP address connection. I’ve also been interested in integrating Skype into the Asterisk setup since the announcement of free outbound calling through the end of 2006. Although there are $1,000 Skype-to-PBX bridges, I am not interested enough in Skype connections to spend more money than my Asterisk server hardware cost. For my investigation, I looked at three “personal-scale” products:

All three products take the same approach. Each product is composed of a SIP interface component and a Skype client control component that uses the Skype API. When a call comes in to one half, it is directed to the other half, typically by redirecting the audio streams from the speakers through an operating system conduit. PSGw uses the term software audio cable, which is the best description.

Uplink Skype to SIP

NCH Swift Sound is an Australian company with expertise in computer-based audio and a few VoIP-related applications. Uplink’s installer offers you the Axon PBX, though it’s not necessary when you plan on using Asterisk. Uplink is a Windows application, and has a $40 price tag for license, though free downloads are available.

I already run one full-time PC for Asterisk, and I didn’t want another one just in case somebody decided to Skype me. My first approach was to try running Uplink in VMware, though I quickly abandoned that when it became clear just how much the VMware emulation layer would require in terms of resources. When the Windows VM needed CPU time, it dramatically affected performance of the applications running under Linux. The sound quality was awful, too. At first, I wondered if the sound quality was due to resource constraints on the shared system, so I ran Uplink on a separate machine. Although sound quality improved, the audio was still not anywhere near conversational quality. It was interrupted by frequent drops and hesitations. The only reason that I could make out what was coming through the telephone is that I had recorded the voice prompts myself.

To correctly get Skype to call out to a phone number, there’s a bit of phone number massaging required. Skype expects a call out number to be done in the international telephone style (+1415…), so you’ll need to add the plus sign on. To dial a skype user from the telephone keypad, you’ll also need to set up a mapping between a number and the name. Here’s some example dialplan code that does both. (Uplink is set up to register with the peer name “skype”.)
//Use “09” as a Skype outbound trunk
//Add leading “+” on to 1-NPA-NXX-XXXX number
// Map 09-888 to echo service
_09888 => {


  1. The easiest setup of the three applications I tested. Uplink installs like any other Windows application, and its configuration is well thought out. It also shows reasonable debugging information as it runs, so it’s pretty easy to see what’s going on inside.


  1. Windows-only solutions require a second box with Linux-based Asterisk systems. (This may be offset if you have a powerful enough machine to run VMware, but my VMware installation bogged down on a 1.6 GHz AMD Turion64 with 512 MB RAM.)
  2. Poor sound quality, regardless of whether Uplink runs in a VM or on an external machine.
  3. Poor call supervision. Frequently, Skype would stay connected even though Asterisk had sent a BYE message to the SIP side of Uplink. I had to fix this by hanging up in the Skype GUI.


Note: The following applies to an old version of ChanSkype. Last Wednesday, they released version 1.2, which could address one of my major concerns.

ChanSkype was announced in early October by a Brazilian company. The approach is perhaps the best of any of these products because it makes Skype instances appear as channels, rather than trying to control clients directly with a co-resident SIP gateway. It has the ability to use multiple Skype instances as outbound trunks from the same machine, which is a unique capability within the products that I looked at.

Configuration of ChanSkype was the most in-depth of any of the products. None of it is particularly hard, and the company provides quite good documentation. My two big challenges were the general configuration complexity, as well as the fact that the channel driver is provided as a 32-bit binary driver and can’t be dynamic linked into a 64-bit Asterisk.

The configuration complexity comes directly from the approach that the product takes. Several instances of the Skype client are each run by using VNC as the display. With several VNC instances running, each Skype client can function as an outbound trunk that is directly addressable by the channel driver. Unfortunately, even if you only want one Skype instance, it still requires VNC.

To set up outbound calling, you’ll need to add the plus sign on to the front of the number, as in the following dialplan code:
//Use “09” as skype trunk
_091X. => {

I had trouble with one-way audio during this test, though I believe that was due to NAT on my own network, and a SIP security device that I am using.


  1. ChanSkype had by far the best audio. The inbound audio when making a telephone call was nearly perfect, though it was hard to tell from the 15-second per-call limit that is embedded into the channel driver.
  2. Unlike the other two products, this one is capable of sending multiple Skype streams outbound because it runs multiple clients simultaneously. This is hard to test with a 15-second call limit, though.
  3. The best integration into the dialplan. Because ChanSkype is a channel driver, it’s easy to say Dial(Skype/skypeinstance/number) and let the channel driver figure out who’s free.


  1. This was the most complex configuration. Even if you only want one outbound Skype trunk, it requires running a VNC server for that client.
  2. If you run Asterisk on AMD64, there may be some extra work to get the 32-bit channel driver running. I run Asterisk on Gentoo, and found that recompiling Asterisk as a 32-bit application is sufficient because there is a wide range of compatibility libraries that can be used. (In talking with the company, I discovered they plan to release a 64-bit version.)
  3. ChanSkype doesn’t take inbound calls. If your purpose is to get cheaper outbound calling, this may not be a problem for you. (Note: ChanSkype 1.2, announced on October 25, lifts this limitation.)

Personal Skype Gateway (PSGw)

PSGw is one of the oldest Skype-to-SIP converters. Although it started on Windows, it was ported to Linux in July of this year. Because of my preference for a single-machine solution, I worked with the Linux version. Like ChanSkype, the Linux PSGw is distributed as a 32-bit application. On my system, however, there are repeated segmentation faults if it is run with 64-bit libraries.

PSGw requires a separate IP address from Asterisk to avoid port conflicts. I solved this with a secondary address on the main network interface, but this may not be possible if you don’t have enough routable IP addresses, or a way to keep the PSGw-to-Asterisk connection from going through a NAT. (At the Interop Labs earlier this year, we found that SIP and NAT don’t mix.)

Once I had successfully installed PSGw, it was easy to start. When I made my first call, PSGw mapped the call from SIP on to Skype and promptly died. As far as I can tell, the premature death was due to a library conflict. On Linux, the Skype API runs over D-Bus, and a key dynamic library used by PSGw is distributed as a 32-bit object. I was able to solve the problem by building a 32-bit chroot area, though that’s definitely not for the faint of heart. (To get Skype running in the 32-bit chroot, I needed to have a second, 32-bit version of the libraries it depends on, as well as the sound daemon used by KDE.)

Even once the 32-bit chroot was in place, there were problems with PSGw staying up if I permanently authorized PSGw to use the Skype API. To revoke the authorization, remove it from the config.xml file for the user you sign on as. Look for this line, and take out any programs that are authorized:


  1. By far the best call supervision. When Asterisk hung up, PSGw would terminate the Skype call. There was never a call leg that stayed up longer than its counterpart.


  1. Most complex setup on AMD64 due to the apparent requirement for a 32-bit chroot. (This isn’t documented anywhere, but the program crashed a lot until I put it into a 32-bit chroot.)
  2. Extremely poor call quality. I couldn’t tell that it was relaying human speech.

Closing thoughts

Based on my testing, ChanSkype seems like the most promising approach. I’ll try the recently-released 1.2 version, and report back.

In the future, it may be possible to use something likethe recently-announced Philips VOIP841, which would seem to offer the ability to be a Skype-to-analog converter that doesn’t require a computer. (Philips also announced Netgear would deliver a PC-less Skype phone.)