Debian Codegraph @

tools/flite_rename_voice

raw
1 #!/bin/sh
2 ###########################################################################
3 ## ##
4 ## Language Technologies Institute ##
5 ## Carnegie Mellon University ##
6 ## Copyright (c) 2010 ##
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 # Renames a clunits/voxdata flite voice build by build_flite
36 #
37 # flite_rename_voice FROMDIR NEWNAME TODIR
38 #
39 # You have to recompile it afterwards
40 #
41 FROMDIR=$1
42 NEWNAME=$2
43 TODIR=$3
44
45 OLDNAME=`cat $FROMDIR/voxdefs.h | awk '{ if ($2 == "VOXNAME") printf("%s",$3)}'`
46
47 mkdir -p $TODIR
48
49 if [ ! -f $FROMDIR/$OLDNAME.c ]
50 then
51 echo Current directory does not contain $FROMDIR/$OLDNAME.c
52 echo no renaming possible
53 exit -1
54 fi
55
56 for i in $FROMDIR/*.c $FROMDIR/*.h $FROMDIR/Makefile
57 do
58 fname=`basename $i`
59 cat $i |
60 sed 's/'$OLDNAME'/'$NEWNAME'/g' |
61 cat >$TODIR/`echo $fname | sed 's/'$OLDNAME'/'$NEWNAME'/g'`
62 done
63
64 for i in $FROMDIR/*.raw
65 do
66 fname=`basename $i`
67 cp -p $i $TODIR/`echo $fname | sed 's/'$OLDNAME'/'$NEWNAME'/g'`
68
69 done
70
71 for i in $FROMDIR/*.voxdata
72 do
73 fname=`basename $i`
74 echo $OLDNAME $NEWNAME |
75 awk '{if (length($1) < length($2))
76 {
77 fo = sprintf("%%%ds",length($2));
78 o = sprintf(fo,$1);
79 n = $2;
80 }
81 else
82 {
83 fn = sprintf("%%%ds",length($1));
84 n = sprintf(fn,$2);
85 o = $1;
86 }
87 printf("#>%s<<%s<\n",n,o);
88 printf("sed '"'"'s%%%s%%%s%%'"'"'\n",o,n)}' >$TODIR/sed.command
89 sh $TODIR/sed.command <$i >$TODIR/`echo $fname | sed 's/'$OLDNAME'/'$NEWNAME'/g'`
90 rm -f $TODIR/sed.command
91 done
92