def start_getHistory(hermes, intent_message): """ callback function for the intent "getHistory", gets called when intent is detected Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received """ #log the input and the received intent start_logging() log_asr_input(intent_message.input) log_received_intent(intent_message) #get history of medications as a dict [non_corrects, history] = get_history() #choose parts of the TTS message randomly final_message = get_random_answer(intent_name='getHistory', key_name='info') + ' ' history_msg = get_random_answer(intent_name='getHistory', key_name='nonCorrects') #create complete TTS message based on received history final_message = final_message + history_msg.format(non_corrects) print(final_message) #terminate the session by sending message to tts log_tts_output(final_message) hermes.publish_end_session(intent_message.session_id, final_message)
def start_infoRefilling(hermes, intent_message): """ Callback function for the intent "infoRefilling", gets called when intent is detected Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received """ #log the input and the received intent start_logging() log_asr_input(intent_message.input) log_received_intent(intent_message) #get the stock information from the controls stock_info = get_stock_info() #get a random answer for constructing the final message to the TTS info_message = get_random_answer( 'infoRefilling', 'info') + 'Folgende Magazine sind noch voll: ' single_message_stock = get_random_answer('infoRefilling', 'stock_info') single_message_empty = get_random_answer('infoRefilling', 'empty') #extract the information from stock_info and form the TTS message message_to_tts = '' for magazine_nr in range(0, len(stock_info)): if stock_info[magazine_nr] in [25, 50, 75]: #magazines that are neither completely empty nor completely full message_to_tts += single_message_stock.format( dic_weekdays[magazine_nr], stock_info[magazine_nr]) elif stock_info[magazine_nr] == 100: #magazines that are completely empty message_to_tts += single_message_empty.format( dic_weekdays[magazine_nr]) else: #magazines that are completely full info_message += dic_weekdays[magazine_nr] + ', ' message_to_tts = info_message[:-2] + '. ' + message_to_tts # terminate the session by sending message to tts log_tts_output(message_to_tts) hermes.publish_end_session(intent_message.session_id, message_to_tts)
def start_confirmation(self): """ Handles the start of the alarm confirmation process via VoiceControl by starting with a TTS message Returns ------- confirmation_started : bool True if voice_control is active and TTS message was sent """ confirmation_started = False if self.parent.is_active: # only start speech synthesis if voice control is active log_event('Starting confirmation... ') INTENT_FILTER_CONFIRMTAKING = [ "carlasailer:confirmTaking", "carlasailer:quitDialog" ] self.parent.send_message_to_TTS(message=get_random_answer( intent_name='confirmTaking', key_name='start')) #, #intent_filter=INTENT_FILTER_CONFIRMTAKING) confirmation_started = True #TODO: delete next line confirmation_started = True return confirmation_started
def continue_contact(hermes, intent_message, names=None): """ No specific person was found for 'contact', send a message to the TTS Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received names : list possible doctors if any where found """ #log the input and the received intent start_logging() log_asr_input(intent_message.input) log_received_intent(intent_message) if names is not None: #user tried to call a doctor, name was not given #suggest possible doctors to be called message_to_tts = get_random_answer('contact', 'suggestDoc') for name in names: message_to_tts += name + ', ' message_to_tts = message_to_tts[:-2] + '. ' + get_random_answer( 'contact', 'notSuccess') else: #no success in extracting person message_to_tts = "Leider konnte ich keine Person ermitteln. " + get_random_answer( 'contact', 'notSuccess') #continue the session but only allow intent contact and quitDialog INTENT_FILTER_CONTACT = ["carlasailer:contact", "carlasailer:quitDialog"] #log the tts output log_tts_output(message_to_tts) hermes.publish_continue_session(intent_message.session_id, message_to_tts, INTENT_FILTER_CONTACT) log_event(' contact: could not be extracted')
def create_msg_for_one_day(alarms): """ Sets up the message for one required day Parameters ---------- alarms : list alarms from the database for the required day """ alarm_day = alarms[0][0] msg = get_random_answer('infoMedication', 'days').format(alarm_day) + ' ' for item in alarms: msg += item[1] + ', ' return msg[:-2], alarm_day
def start_adaptVolume(hermes, intent_message): """ Callback function for the intent "adaptVolume", gets called when intent is detected Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received """ #log the input and the received intent start_logging() log_asr_input(intent_message.input) log_received_intent(intent_message) #extract the desired volume value from the intent message and adapt the volume volume_value = get_required_volume(intent_message.slots) if volume_value is None: #volume value not valid #get a randomly chosen answer from a list of possible answers message_to_tts = get_random_answer('adaptVolume', 'error') else: #volume value is valid change_volume(volume_value) #log the event of changing the volume log_msg = ' changed output volume to: {} '.format(str(volume_value)) log_event(log_msg) #get a randomly chosen answer from a list of possible answers message_to_tts = get_random_answer('adaptVolume', 'adapt') #end by sending a message to the tts and logging log_tts_output(message_to_tts) hermes.publish_end_session(intent_message.session_id, message_to_tts)
def start_repeat(hermes, intent_message): """ Callback function for the intent "repeat", gets called when intent is detected Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received """ #extracting relevant information from the slot values if intent_message.slots.you_me.all() is not None: direction = intent_message.slots.you_me.first().value if direction == 'du': #user wants to know last tts output log = get_last_log_entry(keyword='output') message_to_tts = get_random_answer('repeat', 'last_tts').format(log) elif direction == 'ich': #user wants to know last asr input log = get_last_log_entry(keyword='input') message_to_tts = get_random_answer('repeat', 'last_asr').format(log) else: #error occured, default: repeat last tts log = get_last_log_entry(keyword='output') message_to_tts = get_random_answer('repeat', 'last_tts').format(log) #end the session by sending the message to the tts log_tts_output(message_to_tts) hermes.publish_end_session(intent_message.session_id, message_to_tts)
def continue_durationMobilemode(hermes, intent_message): """ Callback function for the intent "durationMobilemode", gets called when intent is detected Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received """ #log the input and the received intent start_logging() log_asr_input(intent_message.input) log_received_intent(intent_message) #get required days based on slot values in intent message required_days = get_required_days(intent_message.slots) #convert numbers to weekdays and format for output message required_days_str = '' if required_days is not None: for key in required_days: required_days_str += dic_weekdays.get(key) + ', ' #no action in control unit! #log log_msg = ' started mobile dispenser: {}'.format( required_days_str[:-2]) log_event(log_msg) #get a randomly chosen answer from a list of possible answers message_to_tts = get_random_answer('durationMobilemode').format( required_days_str[:-2]) log_tts_output(message_to_tts) else: #error occurred during extraction of required days message_to_tts = 'Mobilmodus konnte nicht gestartet werden. Bitte erneut versuchen.' #end the session by sending the message to the tts hermes.publish_end_session(intent_message.session_id, message_to_tts)
def end_contact(hermes, intent_message, person): """ Person (emergency contact or doctor) could be extracted, send a message to the TTS Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received person : string name of the person to be called """ # terminate the session by sending message to tts # get a randomly chosen answer from a list of possible answers message_to_tts = get_random_answer('contact', 'call').format(person) #log the tts output log_tts_output(message_to_tts) hermes.publish_end_session(intent_message.session_id, message_to_tts) log_event(' contacted: {}'.format(person))
def start_confirmTaking(hermes, intent_message): """ Callback function for the intent "confirmTaking", gets called when intent is detected Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received """ #log the input and the received intent start_logging() log_asr_input(intent_message.input) log_received_intent(intent_message) #send successful alarm confirmation to controls communicator set_alarm_confirmed_by_voice(True) #get a randomly chosen answer from a list of possible answers message_to_tts = get_random_answer('confirmTaking', 'confirm') log_tts_output(message_to_tts) hermes.publish_end_session(intent_message.session_id, message_to_tts)
def start_startMobilemode(hermes, intent_message): """ Callback function for the intent "startMobilemode", gets called when intent is detected Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received """ #log the input and the received intent start_logging() log_asr_input(intent_message.input) log_received_intent(intent_message) #continue the session by sending a message to the tts, allowing only two intents INTENT_FILTER_MOBILEMODE = ["carlasailer:durationMobilemode", "carlasailer:quitDialog"] message_to_tts = get_random_answer('startMobilemode') log_tts_output(message_to_tts) hermes.publish_continue_session(intent_message.session_id, message_to_tts, INTENT_FILTER_MOBILEMODE)
def start_infoMedication(hermes, intent_message): """ Callback function for the intent "infoMedication", gets called when intent is detected Parameters ---------- hermes : <Hermes instance> current instance of the hermes broker intent_message : <intent_message by Snips> message created when intent was received """ #log the input and the received intent start_logging() log_asr_input(intent_message.input) log_received_intent(intent_message) #extract the days to be informed about from slot values global alarm_day required_days = get_required_days(intent_message.slots) print(required_days) if required_days is None: required_days = [] #get day and time of next alarm according to alarm settings if required_days == 8: #info about next alarm [alarm_day, alarm_time] = get_alarm_info() message_to_tts = get_random_answer('infoMedication', 'next').format( alarm_day, alarm_time) elif required_days != 8 and len(required_days) == 1: #info about alarms for one specific weekday alarms = get_alarm_info(required_days) print(alarms) if alarms == []: #no alarms found for that day alarm_day = None message_to_tts = 'Keine Alarme für {} hinterlegt.'.format( dic_weekdays[required_days[0]]) else: [message_to_tts, alarm_day] = create_msg_for_one_day(alarms) else: #info about alarms for multiple days total_alarms = [] message_to_tts = '' for day in required_days: alarms = get_alarm_info([day]) if alarms != []: [day_msg, d] = create_msg_for_one_day(alarms) alarm_day = required_days total_alarms.append(alarms) else: day_msg = 'Für {} sind keine Alarme hinterlegt. '.format( dic_weekdays[day]) message_to_tts += day_msg alarm_day = None #ToDo: multiple days! pass #log if alarm_day is not None: log_msg = ' info about next alarm for: {}'.format(alarm_day) else: log_msg = ' info about next alarm for: ' log_event(log_msg) #end the session by sending message to tts log_tts_output(message_to_tts) hermes.publish_end_session(intent_message.session_id, message_to_tts)