words = str(int(num))
        else:
            pre, post = str(num).split('.')
            words = "{} komma {}".format(pre, post)
    else:
        words = str(num)
    return words


def end_session(hermes, intent_message, text):
    hermes.publish_end_session(intent_message.session_id, text)


if __name__ == "__main__":
    snips_config = toml.load('/etc/snips.toml')
    if 'mqtt' in snips_config['snips-common'].keys():
        MQTT_BROKER_ADDRESS = snips_config['snips-common']['mqtt']
    if 'mqtt_username' in snips_config['snips-common'].keys():
        MQTT_USERNAME = snips_config['snips-common']['mqtt_username']
    if 'mqtt_password' in snips_config['snips-common'].keys():
        MQTT_PASSWORD = snips_config['snips-common']['mqtt_password']

    with Hermes(MQTT_BROKER_ADDRESS) as h:
        h.subscribe_intent(add_prefix("getAddition"), msg_addition)
        h.subscribe_intent(add_prefix("getSubtraktion"), msg_subtraktion)
        h.subscribe_intent(add_prefix("getMultiplikation"), msg_multiplikation)
        h.subscribe_intent(add_prefix("getDivision"), msg_division)
        h.subscribe_intent(add_prefix("getWurzel"), msg_wurzel)
        h.subscribe_intent(add_prefix("getZufall"), msg_zufall)
        h.start()
Ejemplo n.º 2
0
 def start(self):
     with Hermes(mqtt_options=MqttOptions(broker_address=self.mqtt_host,
                                          username=self.mqtt_user,
                                          password=self.mqtt_pass)) as h:
         h.subscribe_intents(self.on_intent).start()
Ejemplo n.º 3
0
def main():
    with Hermes("localhost:1883") as h:
        h.subscribe_intent(INTENT_HOW_ARE_YOU, how_are_you_callback) \
         .start()
Ejemplo n.º 4
0
 def start_blocking(self):
     with Hermes(MQTT_ADDR) as h:
         h.subscribe_intent('pbillerot:Addition', self.addition_callback)\
         .loop_forever()
Ejemplo n.º 5
0
 def start_blocking(self):
     with Hermes("localhost:1883") as h:
         h.subscribe_intents(self.master_intent_callback).start()
 def start_blocking(self, run_event):
     while run_event.is_set():
         with Hermes(MQTT_ADDR) as h:
             h.subscribe_session_started(self.action_session_started) \
                 .subscribe_session_ended(self.action_session_ended) \
                 .start()
from application.IntentCaller import IntentCaller
from application.config.ConfigurationKey import ConfigurationKey
from application.config.ConfigurationTools import SnipsConfigParser
from application.pokeapi.PokeApi import PokeApi

CONFIG_INI_FILE = "config.ini"

MQTT_DEFAULT_ADDRESS = "localhost"
MQTT_DEFAULT_PORT = "1883"

if __name__ == "__main__":

    try:
        configuration = SnipsConfigParser.read_configuration_file(
            CONFIG_INI_FILE)
    except:
        configuration = None

    mqtt_address = "{}:{}".format(
        configuration.get(ConfigurationKey.MQTT.value).get(
            ConfigurationKey.MQTT_ADDRESS.value, MQTT_DEFAULT_ADDRESS),
        str(
            configuration.get(ConfigurationKey.MQTT.value).get(
                ConfigurationKey.MQTT_PORT.value)), MQTT_DEFAULT_PORT)

    with Hermes(mqtt_address) as hermes:
        hermes.subscribe_intents(
            IntentCaller(
                PokeApi(configuration)).master_intent_callback).start()
Ejemplo n.º 8
0
def test_configure_dialogue(mqtt_server):
    from hermes_python.ontology.dialogue import DialogueConfiguration
    conf = DialogueConfiguration()

    with Hermes("localhost:1883") as h:
        h.configure_dialogue(conf)
