Skip to content

Commit

Permalink
audioPlayer and locales figured out
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Apr 28, 2024
1 parent 35704ac commit 868480a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 deletions.
78 changes: 77 additions & 1 deletion src/main/java/org/myrobotlab/service/InMoov2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<ServiceInterface> services = Runtime.getServices();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 /*
Expand Down Expand Up @@ -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<String, List<String>> 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.
Expand Down Expand Up @@ -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);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/myrobotlab/service/config/InMoov2Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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));

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/resource/WebGui/app/service/js/PollyGui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 868480a

Please sign in to comment.