#! python

import re

def read_stdout(f):
	_fpat = re.compile("^File:\s+(.*)$")
	_score = re.compile(r" == \[([0-9]+) frames\] ([0-9.e+-]+) ")
	_mlfname = re.compile('HVite.* -i ([^ ]+.mlf)')
	mlfname = None
	fname = None
	score_per = None
	nframes = None
	for line in f:
		line = line.strip()
		m = _fpat.match(line)
		if m:
			fname = m.group(1)
		m = _score.search(line)
		if m:
			score_per = float(m.group(2))
			nframes = int(m.group(1))
			yield {'nframes': nframes, 'score_per': score_per,
				'mfccname': fname, 'mlfname': mlfname}
		m = _mlfname.match(line):
		if m:
			mlfname = m.group(1)
			score_per = None
			nframes = None
			fname = None


