#!/usr/bin/gawk -f function res_sub(res,wsubst, a,n,s) {n = split(res,a,"_"); for(res="";n>0;n--) {if((s=a[n]) in wsubst) s=wsubst[s]; if(s != "") res = ("_" s res); } return(substr(res,2)); } function getconf(section,key, k) {section = tolower(section); if(!((k=(section SUBSEP key)) in config)) {printf("WARNING: Required key '%s' (in section %s) not specified in '%s'\n",key,section,cfname) > "/dev/stderr"; return(":missing:"); } return(config[k]); } function getconf_alt(section,alt_section,key,default, k,v) {section = tolower(section); if((k=(section SUBSEP key)) in config) v = config[k]; else if((k=(alt_section SUBSEP key)) in config) v = config[k]; else if(default != "") v = default; else {printf("WARNING: Required key '%s' (in section %s) not specified in '%s'\n",key,section,cfname) > "/dev/stderr"; v = ":missing:"; } return(v); } BEGIN { if(ARGC < 6) {printf("Use: AM_EVAL -v [LM/LEX/SEARCH]= [env=val] ...\n\n") > "/dev/stderr"; printf(" \tFile describing one or more configurations (acoustic model,\n\t\tlanguage model, lexicon, ...) for the recognizer\n") > "/dev/stderr"; printf(" \tJust a name, used to create the output files:\n\t\t - .CMD the raw commands as sent to cwr_main\n\t\t - .ERR the error output of cwr_main\n\t\t - .OUT the raw output of cwr_main\n\t\t - .RES a result file extracted from the raw output\n\t\t - .LAT a (word) lattice file (if requested)\n") > "/dev/stderr"; printf(" \tCorpus file to use; gives base file names (no leading\n\t\tdirectory, no suffix) and begin/end times\n") > "/dev/stderr"; printf(" \tDirectory where the sample files can be found\n") > "/dev/stderr"; printf(" \tExtension to add after the base file names in the corpus file\n") > "/dev/stderr"; printf(" [LM/LEX/...]\tSelect a non default language model, lexicon or set of search\n\t\toptions\n") > "/dev/stderr"; printf("Extra arguments must have the format 'env=val' and are values to be added to\nthe list of environment variables.\n") > "/dev/stderr"; exit(1); } # use the DEBUG variable to control error output DEBUG = int(ENVIRON["DEBUG"]); # decode arguments cfname = ARGV[1]; base = ARGV[2]; corpus = ARGV[3]; obsdir = ARGV[4]; suffix = ARGV[5]; export = ""; for(i=6;i "/dev/stderr"; val = (substr(val,1,p-1) ENVIRON[e] substr(val,p+RLENGTH)); } config[section,$1] = val; } } close(cfname); if(DEBUG) for(si in config) printf("INFO: %s\t/%s/\n",gensub(SUBSEP,".",1,si),config[si]); if(!skip_recog) { ## ## start the recognizer and read/configure resources according to the specs in the 'SPRaak.ini' file ## (cmd="pwd") | getline cdir; close(cmd); system(sprintf("/bin/rm -f '%s.RES' '%s.ERR' '%s.OUT' '%s.CMD' '%s.LAT'",base,base,base,base,base)); cwr = ( export "exec cwr_main -i stdin -o '" base ".OUT' -e '" base ".ERR'" ); printf("diary %s.CMD\nsearch mode CWR\nprint 10\n",base) | cwr; # step1. goto the directory of the SPRaak.ini file (every path is assumed to be relative w.r.t. this directory) if((k=("[default]" SUBSEP "basedir")) in config) printf("chdir %s\n",bdir=config[k]) | cwr; else if((len=match(bdir=cfname,"/[^/]*$"))) printf("chdir %s\n",bdir=substr(bdir,1,len-1)) | cwr; else bdir = cdir; # step2. configure the preprocessing printf("load ssp_script %s\n",getconf("[preproc]","script")) | cwr; printf("set ssp obsdir %s\n",obsdir) | cwr; printf("set ssp suffix %s\n",suffix) | cwr; if((k=("[preproc]" SUBSEP "ext." suffix)) in config) printf("set ssp fileformat %s\n",config[k]) | cwr; printf("set ssp timebase CONTINUOUS\n") | cwr; # step3. load/configure the lexicon printf("load phone_set %s %s\n",getconf("[phonset]","CI"),getconf("[phonset]","CD")) | cwr; if(LEX == "") LEX = getconf("[default]","lexicon"); lex = tolower(("[LEX:" LEX "]")); printf("load lexicon %s * %s\n",getconf(lex,"file"),getconf(lex,"unwind")) | cwr; if((k=(lex SUBSEP "constraint")) in config) printf("search constraint %s\n",config[k]) | cwr; # step4. load/configure the acoustic models if((k=("[acmod]" SUBSEP "rmg")) in config) printf("set rmg %s\n",config[k]) | cwr; if((k=("[acmod]" SUBSEP "fast")) in config) printf("set fast models %s\n",config[k]) | cwr; if((k=("[acmod]" SUBSEP "top_n")) in config) printf("set top_n %s\n",config[k]) | cwr; if((k=("[acmod]" SUBSEP "LMO")) in config) printf("set logminout %s\n",config[k]) | cwr; if((k=("[acmod]" SUBSEP "sel")) in config) printf("load hmm %s %s %s\n",getconf("[acmod]","hmm"),getconf("[acmod]","mvg"),getconf("[acmod]","sel")) | cwr; else printf("load hmm %s %s\n",getconf("[acmod]","hmm"),getconf("[acmod]","mvg")) | cwr; # step5. load/configure the language model if(LM == "") LM = getconf("[default]","langmod"); lm = tolower(("[LM:" LM "]")); if((k=(lm SUBSEP "file")) in config) printf("load lm %s %s\n",config[k],getconf(lm,"options")) | cwr; if((k=(lm SUBSEP "mode")) in config) printf("search mode %s\n",config[k]) | cwr; printf("search lmi %s %s\n",getconf(lm,"cost_A"),getconf(lm,"cost_C")) | cwr; # step6. configure the search if(SEARCH == "") SEARCH = (LEX "," LM); search = tolower(("[SEARCH:" SEARCH "]")); if(int(getconf_alt(search,"[default]","wlat","0")) == 1) printf("search trace phones\n%schdir %s\nword_graph init %s.LAT\n%schdir %s\n",(cdir==bdir)?"%":"",cdir,base,(cdir==bdir)?"%":"",bdir) | cwr; printf("search maximum %s 0.6 %s\n",getconf_alt(search,"[default]","threshold","1e30"),getconf_alt(search,"[default]","max_bw","-1")) | cwr; printf("search minimum %s\n",getconf_alt(search,"[default]","min_bw","0")) | cwr; # step7. configure the output printf("print scores on\nprint words on\nprint normalized on\nprint nfr on\n") | cwr; } else {cwr="cat > /dev/null";} ## ## process the entries in the corpus file ## keys["FILENAME"] = corpus; while((getline "/dev/stderr"; break; } if($1 != "-") prev = $1; fname = prev; ifr = (NF>=3) ? $3 : 0; nfr = (NF>=4) ? $4 : -1; printf("echo Processing %s %s %s\n",fname,ifr,nfr) | cwr; printf("echo Reference %s\n",$2,ifr,nfr) | cwr; if(!continuous) {if(nfr != -1) nfr = (ifr+nfr)*fshift; ifr *= fshift; } printf("file %s %s %s\n",fname,ifr,nfr) | cwr; } printf("quit\n") | cwr; close(cwr); nentry = ientry; ## ## make a descent result file ## for(ientry=0;; ) {if((str=getconf_alt(lex,"[default]",("wsubst[" ++ientry "]"),"/")) == "/") break; wsubst[gensub("[ \t].*$","",1,str)] = gensub("^[^ \t]+[ \t]*","",1,str); } cmd = sprintf("scoreres -c %s -r stdin -PAR -nr %s.RES -omit '%s'",corpus,base,getconf_alt(lex,"[default]","omit"," ")); fname = (base ".OUT"); for(ientry=0;getline