将 Vision Events 与您的 Bot 结合使用#
本节介绍如何使您的 Bot 对基于视觉的用户事件做出反应。目前,Tokkio 开箱即用地支持两种类型的视觉事件
PresenceUserAction 事件提供有关用户是否在摄像头视图中的信息。
AttentionUserAction 事件提供有关用户的注意或参与度级别的信息(例如,如果用户将视线从摄像头移开,则可以认为用户分心)。
如果您的 Bot 应该对这些事件做出反应并与之交互,您有两种选择
[推荐] 您可以使用 Colang 库模块,这些模块提供高级支持来处理这些事件,并与 Colang 标准库的其余部分集成。(注意:Colang 库本身直接使用 UMIM 操作事件;请参阅第 2 点。)
您可以直接使用 UMIM Action 事件并编写您的自定义 Colang 逻辑。使用操作 Colang 文档中的部分解释了如何执行此操作,并且 PresenceUserAction 和 AttentionUserAction 这两个操作在 UMIM 文档 UMIM 文档 中有详细说明。
本节的其余部分将描述选项 (2),以及如何使用 Colang 库模块使您的 Bot 对视觉事件做出反应。
注意
如果您正在使用带有 Tokkio 默认设置的参考应用程序之一,则后端和前端已预配置为处理网络摄像头流,以提取这些基于视觉的用户事件。随这些参考应用程序一起提供的两个参考 Bot 提供了关于您可能希望如何在 Bot 中集成对视觉事件做出反应的更完整示例。
先决条件#
在您开始学习本节之前,请确保您
知道如何用 Colang 编写简单的 Bot 脚本。
基本了解 UMIM 架构设计(交互系统的 UMIM 抽象)。
(可选)拥有正在运行的 Tokkio 设置来测试您的 Bot 脚本。
用户存在#
用户存在处理是 avatar.co
Colang 标准库的一部分,默认随 Colang 2.0 一起提供。因此,您可以直接在您的 Bot 中使用它。以下流程可用于与用户存在进行交互。
- user became present
等待用户被检测为存在(例如,在摄像头 ROI 内)。
示例用法
import avatar import core flow main user became present bot say "Hi there, I can see you now!"
- user became absent
等待用户被检测为不存在(例如,在摄像头 ROI 之外)。
示例用法
import avatar import core flow main user became absent bot say "Goodbye! Until next time!"
用户注意力/参与度#
为了在您的 Bot 脚本中集成处理用户注意力事件,我们提供了一个示例 Colang 模块 attention.co
。
安装 Colang 模块#
我们提供了 Colang 模块 attention.co
以及一个 Python 文件,该文件使用 Colang Python 操作 attention.py
实现了一些辅助方法。您可以按照以下步骤将模块安装到您的 Bot 中
从 Bot 配置下载
attention.co
和attention.py
文件。可以在 tokkio-app-param.yaml 中的 chat-controller 配置中的 configNgcPath 找到相应的 NGC 路径将文件复制到您的 Bot 中的以下位置
your_bot/ actions/ actions.py ... attention.co ...
注意
两个 Tokkio 参考应用程序中的 Bot 已经附带此库。如果您想将其集成到您自己的 Bot 脚本中,请按照上述步骤操作
- tracking user attention
为了自动处理用户注意力事件,您需要激活此流程以跟踪上一次用户发言期间的用户注意力水平。此信息将用于更改所有
user said
流程的功能,以便当用户在注意力不集中时说话时,这些流程将不再完成。示例
import avatar import core # attention.co is imported automatically, since it is in the same folder as your main.co flow main # Activate the flow at the beginning to make sure user attention events are tracked properly activate tracking user attention ...
- user said (overwritten)
当您在 Bot 文件夹中包含
attention.co
时,它会覆盖所有user said
相关流程,以便这些流程仅考虑用户在注意力集中时说的话。您可以通过覆盖下面解释的流程attention checks
来覆盖默认的注意力检查。对于您的首次测试,默认实现应该可以很好地与 Tokkio 设置配合使用。示例
import avatar import core # attention.co is imported automatically, since it is in the same folder as your main.co flow main activate tracking user attention # Since attention.co overwrites all user said related flows, this line will wait until the user says # something while being attentive. user said something bot say "I heard you and you are attentive"
- attention checks $event -> $is_attentive
每当系统需要决定用户发言是否在用户注意力集中时完成时,都会调用
attention checks
流程。您可以通过在 Bot 脚本中覆盖此流程来覆盖默认行为。示例
import avatar import core # attention.co is imported automatically, since it is in the same folder as your main.co @override flow attention checks $event -> $is_attentive # Implement your custom attention logic here $is_attentive = True return $is_attentive
- user said something inattentively
用户在注意力不集中时说了些什么。使用此流程告知用户 Bot 假定用户注意力不集中,并且发言将被忽略。
示例
import avatar import core # attention.co is imported automatically, since it is in the same folder as your main.co flow main activate tracking user attention when user said something bot say "I hear you" or when user said something unattentively bot say "You seem distracted. Can you repeat?" and bot gesture "asking if something refers to them, being unsure if they're being addressed"