]> git.basschouten.com Git - openhab-addons.git/commitdiff
[marytts] Add LRU cache (#15227)
authorGwendal Roulleau <dalgwen@users.noreply.github.com>
Wed, 12 Jul 2023 17:23:51 +0000 (19:23 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Jul 2023 17:23:51 +0000 (19:23 +0200)
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
bundles/org.openhab.voice.marytts/README.md
bundles/org.openhab.voice.marytts/src/main/java/org/openhab/voice/marytts/internal/MaryTTSService.java

index cd542dd69f2c603c255a0f26bd66fd5f6c87b518..14a5d4277845ed72b7571d5c19fecad2157a259f 100644 (file)
@@ -43,3 +43,8 @@ The sample frequency depends on the chosen voice and ranges from 16kHz to 48kHz.
 ## Log files
 
 The log messages of Mary TTS are not bundled with the openHAB log messages in the `openhab.log` file of your log directory but are stored in their own log file at `server.log` of your log directory.
+
+## Caching
+
+The MaryTTS service uses the openHAB TTS cache to cache audio files produced from the most recent queries in order to reduce traffic, improve performance and reduce number of requests.
+
index ebecb2d454e94e9909996e6422531ace97f99752..f58033465f9f565a9332f1064f2f0cf587552fee 100644 (file)
@@ -21,9 +21,13 @@ import java.util.Set;
 
 import org.openhab.core.audio.AudioFormat;
 import org.openhab.core.audio.AudioStream;
+import org.openhab.core.voice.AbstractCachedTTSService;
+import org.openhab.core.voice.TTSCache;
 import org.openhab.core.voice.TTSException;
 import org.openhab.core.voice.TTSService;
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,8 +43,8 @@ import marytts.modules.synthesis.Voice;
  * @author Kelly Davis - Initial contribution and API
  * @author Kai Kreuzer - Refactored to updated APIs and moved to openHAB
  */
-@Component
-public class MaryTTSService implements TTSService {
+@Component(service = TTSService.class)
+public class MaryTTSService extends AbstractCachedTTSService {
 
     private final Logger logger = LoggerFactory.getLogger(MaryTTSService.class);
 
@@ -56,7 +60,9 @@ public class MaryTTSService implements TTSService {
      */
     private Set<AudioFormat> audioFormats;
 
-    protected void activate() {
+    @Activate
+    public MaryTTSService(final @Reference TTSCache ttsCache) {
+        super(ttsCache);
         try {
             marytts = new LocalMaryInterface();
             voices = initVoices();
@@ -77,7 +83,7 @@ public class MaryTTSService implements TTSService {
     }
 
     @Override
-    public AudioStream synthesize(String text, org.openhab.core.voice.Voice voice, AudioFormat requestedFormat)
+    public AudioStream synthesizeForCache(String text, org.openhab.core.voice.Voice voice, AudioFormat requestedFormat)
             throws TTSException {
         // Validate arguments
         if (text == null || text.isEmpty()) {