diff --git a/bundles/org.openhab.core.compat1x/META-INF/MANIFEST.MF b/bundles/org.openhab.core.compat1x/META-INF/MANIFEST.MF index b44fe5710..2d2eb340a 100644 --- a/bundles/org.openhab.core.compat1x/META-INF/MANIFEST.MF +++ b/bundles/org.openhab.core.compat1x/META-INF/MANIFEST.MF @@ -22,6 +22,8 @@ Import-Package: com.google.common.base, org.eclipse.emf.common.util, org.eclipse.emf.ecore, org.eclipse.emf.ecore.resource, + org.eclipse.smarthome.config.core, + org.eclipse.smarthome.core.audio, org.eclipse.smarthome.core.autoupdate, org.eclipse.smarthome.core.common.registry, org.eclipse.smarthome.core.events, @@ -32,7 +34,7 @@ Import-Package: com.google.common.base, org.eclipse.smarthome.core.persistence, org.eclipse.smarthome.core.transform, org.eclipse.smarthome.core.types, - org.eclipse.smarthome.io.voice.tts, + org.eclipse.smarthome.core.voice, org.eclipse.smarthome.model.item, org.eclipse.smarthome.model.persistence, org.eclipse.smarthome.model.script.engine, @@ -89,7 +91,6 @@ Export-Package: org.codehaus.jackson, org.openhab.core.types, org.openhab.io.console, org.openhab.io.multimedia.actions, - org.openhab.io.multimedia.tts, org.openhab.io.net.actions, org.openhab.io.net.exec, org.openhab.io.net.http, @@ -104,3 +105,4 @@ Bundle-ClassPath: lib/jl1.0.1.jar, lib/jackson-core-asl-1.9.2.jar, lib/jackson-mapper-asl-1.9.2.jar Service-Component: OSGI-INF/*.xml +Bundle-ActivationPolicy: lazy diff --git a/bundles/org.openhab.core.compat1x/OSGI-INF/audioaction.xml b/bundles/org.openhab.core.compat1x/OSGI-INF/audioaction.xml index 06faebd73..d4ab5d316 100644 --- a/bundles/org.openhab.core.compat1x/OSGI-INF/audioaction.xml +++ b/bundles/org.openhab.core.compat1x/OSGI-INF/audioaction.xml @@ -9,9 +9,10 @@ http://www.eclipse.org/legal/epl-v10.html --> - + + diff --git a/bundles/org.openhab.core.compat1x/OSGI-INF/ttsservicefactory.xml b/bundles/org.openhab.core.compat1x/OSGI-INF/ttsservicefactory.xml deleted file mode 100644 index c2f9ee592..000000000 --- a/bundles/org.openhab.core.compat1x/OSGI-INF/ttsservicefactory.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - diff --git a/bundles/org.openhab.core.compat1x/build.properties b/bundles/org.openhab.core.compat1x/build.properties index 478f73e2f..13b7e3980 100644 --- a/bundles/org.openhab.core.compat1x/build.properties +++ b/bundles/org.openhab.core.compat1x/build.properties @@ -3,14 +3,6 @@ bin.includes = META-INF/,\ .,\ lib/,\ OSGI-INF/,\ - OSGI-INF/autoupdateproviderdelegate.xml,\ - OSGI-INF/eventbridge.xml,\ - OSGI-INF/eventpublisherdelegate.xml,\ - OSGI-INF/bindingconfigreaderfactory.xml,\ - OSGI-INF/actionservicefactory.xml,\ - OSGI-INF/itemuiregistry.xml,\ - OSGI-INF/chartproviderfactory.xml,\ - OSGI-INF/ttsservicefactory.xml,\ lib/jackson-core-asl-1.9.2.jar,\ lib/jackson-mapper-asl-1.9.2.jar source.. = src/main/java/ diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/actions/Audio.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/actions/Audio.java index d631bce05..49a7712e4 100644 --- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/actions/Audio.java +++ b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/actions/Audio.java @@ -18,7 +18,6 @@ import java.net.MalformedURLException; import java.net.Socket; import java.net.URL; import java.net.URLConnection; -import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -33,15 +32,10 @@ import javax.sound.sampled.UnsupportedAudioFileException; import org.apache.commons.collections.Closure; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.eclipse.smarthome.io.voice.tts.TTSService; -import org.openhab.core.compat1x.internal.CompatibilityActivator; +import org.eclipse.smarthome.config.core.ConfigConstants; import org.openhab.core.library.types.PercentType; import org.openhab.core.scriptengine.action.ActionDoc; import org.openhab.core.scriptengine.action.ParamDoc; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +44,6 @@ import javazoom.jl.player.Player; public class Audio { - private static final String RUNTIME_DIR = "runtime"; private static final String SOUND_DIR = "sounds"; private static final Logger logger = LoggerFactory.getLogger(Audio.class); @@ -65,7 +58,8 @@ public class Audio { @ActionDoc(text = "plays a sound from the sounds folder") static public void playSound(@ParamDoc(name = "filename", text = "the filename with extension") String filename) { try { - InputStream is = new FileInputStream(RUNTIME_DIR + File.separator + SOUND_DIR + File.separator + filename); + InputStream is = new FileInputStream( + ConfigConstants.getConfigFolder() + File.separator + SOUND_DIR + File.separator + filename); if (filename.toLowerCase().endsWith(".mp3")) { Player player = new Player(is); playInThread(player); @@ -157,46 +151,46 @@ public class Audio { /** * Says the given text.. - * + * *

* This method checks for registered TTS services. If there is a service * available for the current OS, this will be chosen. Otherwise, it * will pick a (the first) TTS service that is platform-independent. *

- * + * * @param text the text to speak */ @ActionDoc(text = "says a given text through the default TTS service") static public void say(@ParamDoc(name = "text") Object text) { - say(text.toString(), null); + AudioActionService.voiceManager.say(text.toString()); } /** * Text-to-speech with a given voice. - * + * *

* This method checks for registered TTS services. If there is a service * available for the current OS, this will be chosen. Otherwise, it * will pick a (the first) TTS service that is platform-independent. *

- * + * * @param text the text to speak * @param voice the name of the voice to use or null, if the default voice should be used */ @ActionDoc(text = "says a given text through the default TTS service with a given voice") static public void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") String voice) { - say(text, voice, null); + AudioActionService.voiceManager.say(text.toString(), voice); } /** * Text-to-speech with a given voice. - * + * *

