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

Discussion in 'Java' started by Akhil, Mar 1, 2004.

  1. Akhil

    Akhil Guest

    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 ( )
     
    Akhil, Mar 1, 2004
    #1
    1. Advertising

  2. 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 ( )


    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
     
    Andrew Thompson, Mar 1, 2004
    #2
    1. Advertising

  3. 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 ( )

    >
    >
    > 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...
     
    Knute Johnson, Mar 1, 2004
    #3
  4. 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,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 ( )
    >
    >


    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...
     
    Knute Johnson, Mar 1, 2004
    #4
  5. Akhil

    Akhil Guest

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

    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... ?? ???? ???????
     
    Akhil, Mar 2, 2004
    #5
  6. Re: Re : Sound over socket...how to save it in file? ??

    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...
     
    Knute Johnson, Mar 2, 2004
    #6
  7. Akhil

    Akhil Guest

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

    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 "
     
    Akhil, Mar 2, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luc The Perverse

    Sound Quality In Sound API

    Luc The Perverse, Oct 30, 2005, in forum: Java
    Replies:
    4
    Views:
    1,507
    Andrew Thompson
    Oct 31, 2005
  2. Replies:
    0
    Views:
    547
  3. frankrentef
    Replies:
    2
    Views:
    307
    Sean DiZazzo
    Aug 8, 2008
  4. Laszlo Nagy
    Replies:
    1
    Views:
    5,016
    Mark Wooding
    Jan 27, 2009
  5. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,013
    Jean-Paul Calderone
    Jan 27, 2009
Loading...

Share This Page