espeak_ng_data_to_code.praat 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # espeak_ng_data_to_code.praat
  2. # djmw 20120117, 20120124, 20151130, 20171004
  3. #
  4. # This script is specific for my situation (althought it can be adapted easily to any directory structure
  5. # and non-Linux system).
  6. # My espeak-work/ has subdirectories espeak-ng-work and espeak-ng-current.
  7. # Into espeak-ng-work are copied from the original espeak-ng project only those *.c and *.h files that are
  8. # needed for the praat version of the synthesizer .
  9. #
  10. # If the upstream espeak-ng has been modified then I follow the following procedure:
  11. #
  12. # Given the following directories:
  13. # A: ~/projects/praat/espeak-work/espeak-ng-work
  14. # B: ~/projects/praat/espeak-work/espeak-ng-current
  15. # C: ~/projects/praat/external/espeak
  16. #
  17. # 0. I pull the sources from upstream:
  18. # cd ~/projects/espeak-ng
  19. # - git pull https://github.com/espeak-ng/espeak-ng.git
  20. # - make clean
  21. # - make
  22. # - Get the version of espeak-ng from the ~/projects/espeak-ng/config.h file
  23. # 1. I copy the necessary *.c and *.h files from ~/projects/espeak-ng/src/... to espeak-work
  24. # by running this script with only the option "Copy_c_and_h_files" ON (the right version option).
  25. # The *.c files are renamed as *.cpp files. Also a new file espeak-ng-version.h is created.
  26. # 2. I use a three-way diff program (kdiff3) to see which files in A are different from B and
  27. # merge the differences into C.
  28. # 3. Now my *.cpp and *.h are in synchrony with upstream and we copy all files from A to B.
  29. # 4. I generate the new dictionaries and language files in memory by running this script
  30. # with only the option "Create_FileInMemorySet" set to ON.
  31. # 5. I copy the file create_espeak_ng_FileInMemorySet.cpp
  32. # and espeak-ng-version.h from espeak-ng-work/ to external/espeak
  33. # 6. Now the praat synthesizer is up to date.
  34. #
  35. # Function of this script:
  36. # Generates in espeak-ng-work
  37. # 1. create_espeak_ng_FileInMemorySet.cpp
  38. # 2. espeak-ng-version.h
  39. #
  40. # and
  41. #
  42. # 3. Copies the necessary *.c(pp) and *.h from from_dir to to_dir
  43. #
  44. myscriptname$ = "espeak_ng_data_to_code.praat"
  45. date$ = date$()
  46. notify$ = "This file was created automatically on " + date$ + "."
  47. clearinfo
  48. form Espeakdata to code
  49. word Espeak_version 1.49.3-dev
  50. boolean Copy_c_and_h_files 0
  51. boolean Show_cp_command 1
  52. boolean Create_FileInMemorySet 0
  53. endform
  54. gpltext$ = " * Copyright (C) David Weenink 2012-2017" + newline$ +
  55. ... " *" + newline$ +
  56. ... " * This program is free software; you can redistribute it and/or modify " + newline$ +
  57. ... " * it under the terms of the GNU General Public License as published by" + newline$ +
  58. ... " * the Free Software Foundation; either version 2 of the License, or (at" + newline$ +
  59. ... " * your option) any later version." + newline$ +
  60. ... " *" + newline$ +
  61. ... " * This program is distributed in the hope that it will be useful, but" + newline$ +
  62. ... " * WITHOUT ANY WARRANTY; without even the implied warranty of" + newline$ +
  63. ... " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU" + newline$ +
  64. ... " * General Public License for more details." + newline$ +
  65. ... " *" + newline$ +
  66. ... " * You should have received a copy of the GNU General Public License" + newline$ +
  67. ... " * along with this program; if not, write to the Free Software" + newline$ +
  68. ... " * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA." + newline$
  69. fromdir$ = "/home/david/projects/espeak-ng"
  70. todir$ = "/home/david/projects/praat/espeak-work/espeak-ng-work"
  71. espeakdata_dir$ = fromdir$ + "/espeak-ng-data"
  72. espeakdata_voices_dir$ = espeakdata_dir$ + "/voices/!v"
  73. espeakdata_lang_dir$ = espeakdata_dir$ + "/lang"
  74. include_header$ = "#include "+ """" + "espeakdata_FileInMemory.h" + """" + newline$
  75. if create_FileInMemorySet
  76. @create_phonFileInMemorySet
  77. @create_languageFileInMemorySet
  78. dict_fims = Create FileInMemorySet from directory contents: "list", espeakdata_dir$, "*_dict"
  79. voice_fims = Create FileInMemorySet from directory contents: "voices", espeakdata_dir$ + "/voices/!v", "*"
  80. selectObject: language_fims, phon_fims, dict_fims, voice_fims
  81. espeak_ng_fims = Merge
  82. .message$ = "/* espeak_ng_createFileInMemorySet.cpp" + newline$
  83. ... + " * This file was automatically created from files in directories in espeak-ng-data." + newline$
  84. ... + " * Espeak-ng version: " + espeak_version$ + "." + newline$
  85. ... + " * Date: " + date$() + "." + newline$
  86. ... + "*/" + newline$ +newline$
  87. ... + "#include ""espeakdata_FileInMemory.h""" + newline$
  88. .cpp$ = Show as code: "espeak_ng_FileInMemorySet", 30
  89. .cpp$ = .message$ + .cpp$
  90. writeInfoLine: .cpp$
  91. writeFile: todir$ + "/create_espeak_ng_FileInMemorySet.cpp", .cpp$
  92. endif
  93. procedure create_phonFileInMemorySet
  94. fim1 = Create FileInMemory: espeakdata_dir$ + "/phondata"
  95. fim2 = Create FileInMemory: espeakdata_dir$ + "/phonindex"
  96. fim3 = Create FileInMemory: espeakdata_dir$ + "/phontab"
  97. fim4 = Create FileInMemory: espeakdata_dir$ + "/intonations"
  98. fim5 = Create FileInMemory: espeakdata_dir$ + "/phondata-manifest"
  99. selectObject: fim1, fim2, fim3, fim4, fim5
  100. phon_fims = To FileInMemorySet
  101. removeObject: fim1, fim2, fim3, fim4, fim5
  102. endproc
  103. procedure create_languageFileInMemorySet
  104. language_fims = Create FileInMemorySet from directory contents: "l", espeakdata_lang_dir$, "*"
  105. .ldirs = Create Strings as directory list: "dirs", espeakdata_lang_dir$+ "/*"
  106. .ndirs = Get number of strings
  107. for .idir to .ndirs
  108. selectObject: .ldirs
  109. .dir$ = Get string: .idir
  110. .langset = Create FileInMemorySet from directory contents: "l", espeakdata_lang_dir$ + "/" + .dir$ , "*"
  111. plusObject: language_fims
  112. .merged = Merge
  113. removeObject: .langset, language_fims
  114. language_fims = .merged
  115. endfor
  116. removeObject: .ldirs
  117. endproc
  118. # extract only the necesary files to espeak-ng-work.
  119. # changes to these files have to be made in espeak-ng-current
  120. if copy_c_and_h_files
  121. @espeak_ng_copyfiles
  122. endif
  123. procedure espeak_ng_copyfiles
  124. .espeakfiles_c$ = "compiledata.c compiledict.c compilembrola.c dictionary.c" +
  125. ... " encoding.c error.c espeak_api.c espeak_command.c" +
  126. ... " event.c fifo.c ieee80.c intonation.c klatt.c" +
  127. ... " mnemonics.c numbers.c phoneme.c phonemelist.c readclause.c setlengths.c" +
  128. ... " spect.c speech.c synthdata.c synthesize.c " +
  129. ... " synth_mbrola.c translate.c tr_languages.c voices.c wavegen.c"
  130. .espeakfiles_h$ = "error.h espeak_command.h event.h fifo.h klatt.h phoneme.h sintab.h" +
  131. ... " spect.h speech.h synthesize.h translate.h voice.h synthesize.h translate.h voice.h"
  132. .espeakfiles_include_h$ = "speak_lib.h espeak_ng.h encoding.h"
  133. .espeakfiles_ucd_h$ = "ucd.h"
  134. .espeakfiles_ucd_c$ = "case.c categories.c proplist.c"
  135. # check version
  136. .config$ = readFile$ ("~/projects/espeak-ng/config.h")
  137. .version$ = extractWord$ (.config$, "#define VERSION """)
  138. .version$ = replace$ (.version$, """", "", 0)
  139. if .version$ <> espeak_version$
  140. exitScript: "The given version (", espeak_version$, ") differs from package version ", .version$
  141. endif
  142. # rename and cp files from espeak-ng to espeak-work
  143. @copy_rename: fromdir$+"/src/libespeak-ng", .espeakfiles_c$, ".c", ".cpp"
  144. @copy_rename: fromdir$+"/src/libespeak-ng", .espeakfiles_h$, ".h", ".h"
  145. @copy_rename: fromdir$+"/src/include/espeak-ng", .espeakfiles_include_h$, ".h", ".h"
  146. @copy_rename: fromdir$+"/src/ucd-tools/src", .espeakfiles_ucd_c$, ".c", ".cpp"
  147. @copy_rename: fromdir$+"/src/ucd-tools/src/include/ucd", .espeakfiles_ucd_h$, ".h", ".h"
  148. .version_define$ = "#define ESPEAK_NG_VERSION " + "U""" + espeak_version$ + """" + newline$
  149. ... + "#define ESPEAK_NG_VERSIONX " + espeak_version$
  150. writeFile: todir$ + "/espeak_ng_version.h", .version_define$
  151. endproc
  152. procedure copy_rename: .fromdir$, .files$, .ext$, .newext$
  153. .list = Create Strings as tokens: .files$
  154. .numberOfFiles = Get number of strings
  155. for .ifile to .numberOfFiles
  156. .name$ = Get string: .ifile
  157. .newname$ = .name$ - .ext$ + .newext$
  158. .command$ = "cp " + .fromdir$ + "/" + .name$ + " " + todir$ + "/" + .newname$
  159. appendInfoLine: .command$
  160. if show_cp_command
  161. appendInfoLine: .command$
  162. endif
  163. runSystem: .command$
  164. endfor
  165. endproc