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

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