Ejemplo n.º 9
0
         hermes.skill.volume_down(volume_lower)
     else:
         hermes.skill.volume_down(None)
 
 def volumeUp_callback(hermes, intentMessage):
     hermes.skill.set_to_previous_volume()
     if len(intentMessage.slots.volume_lower):
         volume_lower = intentMessage.slots.volume_lower.first().value
         hermes.skill.volume_down(volume_lower)
     else:
         hermes.skill.volume_down(None)
 
 
 if __name__ == "__main__":
 
     with Hermes(HERMES_HOST) as h:
 
         h.skill = SnipsMopidy(MOPIDY_HOST)
 
         h\
             .subscribe_intent("volumeUp", volumeUp_callback) \
             .subscribe_intent("previousSong", previousSong_callback) \
             .subscribe_intent("playSong", playSong_callback) \
             .subscribe_intent("playArtist", playArtist_callback) \
             .subscribe_intent("getInfos", getInfos_callback) \
             .subscribe_intent("speakerInterrupt", speakerInterrupt_callback) \
             .subscribe_intent("resumeMusic", resumeMusic_callback) \
             .subscribe_intent("addSong", addSong_callback) \
             .subscribe_intent("nextSong", nextSong_callback) \
             .subscribe_intent("radioOn", radioOn_callback) \
             .subscribe_intent("playAlbum", playAlbum_callback) \
Ejemplo n.º 10
0
def test_publish_start_session_notification(mqtt_server):
    with Hermes("localhost:1883") as h:
        h.publish_start_session_notification("site_id", "initialization", None)
        h.publish_start_session_notification("site_id", "initialization", "custom_data")
        h.publish_start_session_notification("site_id", "initialization", "custom_data", "text")
Ejemplo n.º 11
0
def test_publish_start_session_action(mqtt_server):
    with Hermes("localhost:1883") as h:
        h.publish_start_session_action(None, None, [], False, False, None)
        h.publish_start_session_action("site_id", None, [], False, False, None)
        h.publish_start_session_action("site_id", "text", [], False, False, None)
        h.publish_start_session_action("site_id", "text", [], False, False, "custom_data")
Ejemplo n.º 12
0
def test_publish_end_session(mqtt_server):
    with Hermes("localhost:1883") as h:
        h.publish_end_session("session_id", "goodbye")
Ejemplo n.º 13
0
from hermes_python.hermes import Hermes, MqttOptions

MQTT_ADDR = " localhost:1883"
with Hermes(mqtt_options=MqttOptions()) as h:
    h.publish_start_session_notification(None, "Super hacker pro", None)
Ejemplo n.º 14
0
#!/usr/bin/env python2
from hermes_python.hermes import Hermes


def intent_received(hermes, intent_message):
    print('Intent {}'.format(intent_message.intent.intent_name))
    for (slot_value, slot) in intent_message.slots.items():
        print('Slot {} -> \n\tRaw: {} \tValue: {}'.format(
            slot_value, slot[0].raw_value, slot[0].slot_value.value.value))

    if intent_message.intent.intent_name == 'normanchan888:book_flight':
        if intent_message.slots.departcity:
            depart_city = intent_message.slots.departcity.first().value
        if intent_message.slots.arrivecity:
            arrive_city = intent_message.slots.arrivecity.first().value
        hermes.publish_continue_session(intent_message.session_id,
                                        "which airport",
                                        ["normanchan888:airport_selection"])

    elif intent_message.intent.intent_name == 'normanchan888:airport_selection':
        if intent_message.slots.airport:
            airport = intent_message.slots.airport.first().value
        hermes.publish_end_session(intent_message.session_id, "Bye")


with Hermes("10.81.0.223:1883") as h:
    h.subscribe_intents(intent_received).start()
Ejemplo n.º 15
0
    globalvalue = "eureka"
    INTENT_FILTER = ["multip:test_end_session"]
    coming_intent = intent_message.intent.intent_name

    if coming_intent == "multip:test_code":
        sentence = "start session"
        hermes.publish_continue_session(intent_message.session_id, sentence,
                                        INTENT_FILTER)
    if coming_intent == "multip:test_end_session":
        sentence = "end session"
        hermes.publish_end_session(intent_message.session_id, sentence)
    #sentence = "continue session"
    #hermes.publish_continue_session(intent_message.session_id, sentence, INTENT_FILTER)
    #print('Intent {}'.format(intent_message.intent))

    #for (slot_value, slot) in intent_message.slots.items():
    #    print('Slot {} -> \n\tRaw: {} \tValue: {}'.format(slot_value, slot[0].raw_value, slot[0].slot_value.value.value))

    #hermes.publish_end_session(intent_message.session_id, 'Ending session')
    #print("*** EUREKA ***")
    #hermes.publish_end_session(intent_message.session_id, sentence)


def test_end_session(hermes, intent_message):
    hermes.publish_end_session(intent_message.session_id, globalvalue)


