示例#1
0
    def __init__(self):

        espeak.synth("Hello Master!")

        self.rec = VoiceRecognizer()

        self.actions = ActionManager().loadActions()

        self.canHear = True
示例#2
0
    def __init__(self):

        espeak.synth("Hello Master!")

        self.rec = VoiceRecognizer()

        self.actions = ActionManager().loadActions()

        # Variable used for command voice control, if True the voice command is executed
        self.canHear = True
示例#3
0
	def __init__(self):

		espeak.synth("Hello Master!")

		self.rec = VoiceRecognizer()

		self.actions = ActionManager().loadActions()

		self.canHear = True;
示例#4
0
class CommandHandler(object):

    CONST_TURN_OFF = "turn off"
    CONST_TURN_ON = "turn on"
    CONST_GOODBYE = "goodbye"

    def __init__(self):

        espeak.synth("Hello Master!")

        self.rec = VoiceRecognizer()

        self.actions = ActionManager().loadActions()

        # Variable used for command voice control, if True the voice command is executed
        self.canHear = True

    def callSubProcess(self, args, text):
        try:
            espeak.synth(text)
            # Breaks the arguments to execute on terminal.
            args = args.split(" ")
            # Execute the command on terminal
            subprocess.Popen(args)
        except Exception as e:
            print "Error on callSubProcess: " + str(e)
            espeak.synth("Sorry, I can't " + text)

    def handle(self):
        voiceCommand = self.rec.speechToText().lower()
        if voiceCommand != "":
            if self.CONST_TURN_OFF in voiceCommand:
                espeak.synth("Turning off the microphone")
                self.canHear = False
            elif self.CONST_TURN_ON in voiceCommand:
                espeak.synth("Turning on the microphone")
                self.canHear = True
                return True

            if self.canHear:
                if self.CONST_GOODBYE in voiceCommand:
                    espeak.synth("bye")
                    return False
                espeak.synth("You said " + voiceCommand)

                for action in self.actions:
                    # For each action on list of actions if voice command is found on list and he's active, he's is executed
                    if voiceCommand in action.voiceCommand:
                        self.callSubProcess(action.args,
                                            "Executing " + voiceCommand)

        return True
示例#5
0
class CommandHandler(object):

    CONST_TURN_OFF = "turn off"
    CONST_TURN_ON = "turn on"
    CONST_GOODBYE = "goodbye"

    def __init__(self):

        espeak.synth("Hello Master!")

        self.rec = VoiceRecognizer()

        self.actions = ActionManager().loadActions()

        self.canHear = True

    def callSubProcess(self, args, text):
        try:
            espeak.synth(text)
            args = args.split(" ")
            subprocess.Popen(args)
        except Exception as e:
            print "Error on callSubProcess: " + str(e)
            espeak.synth("Sorry, I can't " + text)

    def handle(self):
        voiceCommand = self.rec.speechToText().lower()
        if voiceCommand != "":
            if self.CONST_TURN_OFF in voiceCommand:
                espeak.synth("Turning off the microphone")
                self.canHear = False
            elif self.CONST_TURN_ON in voiceCommand:
                espeak.synth("Turning on the microphone")
                self.canHear = True
                return True

            if self.canHear:
                if self.CONST_GOODBYE in voiceCommand:
                    espeak.synth("bye")
                    return False

                espeak.synth("You said " + voiceCommand)
                for action in self.actions:
                    if voiceCommand in action.voiceCommand:
                        self.callSubProcess(action.args,
                                            "Executing " + voiceCommand)

        return True
示例#6
0
class CommandHandler(object):

	CONST_TURN_OFF = "turn off"
	CONST_TURN_ON = "turn on"
	CONST_GOODBYE = "goodbye"

	def __init__(self):

		espeak.synth("Hello Master!")

		self.rec = VoiceRecognizer()

		self.actions = ActionManager().loadActions()

		self.canHear = True;

	def callSubProcess(self, args, text):
		try:
			espeak.synth(text)
			args = args.split(" ")
			subprocess.Popen(args)
		except Exception as e:
			print "Error on callSubProcess: "+str(e)
			espeak.synth("Sorry, I can't "+text)

	def handle(self):
		voiceCommand = self.rec.speechToText().lower()
		if voiceCommand != "":
			if self.CONST_TURN_OFF in voiceCommand:
				espeak.synth("Turning off the microphone")
				self.canHear = False
			elif self.CONST_TURN_ON in voiceCommand:
				espeak.synth("Turning on the microphone")
				self.canHear = True
				return True

			if self.canHear:
				if self.CONST_GOODBYE in voiceCommand:
					espeak.synth("bye")
					return False

				espeak.synth("You said "+voiceCommand)
				for action in self.actions:
					if voiceCommand in action.voiceCommand:
						self.callSubProcess(action.args, "Executing "+voiceCommand)		
				

		return True
示例#7
0
                        key='slider')
          ], [button_subscribe, button_unsubscribe], [button_in, button_out],
          [sg.Button('Power off', font=('Helvetica', 20))],
          [sg.Button('Message', font=('Helvetica', 20))]]
window = sg.Window('Braze device', layout, size=(1000, 500))

device_id = 0
if len(sys.argv) > 1:
    device_id = sys.argv[1]
""" Setup """
mqtt_client = mqtt.Client()
main_driver = stmpy.Driver()
second_driver = stmpy.Driver()
device = Device(main_driver, second_driver, device_id)

voicerecognizer = VoiceRecognizer(main_driver)

main_driver.add_machine(device.stm)
# commend out the line under to disable voice recognizion
second_driver.add_machine(voicerecognizer.stm)


def application(main_driver, second_driver):
    # logging.DEBUG: Most fine-grained logging, printing everything
    # logging.INFO:  Only the most important informational log items
    # logging.WARN:  Show only warnings and errors.
    # logging.ERROR: Show only error messages.
    debug_level = logging.DEBUG
    logger = logging.getLogger(__name__)
    logger.setLevel(debug_level)
    ch = logging.StreamHandler()