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

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