Skip to content

Commit 26296e6

Browse files
BruceVonKMichelle Sintov
authored andcommitted
VIC-3682 SDK relay voice commands (#150)
* Added new UserIntent class as well as user_intent event, tutorial. In progress. * Committing changes, proto not updated * Changed the numeric mapping of UserIntents to a) remove any "searching for IDs" by users, and b) because the Robot code now maps to maintain backward compatibility. * moved tutorials to more logical order * 2018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->20192018->2019 * text cleanup
1 parent 72c4a6e commit 26296e6

6 files changed

Lines changed: 245 additions & 0 deletions

File tree

anki_vector/events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Events(Enum):
5252
robot_changed_observed_face_id = "robot_changed_observed_face_id" # : Robot event for when a known face changes its id.
5353

5454
wake_word = "wake_word" #: Robot event triggered when Vector hears "Hey Vector"
55+
user_intent = "user_intent" #: Robot event triggered after Vector processes voice commands
5556

5657
# Audio
5758
audio_send_mode_changed = "audio_send_mode_changed" #: Robot event containing changes to the robot's audio stream source data processing mode.

anki_vector/user_intent.py

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Copyright (c) 2019 Anki, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License in the file LICENSE.txt or at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
Class and enumeration related to voice commands received by Vector.
17+
18+
When under SDK behavior control, recognized voice commands will be sent as
19+
events. SDK users can respond with their own scripted actions.
20+
21+
"""
22+
23+
# __all__ should order by constants, event classes, other classes, functions.
24+
__all__ = ['UserIntentEvent', 'UserIntent']
25+
26+
from enum import Enum
27+
28+
29+
class UserIntentEvent(Enum):
30+
"""List of UserIntent events available to the SDK.
31+
32+
Vector's voice recognition allows for variation in
33+
grammar and word selection, so the examples are not
34+
the only way to invoke the voice commands.
35+
36+
This list reflect only the voice commands available
37+
to the SDK, as some are not available for development
38+
use."""
39+
#: example "How old are you?"
40+
character_age = 0
41+
#: example "Check the timer."
42+
check_timer = 1
43+
#: example "Go explore."
44+
explore_start = 2
45+
#: example "Stop the timer."
46+
global_stop = 3
47+
#: example "Goodbye!"
48+
greeting_goodbye = 4
49+
#: example "Good morning!"
50+
greeting_goodmorning = 5
51+
#: example "Hello!"
52+
greeting_hello = 6
53+
#: example "I hate you."
54+
imperative_abuse = 7
55+
#: example "Yes."
56+
imperative_affirmative = 8
57+
#: example "I'm sorry."
58+
imperative_apology = 9
59+
#: example "Come here."
60+
imperative_come = 10
61+
#: example "Dance."
62+
imperative_dance = 11
63+
#: example "Fetch your cube."
64+
imperative_fetchcube = 12
65+
#: example "Find your cube."
66+
imperative_findcube = 13
67+
#: example "Look at me."
68+
imperative_lookatme = 14
69+
#: example "I love you."
70+
imperative_love = 15
71+
#: example "Good Robot."
72+
imperative_praise = 16
73+
#: example "No."
74+
imperative_negative = 17
75+
#: example "Bad Robot."
76+
imperative_scold = 18
77+
#: example "Volume 2."
78+
imperative_volumelevel = 19
79+
#: example "Volume up."
80+
imperative_volumeup = 20
81+
#: example "Volume down."
82+
imperative_volumedown = 21
83+
#: example "Go forward."
84+
movement_forward = 22
85+
#: example "Go backward."
86+
movement_backward = 23
87+
#: example "Turn left."
88+
movement_turnleft = 24
89+
#: example "Turn right."
90+
movement_turnright = 25
91+
#: example "Turn around."
92+
movement_turnaround = 26
93+
#: example "I have a question."
94+
knowledge_question = 27
95+
#: example "What's my name?"
96+
names_ask = 28
97+
#: example "Play a game."
98+
play_anygame = 29
99+
#: example "Play a trick."
100+
play_anytrick = 30
101+
#: example "Let's play Blackjack."
102+
play_blackjack = 31
103+
#: example "Fist bump."
104+
play_fistbump = 32
105+
#: example "Pick up your cube."
106+
play_pickupcube = 33
107+
#: example "Pop a wheelie."
108+
play_popawheelie = 34
109+
#: example "Roll your cube."
110+
play_rollcube = 35
111+
#: example "Happy holidays!"
112+
seasonal_happyholidays = 36
113+
#: example "Happy new year!"
114+
seasonal_happynewyear = 37
115+
#: example "Set timer for 10 minutes"
116+
set_timer = 38
117+
#: example "What time is it?"
118+
show_clock = 39
119+
#: example "Take a selfie."
120+
take_a_photo = 40
121+
#: example "What is the weather report?"
122+
weather_response = 41
123+
124+
125+
class UserIntent:
126+
"""Class for containing voice command information from the event stream.
127+
This class, and the contained :class:`UserIntentEvent` include all of the
128+
voice commands that the SDK can intercept.
129+
130+
Some UserIntents include information returned from the cloud and used
131+
when evaluating the voice commands. This information can be parsed as
132+
a JSON formatted string.
133+
134+
.. testcode::
135+
136+
import json
137+
import threading
138+
139+
import anki_vector
140+
from anki_vector.events import Events
141+
from anki_vector.user_intent import UserIntent, UserIntentEvent
142+
143+
def main():
144+
def on_user_intent(robot, event_type, event, done):
145+
user_intent = UserIntent(event)
146+
if user_intent.intent_event is UserIntentEvent.weather_response:
147+
data = json.loads(user_intent.intent_data)
148+
print(f"Weather report for {data['speakableLocationString']}: "
149+
f"{data['condition']}, temperature {data['temperature']} degrees")
150+
done.set()
151+
152+
args = anki_vector.util.parse_command_args()
153+
with anki_vector.Robot(args.serial) as robot:
154+
done = threading.Event()
155+
robot.events.subscribe(on_user_intent, Events.user_intent, done)
156+
157+
print('------ Vector is waiting to be asked "Hey Vector! What is the weather report?" Press ctrl+c to exit early ------')
158+
159+
try:
160+
if not done.wait(timeout=10):
161+
print('------ Vector never heard a request for the weather report ------')
162+
except KeyboardInterrupt:
163+
pass
164+
165+
:param event: an event containing UserIntent data
166+
"""
167+
168+
def __init__(self, event):
169+
self._intent_event = UserIntentEvent(event.intent_id)
170+
self._intent_data = event.json_data
171+
172+
@property
173+
def intent_event(self) -> UserIntentEvent:
174+
""" This returns the voice command event as a UserIntentEvent"""
175+
return self._intent_event
176+
177+
@property
178+
def intent_data(self) -> str:
179+
"""
180+
This gives access to any voice command specific data in JSON format.
181+
182+
Some voice commands contain information from processing. For example, asking Vector
183+
"Hey Vector, what is the weather?" will return the current location and the weather
184+
forecast.
185+
186+
Voice commands without additional information will have an empty intent_data.
187+
"""
188+
return self._intent_data

docs/source/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The API
3232
anki_vector.screen
3333
anki_vector.status
3434
anki_vector.touch
35+
anki_vector.user_intent
3536
anki_vector.util
3637
anki_vector.viewer
3738
anki_vector.vision
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (c) 2019 Anki, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License in the file LICENSE.txt or at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Return information about a voice commands given to Vector
18+
19+
The user_intent event is only dispatched when the SDK program has
20+
requested behavior control and Vector gets a voice command.
21+
22+
After the robot hears "Hey Vector! ..." and a valid voice command is given
23+
(for example "...what time is it?") the event will be dispatched and displayed.
24+
"""
25+
26+
import threading
27+
28+
import anki_vector
29+
from anki_vector.events import Events
30+
from anki_vector.user_intent import UserIntent
31+
32+
33+
def main():
34+
def on_user_intent(robot, event_type, event, done):
35+
user_intent = UserIntent(event)
36+
print(f"Received {user_intent.intent_event}")
37+
print(user_intent.intent_data)
38+
done.set()
39+
40+
args = anki_vector.util.parse_command_args()
41+
with anki_vector.Robot(args.serial) as robot:
42+
done = threading.Event()
43+
robot.events.subscribe(on_user_intent, Events.user_intent, done)
44+
45+
print('------ Vector is waiting for a voice command like "Hey Vector! What time is it?" Press ctrl+c to exit early ------')
46+
47+
try:
48+
if not done.wait(timeout=10):
49+
print('------ Vector never heard a voice command ------')
50+
except KeyboardInterrupt:
51+
pass
52+
53+
54+
if __name__ == '__main__':
55+
main()

0 commit comments

Comments
 (0)