def get_patterns(self,E,phns,phn_times,s, context=False,template_length=32): """ Parameters ---------- E: array edgemap features phns: array strings representing the labels for the utterance phn_times: array times when the """ feature_start, \ feature_step, num_features =\ esp._get_feature_label_times(s, self.num_window_samples, self.num_window_step_samples) feature_labels, \ feature_label_transitions \ = esp._get_labels(phn_times, phns, feature_start, feature_step, num_features, self.sample_rate) pattern_times = esp.get_pattern_times(self.patterns, phns, feature_label_transitions) if context: return [E[:,max(pattern_time[0]-template_length/3,0):\ min(pattern_time[0]+template_length+1+ (template_length)/3,E.shape[1])]\ for pattern_time in pattern_times] else: return [E[:,pattern_time[0]:pattern_time[1]+1]\ for pattern_time in pattern_times]
def get_patterns_specs(self,S,phns,phn_times,s, offset=3): first_window_s_avg, window_s_avg_step, num_windows = esp._get_spectrogram_label_times(s, self.num_window_samples, self.num_window_step_samples) spec_labels, \ spec_label_transitions \ = esp._get_labels(phn_times, phns, first_window_s_avg, window_s_avg_step, num_windows, self.sample_rate) pattern_times = esp.get_pattern_times(self.patterns, phns, spec_label_transitions) return [S[:,pattern_time[0]-offset:pattern_time[1]+1+offset]\ for pattern_time in pattern_times]
def get_pattern_times(self,phns,phn_times,s, template_length=32): feature_start, \ feature_step, num_features =\ esp._get_feature_label_times(s, self.num_window_samples, self.num_window_step_samples) feature_labels, \ feature_label_transitions \ = esp._get_labels(phn_times, phns, feature_start, feature_step, num_features, self.sample_rate) pattern_times = esp.get_pattern_times(self.patterns, phns, feature_label_transitions) return pattern_times
def get_pattern_fronts_backs(self,E,phns,phn_times,s,bg_len, context=False,part_radius=5): """ Parameters ---------- E: array edgemap features phns: array strings representing the labels for the utterance phn_times: array times when the """ feature_start, \ feature_step, num_features =\ esp._get_feature_label_times(s, self.num_window_samples, self.num_window_step_samples) feature_labels, \ feature_label_transitions \ = esp._get_labels(phn_times, phns, feature_start, feature_step, num_features, self.sample_rate) pattern_times = esp.get_pattern_times(self.patterns, phns, feature_label_transitions) if context: return [(E[:,max(pattern_time[0]-part_radius,0):\ min(pattern_time[0]+part_radius,E.shape[0])],\ E[:,max(pattern_time[1]-part_radius,0):\ min(pattern_time[1]+part_radius,E.shape[0])],\ pattern_time) for pattern_time in pattern_times] else: return [(E[:,max(pattern_time[0]-part_radius,0):\ min(pattern_time[0]+part_radius,E.shape[1])],\ E[:,max(pattern_time[1]-part_radius,0):\ min(pattern_time[1]+part_radius,E.shape[1])],\ pattern_time,part_radius) for pattern_time in pattern_times]
def get_patterns_negative(self,E,phns,phn_times,s,length): """ Returns a negative example for the given pattern Parameters ---------- E: array edgemap features phns: array strings representing the labels for the utterance phn_times: array times when the """ feature_start, \ feature_step, num_features =\ esp._get_feature_label_times(s, self.num_window_samples, self.num_window_step_samples) feature_labels, \ feature_label_transitions \ = esp._get_labels(phn_times, phns, feature_start, feature_step, num_features, self.sample_rate) pattern_times = esp.get_pattern_times(self.patterns, phns, feature_label_transitions) end_time = E.shape[1]-length-3 start_time = length+3 neg_pattern_time = np.random.randint(start_time,end_time) # make sure that its not close to the start time of a patter while self._within_pattern_tolerance(neg_pattern_time, pattern_times, length): neg_pattern_time = np.random.randint(start_time,end_time) return E[:,neg_pattern_time:neg_pattern_time+length].copy(), E[:,max(neg_pattern_time-length,0):neg_pattern_time].copy()