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 receive_stop_mobilemode(self, MagazineList): """ Informs the user about the end of mobilemode, gets called with MagazineList from the Controls and depending on the state of it, sends message to TTS Parameters ---------- MagazineList : dict input data of type MagazineList as used by the Controls unit of the stationary dispenser 'Magazine': 0 if error, 1 if at stationary, 2 if at mobile dispenser e.g. MAGAZINE_LIST = {} MAGAZINE_LIST[0] = {'Day': 'Mon', 'Magazine': 1, 'No': 0, 'h': 0, 'm': 0, 'sT': 0, 'mo': 0, 'mi': 0, 'a': 0, 'ni': 0, 'empty': 0, 'AlreadyDetected': 'no'} """ #if voice control is active: if self.parent.is_active: #extract the missing magazines from MagazineList: missing_days = [ nr for nr in range(0, len(MagazineList)) if MagazineList[nr]['Magazine'] == AT_MOBILE ] if len(missing_days) != 0: #if magazines are missing, tell the user to put them back in print('Missing Magazines: ', missing_days) log_event('[end mobileMode] Missing magazines: {}'.format( missing_days)) #convert numbers to weekdays and format for output message missing_days_str = '' if missing_days is not None: for key in missing_days: missing_days_str += dic_weekdays.get(key) + ', ' self.parent.send_message_to_TTS( 'Mobilmodus noch nicht beendet. Bitte folgende Magazine einstecken: {}.' .format(missing_days_str)) else: #if no magazines are missing, mobilemode can be stopped self.parent.send_message_to_TTS('Mobilmodus wurde beendet.') log_event( '[end mobileMode] No missing magazines. Switch to stationary mode.' )
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 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 start_quitDialog(hermes, intent_message): """ Callback function for the intent "quitDialog", 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) #log the intent of the user log_msg = ' User quits.' log_event(log_msg) #end the session with sending an empty message to the tts message_to_tts = ' ' hermes.publish_end_session(intent_message.session_id, message_to_tts)
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_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)