]> git.basschouten.com Git - openhab-addons.git/commitdiff
[voicerss] Fix bad audio format code and use HTTPS URL instead of HTTP (#12092)
authorlolodomo <lg.hc@free.fr>
Sat, 22 Jan 2022 18:12:38 +0000 (19:12 +0100)
committerGitHub <noreply@github.com>
Sat, 22 Jan 2022 18:12:38 +0000 (19:12 +0100)
Fix #12091

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.voice.voicerss/src/main/java/org/openhab/voice/voicerss/internal/VoiceRSSTTSService.java
bundles/org.openhab.voice.voicerss/src/main/java/org/openhab/voice/voicerss/internal/cloudapi/VoiceRSSCloudImpl.java

index 1d89152ace1da9d0ffca64582c3fcd54ae402731..b04459ca5832c1959bcca7070b90eed80519defc 100644 (file)
@@ -217,7 +217,7 @@ public class VoiceRSSTTSService implements TTSService {
             case AudioFormat.CODEC_MP3:
             case AudioFormat.CODEC_VORBIS:
             case AudioFormat.CODEC_AAC:
-                return apiFrequency + "_" + bitDepth + "_mono";
+                return apiFrequency + "_" + bitDepth + "bit_mono";
             default:
                 throw new TTSException("Unsupported audio format: " + format);
         }
index eb30788e8fd7c3c4442c86544d07dcf3fce665b8..88daf7ca50b08251d7d63d6ed0d3befc9d7b4bee 100644 (file)
@@ -52,6 +52,9 @@ public class VoiceRSSCloudImpl implements VoiceRSSCloudAPI {
 
     public static final String DEFAULT_VOICE = "default";
 
+    public static final String API_URL = "https://api.voicerss.org/?key=%s&hl=%s&c=%s&f=%s&src=%s";
+    public static final String API_URL_WITH_VOICE = API_URL + "&v=%s";
+
     private final Logger logger = LoggerFactory.getLogger(VoiceRSSCloudImpl.class);
 
     private static final Set<AudioFormat> SUPPORTED_AUDIO_FORMATS = Set.of(
@@ -285,12 +288,12 @@ public class VoiceRSSCloudImpl implements VoiceRSSCloudAPI {
     private String createURL(String apiKey, String text, String locale, String voice, String audioCodec,
             String audioFormat) {
         String encodedMsg = URLEncoder.encode(text, StandardCharsets.UTF_8);
-        String url = "http://api.voicerss.org/?key=" + apiKey + "&hl=" + locale + "&c=" + audioCodec + "&f="
-                + audioFormat;
+        String url;
         if (!DEFAULT_VOICE.equals(voice)) {
-            url += "&v=" + voice;
+            url = String.format(API_URL_WITH_VOICE, apiKey, locale, audioCodec, audioFormat, encodedMsg, voice);
+        } else {
+            url = String.format(API_URL, apiKey, locale, audioCodec, audioFormat, encodedMsg);
         }
-        url += "&src=" + encodedMsg;
         return url;
     }
 }