How to automatically dial and play a sound?

I want to write a java program which will automatically call somebody and play a sound file once the call is answered. I tried manager API with originate action, but it seems it will only create a connection between two channels. I didn’t find a way how to make the computer automatially call somebody and play a sound file. Any hint or suggestion is highly appreciated!

Requiring a java program is over-specified; is this homework?

Originate connects between a device and and an extension or application, not between channels.

No, it is not a homework. I have an big alarm system. I want the alarm system automatically call corresponding person once an alarm happened and the alarm system will read the alarm details to the listener once the call established.

I did this with two extensions as shown below:

exten => DIAL,1,Playback(hello-world)
exten => DIAL,n,Dial(DAHDI/3,20,m)
exten => DIAL,n,Verbose(1,Dial failed with result ${DIALSTATUS})
;exten => DIAL,n,Hangup()

exten => ANSWER,1,Answer()
exten => ANSWER,n,Wait(5)
exten => ANSWER,n,Background(main-menu)
exten => ANSWER,n,WaitExten(100)
exten => 3,1,SayPhonetic(I Love you)
exten => 3,n,Goto(my_context,Inside,1)
exten => Inside,1,Playback(auth-thankyou)
exten => Inside,n,Hangup()[/code]

The orginate action will use local channel to play sound file:

[code]  OriginateAction dial = new OriginateAction();
    // connect to Asterisk and log in

    // send the originate action and wait for a maximum of 30 seconds for Asterisk
    // to send a reply
    originateResponse = managerConnection.sendAction(dial, 50000);[/code]

The problem is that the local channel will be connected right away whereas the real person will pickup after few rings. How can I make the local channel wait for the pickup?

After making sure that you have answer supervision. I guess this is an FXS line, and you should have answer supervision in that case.

Channel should be DAHDI/3 (assuming that the Dial command is correct). The system will be the calling party, so the m option is of no use, as no human will be played the music on hold. The timeout can be specified on Originate.

context extension and priority should lead you to the dialplan that makes the announcement. You may want to include waits for silence, possibly preceded by waits for speech.

I think you are going to have more problems, so I would suggest booking a course, or paying for consultancy.

The simplest way is to make simple call file, and it will dial, then on connect (you will need something like reverse polarity) - you can send to some extension where to play whatever you want to play to user.
But as it is mentioned - you will need either some education or paying for consultancy, or you can look for Asterisk The Future of Telephony - free book.

Call files have basically the same interface as Originate, so the same questions about what to set the fields to apply. I did think of mentioning them, but it seemed an added complication. However, my original note about java being over-engineering was written with call files in mind.

For answer supervision. I suspect that he’s trying to do third party control to simulate a first party capability, using the computer next to the phone he is calling. As such, I think he has an FXS connection to the phone and answer supervision will be achieved when the phone loops the line.

This does still feel a bit like a student project.