def _make_load(self, value, key=None, uris=None): parser = MagicParser.guess_parser(value) # mono-uri file if '{uri' in value: def loadOne(uri): path = value.format(uri=uri) return parser().read(path)(uri=uri) return loadOne # multi-uris file else: # load the whole file path = value p = parser().read(path) # update list of uris when conditions are met # (i.e. multi-uris file + specific request) if uris == key: self.uris = list(p.uris) return lambda uri: p(uri=uri)
def parse_file(format): Parser = MagicParser.get_parser(format) if request.method == 'POST': uploaded = request.files['file'] parser = Parser() parser.read(uploaded) results = [] for uri in parser.uris: for modality in parser.modalities: results.append(parser(uri=uri, modality=modality).for_json()) return json.dumps(results) if request.method == 'GET': return json.dumps(Parser.__doc__)
from pyannote.parser import MagicParser import numpy from itertools import tee, islice, chain, izip if __name__ == '__main__': #parser_spk = MagicParser().read('../reference/test2.repere') parser_spk = MagicParser().read('../reference/test2.1.0.v2.repere') parser_spo = MagicParser().read('../reference/test2.spoken.repere') fout_spkshow = open( '../spkshow/data/descripteur_prediction/test2.spkshow.spoken', 'w') fout_spkseg = open( '../spkseg/data/descripteur_prediction/test2.spkseg.spoken', 'w') for show in parser_spo.uris: spo = parser_spo(uri=show, modality="spoken") spk = parser_spk(uri=show, modality="speaker") list_spk = {} l_st_previous_next = {} for segment, track, label in spk.itertracks(label=True): if type( label ).__name__ != 'Unknown' and 'BFMTV_' not in label and 'LCP_' not in label: list_spk.setdefault(show + '#' + label, { 'speech': [], 'spo': [] }) list_spk[show + '#' + label]['speech'].append(segment)
from pyannote.parser import MagicParser if __name__ == '__main__': parser = MagicParser().read('../reference/test2.repere') fout_spkseg = open('../reference/list_spkseg', 'w') fout_spkshow = open('../reference/list_spkshow', 'w') list_spkshow = set([]) for show in parser.uris: annotation = parser(uri=show, modality="speaker") for segment, track, label in annotation.itertracks(label=True): if type( label ).__name__ != 'Unknown' and 'BFMTV_' not in label and 'LCP_' not in label: fout_spkseg.write(show + " " + str(segment.start) + " " + str(segment.end) + " " + label + '\n') list_spkshow.add(show + '#' + label) for spk in sorted(list_spkshow): fout_spkshow.write(spk + '\n')
from pyannote.parser import MagicParser import numpy if __name__ == '__main__': #parser_spk = MagicParser().read('../reference/test2.repere') parser_spk = MagicParser().read('../reference/test2.1.0.v2.repere') parser_ocr = MagicParser().read('../reference/test2.OCR.repere') parser_uem = MagicParser().read('../reference/test2.uem') #fout_spkshow = open('../spkshow/data/descripteur_prediction/test2.spkshow.OCR', 'w') fout_spkseg = open('../spkseg/data/descripteur_prediction/test2.spkseg.OCR', 'w') for show in parser_ocr.uris: ocr = parser_ocr(uri=show, modality="written") spk = parser_spk(uri=show, modality="speaker") uem = parser_uem(uri=show) list_spk = {} for segment, track, label in spk.itertracks(label=True): if type(label).__name__ != 'Unknown' and 'BFMTV_' not in label and 'LCP_' not in label : list_spk.setdefault(show+'#'+label, {'speech':[], 'ocr':[], 'dur':[]}) list_spk[show+'#'+label]['speech'].append(segment) list_spk[show+'#'+label]['dur'].append(segment.duration) for segment, track, label in ocr.itertracks(label=True): if show+'#'+label in list_spk: list_spk[show+'#'+label]['ocr'].append(segment) for spk in sorted(list_spk): #spkshow
filter_funcs = [ lambdify([speech], sympify(expression)) for expression in filters] filter_func = lambda speech: \ any(~func(speech) for func in filter_funcs) else: filter_func = None spotting(protocol, subset, latencies, hypotheses, output_prefix, filter_func=filter_func) sys.exit(0) # hypothesis hypothesis_mdtm = arguments['<hypothesis.mdtm>'] hypotheses = MagicParser().read(hypothesis_mdtm, modality='speaker') if arguments['detection']: detection(protocol, subset, hypotheses, collar=collar, skip_overlap=skip_overlap) if arguments['segmentation']: segmentation(protocol, subset, hypotheses, tolerance=tolerance) if arguments['diarization']: greedy = arguments['--greedy'] diarization(protocol, subset, hypotheses, greedy=greedy, collar=collar, skip_overlap=skip_overlap) if arguments['identification']: identification(protocol, subset, hypotheses,