* This method checks for registered TTS services. If there is a service * available for the current OS, this will be chosen. Otherwise, it * will pick a (the first) TTS service that is platform-independent. *

- * + * * @param text the text to speak * @param voice the name of the voice to use or null, if the default voice should be used * @param device the name of audio device to be used to play the audio or null, if the default output device should @@ -204,18 +198,8 @@ public class Audio { */ @ActionDoc(text = "says a given text through the default TTS service with a given voice") static public void say(@ParamDoc(name = "text") Object text, @ParamDoc(name = "voice") String voice, - @ParamDoc(name = "device") String device) { - if (StringUtils.isNotBlank(text.toString())) { - TTSService ttsService = getTTSService(CompatibilityActivator.getContext(), System.getProperty("osgi.os")); - if (ttsService == null) { - ttsService = getTTSService(CompatibilityActivator.getContext(), "any"); - } - if (ttsService != null) { - ttsService.say(text.toString(), voice, device); - } else { - logger.error("No TTS service available - tried to say: {}", text); - } - } + @ParamDoc(name = "sink") String sink) { + AudioActionService.voiceManager.say(text.toString(), voice, sink); } @ActionDoc(text = "sets the master volume of the host") @@ -387,31 +371,6 @@ public class Audio { }.start(); } - /** - * Queries the OSGi service registry for a service that provides a TTS implementation - * for a given platform. - * - * @param context the bundle context to access the OSGi service registry - * @param os a valid osgi.os string value or "any" if service should be platform-independent - * @return a service instance or null, if none could be found - */ - static private TTSService getTTSService(BundleContext context, String os) { - if (context != null) { - String filter = os != null ? "(os=" + os + ")" : null; - try { - Collection> refs = context.getServiceReferences(TTSService.class, filter); - if (refs != null && refs.size() > 0) { - return context.getService(refs.iterator().next()); - } else { - return null; - } - } catch (InvalidSyntaxException e) { - // this should never happen - } - } - return null; - } - private static boolean isMacOSX() { return System.getProperty("osgi.os").equals("macosx"); } diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/actions/AudioActionService.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/actions/AudioActionService.java index 1b51c9f3e..ca0d1bc2a 100644 --- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/actions/AudioActionService.java +++ b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/actions/AudioActionService.java @@ -8,19 +8,28 @@ */ package org.openhab.io.multimedia.actions; +import org.eclipse.smarthome.core.voice.VoiceManager; import org.openhab.core.scriptengine.action.ActionService; public class AudioActionService implements ActionService { - @Override - public String getActionClassName() { - return Audio.class.getCanonicalName(); - } + public static VoiceManager voiceManager; - @Override - public Class getActionClass() { - return Audio.class; - } + @Override + public String getActionClassName() { + return Audio.class.getCanonicalName(); + } + @Override + public Class getActionClass() { + return Audio.class; + } + + protected void setVoiceManager(VoiceManager voiceManager) { + AudioActionService.voiceManager = voiceManager; + } + + protected void unsetVoiceManager(VoiceManager voiceManager) { + AudioActionService.voiceManager = null; + } } - \ No newline at end of file diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/TTSService.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/TTSService.java deleted file mode 100644 index bdae52953..000000000 --- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/TTSService.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2015-2016 by the respective copyright holders. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.openhab.io.multimedia.tts; - -/** - * This is the interface that a text-to-speech service has to implement. - * - * @author Kai Kreuzer - Initial contribution and API - * - */ -public interface TTSService { - - /** - * Speaks the text with a given voice - * - * @param text - * the text to speak - * @param voice - * the name of the voice to use or null, if the default voice - * should be used - * @param device - * the name of audio device to be used to play the audio or null, - * if the default output device should be used - */ - void say(String text, String voice, String outputDevice); - -} diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/internal/TTSServiceDelegate.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/internal/TTSServiceDelegate.java deleted file mode 100644 index d0d2d6d3f..000000000 --- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/internal/TTSServiceDelegate.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2015-2016 by the respective copyright holders. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.openhab.io.multimedia.tts.internal; - -import org.eclipse.smarthome.io.voice.tts.TTSService; - -/** - * This class serves as a mapping from the "old" org.openhab namespace to the - * new org.eclipse.smarthome namespace for the action service. It wraps an - * instance with the old interface into a class with the new interface. - * - * @author Tobias Bräutigam - Initial contribution and API - */ -public class TTSServiceDelegate implements TTSService { - - private org.openhab.io.multimedia.tts.TTSService service; - - public TTSServiceDelegate(org.openhab.io.multimedia.tts.TTSService service) { - this.service = service; - } - - @Override - public void say(String text, String voice, String outputDevice) { - service.say(text, voice, outputDevice); - } - -} diff --git a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/internal/TTSServiceFactory.java b/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/internal/TTSServiceFactory.java deleted file mode 100644 index 9a2c04a3e..000000000 --- a/bundles/org.openhab.core.compat1x/src/main/java/org/openhab/io/multimedia/tts/internal/TTSServiceFactory.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) 2015-2016 by the respective copyright holders. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.openhab.io.multimedia.tts.internal; - -import java.util.Dictionary; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; - -import org.openhab.io.multimedia.tts.TTSService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class listens for services that implement the old tts service interface - * and registers an according service for each under the new interface. - * - * @author Tobias Bräutigam - Initial contribution and API (copied from - * ActionServiceFactory) - */ -public class TTSServiceFactory { - private static final Logger logger = LoggerFactory.getLogger(TTSServiceFactory.class); - - private Map> delegates = new HashMap<>(); - private BundleContext context; - - private Map ttsServices = new HashMap<>(); - - public void activate(BundleContext context) { - this.context = context; - for (TTSService service : ttsServices.keySet()) { - registerDelegateService(service, ttsServices.get(service)); - } - } - - public void deactivate() { - for (ServiceRegistration serviceReg : delegates.values()) { - serviceReg.unregister(); - } - delegates.clear(); - this.context = null; - } - - public void addTTSService(TTSService service, Map prop) { - if (context != null) { - registerDelegateService(service, prop); - } else { - ttsServices.put(service, prop); - } - } - - public void removeTTSService(TTSService service) { - if (context != null) { - unregisterDelegateService(service); - } - } - - private void registerDelegateService(TTSService ttsService, Map properties) { - if (!delegates.containsKey(ttsService.getClass().getName())) { - TTSServiceDelegate service = new TTSServiceDelegate(ttsService); - Dictionary props = new Hashtable(); - if (properties != null && properties.containsKey("os")) { - props.put("os", properties.get("os")); - } - ServiceRegistration serviceReg = context - .registerService(org.eclipse.smarthome.io.voice.tts.TTSService.class, service, props); - delegates.put(ttsService.getClass().getName(), serviceReg); - } - } - - private void unregisterDelegateService(TTSService service) { - if (delegates.containsKey(service.getClass().getName())) { - ServiceRegistration serviceReg = delegates - .get(service.getClass().getName()); - delegates.remove(service.getClass().getName()); - serviceReg.unregister(); - } - } -}