import org.openhab.core.audio.AudioFormat;
import org.openhab.core.audio.AudioStream;
import org.openhab.core.audio.FixedLengthAudioStream;
+import org.openhab.core.common.Disposable;
import org.openhab.core.voice.Voice;
/**
* @author Florian Schmidt - Initial Contribution
*/
@NonNullByDefault
-class PicoTTSAudioStream extends FixedLengthAudioStream {
+class PicoTTSAudioStream extends FixedLengthAudioStream implements Disposable {
+
private final Voice voice;
private final String text;
private final AudioFormat audioFormat;
throw new AudioException("No temporary audio file available.");
}
}
+
+ @Override
+ public void dispose() throws IOException {
+ File localFile = file;
+ if (localFile != null && localFile.exists()) {
+ try {
+ if (!localFile.delete()) {
+ throw new IOException("Failed to delete the file " + localFile.getAbsolutePath());
+ }
+ } catch (SecurityException e) {
+ throw new IOException("Failed to delete the file " + localFile.getAbsolutePath(), e);
+ }
+ }
+ }
}
import org.openhab.core.audio.AudioException;
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.openhab.core.voice.Voice;
+import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
/**
* @author Florian Schmidt - Initial Contribution
*/
-@Component
+@Component(service = TTSService.class)
@NonNullByDefault
-public class PicoTTSService implements TTSService {
+public class PicoTTSService extends AbstractCachedTTSService {
+
+ @Activate
+ public PicoTTSService(@Reference TTSCache ttsCache) {
+ super(ttsCache);
+ }
+
private final Set<Voice> voices = Stream
.of(new PicoTTSVoice("de-DE"), new PicoTTSVoice("en-US"), new PicoTTSVoice("en-GB"),
new PicoTTSVoice("es-ES"), new PicoTTSVoice("fr-FR"), new PicoTTSVoice("it-IT"))
}
@Override
- public AudioStream synthesize(String text, Voice voice, AudioFormat requestedFormat) throws TTSException {
+ public AudioStream synthesizeForCache(String text, Voice voice, AudioFormat requestedFormat) throws TTSException {
if (text.isEmpty()) {
throw new TTSException("The passed text can not be empty");
}