Get jasper to ask "are you sure"

69 views
Skip to first unread message

agr...@gmail.com

unread,
Jun 11, 2017, 7:24:30 AM6/11/17
to Jasper Support Forum
I am trying to figure out how to get jasper to receive a command, then ask for confirmation before executing. I would like to make a shutdown script, but I think it would be best for jasper to double check before actually shutting down. I know i should use the active listen command, but I can't figure out how to tell jasper what to do if I say yes vs no. Below is the code I have so far (from this forum)

# -*- coding: utf-8-*-
import random
import re
import os
import subprocess

WORDS = ["SHUTDOWN", "SHUT", "DOWN"]

PRIORITY = 3

def handle(text, mic, profile):
    import subprocess
    """
        Responds to user-input, typically speech text, by shutting down the computer
        Arguments:
        text -- user-input, typically transcribed speech
        mic -- used to interact with the user (for both input and output)
        profile -- contains information related to the user (e.g., phone
                   number)
    """
    mic.say("Okay, I'm shutting down. Have a good day Alexander")

    command = "/usr/bin/sudo /sbin/shutdown -h now"
    process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
    output = process.communicate()[0]


def isValid(text):
    """
        Returns True if the input is related to the shutdown module
        Arguments:
        text -- user-input, typically transcribed speech
    """
    return bool(re.search(r'\b(SHUTDOWN|SHUT DOWN)\b', text, re.IGNORECASE))


Aditya Khandkar

unread,
Jun 11, 2017, 1:47:22 PM6/11/17
to Jasper Support Forum
yup, you can use ActiveListen() to make Jasper ask for confirmation.
Here's a snippet:
def shutdown():
    mic
.say('Do you want to shutdown the system?')
    reply
= mic.ActiveListen()
   
if 'YES' in reply:
        mic
.say('Shutting down')
       
#put your shutdown command here
   
elif 'NO' in reply:
       
# abort shutdown
        mic
.say('Shutdown aborted')
   



Reply all
Reply to author
Forward
0 new messages