| 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 |
## Find power normalization factor for each waveform file ## |
| 36 |
## Finds power for each labelled vowel ## |
| 37 |
## Finds mean power for each vowel ## |
| 38 |
## Finds power factor for each file (used by make_lpc) ## |
| 39 |
## ## |
| 40 |
## ## |
| 41 |
## Naively assumes that vowels in phoneset start with (upper or lower ## |
| 42 |
## letter vowels) ## |
| 43 |
## ## |
| 44 |
## usage: bin/find_powerfactors lab/*.lab ## |
| 45 |
## ## |
| 46 |
########################################################################### |
| 47 |
|
| 48 |
if [ $# = 0 ] |
| 49 |
then |
| 50 |
echo "Find power normalization factor for each file" |
| 51 |
echo "Usage: bin/find_powerfactors lab/*.lab" |
| 52 |
echo "Will create etc/powfacts used by bin/make_lpc" |
| 53 |
exit 1 |
| 54 |
fi |
| 55 |
|
| 56 |
# Modification by Milan Zamazal <[email protected]>: Ensure locales don't break awk operation. |
| 57 |
unset LC_ALL |
| 58 |
export LC_NUMERIC=C |
| 59 |
|
| 60 |
for i in $* |
| 61 |
do |
| 62 |
fname=`basename $i .lab` |
| 63 |
echo $fname >/dev/tty |
| 64 |
cat $i | |
| 65 |
awk 'BEGIN {fname="'$fname'"; } |
| 66 |
{if (($3 ~ /^[AaEeIiOoUu].*/) && |
| 67 |
($3 != "using")) |
| 68 |
{ |
| 69 |
printf("echo START %s %s\n",fname,$3); |
| 70 |
printf("ch_wave -start %f -end %f wav/%s.wav -otype raw -ostype ascii\n",ltime,$1,fname); |
| 71 |
} |
| 72 |
if ($3 != "DB") |
| 73 |
ltime=$1}' | sh | |
| 74 |
awk 'BEGIN {fname="start";} |
| 75 |
{if ($1 == "START") |
| 76 |
{ |
| 77 |
if (fname != "start") |
| 78 |
print fname,ph,t,sqrt(t/l) |
| 79 |
fname = $2; |
| 80 |
ph=$3; |
| 81 |
l=1; |
| 82 |
t=0; |
| 83 |
} |
| 84 |
else |
| 85 |
{ |
| 86 |
t += $1*$1; |
| 87 |
l++; |
| 88 |
}} |
| 89 |
END { print fname,ph,t,sqrt(t/l) }' |
| 90 |
done >etc/all_vpower |
| 91 |
|
| 92 |
# Find the mean power for each vowel |
| 93 |
cat etc/all_vpower | |
| 94 |
awk '{vp[$2] += $4; |
| 95 |
vn[$2] += 1;} |
| 96 |
END {for (i in vp) |
| 97 |
printf("vp[\"%s\"] = %f;\n",i,vp[i]/vn[i]); }' >etc/mean_vpow |
| 98 |
|
| 99 |
# find the power modficiation factor for each file |
| 100 |
# Modification by Milan Zamazal <[email protected]>: Do not store the output to |
| 101 |
# etc/powfacts directly, to force hard link breakage when using Arch revision |
| 102 |
# libraries. |
| 103 |
cat etc/all_vpower | |
| 104 |
awk 'BEGIN {'"`cat etc/mean_vpow`"' lfile = ""; t = 0; nt = 0; |
| 105 |
} |
| 106 |
{if (($1 != lfile) && (lfile != "")) |
| 107 |
{ |
| 108 |
printf("%s %f\n",lfile,nt/t); |
| 109 |
nt = 0; |
| 110 |
t = 0; |
| 111 |
} |
| 112 |
if (vp[$2] != 0) |
| 113 |
{ |
| 114 |
t += $4; |
| 115 |
nt += vp[$2]; |
| 116 |
} |
| 117 |
lfile = $1; |
| 118 |
} |
| 119 |
END { |
| 120 |
printf("%s %f\n",lfile,nt/t); |
| 121 |
}' >etc/powfacts.new |
| 122 |
mv etc/powfacts.new etc/powfacts |