def get_labels_for_file(self, wav_path, frame_sec): sname = get_sname(wav_path) sample = self.labels[self.labels.Sample == sname] incidents = sample.loc[:, 'type_voc_0':'end_voc_5'] incidents = incidents.dropna(axis=1, how='all') incidents = incidents.values[0] rate, audio = wav.read(wav_path) laughts = self._interval_generator(incidents) laughts = [ interv_to_range(x, len(audio), self.duration) for x in laughts ] laught_along = [ 1 if in_any(t, laughts) else 0 for t, _ in enumerate(audio) ] frame_size = int(self.sample_rate * frame_sec) is_laughter = np.array( [self.most(la) for la in chunks(laught_along, frame_size)]) frame_step = int(frame_size / 5) is_laughter = [ self.most(laught_along[i:i + frame_size]) for i in range(0, self.default_len - frame_size, frame_step) ] df = pd.DataFrame({'IS_LAUGHTER': is_laughter, 'SNAME': sname}) return df
def _interval_generator(incidents): for itype, start, end in chunks(incidents, 3): if itype == 'laughter': yield start, end