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