#substitute scalar value to <decode_script> argument script_value = script % value #build the command cmd = '%s "%s" %s >%s' % (decode, script_value, dir, log2) os.system('echo "%s " >>%s' % (cmd, log)) #run the script os.system(cmd) #read the wer file f = open(dir + '/wer', 'r') line = f.readline().rstrip() f.close() #parse ... print line, os.system('echo "%s" >>%s' % (line, log)) arr = line.split(' ') try: acc = 100.0 - float(arr[3]) print 'acc:%f' % acc return acc except: print 'Error: Could not find WER value!!!' raise NoWerFoundError # run the maximization value = findmax.findMax(tryScalarValue, min, max) print 'Guessing %g' % value tryScalarValue(value) print 'Best-value=%g' % value print '%g' % value
script_value = script % value #build the command cmd = '%s "%s" %s >%s' % (decode,script_value,dir,log2) os.system('echo "%s " >>%s'%(cmd,log)) #run the script os.system(cmd) #read the wer file f = open(dir+'/wer','r') line = f.readline().rstrip() f.close() #parse ... print line, os.system('echo "%s" >>%s'%(line,log)) arr = line.split(' ') try: acc = 100.0-float(arr[3]) print 'acc:%f' % acc return acc except: print 'Error: Could not find WER value!!!' raise NoWerFoundError # run the maximization value = findmax.findMax(tryScalarValue,min,max) print 'Guessing %g' % value tryScalarValue(value) print 'Best-value=%g' % value print '%g' % value
#clean-up previous os.system('rm -f %s/*' % dir) #generate new script os.system('cat %s | sed -e \'s|^\(acousticscale\)=.*|\\1=%f|\' -e \'s|^\(dir\)=.*|\\1=%s|\' > %s' %(script,scale,dir,script_tgt)) #run the script os.system('bash '+script_tgt+' &> /dev/null') #read the wer file f = open(dir+'/wer','r') line = f.readline().rstrip() f.close() #parse ... print line, arr = line.split(' ') try: acc = 100.0-float(arr[3]) print 'acc:%f' % acc return acc except: print 'Error: Could not find WER value!!!' raise NoWerFoundError # run the maximization scale = findmax.findMax(tryScaleValue,min,max) print 'Guessing %g' % scale tryScaleValue(scale) print 'Scale=%g' % scale print '%g' % scale