Results 1 to 2 of 2
- 09-09-2009, 02:03 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
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 withbelow)Java Code:bouts.write(b)
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..." ); } }
- 09-10-2009, 01:58 PM #2
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Finished Product: What now?
By Unome in forum Java AppletsReplies: 5Last Post: 02-11-2009, 10:41 AM -
How to construct my finished program?
By matpj in forum New To JavaReplies: 0Last Post: 01-14-2009, 05:37 PM -
finished paint!
By diggitydoggz in forum New To JavaReplies: 3Last Post: 01-04-2009, 10:33 AM -
How to run a code when a download is finished
By aneesahamedaa in forum New To JavaReplies: 4Last Post: 10-14-2008, 12:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks