diff --git a/src/main/java/org/myrobotlab/service/InMoov2.java b/src/main/java/org/myrobotlab/service/InMoov2.java index 7448db6d46..5ff30ed3c6 100644 --- a/src/main/java/org/myrobotlab/service/InMoov2.java +++ b/src/main/java/org/myrobotlab/service/InMoov2.java @@ -36,6 +36,7 @@ import org.myrobotlab.service.Log.LogEntry; import org.myrobotlab.service.abstracts.AbstractSpeechSynthesis; import org.myrobotlab.service.config.InMoov2Config; +import org.myrobotlab.service.data.AudioData; import org.myrobotlab.service.data.JoystickData; import org.myrobotlab.service.data.Locale; import org.myrobotlab.service.interfaces.IKJointAngleListener; @@ -229,6 +230,8 @@ public static void main(String[] args) { protected String voiceSelected; + protected boolean pirActive = false; + public InMoov2(String n, String id) { super(n, id); locales = Locale.getLocaleMap("en-US", "fr-FR", "es-ES", "de-DE", "nl-NL", "ru-RU", "hi-IN", "it-IT", "fi-FI", "pt-PT", "tr-TR"); @@ -402,7 +405,7 @@ synchronized public void boot() { if (config.startupSound) { String startupsound = FileIO.gluePaths(getResourceDir(), "/system/sounds/startupsound.mp3"); - invoke("publishPlayAudioFile", startupsound); + playAudioFile(startupsound); } List services = Runtime.getServices(); @@ -979,6 +982,11 @@ public boolean isMute() { public boolean isSpeaking() { return isSpeaking; } + + public boolean isPirActive() { + return pirActive; + } + /** * execute python scripts in the app directory on startup of the service @@ -1189,6 +1197,23 @@ public PredicateEvent onChangePredicate(PredicateEvent event) { // do defaults ? return event; } + + /** + * Subscription for audioPlayer starting to play a file. + * @param data + */ + public void onAudioStart(AudioData data) { + processMessage("onAudioStart", data); + } + + /** + * Subscription for audioPlayer stopping an audio file. + * @param data + */ + public void onAudioEnd(AudioData data) { + processMessage("onAudioEnd", data); + } + /** * comes in from runtime which owns the config list @@ -1371,6 +1396,12 @@ public boolean onSense(boolean b) { } else { invoke("publishEvent", "PIR OFF"); } + + // Better - processed through a potentially configured "processor" + // "named" message since sender is this service + processMessage("onSense", b); + pirActive = b; + return b; } @@ -1440,6 +1471,11 @@ public void onText(String text) { log.info("onText - {}", text); invoke("publishText", text); } + + public void playAudioFile(String filename) { + log.info("playAudioFile {}", filename); + invoke("publishPlayAudioFile", filename); + } // TODO FIX/CHECK this, migrate from python land @Deprecated /* @@ -1484,6 +1520,34 @@ public void powerUp() { public void processMessage(String method) { processMessage(method, (Object[]) null); } + + public void playMusic() { + AudioFile af = (AudioFile) getPeer("audioPlayer"); + if (af != null) { + af.startPlaylist(); + } + } + + public void nextPlay() { + AudioFile af = (AudioFile) getPeer("audioPlayer"); + if (af != null) { + af.skip(); + } + } + + public void searchPlay(String requestedSong) { + AudioFile af = (AudioFile) getPeer("audioPlayer"); + if (af != null) { + Map> pls = af.getPlaylists(); + for(String playlist: pls.keySet()) { + for (String song : pls.get(playlist)) { + if (song.contains(requestedSong)) { + af.play(song); + } + } + } + } + } /** * Will publish processing messages to the processor(s) currently subscribed. @@ -2009,6 +2073,18 @@ public void setLocale(String code) { // super.setLocale(code); for (ServiceInterface si : Runtime.getLocalServices().values()) { if (!si.equals(this)) { + // by default, InMoov2 tries to set all Locales on all services + // from its configured Locale, or a default Locale set on the OS. + // This works ok when ProgramAB is providing translations, however, + // in the case of "brain" translation will be provided at a different + // layer, therefore resetting chatBot to en-US bot from configured "brain" bot + // is prevented + if (si instanceof ProgramAB) { + ProgramAB chatbot = (ProgramAB)si; + if ("brain".equals(chatbot.getCurrentBotName())){ + continue; + } + } si.setLocale(code); } } diff --git a/src/main/java/org/myrobotlab/service/config/InMoov2Config.java b/src/main/java/org/myrobotlab/service/config/InMoov2Config.java index 98a593a2d3..d0a022b139 100644 --- a/src/main/java/org/myrobotlab/service/config/InMoov2Config.java +++ b/src/main/java/org/myrobotlab/service/config/InMoov2Config.java @@ -154,9 +154,6 @@ public class InMoov2Config extends ServiceConfig { public boolean virtual = false; - /** - * false for now to not interfere - */ public boolean execScript = false; public InMoov2Config() { @@ -538,8 +535,7 @@ public Plan getDefault(Plan plan, String name) { listeners.add(new Listener("publishStopAnimation", getPeerName("neoPixel"))); // listeners.add(new Listener("publishProcessMessage", // getPeerName("python"), "onPythonMessage")); - listeners.add(new Listener("publishProcessMessage", getPeerName("python"), "onPythonMessage")); - + listeners.add(new Listener("publishProcessMessage", getPeerName("python"), "onPythonMessage")); listeners.add(new Listener("publishPython", getPeerName("python"))); // InMoov2 --to--> InMoov2 @@ -551,6 +547,10 @@ public Plan getDefault(Plan plan, String name) { listeners.add(new Listener("publishMoveTorso", getPeerName("torso"), "onMove")); // service --to--> InMoov2 + AudioFileConfig audioPlayer = (AudioFileConfig) plan.get(getPeerName("audioPlayer")); + audioPlayer.listeners.add(new Listener("publishAudioStart", name)); + audioPlayer.listeners.add(new Listener("publishAudioEnd", name)); + AudioFileConfig mouth_audioFile = (AudioFileConfig) plan.get(getPeerName("mouth.audioFile")); mouth_audioFile.listeners.add(new Listener("publishPeak", name)); diff --git a/src/main/resources/resource/WebGui/app/service/js/PollyGui.js b/src/main/resources/resource/WebGui/app/service/js/PollyGui.js index f9e42cdb40..fcc6634646 100644 --- a/src/main/resources/resource/WebGui/app/service/js/PollyGui.js +++ b/src/main/resources/resource/WebGui/app/service/js/PollyGui.js @@ -33,6 +33,10 @@ angular.module('mrlapp.service.PollyGui', []).controller('PollyGuiCtrl', ['peer' $scope.spoken = data $scope.$apply() break + case 'onStatus': + $scope.status = data + $scope.$apply() + break default: console.error("ERROR - unhandled method " + $scope.name + " " + inMsg.method) break