with Hermes('raspberrypi.local:1883') as h:
    h.subscribe_intents(test_code).start()
    #h.subscribe_intent("multip:test_code", test_code).start()
Ejemplo n.º 16
0
        print(
            "Session_state is None ==> intent triggered outside of dialog session"
        )
        return session_state, "", False

    answer = get_intent_slots(intent_message)
    # We just try keep listening to the user until we get an answer
    if len(answer) == 0:
        return session_state, "Możesz powtórzyć?", True

    session_state["slot"] = answer
    return session_state, "", False


def session_started(hermes, session_ended_message):
    return


def session_ended(hermes, session_ended_message):
    return


with Hermes(mqtt_options=sc.get_hermes_mqtt_options()) as h:
    h.subscribe_intents(start_session)
    for a in INTENT_FILTER_GET_ANSWER:
        h.subscribe_intent(a, user_gives_answer)
    h.subscribe_intent(INTENT_INTERRUPT, user_quits) \
        .subscribe_session_ended(session_ended) \
        .subscribe_session_started(session_started) \
        .start()
Ejemplo n.º 17
0
class Assistant:
    def __init__(self):
        self.intents = {}
        self.last_message = None

        snips_config = toml.load('/etc/snips.toml')

        mqtt_username = None
        mqtt_password = None
        mqtt_broker_address = "localhost:1883"

        if 'mqtt' in snips_config['snips-common'].keys():
            mqtt_broker_address = snips_config['snips-common']['mqtt']
        if 'mqtt_username' in snips_config['snips-common'].keys():
            mqtt_username = snips_config['snips-common']['mqtt_username']
        if 'mqtt_password' in snips_config['snips-common'].keys():
            mqtt_password = snips_config['snips-common']['mqtt_password']

        mqtt_opts = MqttOptions(username=mqtt_username,
                                password=mqtt_password,
                                broker_address=mqtt_broker_address)

        self.hermes = Hermes(mqtt_options=mqtt_opts)
        self.conf = read_configuration_file()

        if 'OPENHAB_SERVER_URL' in environ:
            self.conf['secret']['openhab_server_url'] = environ.get(
                'OPENHAB_SERVER_URL')
        if 'OPENHAB_DEFAULT_ROOM' in environ:
            self.conf['secret']['default_room'] = environ.get(
                'OPENHAB_DEFAULT_ROOM')
        if 'OPENHAB_SITEID2ROOM_MAPPING' in environ:
            self.conf['secret']['siteid2room_mapping'] = environ.get(
                'OPENHAB_SITEID2ROOM_MAPPING')
        if 'OPENHAB_SOUND_FEEDBACK' in environ:
            self.conf['secret']['sound_feedback'] = environ.get(
                'OPENHAB_SOUND_FEEDBACK')

        self.sound_feedback = self.conf['secret']["sound_feedback"] == "on"

    def add_callback(self, intent_name, callback):
        self.intents[intent_name] = callback

    def register_sound(self, sound_name, sound_data):
        self.hermes.register_sound(RegisterSoundMessage(
            sound_name, sound_data))

    def callback(self, intent_message):
        intent_name = intent_message.intent.intent_name

        if intent_name in self.intents:
            success, message = self.intents[intent_name](self, intent_message,
                                                         self.conf)

            self.last_message = message

            if self.sound_feedback:
                if success is None:
                    self.hermes.publish_end_session(intent_message.session_id,
                                                    message)
                elif success:
                    self.hermes.publish_end_session(intent_message.session_id,
                                                    "[[sound:success]]")
                else:
                    # TODO: negative sound
                    self.hermes.publish_end_session(intent_message.session_id,
                                                    message)
            else:
                self.hermes.publish_end_session(intent_message.session_id,
                                                message)

    def inject(self, entities):
        self.hermes.request_injection(
            InjectionRequestMessage([AddFromVanillaInjectionRequest(entities)
                                     ]))

    def __enter__(self):
        self.hermes.connect()
        return self

    def __exit__(self, exception_type, exception_val, trace):
        if not exception_type:
            self.hermes.disconnect()
            return self
        return False

    def start(self):
        def helper_callback(hermes, intent_message):
            self.callback(intent_message)

        with open(path.join(path.dirname(__file__), 'success.wav'), 'rb') as f:
            self.register_sound("success", bytearray(f.read()))

        self.hermes.subscribe_intents(helper_callback)
        self.hermes.start()
