Transforms a stream directly using pipes instead of toByteArray()
This commit was merged in pull request #15.
This commit is contained in:
@@ -1 +1 @@
|
|||||||
version=4.1
|
version=4.2
|
||||||
@@ -152,10 +152,20 @@ public class RecordState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void rawToWave(ByteArrayOutputStream input, File wavFile) throws IOException {
|
public void rawToWave(ByteArrayOutputStream input, File wavFile) throws IOException {
|
||||||
|
// Transform output to input stream with pipes
|
||||||
|
PipedInputStream pis = new PipedInputStream();
|
||||||
|
final PipedOutputStream out = new PipedOutputStream(pis);
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
input.writeTo(out);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
AudioFormat format = getAudioFormat();
|
AudioFormat format = getAudioFormat();
|
||||||
byte[] audioData = input.toByteArray();
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(audioData);
|
AudioInputStream audioInputStream = new AudioInputStream(pis, format, input.size() / format.getFrameSize());
|
||||||
AudioInputStream audioInputStream = new AudioInputStream(bais, format, audioData.length / format.getFrameSize());
|
|
||||||
|
|
||||||
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, wavFile);
|
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, wavFile);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user