Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Sound over socket...how to save it in file? ??

Reply
Thread Tools

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

 
 
Akhil
Guest
Posts: n/a
 
      03-01-2004
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,tempBuffe r.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 ( http://www.velocityreviews.com/forums/(E-Mail Removed) )


 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      03-01-2004
On Mon, 1 Mar 2004 13:50:37 -0600, Akhil wrote:

> 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..
<http://www.physci.org/codes/sscce.jsp>

> // 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 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.

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      03-01-2004
Andrew Thompson wrote:

> On Mon, 1 Mar 2004 13:50:37 -0600, Akhil wrote:
>
>
>>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..
> <http://www.physci.org/codes/sscce.jsp>
>
>>// 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 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.
>


You work too cheap Andrew!

--

Knute Johnson
email s/nospam/knute/
Molon labe...
 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      03-01-2004
Akhil wrote:

> 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,tempBuffe r.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 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?

--

Knute Johnson
email s/nospam/knute/
Molon labe...
 
Reply With Quote
 
Akhil
Guest
Posts: n/a
 
      03-02-2004
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... ?? ???? ???????



 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      03-02-2004
Akhil wrote:
> 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().

--

Knute Johnson
email s/nospam/knute/
Molon labe...
 
Reply With Quote
 
Akhil
Guest
Posts: n/a
 
      03-02-2004
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 "

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a short way to save typing script over and over.... frankrentef Python 2 08-08-2008 02:57 AM
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
Playing sound through non default sound card dkga_dkga@yahoo.com Java 0 03-05-2006 04:38 AM
Sound Quality In Sound API Luc The Perverse Java 4 10-31-2005 04:36 AM
No sound. Yellow exclamation by" Windows sound system". =?Utf-8?B?VGFueWE=?= MCSE 2 10-26-2003 07:44 PM



Advertisments