Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asterisk, How can i play an audio file

Tags:

pbx

asterisk

Here is the dial plan

[testInComingCalls]

exten => s,1,Answer

exten => 30953025,1,Dial(SIP/20000,20)

I would like to play an audio file as soon as somebody answered the call..

Please give me some idea how to call a php file, send the input and based on the output forward the call.

like image 980
Shyju Pulari Avatar asked Jan 31 '14 05:01

Shyju Pulari


People also ask

How can I use audio and video files with asterisk?

There are three basic requirements for making use of specific audio or video media with Asterisk. The Asterisk core must support the format or a module may be required to add the support. Asterisk configuration must be modified appropriately. The devices interfacing with Asterisk must support the format and be configured to use it.

What types of media does Asterisk Support?

Asterisk supports a variety of audio and video media. Asterisk provides CODEC modules to facilitate encoding and decoding of audio streams. Additionally file format modules are provided to handle writing to and reading from the file-system.

Does Asterisk Support codec and file formats?

Asterisk provides CODEC modules to facilitate encoding and decoding of audio streams. Additionally file format modules are provided to handle writing to and reading from the file-system. The tables on this page describe what capabilities Asterisk supports and specific details for each format.

What is the range of Asterisk's Sound?

The human voice generates sound between 80 hz to 12,000 hz (12 khz) but a normal telephone transmits only 300-3500 hz. Even though Asterisk supports high-quality audio, the sound Asterisk plays or records is limited by the phones in use.


2 Answers

Since most of the Dial options act on the called party, not the caller, you have to get a little creative. It is a little odd to do such things to the caller as opposed to the called party, but hey, it's Asterisk: there's usually a way to do whatever you want.

One approach would be to use the lesser known (and somewhat strange) G option. Quoting from the documentation:

If the call is answered, transfer the calling party to the specified priority and the called party to the specified priority plus one.

  • context
  • exten
  • priority

Basically, the G option takes the caller/called channel and - instead of bridging them together - bounces both of them out to the dialplan. You can then get a little creative to perform your Playback operation before putting them in a Bridge together. The following Dialplan should work (caveat: I haven't tested this and I'm sitting on a laptop on a couch, but this should get you close):

[default]

exten => 1000,1,NoOp()
 same => n,Dial(SIP/alice,,G(default^bridge_and_play^1))
 same => n,Hangup()

exten => bridge_and_play,1,Goto(jump_caller,1)
 same => n,Goto(jump_called,1)
 same => n,Hangup()

exten => jump_caller,1,NoOp()
 same => n,Answer()
 same => n,Playback(tt-monkeys)
 same => n,Bridge(${bridge_this})
 same => n,Hangup()

exten => jump_called,1,NoOp()
 same => n,Set(MASTER_CHANNEL(bridge_this)=${CHANNEL})
 same => n,Wait(1000)
 same => n,Hangup()
like image 56
Matt Jordan Avatar answered Sep 28 '22 05:09

Matt Jordan


Who do you want to play the audio to, the caller or the callee?

You can use the M flag to Dial to run a macro on the call right before it's bridged, it runs on the callee SIP/200000. Example:

[testInComingCalls]
exten => 30953025,1,Dial(SIP/20000,20,M(onanswer))

[macro-onanswer]
exten => s,1,Playback(hello-world)
like image 41
Tim Avatar answered Sep 28 '22 04:09

Tim