1#!/bin/sh 2#####################################################-*-mode:shell-script-*- 3## ## 4## Carnegie Mellon University and ## 5## Alan W Black and Kevin A. Lenzo ## 6## Copyright (c) 1998-2000 ## 7## All Rights Reserved. ## 8## ## 9## Permission is hereby granted, free of charge, to use and distribute ## 10## this software and its documentation without restriction, including ## 11## without limitation the rights to use, copy, modify, merge, publish, ## 12## distribute, sublicense, and/or sell copies of this work, and to ## 13## permit persons to whom this work is furnished to do so, subject to ## 14## the following conditions: ## 15## 1. The code must retain the above copyright notice, this list of ## 16## conditions and the following disclaimer. ## 17## 2. Any modifications must be clearly marked as such. ## 18## 3. Original authors' names are not deleted. ## 19## 4. The authors' names are not used to endorse or promote products ## 20## derived from this software without specific prior written ## 21## permission. ## 22## ## 23## CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK ## 24## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ## 25## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ## 26## SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE ## 27## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ## 28## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ## 29## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ## 30## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ## 31## THIS SOFTWARE. ## 32## ## 33########################################################################### 34## ## 35## Normalize cepstrum parameters ## 36## note this is zscoring, not just mean normalization ## 37########################################################################### 38 39if [ ! "$ESTDIR" ] 40then 41 echo "environment variable ESTDIR is unset" 42 echo "set it to your local speech tools directory e.g." 43 echo ' bash$ export ESTDIR=/home/awb/projects/speech_tools/' 44 echo or 45 echo ' csh% setenv ESTDIR /home/awb/projects/speech_tools/' 46 exit 1 47fi 48 49if [ $# = 0 ] 50then 51 echo "Normalize cepstral coefficients" 52 echo "Usage: bin/make_cmn mcep/*.mcep" 53 echo "Note this creates the stats file in etc/cep.meanstddev and " 54 echo "overwrites the mcep files with their normalized versions " 55 exit 1 56fi 57 58echo "Building meanstddev file" 59 60for i in $* 61do 62 $ESTDIR/bin/ch_track -otype ascii $i 63done | 64awk '{ 65 for (i=1; i<=NF; i++) 66 { 67 count[i] += 1 68 sum[i] += $i 69 sumsq[i] += $i*$i 70 } 71 numchannels=NF; 72 } 73 function std (sum, sumx, n) 74 { 75 if (n==1) 76 n=2; 77 return sqrt(((n*sumx)-(sum*sum)) / (n*(n-1))) 78 } 79 function mean (sum,n) 80 { 81 return sum/n; 82 } 83 END { 84 for (i=1; i<=NF; i++) 85 printf("%3.3f %3.3f\n",mean(sum[i],count[i]),std(sum[i],sumsq[i],count[i])); 86 }' >etc/cep.meanstddev 87 88cat etc/cep.meanstddev | 89awk 'BEGIN {printf("BEGIN {\n")} 90 {printf("mean[%d]=%s; stddev[%d]=%s;\n",NR,$1,NR,$2);} 91 END {printf("}\n")}' >etc/norm.awk 92echo '{if (header==0) 93 { 94 print $0; 95 if ($1 == "EST_Header_End") 96 header=1; 97 } 98 else 99 { 100 printf("%s %s ",$1,$2) 101 for (i=1; i<=(NF-2); i++) 102 printf("%f ",($(i+2)-mean[i])/stddev[i]); 103 printf("\n"); 104 }}' >>etc/norm.awk 105 106exit 107 108$CMN -findmsd -omsd etc/cep.meanstddev $* 109 110for i in $* 111do 112 fname=`basename $i .wav` 113 echo $fname 114 $CMN -applymsd -imsd etc/cep.meanstddev $i 115done 116 117 118