【问题标题】:Checking word inside a string in Coregraphe在Coregraphe中检查字符串中的单词
【发布时间】:2019-08-28 13:34:13
【问题描述】:

如果我告诉Pepper 的单词(从对话框外部保存)在列表中(创建为字符串,并从 Matlab 中的 SSH 保存到 ALMemory)中,我必须检查 Python 框,如果是或不是,做某事。 我该怎么做?

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")

【问题讨论】:

  • 您的代码看起来差不多。你有任何错误吗?
  • 是的,机器人不会告诉'Available'

标签: python pepper


【解决方案1】:

我个人只会在网络上使用 js 来管理它,当涉及到这种东西盒时,它带来的麻烦多于它的价值。使用您想要的字符串引发一个事件并检查该单词是否在列表中。之后,您可以使用 tts(正如您似乎正在尝试做的那样)或 raise 和 event(发送真/假作为参数)并使用它来触发您想要的任何东西。

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
}

对话框

u: (word) $eventName="word"

编舞

【讨论】:

    【解决方案2】:

    您需要先使用self.list,然后其他功能才能访问它。 您还需要在调用 food() 时将 users_food 传递给函数。 假设list是一个字符串列表,users_food是一个字符串。

    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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 2020-02-17
      • 1970-01-01
      • 1970-01-01
      • 2017-02-28
      • 2015-12-05
      相关资源
      最近更新 更多