def _get_ssl_results(start_time, finish_time, path): start_time_string = ros_time_to_sqlite_time(start_time) finish_time_string = ros_time_to_sqlite_time(finish_time) # query all elements of type in question sql_query = """ SELECT ssl.ssl_key, time_from, time_to, sourceId, angleVertical, angleHorizontal FROM ssl LEFT JOIN ssl_combo ON ssl.ssl_key = ssl_combo.ssl_key LEFT JOIN ssl_dir ON ssl_dir.dir_key = ssl_combo.dir_key WHERE time_from BETWEEN "{time_from}" AND "{time_to}" OR time_to BETWEEN "{time_from}" AND "{time_to}"; """.format(time_from=start_time_string, time_to=finish_time_string) connection = sqlite3.connect(path) cursor = connection.cursor() cursor.execute(sql_query) result_raw = cursor.fetchall() connection.commit() connection.close() # edge case: no entry yet if len(result_raw) == 1 and not [ x for x in result_raw[0] if x is not None ]: return [] # recreate ros type instances ssl_results = {} for entry in result_raw: # add sslInfo if key not yet in dict ssl_key = entry[0] if ssl_key not in ssl_results: ssl_results[ssl_key] = SSLInfo() time_stamp = RecordingTimeStamps() time_stamp.start = sqlite_time_to_ros_time(entry[1]) time_stamp.finish = sqlite_time_to_ros_time(entry[2]) ssl_results[ssl_key].duration = time_stamp ssl_results[ssl_key].directions = [] # add sslDir info to sslInfo sslDir = SSLDir() sslDir.sourceId = entry[3] sslDir.angleVertical = entry[4] sslDir.angleHorizontal = entry[5] ssl_results[ssl_key].directions.append(sslDir) return [ssl_results[x] for x in ssl_results]
def _get_speech_rec_results(start_time, finish_time, path): start_time_string = ros_time_to_sqlite_time(start_time) finish_time_string = ros_time_to_sqlite_time(finish_time) # query all elements of type in question sql_query = """ SELECT speech.speech_key, time_from, time_to, recognizedSpeech, probability FROM speech LEFT JOIN speech_combo ON speech.speech_key = speech_combo.speech_key LEFT JOIN speech_hypo ON speech_hypo.hypo_key = speech_combo.hypo_key WHERE time_from BETWEEN "{time_from}" AND "{time_to}" OR time_to BETWEEN "{time_from}" AND "{time_to}"; """.format(time_from=start_time_string, time_to=finish_time_string) connection = sqlite3.connect(path) cursor = connection.cursor() cursor.execute(sql_query) result_raw = cursor.fetchall() connection.commit() connection.close() # edge case: no entry yet if len(result_raw) == 1 and not [ x for x in result_raw[0] if x is not None ]: return [] # recreate ros type instances speech_results = {} for entry in result_raw: # add SpeechInfo if key not yet in dict speech_key = entry[0] if speech_key not in speech_results: speech_results[speech_key] = SpeechInfo() time_stamp = RecordingTimeStamps() time_stamp.start = sqlite_time_to_ros_time(entry[1]) time_stamp.finish = sqlite_time_to_ros_time(entry[2]) speech_results[speech_key].duration = time_stamp speech_results[speech_key].hypotheses = [] # add speech hypothesis info to SpeechInfo speech_hyp = SpeechHypothesis() speech_hyp.recognizedSpeech = entry[3] speech_hyp.probability = entry[4] speech_results[speech_key].hypotheses.append(speech_hyp) return [speech_results[x] for x in speech_results]
def play(self): for block in soundfile.blocks(self.file, blocksize=self.framesize): if not self.start_time: self.start_time = rospy.Time.now() end_time = self.start_time + self.frametime timestamps = RecordingTimeStamps() timestamps.start = self.start_time timestamps.finish = end_time rospy.sleep(end_time - rospy.Time.now()) self.esiaf_handler.publish(self.topic, block, msg_to_string(timestamps)) self.start_time = end_time
def input_callback(audio, timeStamps): # deserialize inputs _recording_timestamps = RecordingTimeStamps() msg_from_string(_recording_timestamps, timeStamps) # call dao wrapper doa = wrapper.process_audio(audio.transpose()) rospy.loginfo('DOA from ' + str(_recording_timestamps.finish.secs) + ': ' + str(doa)) # assemble output doa_esiaf = SSLDir() doa_esiaf.angleHorizontal = doa doa_esiaf.angleVertical = 0.0 doa_esiaf.sourceId = 'no tracking' doas = [msg_to_string(doa_esiaf)] handler.set_ssl_dirs(data['esiaf_output_topic'], doas) # publish output handler.publish(data['esiaf_output_topic'], audio, timeStamps) # assemble output output = SSLInfo() output.duration = _recording_timestamps output.directions = [doa_esiaf] ssl_publisher.publish(output)
def _get_basic_results(type_name, start_time, finish_time, path): if type_name not in [ DESIGNATION_DICT[x][0] for x in DESIGNATION_DICT if DESIGNATION_DICT[x][0] not in ['VAD', 'SSL', 'SpeechRec'] ]: raise Exception('Type "' + type_name + '" not supported to retrieve!') start_time_string = ros_time_to_sqlite_time(start_time) finish_time_string = ros_time_to_sqlite_time(finish_time) # query all elements of type in question sql_query = """ SELECT {type}, probability, time_from, time_to FROM {type} WHERE time_from BETWEEN "{time_from}" AND "{time_to}" OR time_to BETWEEN "{time_from}" AND "{time_to}"; """.format(type=type_name, time_from=start_time_string, time_to=finish_time_string) connection = sqlite3.connect(path) cursor = connection.cursor() cursor.execute(sql_query) result_raw = cursor.fetchall() connection.commit() connection.close() # get class of type type_class = None for designation in DESIGNATION_DICT: if DESIGNATION_DICT[designation][0] == type_name: type_class = DESIGNATION_DICT[designation][1] # edge case: no entry yet if len(result_raw) == 1 and not [ x for x in result_raw[0] if x is not None ]: return [] # iterate over all retrieved instances ros_type_list = [] for instance in result_raw: # create new type and fill it with raw result type_instance = type_class() setattr(type_instance, type_name, instance[0]) type_instance.probability = instance[1] type_instance.duration = RecordingTimeStamps() type_instance.duration.start = sqlite_time_to_ros_time(instance[2]) type_instance.duration.finish = sqlite_time_to_ros_time(instance[3]) ros_type_list.append(type_instance) return ros_type_list
def add_audio_data(self, audio_data, recording_timestamps): _recording_timestamps = RecordingTimeStamps() msg_from_string(_recording_timestamps, recording_timestamps) rospy.loginfo('got audio!') if not self.start: self.start = _recording_timestamps.start self.decoder.start_utt() self.finish = _recording_timestamps.finish bytearray = audio_data.tobytes() self.decoder.process_raw(bytearray, False, False)
def vad_finished_callback(self): self.decoder.end_utt() result = '' if self.decoder.hyp(): result = self.hypothesis() rospy.loginfo('understood: \'' + str(result) + '\'') hypo = SpeechHypothesis() hypo.recognizedSpeech = result hypo.probability = 1.0 time = RecordingTimeStamps() time.start = self.start time.finish = self.finish speechInfo = SpeechInfo() speechInfo.hypotheses = [hypo] speechInfo.duration = time self.speech_publisher.publish(speechInfo) self.start = None self.finish = None
def input_callback(audio, timeStamps): # deserialize inputs _recording_timestamps = RecordingTimeStamps() msg_from_string(_recording_timestamps, timeStamps) # voice vector call emotion, probability = wrapper.recognize_emotion(audio) # assemble output output = EmotionInfo() output.duration = _recording_timestamps output.emotion = emotion output.probability = probability # publish output emotion_publisher.publish(output) rospy.loginfo('Person is ' + emotion)
def input_callback(audio, timeStamps): # deserialize inputs _recording_timestamps = RecordingTimeStamps() msg_from_string(_recording_timestamps, timeStamps) # gender rec call gender, probability = wrapper.recognize_gender(audio) # assemble output output = GenderInfo() output.duration = _recording_timestamps output.gender = gender output.probability = probability # publish output gender_publisher.publish(output) rospy.loginfo('Person is ' + gender)
def _get_vad_results(start_time, finish_time, path): start_time_string = ros_time_to_sqlite_time(start_time) finish_time_string = ros_time_to_sqlite_time(finish_time) sql_query = """ SELECT probability, time_from, time_to FROM vad WHERE time_from BETWEEN "{time_from}" AND "{time_to}" OR time_to BETWEEN "{time_from}" AND "{time_to}"; """.format(time_from=start_time_string, time_to=finish_time_string) connection = sqlite3.connect(path) cursor = connection.cursor() cursor.execute(sql_query) result_raw = cursor.fetchall() connection.commit() connection.close() # edge case: no entry yet if len(result_raw) == 1 and not [ x for x in result_raw[0] if x is not None ]: return [] # iterate over all retrieved instances ros_type_list = [] for instance in result_raw: # create new type and fill it with raw result type_instance = VADInfo() type_instance.probability = instance[0] type_instance.duration = RecordingTimeStamps() type_instance.duration.start = sqlite_time_to_ros_time(instance[1]) type_instance.duration.finish = sqlite_time_to_ros_time(instance[2]) ros_type_list.append(type_instance) return ros_type_list
dur = rospy.Duration(5) dur2 = integer_to_ros_duration(int(str(dur))) assert dur == dur2 dur3 = rospy.Duration(int(str(1.5 * dur2))) assert type(dur3) == type(dur2) db_path = 'database.db' time_one_org = datetime.datetime(2018, 1, 1, 12, 0, 0, 1) time_two_org = datetime.datetime(2018, 1, 1, 12, 0, 1, 100) time_one = sqlite_time_to_ros_time(str(time_one_org)) time_two = sqlite_time_to_ros_time(str(time_two_org)) time_stamps = RecordingTimeStamps() time_stamps.start = time_one time_stamps.finish = time_two db_startup(db_path, True) gender_msg = GenderInfo() gender_msg.gender = 'male' gender_msg.probability = 0.9 gender_msg.duration = time_stamps emotion_msg = EmotionInfo() emotion_msg.emotion = 'neutral' emotion_msg.probability = 0.8 emotion_msg.duration = time_stamps