Sound over socket...how to save it in file? ??

A

Akhil

Hi there!
One of my application has a client and server. The client Captures the sound and sends to server which stores it in a file. I am able to play the data but when I write my data in file & play in Winamp it says... "Invalid File Format" Here is my sample code of Client & Server

// Client
targetDataLine.start();
ByteArrayOutputStream out= new ByteArrayOutputStream();
numBytesRead=0;
while(stopRecord ==false)
{
numBytesRead = targetDataLine.read(data,0,data.length);
out.write(data,0,numBytesRead);
}
targetDataLine.stop();

// Server
while((cnt = soket.getInputStream().read(tempBuffer,0,tempBuffer.length)) != -1)
{
if(cnt > 0)
{
out.write(tempBuffer,0,cnt);//What do I do with this now?

//This is to play it at speaker...
sourceDataLine.write(tempBuffer, 0, cnt);
}
}

I must be thankful 2 u if u can throw-in ur suggestions at my inbox ( (e-mail address removed) )
 
A

Andrew Thompson

Hi there!
One of my application has a client and server.
The client Captures the sound and sends to server
which stores it in a file. I am able to play the data
but when I write my data in file & play in Winamp
it says... "Invalid File Format" Here is my sample
code of Client & Server

This has little or nothing to do with sockets,
I would guess, so remove them from the eqaution.

Write an SSCCE that opens a single file and
save it in the format you want..
// Client
targetDataLine.start();
ByteArrayOutputStream out= new ByteArrayOutputStream();

These code snippets are not very helpful.
Let's see a short, working example.
I must be thankful 2 u if u can throw-in
ur suggestions at my inbox ( (e-mail address removed) )

Sure, my fees for private one-on-one
help are $35/email, send me your credit
card number and we can commence immediately.
Alternatively return here for your answer.
 
K

Knute Johnson

Andrew said:
This has little or nothing to do with sockets,
I would guess, so remove them from the eqaution.

Write an SSCCE that opens a single file and
save it in the format you want..



These code snippets are not very helpful.
Let's see a short, working example.




Sure, my fees for private one-on-one
help are $35/email, send me your credit
card number and we can commence immediately.
Alternatively return here for your answer.

You work too cheap Andrew!
 
K

Knute Johnson

Akhil said:
Hi there!
One of my application has a client and server. The client Captures the sound and sends to server which stores it in a file. I am able to play the data but when I write my data in file & play in Winamp it says... "Invalid File Format" Here is my sample code of Client & Server

// Client
targetDataLine.start();
ByteArrayOutputStream out= new ByteArrayOutputStream();
numBytesRead=0;
while(stopRecord ==false)
{
numBytesRead = targetDataLine.read(data,0,data.length);
out.write(data,0,numBytesRead);
}
targetDataLine.stop();

// Server
while((cnt = soket.getInputStream().read(tempBuffer,0,tempBuffer.length)) != -1)
{
if(cnt > 0)
{
out.write(tempBuffer,0,cnt);//What do I do with this now?

//This is to play it at speaker...
sourceDataLine.write(tempBuffer, 0, cnt);
}
}

I must be thankful 2 u if u can throw-in ur suggestions at my inbox ( (e-mail address removed) )

Well I can tell you for sure that you are using a file format that isn't
recognizable by Winamp. Where is the code that writes the file to disk?
That's what you are asking about right?
 
A

Akhil

Yeah! The code for writing to disk is not here... I know we can use AudioSystem.write() for writing to file... as the syntax goes...

AudioSystem.write(AudioInputStream stream,
AudioFileFormat.Type ,
File file);

There is no prob with last two parameters in that because second param can be set for AudioSystem.Type.WAVE and last is a File object. But wht abt the first parameter... (my input stream is a socket) ? ?? ?????????? And should I bother about header of the WAVE file to be generated... ?? ???? ???????
 
K

Knute Johnson

Akhil said:
Yeah! The code for writing to disk is not here... I know we can use AudioSystem.write() for writing to file... as the syntax goes...

AudioSystem.write(AudioInputStream stream,
AudioFileFormat.Type ,
File file);

There is no prob with last two parameters in that because second param can be set for AudioSystem.Type.WAVE and last is a File object. But wht abt the first parameter... (my input stream is a socket) ? ?? ?????????? And should I bother about header of the WAVE file to be generated... ?? ???? ???????

If you want it to be a .wav file when you are done you need to bother.

Why don't you tell us all of what you are trying to do? I'm sure I'm
not the only one that doesn't know why you are sending the audio data
over a socket if you are going to write it to the local disk. You can
get an AudioInputStream from an InputStream and then write the data with
AudioSystem.write().
 
A

Akhil

Ok.. Ok... Let me dive deeper now. My final objective is a
simple Audio Conferencing system.

With Client and Server prgm in my hand i am able to send
audio from client to server. I have played the incoming
sound at server's speaker which is working fine. Also the server is able to broadcast the incoming voices to all
clients which is played at their respective speakers. I AM
DONE WITH THIS.

But I want to retain the conference some time later again.
And hence wish to save the incoming data at server to its
local disk.

To be crystal clear, you may consider me having a LAN in
which I shout at Machine A and save it at machine B.
Obviously I would need SOCKET for this.

Coming to having an AudioInputStream with socket's
InputStream... I get an exception of " mark/ reset not
supported "
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top