diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/cache/TTSLRUCacheImpl.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/cache/TTSLRUCacheImpl.java index ace6df0dce6..96e4d9bc5e1 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/cache/TTSLRUCacheImpl.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/cache/TTSLRUCacheImpl.java @@ -53,9 +53,11 @@ public class TTSLRUCacheImpl implements TTSCache { // a small default cache size for all the TTS services (in kB) private static final long DEFAULT_CACHE_SIZE_TTS = 10240; + private static final int DEFAULT_MAX_TEXT_LENGTH_CACHE_TTS = 150; static final String CONFIG_CACHE_SIZE_TTS = "cacheSizeTTS"; static final String CONFIG_ENABLE_CACHE_TTS = "enableCacheTTS"; + static final String CONFIG_MAX_TEXTLENGTH_CACHE_TTS = "maxTextLengthCacheTTS"; static final String VOICE_TTS_CACHE_PID = "org.openhab.voice.tts"; @@ -66,6 +68,12 @@ public class TTSLRUCacheImpl implements TTSCache { * current request is not known and may or may not exceed the limit. */ protected long cacheSizeTTS = DEFAULT_CACHE_SIZE_TTS * 1024; + /** + * The maximum length of texts handled by the TTS cache (in character). If exceeded, will pass the text to + * the TTS without storing it. (One can safely assume that long TTS are generated for report, probably not meant to + * be repeated) + */ + private long maxTextLengthCacheTTS = DEFAULT_MAX_TEXT_LENGTH_CACHE_TTS; protected boolean enableCacheTTS = true; private StorageService storageService; @@ -89,6 +97,8 @@ protected void modified(Map config) { this.enableCacheTTS = ConfigParser.valueAsOrElse(config.get(CONFIG_ENABLE_CACHE_TTS), Boolean.class, true); this.cacheSizeTTS = ConfigParser.valueAsOrElse(config.get(CONFIG_CACHE_SIZE_TTS), Long.class, DEFAULT_CACHE_SIZE_TTS) * 1024; + this.maxTextLengthCacheTTS = ConfigParser.valueAsOrElse(config.get(CONFIG_MAX_TEXTLENGTH_CACHE_TTS), + Integer.class, DEFAULT_MAX_TEXT_LENGTH_CACHE_TTS); if (enableCacheTTS) { this.lruMediaCache = new LRUMediaCache<>(storageService, cacheSizeTTS, VOICE_TTS_CACHE_PID, @@ -100,7 +110,8 @@ protected void modified(Map config) { public AudioStream get(CachedTTSService tts, String text, Voice voice, AudioFormat requestedFormat) throws TTSException { LRUMediaCache lruMediaCacheLocal = lruMediaCache; - if (!enableCacheTTS || lruMediaCacheLocal == null) { + if (!enableCacheTTS || lruMediaCacheLocal == null + || (maxTextLengthCacheTTS > 0 && text.length() > maxTextLengthCacheTTS)) { return tts.synthesizeForCache(text, voice, requestedFormat); } diff --git a/bundles/org.openhab.core.voice/src/main/resources/OH-INF/config/voice.xml b/bundles/org.openhab.core.voice/src/main/resources/OH-INF/config/voice.xml index 2c12124c1ad..fb2bd85dcec 100644 --- a/bundles/org.openhab.core.voice/src/main/resources/OH-INF/config/voice.xml +++ b/bundles/org.openhab.core.voice/src/main/resources/OH-INF/config/voice.xml @@ -59,6 +59,12 @@ The limit size of the TTS cache (in kB). 10240 + + + The maximum length of texts handled by the TTS cache (in character). If exceeded, will pass the text to + the TTS without storing it. 0 for no limit. + 150 + diff --git a/bundles/org.openhab.core.voice/src/main/resources/OH-INF/i18n/voice.properties b/bundles/org.openhab.core.voice/src/main/resources/OH-INF/i18n/voice.properties index cc63e3d4b52..92044fc72b7 100644 --- a/bundles/org.openhab.core.voice/src/main/resources/OH-INF/i18n/voice.properties +++ b/bundles/org.openhab.core.voice/src/main/resources/OH-INF/i18n/voice.properties @@ -17,6 +17,12 @@ system.config.voice.listeningMelody.description = A melody to be played to adver system.config.voice.listeningMelody.option.Bb = Bb system.config.voice.listeningMelody.option.F# = F# system.config.voice.listeningMelody.option.E = E +system.config.voice.enableCacheTTS.label = Enable TTS caching +system.config.voice.enableCacheTTS.description = true to allow TTS services to cache audio files on disk. +system.config.voice.cacheSizeTTS.label = TTS Cache Size +system.config.voice.cacheSizeTTS.description = The limit size of the TTS cache (in kB). +system.config.voice.maxTextLengthCacheTTS.label = TTS Cache Maximum Text Length +system.config.voice.maxTextLengthCacheTTS.description = The limit length of a text handled by the TTS cache. If exceeded, will passthrough to the TTS without storing it. 0 for no limit. error.ks-error = Encountered error while spotting keywords, {0} error.stt-error = Encountered error while recognizing text, {0}