Softphone, webphone and VoIP server Forum

HomeHomeDiscussionsDiscussionsMizu SoftphoneMizu SoftphoneProcess audio streamingProcess audio streaming
New Post
6/9/2017 11:03 PM
Dear all,

I created an UDP socket in Java to receive media streaming. I'm receiving UDP datagrams  from JVoip and I would like to play the sound as soon as the datagram arrives (imagine I forward those datagrams to a remote machine to listen to the conversation). Do you suggest a Java library to  play or 'make sound' your PCM messages? How can I convert  your UDP datagrams (PCM) into wav? .

I am planning to play and listen to the conversation in real time from a remote machine, so storing them in a file before sending them would not be an option. I receive the UDP datagrams but honestly I dont know how to process them to play the sound in Java. I was thinking of converting each UDP message into wav and then play it, but no idea how to do it.  

Thanks in advance.
New Post
6/10/2017 3:26 AM

This can be done very easily.

The packets sent by the webphone are raw PCM audio packets which can be played as-is by any audio module, so you need only very basic audio handling which can be easily implemented in any languages.

If you are using Java, then it looks like this:

//import required libraries
import javax.sound.sampled.*;

//initialize audio
AudioFormat format = new AudioFormat(8000, 16, 1, true, false);  
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
SourceDataLine line = (SourceDataLine)AudioSystem.getLine(info);;

//playback (you can pass the UDP packets as-is as received from JVoIP)
//this is usually called many times from your UDP socket thread or on UDP packet received event
line.write(buffer, 0, length);

//close when you are finished with all playback

You must add proper exception handling for the above code (try/catch). Exceptions might occur if there is no suitable playback audio device.
More details about Java audio can be found here.
If you are interested in both streams (in/out) then you will need 2 separate lines (don’t just feed both streams to the same line).
The same can be done in a very similar way in any programming language (just search for it's audio playback module/interface/functions).


1. Third party software:
Use some third-party software which is capable to playback raw PCM packets.

2. RTP stream:
If you have a software which is capable to process RTP packets then just set the sendmedia_type to 1 so the JVoIP will emit RTP packets which can be processed as is by such software.

3. Wave files:
If you don't need real-time audio, then just use the voicerecording and related parameters to obtain voice files in wave or other formats at the end of each call.

4. Barge-In:
If you just wish to listen into conversation, then you can use the JVoIP itself for the job. It's barge-in feature allows you to bare into any call and create a hidden conference endpoint, so you can hear the conversation. This is often used in callcenters by supervisors. Let me know if you need this.

New Post
6/11/2017 6:45 PM

Thank you very much for the useful information!. Is there a UDP packet that indicates  a call has finished ?.

Best regards
New Post
6/12/2017 4:16 AM
These kind of things are sent as the usual notifications (as described in the documentation "Notifications" chapter). More exactly you will have the following notifications at the end of calls:
  • a STATUS notification with the statustext set to one of the following values: CallDisconnect,Hangup,Finishing,Finished,Call Finished
    (In case if you need to explicitly handle multiple lines, then check the line parameter, otherwise you can process only messages where line is -1)
  • a CDR notification is also sent after each call


HomeHomeDiscussionsDiscussionsMizu SoftphoneMizu SoftphoneProcess audio streamingProcess audio streaming

You need to register / login to be able to post in the forum