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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. exclude_voices = []
  19. def find_voices(path):
  20. for filename in os.listdir(path):
  21. voice_path = os.path.join(path, filename)
  22. if os.path.isdir(voice_path):
  23. if not filename in ['!v', 'mb']:
  24. find_voices(voice_path)
  25. else:
  26. if filename in special_voices.keys():
  27. voices.add(special_voices[filename])
  28. elif filename not in exclude_voices:
  29. voices.add(filename)
  30. def find_phoneme_data(path):
  31. for filename in os.listdir(path):
  32. phondata_path = os.path.join(path, filename)
  33. if filename.startswith('ph_'):
  34. phoneme_data.add(phondata_path)
  35. find_voices('espeak-data/voices')
  36. find_phoneme_data('phsource')
  37. for filename in os.listdir('dictsource'):
  38. if filename.endswith('_rules') or filename.endswith('_list') or filename.endswith('_listx'):
  39. dic, cat = filename.split('_')
  40. if dic in voices:
  41. if not dic in dictionaries.keys():
  42. dictionaries[dic] = []
  43. dictionaries[dic].append('dictsource/%s' % filename)
  44. def write_phoneme_data_rules(f):
  45. f.write('##### phoneme data:\n')
  46. f.write('\n')
  47. f.write('espeak-data/phondata: phsource/phonemes.stamp\n')
  48. f.write('espeak-data/phondata-manifest: phsource/phonemes.stamp\n')
  49. f.write('espeak-data/phonindex: phsource/phonemes.stamp\n')
  50. f.write('espeak-data/phontab: phsource/phonemes.stamp\n')
  51. f.write('espeak-data/intonations: phsource/phonemes.stamp\n')
  52. f.write('\n')
  53. f.write('phsource/phonemes.stamp: \\\n')
  54. for phonfile in sorted(phoneme_data):
  55. f.write('\t%s \\\n' % phonfile)
  56. f.write('\tphsource/phonemes\n')
  57. f.write('\tESPEAK_DATA_PATH=$(PWD) src/espeakedit --compile && touch $@\n')
  58. f.write('\n')
  59. def write_dictionary_make_rules(f):
  60. f.write('##### dictionaries:\n')
  61. f.write('\n')
  62. f.write('dictionaries: \\\n')
  63. for n, name in enumerate(sorted(dictionaries.keys())):
  64. if not name in ['bo']: # espeak fails to read these voices
  65. if n == len(dictionaries.keys()) - 1:
  66. f.write('\tespeak-data/%s_dict\n' % name)
  67. else:
  68. f.write('\tespeak-data/%s_dict \\\n' % name)
  69. for name, files in sorted(dictionaries.items()):
  70. f.write('\n')
  71. f.write('%s: espeak-data/%s_dict\n' % (name, name))
  72. f.write('dictsource/%s_extra:\n' % name)
  73. f.write('\ttouch dictsource/%s_extra\n' % name)
  74. f.write('espeak-data/%s_dict: src/espeak phsource/phonemes.stamp %s dictsource/%s_extra\n' % (name, ' '.join(sorted(files)), name))
  75. f.write('\tcd dictsource && ESPEAK_DATA_PATH=$(PWD) LD_LIBRARY_PATH=../src:${LD_LIBRARY_PATH} ../src/espeak --compile=%s && cd ..\n' % name)
  76. try:
  77. filename = sys.argv[1]
  78. except:
  79. filename = None
  80. if filename:
  81. with open(filename, 'r') as f:
  82. prelude = f.read().split('##### phoneme data:\n')[0]
  83. with open(filename, 'w') as f:
  84. f.write(prelude)
  85. write_phoneme_data_rules(f)
  86. write_dictionary_make_rules(f)
  87. else:
  88. write_phoneme_data_rules(sys.stdout)
  89. write_dictionary_make_rules(sys.stdout)