简体   繁体   English

如何结束聆听动作

[英]How to end Listen action

I'm struggling to understand how, and if it is possible, to end a listen action on Pepper after it is started.我正在努力理解如何以及如果可能的话,在 Pepper 启动后结束监听操作。 What i want to achieve in my application is the following:我想在我的应用程序中实现以下目标:

  • Pepper asks a question to the user, which in turn can answer either with voice or a touch input on the tablet. Pepper 向用户提出问题,而用户又可以通过语音或平板电脑上的触摸输入来回答。
  • If the answer is negative, Pepper will have to execute an animation and at the same time reply with a phrase.如果答案是否定的,Pepper 将不得不执行 animation 并同时回复一个短语。

This is the part of the code to handle voice input, and it works as expected:这是处理语音输入的代码部分,它按预期工作:

public void onRobotFocusGained(QiContext qiContext) {
         ...

        //Pepper greets the approached user
        animation_future = greeting_animation.async().run();
        //After the animation is finished, wait for human input
        animation_future.andThenConsume(chatting ->{
            listen = ListenBuilder.with(qiContext).withPhraseSet(response).buildAsync();
            listen.andThenConsume(heardPhrase->{
                //Pepper start listening
                result = heardPhrase.run();
                //If the response contains "yes"
                if( (result.getHeardPhrase().getText().toLowerCase()).equals("si")){
                    //User need helps, Pepper start discussing with it
                    helpNeeded_chat.async().run();
                    //Otherwise
                }else if( (result.getHeardPhrase().getText().toLowerCase()).equals("no")){
                    //No help is required, Pepper says goodbye
                    animation_future = goodbye_animation.async().run();
                    //A new user comes by - Restart scenario
                    animation_future.andThenConsume(restart->{
                        Log.i(TAG, "Interaction ended. Restarting.");
                        //Restart by starting this same activity
                        startActivity(new Intent(this, MainActivity.class));
                    });
                }
            });
        });
    }

While this is the part that handles touch inputs (defined in its own method outside onRobotFocusGained):虽然这是处理触摸输入的部分(在 onRobotFocusGained 之外的自己的方法中定义):

final Button button_no = findViewById(R.id.button_no);
button_no.setOnClickListener(v->{
    ...
    listen.requestCancellation();
    //Help is refused - Restart scenario
    animation_future = goodbye_animation.async().run();
    animation_future.andThenConsume(restart->{
        Log.i(TAG, "Interaction ended. Restarting.");
        //Restart by starting this same activity
        startActivity(new Intent(this, MainActivity.class));
    });
});

In this case since the Listen action keeps running then the warning Pepper can not speak while is listening is thrown thus preventing correct ending of the task.在这种情况下,由于 Listen 操作一直在运行,因此会引发警告Pepper 在侦听时无法说话,从而阻止正确结束任务。 What I have found is that the only method that might allow to terminate actions is requestCancellation() but it doesn't seems to work in my case, the boolean method isCancelled() to check whether the action is terminated keeps returning always False .我发现唯一可能允许终止操作的方法是requestCancellation()但在我的情况下它似乎不起作用,用于检查操作是否终止的 boolean 方法isCancelled()始终返回False

It is actually possible to stop the Listen action or do I have to entirely change the way in which my code is structured (ie use a chatbot from the very beginning)?实际上可以停止 Listen 操作,还是我必须完全改变代码的结构方式(即从一开始就使用聊天机器人)?

When you are calling listen.requestCancellation() , you are in fact cancelling the building of the listen action.当您调用listen.requestCancellation()时,实际上是在取消侦听操作的构建 You defined listen with: listen = ListenBuilder.with(qiContext).withPhraseSet(response).buildAsync();您定义了listenlisten = ListenBuilder.with(qiContext).withPhraseSet(response).buildAsync(); . .

Instead, you should cancel the future returned when you run the action: result = heardPhrase.run();相反,您应该取消运行操作时返回的未来: result = heardPhrase.run(); . . Calling result.requestCancellation() should do the trick for you.调用result.requestCancellation()应该可以为您解决问题。

The thumb rule is that Qi SDK actions are first built then run .经验法则是 Qi SDK 动作首先构建然后运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何收听按钮动作添加组合框并再次收听动作Java - How to listen to button action add combobox and listen to action again Java 如何从活动中收听lottie动画结束 - How to listen for lottie animation end from activity 如何取消选中 radiogroup 中的单选按钮并收听动作 - How to uncheck a radio button in radiogroup and listen to the action 如何在片段上监听来自Activity的按钮的单击动作? - How to listen click action of the button which is from Activity on fragment? 递归-仅在最后执行操作 - Recursion — how to do an action only at the end 如何在Android onMediaButtonEvent中收听“ ACTION_DOWN”(按键)事件,以测量时间? - How to listen to “ACTION_DOWN” (key pressed) event in Android onMediaButtonEvent, in order to measure the time? 是否有“Spring 3 MVC方式”来收听结束会话事件? - Is there a “Spring 3 MVC way” to listen to the end session event? 如何在JAV中使用appium驱动程序结束滚动动作? - How to end the scroll action using appium driver in jav? 摇摆动作听众不会听我的 - Swing action listener won't listen to me Java - swing在表单的文本字段中侦听动作 - Java - swing listen an action in a text field of a form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM