Play sound during a call


I am looking for an unusual feature: I want to play some music during a phone call - basically let the partner comment on the music and talk about it. It should be with as little messing around as possible - so hopefully no “I am parking your call” or “I will transfer you to a conference”.
The music will be chosen during the course of the phone call … lets assume that I place a sound file corresponding to my extn number into a specific directory



exten => 101,1,Musiconhold(song1)

where song1 is a context defined in musiconhold.conf:

[song1] mode=files directory=/var/lib/asterisk/song1

all you’d need to do is drag song1.mp3 or song1.wav into whatever directory you have defined and reload asterisk.

then, have the partner dial x101, and the song should play.

you might need to set the absolute timeout or disable it altogether - i forget what the default is.


thanks for the quick response - I am not sure this will work, though: the partner in this case will be an outside caller and probably should not be able to transfer calls.
The scenario is somewhat similar to a conference, with the music one of the partners


Make sure is executable.

exten => s,1,Answer
exten => s,n,Read(dst|pls-entr-num-uwish2-call)
exten => s,n,Goto(${dst},1)
exten => 98,1,System(/usr/src/
exten => 98,n,Playback(auth-thankyou);
exten => 98,n,Playback(vm-goodbye);
exten => 98,n,Hangup
exten => 99,1,Meetme(100|dAx);
exten => 100,1,Meetme(100|dx);
exten => 300,1,MusicOnHold(default)
exten => h,1,Hangup -
cp /usr/src/ /usr/src/
mv /usr/src/ /var/spool/asterisk/outgoing/
cp /usr/src/ /usr/src/ -
MaxRetries: 0
WaitTime: 10
Context: custom-music-meetme
Extension: 300
Priority: 1



could you explain this a bit - I still cannot see how I get the original caller and myself transferred to the conference, and what the $dst is good for.
Once I am in the conference, the “call” from the music player works nicely. I had to replace Musiconhold() by MP3player, however


With that particular dialplan. First you establish the music playing by dialing 98 then you and the other party would establish a call. You would then transfer them to extension 100. You would hang up and dial into extension 99.


what is the difference between a conference and what i proposed? you making this way too complicated, IMHO.

hell, if you know he’s going to be calling in from the same number each time (or calling a dedicated number just for him) you can set up a context that does nothing BUT play back music.

i think a conference is a bit overkill, unless you specifically NEED to have multiple users listening in at the same time.


well, the situation is different: people call in, and every now and then the best way to handle the call is to play some music to the caller, e.g. "there are at least two different songs by the same title. I am going to play the first one now"
So it is different callers every time, and I cannot anticipate when such a call comes in. In fact, it is possible that two simultaneous callers will receive the same treatment (but likely different music - that part probably can be handled by symlinking the music to play to a file named like the extension used


Considering his nickname, i think it could be kind of a “voting/poll” system where a special extension is for a certain music?

Musicman, it would help knowing better what you are doing there.

Meantime, i think about an “injection”-script.
If this is for ANY commercial use, have a billion dollar cheque handy.

Ich weiss, wo Du wohnst…muaaahhhaaa

Musicman, what is it you are exactly doing ?

  1. More then ONE song per line/caller/extension ?
  2. What technologie ? ISDN / ZAP ? Or SIP ?

how would you determine what songs to play? would it be based off of who was calling, or what number they dialed, or an extension they would need to press…

in other words, would you need a ‘directory’ of music, something like this:

“press 101 to hear b-smooth, 102 to hear p-diddy, 103…”

give us an idea of how you want to present options (if any) to the caller and we can get this sucker straightened out but quick.

I think he wants to be able to talk to the party listening to the music.



it is is a simple situation: a customer calls and asks for a particular song. One common response is “there are at least two candidates” followed by "if you have a web browser around, please enter one of the following codes and listen to the recordings"
Now, if they cannot do that, the next step often is to play one of the recordings - this is currently done by playing the recording and switching the phone to mic / speakers.
So it is the operator taking the call that would choose the music (and has a computer to work with). And certainly the operator wants to talk to the customer while the music is playing (“no, that’s definitely not the one I was looking for. may I hear the other ones”)
Customers are calling in via isdn (and may get routed to one of a few operators), local phones will be iax or sip (currently testing a dect on an iax ata)


Ok, so kind of a radiostation where listerners calling
"Ive heard a song 7 minutes ago, what was it" and the receptionist plays all 2 (or 3) songs that were played within this timeframe.

Well, the problems:

  1. There is no “injecting” into bridged lines
    There is a ChanSpy and Zapbarge, but (imho) both are “quiet” listerner funtions
  2. You are using old phones on an ATA (i would suggest a hardware SIP phone here)

What i just did here:

I simulated such call.
I press 2 keys on my phone then (as the callee):
Conference and “38”

38 is a softphone on my computer which i pull in the conference.
That is very quickly done and not any “hassle” - so a “standard” user could do this as well.

The trick is:
The softphone’s (extension 38 in my testscenario here) audiosource is not a microphone or headset, its the waveout of my soundcard !

That gives me a nice little abillity:
Whatever i play on my WinAmp here, is feeded into the conference…yay.

So i simply click the musicfile and both, caller and callee can listen to it and still talk.

Thats the only way i can think of, to do it without any “acrobatic stunts”.

Maybe there will be kind of a nativ “injection” or “MOH life to channel” function in Asterisk someday, but till then: The above way is quick and easy to do - still2 keys to press but works.

The major advantage:
You dont need to deal with soundfiles and gsm conversion etc.

Whatever you can play in your WinAmp is ready to go !


so in the absence of a conference button, what would be the best way to turn an existing call into a conference - so far I only know how to participate in an existing conference by dialing the conf exten

About the phone: there will be need for a new PBX at the office in a few months, and as the owner seems to prefer cheap stock equipment, I am trying to set up all sorts of cool things on my home system that a stock PBX won’t do. There is a need for portable phones in this setup, and I would of course prefer a dect phone that plugs right into the ethernet, or something like a snom with an additional dect handset. I certainly want different ringtones

Another feature I would like to setup (this will be the one to make the stock pbx vs asterisk decision): if a call comes in, I want 3 or 4 phones to ring, so anyone of these people could pick up and service the caller. As long as the call is in progress, further calls receive a busy … no, I dont want callers to pay for announcements and waiting loops - this is what the current pbx already does. Now, if a call comes in from a recognized caller id, it would still ring the remaining phones, or potentially ring the boss.


Using a manager redirect you can send both the side of the call into a conference. You would have to trigger a script somehow with a web browser, command line, etc…



is there a way for a script to find out current links (other than by following events all the time?)
Suppose I got a call from capi connected to a phone at IAX2/phone3. The channel will be something like IAX2/phone3-7 … but I dont know how to get at that channel name. Is there a way to store current channel into the database as part of dial processing?
This way I could put the call on hold, dial a special exten that would retrieve the channel, and use it to have both sides of the call traqnsferred to a meetme room

I have looked around quite a bit, but isn’t there an easy way to turn a call into a conference … how would a conference button on the phone work? (RichardHH mentioned one, above)


you could pull people into and out of conferences using software like FOP. this would require human interaction though, not sure if you’re looking for a script to do all the dirty work. assuming you take the advise of using a softphone/Winamp as the music source, this should be an easy solution as long as your operators can work FOP.


thanks for the recommendation - I will certainly implement FOP somewhere in the system, and add some web management features (like: if another call comes in via capi from a certain number, use call deflection to route it elsewhere)
I am sure the operators can handle FOP - I doubt that it will work for the boss if he tries it :frowning:


If you would be happy with a ‘hardware’ solution here is an idea.

Take a look at Autohybrid from (or check out some of their other products). This is the same type of product radio stations use. It would then be simple to have a small sound mix board connect to it.

Another product would be the Instreamer by Barix