def test_remove_and_extent(): t = Timeline(uri='MyAudioFile') t.add(Segment(6, 8)) t.add(Segment(7, 9)) t.add(Segment(6, 9)) t.remove(Segment(6, 9)) assert t.extent() == Segment(6, 9)
def remove_excluded(self): if len(self.excluded) == 0: return from pyannote.core import Segment, Timeline segments = [] for recording, _segments in self.segments.groupby( "recording_filename"): sampled = Timeline(segments=[ Segment(segment_onset, segment_offset) for segment_onset, segment_offset in _segments[ ["segment_onset", "segment_offset"]].values ]) excl_segments = self.excluded.loc[ self.excluded["recording_filename"] == recording] excl = Timeline(segments=[ Segment(segment_onset, segment_offset) for segment_onset, segment_offset in excl_segments[ ["segment_onset", "segment_offset"]].values ]) # sampled = sampled.extrude(sampled) # not released yet extent_tl = Timeline([sampled.extent()], uri=sampled.uri) truncating_support = excl.gaps(support=extent_tl) sampled = sampled.crop(truncating_support, mode="intersection") segments.append( pd.DataFrame( [[recording, s.start, s.end] for s in sampled], columns=[ "recording_filename", "segment_onset", "segment_offset" ], )) self.segments = pd.concat(segments)
def test_update_extent(): timeline = Timeline([Segment(0, 1), Segment(2, 3), Segment(4, 5)]) other_timeline = Timeline([Segment(1.5, 6)]) timeline.update(other_timeline) assert timeline.extent() == Segment(0, 6)
def trn_iter(self): # the train set comes from Fisher, Switchboard and Mixer NIST SRE datasets # the list for training has no speaker's turn annotations, since every utterance has one speaker only # the provided file list also requires special care for Idiap location, since the folder structure is different extend_uri = None if os.path.isdir("/idiap") and "USER" in os.environ: extend_uri = { 'fishe1': 8, 'fishe2': 8, 'mix05': 2, 'mix06': 2, 'swcellp1': 5, 'swcellp2': 5, 'swph2': 5, 'swph3': 5 } # load UEM list, which was generated by recording the duration of each utterance data_dir = Path(__file__).parent / 'data' / 'speaker_diarization' annotated = data_dir / f'train-world.uem' names = ['uri', 'NA0', 'start', 'end'] annotated = read_table(annotated, delim_whitespace=True, names=names) # load the list of utterances with speaker_ids, it's not an MDTM file annotation = data_dir / f'train-world.lst' names = ['uri', 'speaker'] annotation = read_table(annotation, delim_whitespace=True, names=names) AnnotatedGroups = annotated.groupby(by='uri') AnnotationGroups = annotation.groupby(by='uri') samples_with_annotations = AnnotationGroups.groups.keys() for raw_uri, annotated in AnnotatedGroups: # process only those uris that we have inside annotations if raw_uri in samples_with_annotations: # from raw_uri, construct correct path to the audio file uri = raw_uri if extend_uri is not None: uriparts = raw_uri.split('/') if uriparts[0] in extend_uri.keys(): uri = os.path.join( uriparts[0], uriparts[1][:extend_uri[uriparts[0]]], uriparts[1]) segments = [] for segment in annotated.itertuples(): segments.append( Segment(start=segment.start, end=segment.end)) timeline = Timeline(uri=uri, segments=segments) annotation = Annotation(uri=uri) for t, turn in enumerate( AnnotationGroups.get_group(raw_uri).itertuples()): segment = timeline.extent() annotation[segment, t] = turn.speaker current_file = { 'database': 'SRE', 'uri': uri, 'annotated': timeline, 'annotation': annotation } yield current_file