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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # Map voice names to dictionaries when these do not match.
  12. special_voices = {
  13. 'bs': 'hbs',
  14. 'hr': 'hbs',
  15. 'zh-yue': 'zhy',
  16. }
  17. exclude_voices = []
  18. def find_voices(path):
  19. for filename in os.listdir(path):
  20. voice_path = os.path.join(path, filename)
  21. if os.path.isdir(voice_path):
  22. if not filename in ['!v', 'mb']:
  23. find_voices(voice_path)
  24. else:
  25. if filename in special_voices.keys():
  26. voices.add(special_voices[filename])
  27. elif filename not in exclude_voices:
  28. voices.add(filename)
  29. find_voices('espeak-data/voices')
  30. for filename in os.listdir('dictsource'):
  31. if filename.endswith('_rules') or filename.endswith('_list') or filename.endswith('_listx'):
  32. dic, cat = filename.split('_')
  33. if dic in voices:
  34. if not dic in dictionaries.keys():
  35. dictionaries[dic] = []
  36. dictionaries[dic].append('dictsource/%s' % filename)
  37. def write_dictionary_make_rules(f):
  38. f.write('##### dictionaries:\n')
  39. f.write('\n')
  40. f.write('dictionaries: \\\n')
  41. for n, name in enumerate(sorted(dictionaries.keys())):
  42. if not name in ['bo']: # espeak fails to read these voices
  43. if n == len(dictionaries.keys()) - 1:
  44. f.write('\tespeak-data/%s_dict\n' % name)
  45. else:
  46. f.write('\tespeak-data/%s_dict \\\n' % name)
  47. for name, files in sorted(dictionaries.items()):
  48. f.write('\n')
  49. f.write('%s: espeak-data/%s_dict\n' % (name, name))
  50. f.write('dictsource/%s_extra:\n' % name)
  51. f.write('\ttouch dictsource/%s_extra\n' % name)
  52. f.write('espeak-data/%s_dict: src/espeak espeak-data/phontab %s dictsource/%s_extra\n' % (name, ' '.join(sorted(files)), name))
  53. f.write('\tcd dictsource && ESPEAK_DATA_PATH=$(PWD) LD_LIBRARY_PATH=../src:${LD_LIBRARY_PATH} ../src/espeak --compile=%s && cd ..\n' % name)
  54. try:
  55. filename = sys.argv[1]
  56. except:
  57. filename = None
  58. if filename:
  59. with open(filename, 'r') as f:
  60. prelude = f.read().split('##### dictionaries:\n')[0]
  61. with open(filename, 'w') as f:
  62. f.write(prelude)
  63. write_dictionary_make_rules(f)
  64. else:
  65. write_dictionary_make_rules(sys.stdout)