Ejemplo n.º 18
0
 def start_blocking(self):
     with Hermes(self.mqtt_addr) as h:
         h.subscribe_intents(self.master_intent_callback).start()
Ejemplo n.º 19
0
 def start_blocking(self):
     with Hermes(MQTT_ADDR) as h:
         h.subscribe_intent('harthur:ComputeSum', self.compute_sum_callback)\
         .subscribe_intent('intent_2', self.intent_2_callback)\
         .loop_forever()
Ejemplo n.º 20
0
                    'Evento no repetitivo: recordando tomar ' + e.med + ' a ' +
                    e.usuario)
    else:
        print("El evento ya ha sido confirmado")
        if (e.rep):
            Snips.planificador1.remove_job(
                'Evento repetitivo: recordando tomar ' + e.med + ' a ' +
                e.usuario + ' cada ' + e.cuando)
        else:
            Snips.planificador1.remove_job(
                'Evento no repetitivo: recordando tomar ' + e.med + ' a ' +
                e.usuario)


if __name__ == '__main__':
    opciones_MQTT = MqttOptions()
    global_variables()
    HiloBoton = boton()
    HiloBoton.start()

    with Hermes(mqtt_options=opciones_MQTT) as h:
        h\
        .subscribe_intent("caguilary:Anadir_Evento", subscribir_Anadir_llamada) \
        .subscribe_intent("caguilary:Cambiar_Usuario", subscribir_Cambiar_usuario_llamada) \
        .subscribe_intent("caguilary:Confirmar", subscribir_Confirmar_llamada) \
        .subscribe_intent("caguilary:Negar", subscribir_Negar_llamada) \
        .subscribe_intent("caguilary:Anadir_usuario", subscribir_Anadir_usuario_llamada) \
        .subscribe_intent("caguilary:usuario_Activo", subscribir_Comprobar_usuario_llamada) \
        .subscribe_intent("caguilary:Borrar_Evento", subscribir_Borrar_llamada) \
        .start()
Ejemplo n.º 21
0
 def start_blocking(self):
     with Hermes(MQTT_ADDR) as h:
         h.subscribe_intents(self.FreeboxTelecommande_callback).start()
Ejemplo n.º 22
0
 def __init__(self):
     with Hermes(mqtt_options=MqttOptions()) as h:
         threading.Thread.__init__(self)
            result_sentence = "Wir sind im Jahr {year}".format(year=year)
        elif datetype == 'weeknumber' or 'kw' in datetype:
            weeknumber = datetime.datetime.now().isocalendar()[1]
            result_sentence = "Wir haben gerade die Kalenderwoche {weeknumber}".format(weeknumber=weeknumber)
        elif datetype == 'minute':
            minutes = datetime.datetime.now().minute
            result_sentence = "Wir haben die Minute {minutes}".format(minutes=minutes)
        elif datetype == 'hour':
            hours = datetime.datetime.now().hour
            result_sentence = "Wir haben gerade die Stunde {hours}".format(hours=hours)
        elif datetype == 'month':
            month = datetime.datetime.now().month
            month_list = ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','Novenber','Dezember']
            result_sentence = "Wir haben den Monat {month}".format(month=month_list[month - 1])
        current_session_id = intent_message.session_id
        hermes.publish_end_session(current_session_id, result_sentence)


if __name__ == "__main__":
    snips_config = toml.load('/etc/snips.toml')
    if 'mqtt' in snips_config['snips-common'].keys():
        MQTT_BROKER_ADDRESS = snips_config['snips-common']['mqtt']
    if 'mqtt_username' in snips_config['snips-common'].keys():
        MQTT_USERNAME = snips_config['snips-common']['mqtt_username']
    if 'mqtt_password' in snips_config['snips-common'].keys():
        MQTT_PASSWORD = snips_config['snips-common']['mqtt_password']

    mqtt_opts = MqttOptions(username=MQTT_USERNAME, password=MQTT_PASSWORD, broker_address=MQTT_BROKER_ADDRESS)
    with Hermes(mqtt_options=mqtt_opts) as h:
        h.subscribe_intents(subscribe_intent_callback).start()
Ejemplo n.º 24
0
def say(MensajeIntent, texto):
    with Hermes(mqtt_options=MqttOptions()) as clienteMQTT:
        clienteMQTT.publish_start_session_notification(MensajeIntent, texto,
                                                       None)
