Results 1 to 2 of 2
  1. #1
    Andy09 is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default Broken pipe exception while feeding a console's inputstream from a non-finished file

    Hi guys,
    I'm into streaming mp3 from a Text To Speech enging (TTS). The challange is that the TTS outputs raw PCM and it does that in real time. 10 seconds of speech takes 10 seconds to generate. To minimize the time users have to wait for the response I want to start sending them the sound as soon as the process has started.
    I'm doing the TTS call in a separate thread. The thread synchs with the caller thread when it has started to produce sound. Then I call Lame (I use Lame to do MP3 conversion) via the console. The Lame command takes takes standard input as its source of data.
    When I know that the TTS process has started to produce PCM which it writes to a file I start to read that file (while it is still being written to by the TTS thread). The bytes read from that file I want to feed into the consoles standard input so Lame can do the conversion.
    It is when trying to write the bytes into that stream I get the java.io.IOException: Broken pipe exception (the row with
    Java Code:
     bouts.write(b)
    below)
    Here is the code-snippet. Before this the TTS thread has been started and synched with this thread at a point telling that it has started the conversion.
    Any hints on how this should be done?
    brgds
    Andy


    Java Code:
    String command = "/bin/bash -c  \"/usr/bin/lame -r -x -m m -b 32 -s 22.05 - - > output.mp3\" ";
                    log.info("COMMAND: "+command );
                   
                    BufferedOutputStream bouts=null;
                    BufferedInputStream bfins=null;
                    BufferedReader br2=null;
                    BufferedReader input=null;
                   
                    try {
                        Runtime rt = Runtime.getRuntime();
                        Process pr = rt.exec(command);                           
                        bouts=new BufferedOutputStream(pr.getOutputStream());//will use this stream to send data to Lame
                        File tmpFile = new File(tmpOutputFileNamePath);// this is the file into which  data is being written from the TTS thread
                        while(tmpFile.exists()==false)
                        {
                            log.info("File does not exist yet... going to sleep" );       
                            Thread.sleep(500);
                        }
                        bfins = new BufferedInputStream(new FileInputStream(tmpFile));
                       
                        int b=0;
                        int noOfBytesAvailable=0;
                        // Read chunks of bytes and write them to the Lame input stream
                        while(ttsThreadObj.isAlive()) // TODO might miss some data when the thread has finished
                        {
                            noOfBytesAvailable= bfins.available();
                            if(noOfBytesAvailable>0)
                            {
                                log.info(noOfBytesAvailable +" bytes available" );   
                                for( ;noOfBytesAvailable>0;noOfBytesAvailable--)             
                                {
                                    b=bfins.read();                               
                                    bouts.write(b);   //Broken Pipe Exception!!! here
                                } 
                            }
                            else {
                                log.info("Nothing available..." );         
                            }
                        }

  2. #2
    Andy09 is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default

    well I solved that myself. The problem was the command having " which caused the command to throw an error. (Saw that when reading the errorstream).
    Replacing the commandline with
    Java Code:
    String command = "/usr/bin/lame -r -x -m m -b 32 -s 22.05 - output.mp3  ";
    made things work.
    /Andy

Similar Threads

  1. Finished Product: What now?
    By Unome in forum Java Applets
    Replies: 5
    Last Post: 02-11-2009, 10:41 AM
  2. How to construct my finished program?
    By matpj in forum New To Java
    Replies: 0
    Last Post: 01-14-2009, 05:37 PM
  3. finished paint!
    By diggitydoggz in forum New To Java
    Replies: 3
    Last Post: 01-04-2009, 10:33 AM
  4. How to run a code when a download is finished
    By aneesahamedaa in forum New To Java
    Replies: 4
    Last Post: 10-14-2008, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •