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

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