mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 23:22:02 +01:00
[mactts] Fixed MacTTS producing empty files (#9418)
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
parent
d24decb487
commit
765e477702
@ -23,6 +23,8 @@ import org.openhab.core.audio.AudioFormat;
|
|||||||
import org.openhab.core.audio.AudioStream;
|
import org.openhab.core.audio.AudioStream;
|
||||||
import org.openhab.core.audio.FixedLengthAudioStream;
|
import org.openhab.core.audio.FixedLengthAudioStream;
|
||||||
import org.openhab.core.voice.Voice;
|
import org.openhab.core.voice.Voice;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the {@link AudioStream} interface for the {@link MacTTSService}
|
* Implementation of the {@link AudioStream} interface for the {@link MacTTSService}
|
||||||
@ -32,6 +34,8 @@ import org.openhab.core.voice.Voice;
|
|||||||
*/
|
*/
|
||||||
class MacTTSAudioStream extends FixedLengthAudioStream {
|
class MacTTSAudioStream extends FixedLengthAudioStream {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(MacTTSAudioStream.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Voice} this {@link AudioStream} speaks in
|
* {@link Voice} this {@link AudioStream} speaks in
|
||||||
*/
|
*/
|
||||||
@ -80,12 +84,19 @@ class MacTTSAudioStream extends FixedLengthAudioStream {
|
|||||||
private InputStream createInputStream() throws AudioException {
|
private InputStream createInputStream() throws AudioException {
|
||||||
String outputFile = generateOutputFilename();
|
String outputFile = generateOutputFilename();
|
||||||
String command = getCommand(outputFile);
|
String command = getCommand(outputFile);
|
||||||
|
logger.debug("Executing on command line: {}", command);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Process process = Runtime.getRuntime().exec(command);
|
Process process = Runtime.getRuntime().exec(command);
|
||||||
process.waitFor();
|
process.waitFor();
|
||||||
file = new File(outputFile);
|
file = new File(outputFile);
|
||||||
|
if (!file.exists()) {
|
||||||
|
throw new AudioException("Generated file '" + outputFile + "' does not exist.'");
|
||||||
|
}
|
||||||
this.length = file.length();
|
this.length = file.length();
|
||||||
|
if (this.length == 0) {
|
||||||
|
throw new AudioException("Generated file '" + outputFile + "' has no content.'");
|
||||||
|
}
|
||||||
return getFileInputStream(file);
|
return getFileInputStream(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AudioException("Error while executing '" + command + "'", e);
|
throw new AudioException("Error while executing '" + command + "'", e);
|
||||||
@ -136,7 +147,7 @@ class MacTTSAudioStream extends FixedLengthAudioStream {
|
|||||||
|
|
||||||
stringBuffer.append("say");
|
stringBuffer.append("say");
|
||||||
|
|
||||||
stringBuffer.append(" --voice=\"" + this.voice.getLabel() + "\"");
|
stringBuffer.append(" --voice=" + this.voice.getLabel());
|
||||||
stringBuffer.append(" --output-file=" + outputFile);
|
stringBuffer.append(" --output-file=" + outputFile);
|
||||||
stringBuffer.append(" --file-format=" + this.audioFormat.getContainer());
|
stringBuffer.append(" --file-format=" + this.audioFormat.getContainer());
|
||||||
stringBuffer.append(" --data-format=LEI" + audioFormat.getBitDepth() + "@" + audioFormat.getFrequency());
|
stringBuffer.append(" --data-format=LEI" + audioFormat.getBitDepth() + "@" + audioFormat.getFrequency());
|
||||||
|
Loading…
Reference in New Issue
Block a user