make_cmulex 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/bin/sh
  2. ###########################################################################
  3. ## ##
  4. ## Language Technologies Institute ##
  5. ## Carnegie Mellon University ##
  6. ## Copyright (c) 2004 ##
  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. ## Make the files from the Festival Released version ##
  36. ## ##
  37. ###########################################################################
  38. if [ "x$FLITEDIR" = "x" ]
  39. then
  40. FLITEDIR=`pwd`/../..
  41. fi
  42. if [ $# = 0 ]
  43. then
  44. $0 setup
  45. $0 lts
  46. $0 lex
  47. $0 compresslex
  48. $0 install
  49. exit
  50. fi
  51. if [ "$1" = "setup" ]
  52. then
  53. tar zxvf festlex_CMU.tar.gz
  54. cp -p $FESTVOXDIR/src/lts/build_lts festival/lib/dicts/cmu
  55. cp -p $FESTVOXDIR/src/lts/build_lts_rules festival/lib/dicts/cmu
  56. mkdir festival/lib/dicts/cmu/c
  57. mkdir festival/lib/dicts/cmu/wfst
  58. mkdir festival/lib/dicts/cmu/lts_scratch
  59. fi
  60. if [ "$1" = "lts" ]
  61. then
  62. (cd festival/lib/dicts/cmu;
  63. festival --heap 10000000 -b allowables.scm '(dump-flat-entries-all "cmudict-0.4.out" "lts_scratch/lex_entries.out")'
  64. ./build_lts cummulate
  65. ./build_lts align
  66. ./build_lts build
  67. ./build_lts merge
  68. ./build_lts test
  69. 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/")';
  70. festival --heap 10000000 -b $FLITEDIR/tools/make_lts.scm lts_scratch/lex_lts_rules.scm '(ltsregextoC "cmu" lex_lts_rules "wfst/" "c")';
  71. )
  72. fi
  73. if [ "$1" = "lex" ]
  74. then
  75. ( cd festival/lib/dicts/cmu;
  76. # Find the words to prune from the built lexicon
  77. # We will prune words that aren't homographs and the LTS gets correct
  78. # Use the lts_test.log to find the failed entries and only
  79. # include them in the list
  80. festival -b cmulex.scm ~/projects/flite/tools/make_lex.scm '(remove_predictable_entries "cmudict-0.4.out" "pruned_lex.scm" "lex_lts_rules.scm")'
  81. festival --heap 10000000 -b '(lex.compile "pruned_lex.scm" "pruned_lex.out")'
  82. festival --heap 10000000 -b $FLITEDIR/tools/make_lex.scm '(lextoC "cmu" "pruned_lex.out" "c")' ;
  83. )
  84. fi
  85. if [ "$1" = "lex2" ]
  86. then
  87. # experiment: put Letter_Phone(s) together as things to compress
  88. # does give much smaller result, though needs to be less than 256 symbols
  89. # not fully implemented
  90. ( cd festival/lib/dicts/cmu;
  91. # Use the lts_test.log to find the failed entries and only
  92. # include them in the list
  93. # this needs festival-1.96 or later to get the pos from the lts_test.log
  94. grep "^failed " lts_test.log |
  95. sed 's/(/( /g;s/)/ )/g' |
  96. awk '{printf("( \"");
  97. for (i=3; $i != ")"; i++)
  98. printf("%s",$i);
  99. i++;
  100. printf("\" %s ( ",$i);
  101. i++; i++
  102. for ( ; $i != ")"; i++)
  103. if ($i != "#")
  104. printf("%s ",$i);
  105. printf("))\n");
  106. }' |
  107. tr -d '()"' |
  108. awk '{if ($2 == "nil")
  109. printf("0_start ");
  110. else
  111. printf("%s_start ",$2);
  112. for (i=1; i<=length($1); i++)
  113. printf("%s_%s ",substr($1,i,1),$(i+2));
  114. printf("\n");}' >pruned_lex2.data
  115. # festival --heap 10000000 -b $FLITEDIR/tools/make_lex.scm '(lextoC "cmu" "pruned_lex.out" "c")' ;
  116. )
  117. fi
  118. if [ "$1" = "compresslex" ]
  119. then
  120. # Compress the entries and phone strings by finding best ngrams
  121. ( cd festival/lib/dicts/cmu/c;
  122. $FLITEDIR/tools/huff_table phones cmu_lex_data cmu_lex_phones_huff_table.c
  123. $FLITEDIR/tools/huff_table entries cmu_lex_data cmu_lex_entries_huff_table.c
  124. paste huff.entries.compressed huff.phones.compressed huff.tmp.corpus |
  125. tr -d " " |
  126. awk 'BEGIN {pcount = 1;
  127. printf("/* index to compressed data */\n");
  128. }
  129. function unenoctal(x)
  130. {
  131. y = ((substr(x,1,1)+0)*64) + ((substr(x,2,1)+0)*8) + (substr(x,3,1)+0);
  132. return y;
  133. }
  134. {printf(" ");
  135. for (i=length($2)-3; i>0; i-=4)
  136. {
  137. printf("%d,",unenoctal(substr($2,i+1,3)));
  138. pcount++;
  139. }
  140. pcount++;
  141. printf(" 255, /* %d %s */ ",pcount,$3);
  142. for (i=1; i<length($1); i+=4)
  143. {
  144. printf("%d,",unenoctal(substr($1,i+1,3)));
  145. pcount++;
  146. }
  147. printf("0,\n");
  148. pcount++;
  149. }
  150. END { printf("/* num_bytes = %d */\n",pcount);}' >cmu_lex_data_compressed.c
  151. grep "num_bytes = " cmu_lex_data_compressed.c |
  152. awk '{print $4}' >cmu_lex_num_bytes_compressed.c
  153. )
  154. fi
  155. if [ "$1" = "install" ]
  156. then
  157. cp -p festival/lib/dicts/cmu/c/cmu_lex_data.c .
  158. cp -p festival/lib/dicts/cmu/c/cmu_lex_data_compressed.c cmu_lex_data_raw.c
  159. cp -p festival/lib/dicts/cmu/c/cmu_lex_phones_huff_table.c .
  160. cp -p festival/lib/dicts/cmu/c/cmu_lex_entries_huff_table.c .
  161. cp -p festival/lib/dicts/cmu/c/cmu_lex_entries.c .
  162. cp -p festival/lib/dicts/cmu/c/cmu_lex_num_bytes_compressed.c cmu_lex_num_bytes.c
  163. cp -p festival/lib/dicts/cmu/c/cmu_lts_model.c .
  164. cp -p festival/lib/dicts/cmu/c/cmu_lts_model.h .
  165. cp -p festival/lib/dicts/cmu/c/cmu_lts_rules.c .
  166. fi