]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mactts] Fixed MacTTS producing empty files (#9418)
authorKai Kreuzer <kai@openhab.org>
Fri, 18 Dec 2020 20:34:03 +0000 (21:34 +0100)
committerGitHub <noreply@github.com>
Fri, 18 Dec 2020 20:34:03 +0000 (12:34 -0800)
Signed-off-by: Kai Kreuzer <kai@openhab.org>
bundles/org.openhab.voice.mactts/src/main/java/org/openhab/voice/mactts/internal/MacTTSAudioStream.java

index ad301a783bc5b5c627aee8b11c04648d52f0bd91..2336b591b46b16690376c271366741c1eaf841a8 100644 (file)
@@ -23,6 +23,8 @@ import org.openhab.core.audio.AudioFormat;
 import org.openhab.core.audio.AudioStream;
 import org.openhab.core.audio.FixedLengthAudioStream;
 import org.openhab.core.voice.Voice;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Implementation of the {@link AudioStream} interface for the {@link MacTTSService}
@@ -32,6 +34,8 @@ import org.openhab.core.voice.Voice;
  */
 class MacTTSAudioStream extends FixedLengthAudioStream {
 
+    private final Logger logger = LoggerFactory.getLogger(MacTTSAudioStream.class);
+
     /**
      * {@link Voice} this {@link AudioStream} speaks in
      */
@@ -80,12 +84,19 @@ class MacTTSAudioStream extends FixedLengthAudioStream {
     private InputStream createInputStream() throws AudioException {
         String outputFile = generateOutputFilename();
         String command = getCommand(outputFile);
+        logger.debug("Executing on command line: {}", command);
 
         try {
             Process process = Runtime.getRuntime().exec(command);
             process.waitFor();
             file = new File(outputFile);
+            if (!file.exists()) {
+                throw new AudioException("Generated file '" + outputFile + "' does not exist.'");
+            }
             this.length = file.length();
+            if (this.length == 0) {
+                throw new AudioException("Generated file '" + outputFile + "' has no content.'");
+            }
             return getFileInputStream(file);
         } catch (IOException e) {
             throw new AudioException("Error while executing '" + command + "'", e);
@@ -136,7 +147,7 @@ class MacTTSAudioStream extends FixedLengthAudioStream {
 
         stringBuffer.append("say");
 
-        stringBuffer.append(" --voice=\"" + this.voice.getLabel() + "\"");
+        stringBuffer.append(" --voice=" + this.voice.getLabel());
         stringBuffer.append(" --output-file=" + outputFile);
         stringBuffer.append(" --file-format=" + this.audioFormat.getContainer());
         stringBuffer.append(" --data-format=LEI" + audioFormat.getBitDepth() + "@" + audioFormat.getFrequency());