Skip to content

Commit

Permalink
[marytts] Add LRU cache (openhab#15227)
Browse files Browse the repository at this point in the history
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
dalgwen authored and austvik committed Mar 27, 2024
1 parent 9d5fa85 commit 91dadee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions bundles/org.openhab.voice.marytts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@

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;

Expand All @@ -39,8 +43,8 @@
* @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);

Expand All @@ -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();
Expand All @@ -77,7 +83,7 @@ public Set<AudioFormat> getSupportedFormats() {
}

@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()) {
Expand Down

0 comments on commit 91dadee

Please sign in to comment.