Ejemplo n.º 25
0
 def start_blocking(self):
     with Hermes(MQTT_ADDR) as h:
         h.subscribe_intents(self.master_intent_callback).start()
Ejemplo n.º 26
0
                job = 'recordando tomar ' + event.med + ' a ' + event.user
                if (self.exist_Job(job)):
                    Snips.scheduler1.remove_job(job)
                    say('default', msg)

            time.sleep(1)


if __name__ == '__main__':
    mqtt_opts = MqttOptions()
    idFile = 0
    global_variables()
    thread1 = button()
    thread1.start()

    with Hermes(mqtt_options=mqtt_opts) as h, Hermes(
            mqtt_options=mqtt_opts) as mqttClient, open(
                '/home/pi/prueba.csv', 'a+') as csvfile:
        fieldnames = [
            'timestamp', 'id', 'Tipo', '¿Repetitivo?', 'Recordatorio',
            'Medicamento', 'Nombre_Usuario', 'Modo de aceptar', 'Error_output'
        ]
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        writer.writeheader()
        h\
        .subscribe_intent("caguilary:Anadir", subscribe_Anadir_callback) \
        .subscribe_intent("caguilary:user", subscribe_user_callback) \
        .subscribe_intent("caguilary:Confirmar", subscribe_confirmar_callback) \
        .subscribe_intent("caguilary:Negar", subscribe_Negar_callback) \
        .subscribe_intent("caguilary:Anadir_usuario", subscribe_AnadirUsuario_callback) \
        .subscribe_intent("caguilary:userActivo", subscribe_CheckUsuario_callback) \
Ejemplo n.º 27
0
                intent_message.session_id,
                sentence + " ¿Quieres que lea más titulares?",
                ['juancarlos:Siguiente', 'juancarlos:Cancelar'],
                custom_data=json.dumps({
                    'i': i,
                    'titulares': titulares,
                    'descripcion': descripcion
                }))
    else:
        hermes.publish_end_session(intent_message.session_id,
                                   'Esas son todas las noticias')


def intent_stop(hermes, intent_message):
    return hermes.publish_end_session(intent_message.session_id, '')


with Hermes(MQTT_ADDR) as h:
    #dialogue_conf = \
    #    DialogueConfiguration().enable_intents(['juancarlos:Cancelar',
    #        'juancarlos:Siguiente'])

    #h.configure_dialogue(dialogue_conf)

    h.subscribe_intent('juancarlos:DiTitulares',
                       intent_received).subscribe_intent(
                           'juancarlos:Cancelar',
                           intent_stop).subscribe_intent(
                               'juancarlos:Siguiente',
                               intent_continuar).start()
Ejemplo n.º 28
0
#!/usr/bin/env python2
from hermes_python.hermes import Hermes
from hermes_python.ontology import *
​
def intent_received(hermes, intent_message):
    result_sentence = "hello in this lonely dog"
    hermes.publish_end_session(intent_message.session_id, result_sentence)

with Hermes('localhost:1883') as h:
    h.subscribe_intents(intent_received).start()
Ejemplo n.º 29
0
    action_wrapper(hermes, intentMessage, conf)


def action_wrapper(hermes, intentMessage, conf):
    """ Write the body of the function that will be executed once the intent is recognized. 
    In your scope, you have the following objects : 
    - intentMessage : an object that represents the recognized intent
    - hermes : an object with methods to communicate with the MQTT bus following the hermes protocol. 
    - conf : a dictionary that holds the skills parameters you defined 
    Refer to the documentation for further details. 
    """
    first = int(intentMessage.slots.firstTerm.first().value)
    second = int(intentMessage.slots.secondTerm.first().value)
    if second != 0:
        calc = first / second
        if str(calc)[-2:] == ".0":
            calc = int(calc)
        result_sentence = " La division de {} par {} égale {} .".format(
            first, second, calc)
    else:
        result_sentence = "La division par zéro est impossible."

    current_session_id = intentMessage.session_id
    hermes.publish_end_session(current_session_id, result_sentence)


if __name__ == "__main__":
    with Hermes("localhost:1883") as h:
        h.subscribe_intent("Zackfun:getDivision", subscribe_intent_callback) \
.start()
Ejemplo n.º 30
0
 def start_blocking(self):
     with Hermes(MQTT_ADDR) as h:
         h.subscribe_intents(self.intent_1_callback) \
         .loop_forever()