eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mkdictlist 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2011 Reece H. Dunn
  4. # Licence: GPLv3
  5. #
  6. # A script for generating the dictionary Makefile rules from the files in dictsource.
  7. import sys
  8. import os
  9. voices = set()
  10. dictionaries = {}
  11. phoneme_data = set()
  12. # Map voice names to dictionaries when these do not match.
  13. special_voices = {
  14. 'bs': 'hbs',
  15. 'hr': 'hbs',
  16. 'zh-yue': 'zhy',
  17. }
  18. # Support for extended dictionaries.
  19. extended_dictionaries = {
  20. 'ru': 'ru_listx',
  21. 'zh': 'zh_listx',
  22. 'zhy': 'zhy_list',
  23. }
  24. exclude_voices = []
  25. def find_voices(path):
  26. for filename in os.listdir(path):
  27. voice_path = os.path.join(path, filename)
  28. if os.path.isdir(voice_path):
  29. if not filename in ['!v', 'mb']:
  30. find_voices(voice_path)
  31. else:
  32. if filename in special_voices.keys():
  33. voices.add(special_voices[filename])
  34. elif filename not in exclude_voices:
  35. voices.add(filename)
  36. def find_phoneme_data(path):
  37. for filename in os.listdir(path):
  38. phondata_path = os.path.join(path, filename)
  39. if filename.startswith('ph_'):
  40. phoneme_data.add(phondata_path)
  41. find_voices('espeak-data/voices')
  42. find_phoneme_data('phsource')
  43. for filename in os.listdir('dictsource'):
  44. if filename.endswith('_rules') or filename.endswith('_list') or filename in ['bg_listx', 'it_listx']:
  45. dic, cat = filename.split('_')
  46. if dic in voices:
  47. if not dic in dictionaries.keys():
  48. dictionaries[dic] = []
  49. dictionaries[dic].append('dictsource/%s' % filename)
  50. def write_phoneme_data_rules(f):
  51. f.write('##### phoneme data:\n')
  52. f.write('\n')
  53. f.write('espeak-data/phondata: phsource/phonemes.stamp\n')
  54. f.write('espeak-data/phondata-manifest: phsource/phonemes.stamp\n')
  55. f.write('espeak-data/phonindex: phsource/phonemes.stamp\n')
  56. f.write('espeak-data/phontab: phsource/phonemes.stamp\n')
  57. f.write('espeak-data/intonations: phsource/phonemes.stamp\n')
  58. f.write('\n')
  59. f.write('phsource/phonemes.stamp: \\\n')
  60. for phonfile in sorted(phoneme_data):
  61. f.write('\t%s \\\n' % phonfile)
  62. f.write('\tphsource/phonemes \\\n')
  63. f.write('\tsrc/espeakedit\n')
  64. f.write('\tESPEAK_DATA_PATH=$(PWD) src/espeakedit --compile && touch $@\n')
  65. f.write('\n')
  66. def write_dictionary_make_rules(f):
  67. f.write('##### dictionaries:\n')
  68. f.write('\n')
  69. f.write('dictionaries: \\\n')
  70. for n, name in enumerate(sorted(dictionaries.keys())):
  71. if not name in ['bo']: # espeak fails to read these voices
  72. if n == len(dictionaries.keys()) - 1:
  73. f.write('\tespeak-data/%s_dict\n' % name)
  74. else:
  75. f.write('\tespeak-data/%s_dict \\\n' % name)
  76. for name, files in sorted(dictionaries.items()):
  77. f.write('\n')
  78. f.write('%s: espeak-data/%s_dict\n' % (name, name))
  79. f.write('dictsource/%s_extra:\n' % name)
  80. f.write('\ttouch dictsource/%s_extra\n' % name)
  81. if name in extended_dictionaries.keys():
  82. ext = extended_dictionaries[name]
  83. f.write('dictsource/%s:\n' % ext)
  84. f.write('\tln -svf extra/%s dictsource/\n' % ext)
  85. f.write('if HAVE_%s_EXTENDED_DICTIONARY\n' % name.upper())
  86. f.write('espeak-data/%s_dict: src/espeak phsource/phonemes.stamp %s dictsource/%s_extra dictsource/%s\n' % (name, ' '.join(sorted(files)), name, ext))
  87. f.write('else\n')
  88. f.write('espeak-data/%s_dict: src/espeak phsource/phonemes.stamp %s dictsource/%s_extra\n' % (name, ' '.join(sorted(files)), name))
  89. if name in extended_dictionaries.keys():
  90. f.write('endif\n')
  91. f.write('\tcd dictsource && ESPEAK_DATA_PATH=$(PWD) LD_LIBRARY_PATH=../src:${LD_LIBRARY_PATH} ../src/espeak --compile=%s && cd ..\n' % name)
  92. try:
  93. filename = sys.argv[1]
  94. except:
  95. filename = None
  96. if filename:
  97. with open(filename, 'r') as f:
  98. prelude = f.read().split('##### phoneme data:\n')[0]
  99. with open(filename, 'w') as f:
  100. f.write(prelude)
  101. write_phoneme_data_rules(f)
  102. write_dictionary_make_rules(f)
  103. else:
  104. write_phoneme_data_rules(sys.stdout)
  105. write_dictionary_make_rules(sys.stdout)