File: build_lex

package info (click to toggle)
flite 2.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 83,796 kB
  • sloc: ansic: 693,645; sh: 5,000; lisp: 3,057; cpp: 994; makefile: 893; xml: 52; perl: 33
file content (184 lines) | stat: -rwxr-xr-x 7,457 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh
###########################################################################
##                                                                       ##
##                  Language Technologies Institute                      ##
##                     Carnegie Mellon University                        ##
##                       Copyright (c) 2004-2012                         ##
##                        All Rights Reserved.                           ##
##                                                                       ##
##  Permission is hereby granted, free of charge, to use and distribute  ##
##  this software and its documentation without restriction, including   ##
##  without limitation the rights to use, copy, modify, merge, publish,  ##
##  distribute, sublicense, and/or sell copies of this work, and to      ##
##  permit persons to whom this work is furnished to do so, subject to   ##
##  the following conditions:                                            ##
##   1. The code must retain the above copyright notice, this list of    ##
##      conditions and the following disclaimer.                         ##
##   2. Any modifications must be clearly marked as such.                ##
##   3. Original authors' names are not deleted.                         ##
##   4. The authors' names are not used to endorse or promote products   ##
##      derived from this software without specific prior written        ##
##      permission.                                                      ##
##                                                                       ##
##  CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK         ##
##  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      ##
##  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   ##
##  SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE      ##
##  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    ##
##  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   ##
##  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          ##
##  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       ##
##  THIS SOFTWARE.                                                       ##
##                                                                       ##
###########################################################################
##                                                                       ##
##  Make a flite lexicon from a Festival compiled lexicon                ##
##                                                                       ##
##  This is offered as an example, though it's not robust                ##
##                                                                       ##
###########################################################################

if [ "x$FLITEDIR" = "x" ]
then
   FLITEDIR=`pwd`/../..
fi

## Change these two lines
LEXNAME=cmu_iq
LEXFILE=cmu_iq_lex.out

if [ $# = 0 ]
then
   $0 setup
   $0 lts
   $0 lts2c
   $0 lex
   $0 compresslex
   $0 install
   exit
fi

if [ "$1" = "setup" ]
then
   $FESTVOXDIR/src/lts/build_lts setup $LEXFILE utf8
   mkdir c
   mkdir wfst
   cp -p $FESTVOXDIR/src/lts/build_lts .
   cp -p $FESTVOXDIR/src/lts/build_lts_rules .
fi

if [ "$1" = "lts" ]
then
   # Let's assume you have your allowables.scm already
   ./build_lts make_allowables_smt
   ./build_lts cummulate
   ./build_lts align
   ./build_lts build
   ./build_lts merge
   ./build_lts test
fi

if [ "$1" = "lts2c" ]
then
   festival --heap 10000000 -b $FLITEDIR/tools/make_lts_wfst.scm lts_scratch/lex_lts_rules.scm '(lts_to_rg_to_wfst lex_lts_rules "wfst/")';
   festival --heap 10000000 -b $FLITEDIR/tools/make_lts.scm lts_scratch/lex_lts_rules.scm '(ltsregextoC "'$LEXNAME'" lex_lts_rules "wfst/" "c")';
fi

if [ "$1" = "lex" ]
then
     # Find the words to prune from the built lexicon
     # We will prune words that aren't homographs and the LTS gets correct
     # Use the lts_test.log to find the failed entries and only
     # include them in the list 
#     festival -b cmulex.scm ~/projects/flite/tools/make_lex.scm '(remove_predictable_entries "cmudict-0.4.out" "pruned_lex.scm" "lex_lts_rules.scm")'
#     festival --heap 10000000 -b '(lex.compile "pruned_lex.scm" "pruned_lex.out")'
     festival --heap 10000000 -b $FLITEDIR/tools/make_lex.scm '(lextoC "'$LEXNAME'" "lts_scratch/lex_entries.out" "c")' ;

fi

if [ "$1" = "lex2" ]
then
   # experiment: put Letter_Phone(s) together as things to compress
   # does give much smaller result, though needs to be less than 256 symbols
   # not fully implemented
   ( cd festival/lib/dicts/cmu;
     # Use the lts_test.log to find the failed entries and only
     # include them in the list 
     # this needs festival-1.96 or later to get the pos from the lts_test.log
     grep "^failed " lts_test.log |
     sed 's/(/( /g;s/)/ )/g' |
     awk '{printf("( \"");
           for (i=3; $i != ")"; i++)
               printf("%s",$i);
           i++;
           printf("\" %s ( ",$i);
           i++; i++
           for ( ; $i != ")"; i++)
              if ($i != "#")
                 printf("%s ",$i);
           printf("))\n");
         }' |
     tr -d '()"' |
     awk '{if ($2 == "nil") 
              printf("0_start ");
           else
              printf("%s_start ",$2);
           for (i=1; i<=length($1); i++)
              printf("%s_%s ",substr($1,i,1),$(i+2));
           printf("\n");}' >pruned_lex2.data
#     festival --heap 10000000 -b $FLITEDIR/tools/make_lex.scm '(lextoC "cmu" "pruned_lex.out" "c")' ;
   )
fi

if [ "$1" = "compresslex" ]
then
   # Compress the entries and phone strings by finding best ngrams 
   ( cd c;
     $FLITEDIR/tools/huff_table phones ${LEXNAME}_lex_data ${LEXNAME}_lex_phones_huff_table.c
     $FLITEDIR/tools/huff_table entries ${LEXNAME}_lex_data ${LEXNAME}_lex_entries_huff_table.c
     paste huff.entries.compressed huff.phones.compressed huff.tmp.corpus | 
     tr -d " " |
     awk 'BEGIN {pcount = 1;
                 printf("/* index to compressed data */\n");
                }
          function unenoctal(x)
          {
             y = ((substr(x,1,1)+0)*64) + ((substr(x,2,1)+0)*8) + (substr(x,3,1)+0);
             return y;
          }
          {printf("   ");
           for (i=length($2)-3; i>0; i-=4)
           {
              printf("%d,",unenoctal(substr($2,i+1,3)));
              pcount++;
           }
           pcount++;
           printf(" 255, /* %d %s */ ",pcount,$3);
           for (i=1; i<length($1); i+=4)
           {
              printf("%d,",unenoctal(substr($1,i+1,3)));
              pcount++;
           }
           printf("0,\n");
           pcount++;
          }
        END { printf("/* num_bytes = %d */\n",pcount);}' >${LEXNAME}_lex_data_compressed.c
     grep "num_bytes = " ${LEXNAME}_lex_data_compressed.c |
     awk '{print $4}' >${LEXNAME}_lex_num_bytes_compressed.c
   )
fi

if [ "$1" = "install" ]
then
   cp -p c/${LEXNAME}_lex_data.c .
   cp -p c/${LEXNAME}_lex_data_compressed.c ./${LEXNAME}_lex_data_raw.c
   cp -p c/${LEXNAME}_lex_num_bytes_compressed.c ./${LEXNAME}_lex_num_bytes.c
   cp -p c/${LEXNAME}_lex_entries.c .
   cp -p c/${LEXNAME}_lex_phones_huff_table.c .
   cp -p c/${LEXNAME}_lex_entries_huff_table.c .
   cp -p c/${LEXNAME}_lts_model.c .
   cp -p c/${LEXNAME}_lts_model.h .
   cp -p c/${LEXNAME}_lts_rules.c .
fi