| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | 
							- #!/usr/bin/python
 - #
 - # Copyright (C) 2011 Reece H. Dunn
 - # Licence: GPLv3
 - #
 - # A script for generating the dictionary Makefile rules from the files in dictsource.
 - 
 - import sys
 - import os
 - 
 - voices = set()
 - dictionaries = {}
 - phoneme_data = set()
 - 
 - # Map voice names to dictionaries when these do not match.
 - special_voices = {
 - 	'bs': 'hbs',
 - 	'hr': 'hbs',
 - 	'zh-yue': 'zhy',
 - }
 - 
 - exclude_voices = []
 - 
 - def find_voices(path):
 - 	for filename in os.listdir(path):
 - 		voice_path = os.path.join(path, filename)
 - 		if os.path.isdir(voice_path):
 - 			if not filename in ['!v', 'mb']:
 - 				find_voices(voice_path)
 - 		else:
 - 			if filename in special_voices.keys():
 - 				voices.add(special_voices[filename])
 - 			elif filename not in exclude_voices:
 - 				voices.add(filename)
 - 
 - def find_phoneme_data(path):
 - 	for filename in os.listdir(path):
 - 		phondata_path = os.path.join(path, filename)
 - 		if filename.startswith('ph_'):
 - 			phoneme_data.add(phondata_path)
 - 
 - find_voices('espeak-data/voices')
 - find_phoneme_data('phsource')
 - 
 - for filename in os.listdir('dictsource'):
 - 	if filename.endswith('_rules') or filename.endswith('_list') or filename.endswith('_listx'):
 - 		dic, cat = filename.split('_')
 - 		if dic in voices:
 - 			if not dic in dictionaries.keys():
 - 				dictionaries[dic] = []
 - 			dictionaries[dic].append('dictsource/%s' % filename)
 - 
 - def write_phoneme_data_rules(f):
 - 	f.write('##### phoneme data:\n')
 - 	f.write('\n')
 - 	f.write('espeak-data/phondata: phsource/phonemes.stamp\n')
 - 	f.write('espeak-data/phondata-manifest: phsource/phonemes.stamp\n')
 - 	f.write('espeak-data/phonindex: phsource/phonemes.stamp\n')
 - 	f.write('espeak-data/phontab: phsource/phonemes.stamp\n')
 - 	f.write('espeak-data/intonations: phsource/phonemes.stamp\n')
 - 	f.write('\n')
 - 	f.write('phsource/phonemes.stamp: \\\n')
 - 	for phonfile in phoneme_data:
 - 		f.write('\t%s \\\n' % phonfile)
 - 	f.write('\tphsource/phonemes\n')
 - 	f.write('\tESPEAK_DATA_PATH=$(PWD) src/espeakedit --compile && touch $@\n')
 - 	f.write('\n')
 - 
 - def write_dictionary_make_rules(f):
 - 	f.write('##### dictionaries:\n')
 - 	f.write('\n')
 - 	f.write('dictionaries: \\\n')
 - 	for n, name in enumerate(sorted(dictionaries.keys())):
 - 		if not name in ['bo']: # espeak fails to read these voices
 - 			if n == len(dictionaries.keys()) - 1:
 - 				f.write('\tespeak-data/%s_dict\n' % name)
 - 			else:
 - 				f.write('\tespeak-data/%s_dict \\\n' % name)
 - 	for name, files in sorted(dictionaries.items()):
 - 		f.write('\n')
 - 		f.write('%s: espeak-data/%s_dict\n' % (name, name))
 - 		f.write('dictsource/%s_extra:\n' % name)
 - 		f.write('\ttouch dictsource/%s_extra\n' % name)
 - 		f.write('espeak-data/%s_dict: src/espeak phsource/phonemes.stamp %s dictsource/%s_extra\n' % (name, ' '.join(sorted(files)), name))
 - 		f.write('\tcd dictsource && ESPEAK_DATA_PATH=$(PWD) LD_LIBRARY_PATH=../src:${LD_LIBRARY_PATH} ../src/espeak --compile=%s && cd ..\n' % name)
 - 
 - try:
 - 	filename = sys.argv[1]
 - except:
 - 	filename = None
 - 
 - if filename:
 - 	with open(filename, 'r') as f:
 - 		prelude = f.read().split('##### phoneme data:\n')[0]
 - 	with open(filename, 'w') as f:
 - 		f.write(prelude)
 - 		write_phoneme_data_rules(f)
 - 		write_dictionary_make_rules(f)
 - else:
 - 	write_phoneme_data_rules(sys.stdout)
 - 	write_dictionary_make_rules(sys.stdout)
 
 
  |