New Asterisk API: Audiohooks

There is a new Asterisk API in town, and it is called Audiohooks. It was developed by Joshua Colp, a fellow Asterisk developer and friend. As you may have inferred from the name, the audiohooks API lets you add hooks into the audio passing through an Asterisk channel. There are a lot of exciting things that can be done with this, including places where it is already in use.

First, let me explain how this came about. Since Asterisk 1.2, there have been a couple of applications called ChanSpy and MixMonitor that allow you to listen in on any call on the system or record any call, respectively. (Even earlier than 1.2, there was the Monitor application, but MixMonitor is more efficient when it comes to mixing the Tx and Rx audio for a channel.) This is especially useful in call centers … or for Big Brother. However, the implementation has been problematic. It has been a long road of crashes and deadlocks that has caused the underlying code to be re-written multiple times. The Audiohooks is the latest chapter in the saga of ChanSpy and MixMonitor.

If you’re hardcore, here is the header file that defines the API. However, I’ll continue here and give an explanation of the cool things this will let us do.

The Audiohooks API can be used in one of 3 modes.

  1. Spy
  2. Whisper
  3. Manipulate

The spy mode allows the code to receive all audio coming in and out of a channel. This is used for both ChanSpy and MixMonitor today. The Whisper mode allows code to provide audio that will be mixed with the audio coming in and/or out of a channel. This is in use today for the whisper mode of ChanSpy.

The Manipulate mode is perhaps the most exciting mode. It allows code to modify the audio coming in and out of a channel. This is being used today in the func_volume module. This module provides the VOLUME() dialplan function which provides channel technology independent gain control. You can use it and press digits on your phone to increase or decrease the volume of the audio coming in and out of your channel.

Here are some more ideas for things that this API would make fairly straight forward to implement:

  1. Application independent announcements – This API would make it pretty easy to implement a generic mechanism for scheduled and periodic announcements that would just be mixed with whatever other audio is going to the channel from whatever application it is currently executing.
  2. Cool Audio Effects. People have written modules before, such as this one, that allow you to add fancy effects to your voice in Asterisk. However, none of them have ever made it into the tree because we wanted to agree on a solid API for doing this type of thing first.
  3. Fake static. For years, developers have been joking around about adding the ability to introduce fake static into the audio of a call. You know, let’s say you’ve been on the phone for 30 minutes and you really just want to hang up, but you’d like to blame it on something else. Well, just start pressing the magic key on your phone to start increasing the amount of static introduced into the audio! “I’m losing you! Bad connection! I’ll talk to you later!”.

There are plenty more cool things that could be done. If you have an idea, I’d love to hear it. Most of all, thanks to Josh for the cool code!

8 thoughts on “New Asterisk API: Audiohooks

  1. Hi

    Idea? I have one :). One of the most missing feature in Asterisk is to push announcement to an audio channels via CTI/AMI. Why this? There are callcenters, that provides in-talk playbacks to customers (pre-recorded sound documents, or recorded talks). The other example: the customers calls into an ACD, the agent picks up the phone, and her/his name automatically played, hearing both caller, and called party.
    Sorry for my english.
    Peter

  2. Interesting idea. The way that you would go about accomplishing this today is to have the call in a MeetMe conference. Then, to play sounds, you initiate a playback of a file into the conference.

    It’s not the most efficient way to do this in terms of system resources, but it would work .

    We will have more efficient ways of developing applications like this in the next major release.

  3. Is it possible with this API to “spy” on multiple channels at once? Could you also spy on one channel, but then whisper on another?

    This would be great for creating nets like NASA, and the missile ranges use, where you might have the countdown net, the maintenance net, a local private net, etc. and you want to listen on all of them at once to monitor status, and then be able to respond on a particular net.

    That would be a killer app!

  4. Pingback: JACK interfaces for Asterisk

  5. Hello,
    We are looking for a way for our call center supervisors to barge into a call and be able to speak with the caller (as opposed to the Agent).
    (We do not use Zaptel drivers)
    Thanks,
    Vance

  6. Vance,

    Thanks for the comment. This functionality has been implemented in the ChanSpy application, and will be available in Asterisk version 1.6.1. This is one of the features that came from Switchvox.

  7. I was wondering if there is a way to inciate an audio playback to the callee and caller via the AMI. Basically I am looking for the same thing that was mentioned in the first post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s