2

I have to check with a Python box if a word I've told to Pepper (saved externally from a dialog box) is inside a list (created as string,and saved into ALMemory from SSH in Matlab), and do something if yes or not. How can I do this?

def onInput_onStart(self):
    #self.onStopped() #activate the output of the box
    picklist = ALProxy("ALMemory")
    list=picklist.getData("myFood")

def food(self):
    if food in list:
        tts=ALProxy("ALDialog")
        tts.say("Available")
kiner_shah
  • 3,939
  • 7
  • 23
  • 37

2 Answers2

0

I personally would just manage it on the web using js, when it comes to this kind of stuff boxes give more trouble than it's worth. Raise an event with the string you want and check if the word is inside the list. After that you can either use the tts (as you seem to be trying to do) or raise and event (sending the true/false as a parameter) and use it to trigger whatever you want.

Javascript:

session = null
QiSession(connected, disconnected, location.host);
tts = null;
function connected(s) {
    console.log("Session connected");
    session = s;
    startSubscribe();

    session.service("ALTextToSpeech").then(function (t) {
        tts = t;
    });
}

function disconnected(error) {
    console.log("Session disconnected");
}

function startSubscribe() {
    session.service("ALMemory").then(function (memory) {
        memory.subscriber("toTablet").then(function (subscriber) {
            subscriber.signal.connect(functionThatChecks)
        });
    });
}

function functionThatChecks(word)
{
    tts.stopAll();
    /*Check if exists*/
    tts.say("It exists"); //Or raise an event
}

Dialog

u: (word) $eventName="word"

Choregraphe

Example

Luis Fernandez
  • 539
  • 1
  • 4
  • 24
0

You need to use self.list before other functions can access it. You also need to pass users_food to the function when you call food(). Assuming that list is a list of strings, and users_food is a string.

def onInput_onStart(self):
    #self.onStopped() #activate the output of the box
    picklist = ALProxy("ALMemory")
    self.list=picklist.getData("myFood")

def food(self, users_food):
    if users_food in self.list:
        tts=ALProxy("ALDialog")
        tts.say("Available")
Anders_K
  • 982
  • 9
  • 28