Reduce dependency on commons-io and commons-codec (#10614)
Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
<version>2.8.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
package org.openhab.voice.marytts.internal;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.SequenceInputStream;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openhab.core.audio.AudioException;
|
||||
import org.openhab.core.audio.AudioFormat;
|
||||
import org.openhab.core.audio.AudioSource;
|
||||
@@ -54,12 +54,23 @@ class MaryTTSAudioStream extends FixedLengthAudioStream {
|
||||
* @throws IOException
|
||||
*/
|
||||
public MaryTTSAudioStream(AudioInputStream inputStream, AudioFormat audioFormat) throws IOException {
|
||||
rawAudio = IOUtils.toByteArray(inputStream);
|
||||
// The length of an AudioInputStream is expressed in sample frames, not bytes so readAllBytes() cannot be used.
|
||||
rawAudio = inputStreamToBytes(inputStream);
|
||||
this.length = rawAudio.length + 36;
|
||||
this.inputStream = new SequenceInputStream(getWavHeaderInputStream(length), new ByteArrayInputStream(rawAudio));
|
||||
this.audioFormat = audioFormat;
|
||||
}
|
||||
|
||||
private byte[] inputStreamToBytes(InputStream inputStream) throws IOException {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
int n = 0;
|
||||
byte[] buffer = new byte[4096];
|
||||
while (-1 != (n = inputStream.read(buffer))) {
|
||||
output.write(buffer, 0, n);
|
||||
}
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioFormat getFormat() {
|
||||
return this.audioFormat;
|
||||
@@ -146,7 +157,10 @@ class MaryTTSAudioStream extends FixedLengthAudioStream {
|
||||
|
||||
@Override
|
||||
public synchronized void reset() throws IOException {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
this.inputStream = new SequenceInputStream(getWavHeaderInputStream(length), new ByteArrayInputStream(rawAudio));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user