Softphone, webphone and VoIP server Forum
All Forums
1
2
3
4
5
Home
Discussions
Mizu Softphone
Process audio streaming
Previous
Next
6/9/2017 11:03 PM
Hulk
Joined: 6/9/2017
Posts: 2
Process audio streaming
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.
6/10/2017 3:26 AM
SuperUser Account
Joined: 5/9/2008
Posts: 492
Re: Process audio streaming
Hello
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 java.io.*;
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);
line.open(format);
line.start();
//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
line.flush();
line.stop();
line.close();
Note:
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).
Alternatives:
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.
6/11/2017 6:45 PM
Hulk
Joined: 6/9/2017
Posts: 2
Re: Process audio streaming
Hello,
Thank you very much for the useful information!. Is there a UDP packet that indicates a call has finished ?.
Best regards
6/12/2017 4:16 AM
SuperUser Account
Joined: 5/9/2008
Posts: 492
Re: Process audio streaming
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
Page 1 of 1
Previous
Next
Home
Discussions
Mizu Softphone
Process audio streaming
You need to
register
/
login
to be able to post in the forum
Forum home
Resources
VoIP Forum home
Webphone
Java SIP client
Java SIP client
Softphone for Android
VoIP Hosting
All-In-One VoIP solution
Softswitch
Windows softphone
Customized Softphone
Documentation
Download
Wiki
Blog
Email to support
send email
Home
|
Software
|
Solutions
|
Services
|
Support
|
Company
Privacy Statement
|
Terms Of Use
Copyright (©) 2024 Mizutech S.R.L.