diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-10-14 17:59:46 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-10-15 15:45:41 +0300 |
commit | 704dcd0c9dccac25d4317d48ce462ceda120570a (patch) | |
tree | fcc8cc2839bf375dc357c0ec6b9055f2c84ac683 | |
parent | cf025d9107ff67979a1980d41ebdccc954fba8e6 (diff) |
Generating languages.hpp with TTS language supported by TTS while creating sounds.txt
-rwxr-xr-x | sound/tts/generate_sound_localizations.sh | 2 | ||||
-rwxr-xr-x | sound/tts/languages.py | 67 | ||||
-rwxr-xr-x | sound/tts/languages_dir.py | 34 |
3 files changed, 68 insertions, 35 deletions
diff --git a/sound/tts/generate_sound_localizations.sh b/sound/tts/generate_sound_localizations.sh index f62fe5b181..cc2ef4e536 100755 --- a/sound/tts/generate_sound_localizations.sh +++ b/sound/tts/generate_sound_localizations.sh @@ -17,7 +17,7 @@ mkdir $SOUND_TMP_DIR python $MY_PATH/sound_csv_to_sound_txt.py $MY_PATH/sound.csv $MY_PATH/sound.txt $MY_PATH/languages.txt mkdir $SOUND_TMP_DIR/json -python $MY_PATH/languages_dir.py $MY_PATH/languages.txt $SOUND_TMP_DIR/json/ +python $MY_PATH/languages.py $MY_PATH/languages.txt $MY_PATH/languages.hpp $SOUND_TMP_DIR/json/ $MY_PATH/../../tools/twine/twine --format jquery generate-all-string-files $MY_PATH/sound.txt $SOUND_TMP_DIR/json readonly SOUND_OUTPUT_DIR=$MY_PATH/../../data/sound-strings/ diff --git a/sound/tts/languages.py b/sound/tts/languages.py new file mode 100755 index 0000000000..3a9b164584 --- /dev/null +++ b/sound/tts/languages.py @@ -0,0 +1,67 @@ +#!/usr/bin/python + +from __future__ import print_function +from optparse import OptionParser + +import os + +languages_hpp_template = """\ +#pragma once + +#include "std/array.hpp" +#include "std/string.hpp" + +// This file is autogenerated while exporting sounds.csv from the google table. +// It contains the list of languages which can be used by TTS. +// It shall be included to Android(jni) and iOS part to get the languages list. + +namespace routing +{{ +namespace turns +{{ +namespace sound +{{ +array<string, {lang_list_size}> const kLanguageList = +{{{{ +{lang_list} +}}}}; +}} // namespace sound +}} // namespace turns +}} // namespace routing +""" + +def parse_args(): + opt_parser = OptionParser(usage="This tool creates directories for languages for twine." + + "All directory names shall be listed in languages file with space separator.\n" + + "Example: python %prog path_to_language.txt path_to_languages.hpp path_to_dir_with_json_files", + version="%prog 1.0") + + (options, args) = opt_parser.parse_args() + + if len(args) != 3: + opt_parser.error("Wrong number of arguments.") + return args + +def make_language_dirs(langs_name, json_dir_name): + print ("Creating directories for languages in json.") + with open(langs_name, "r") as langs_file: + for lang in langs_file.read().split(): + new_dir = os.path.join(json_dir_name, lang + ".json") + if not os.path.exists(new_dir): + os.makedirs(new_dir) + +def make_languages_hpp(langs_name, hpp_name): + print ("Creating {fine_name}".format(fine_name = hpp_name)) + with open(langs_name, 'r') as langs_file: + languages_list = langs_file.read().split() + lang_str = ",\n".join([" \"{}\"".format(language) for language in languages_list]) + with open(hpp_name, "w") as hpp_file: + hpp_file.write(languages_hpp_template.format(lang_list_size = len(languages_list), lang_list = lang_str)) + +def run(): + langs_name, langs_hpp_name, json_dir_name = parse_args() + make_language_dirs(langs_name, json_dir_name) + make_languages_hpp(langs_name, langs_hpp_name) + +if __name__ == "__main__": + run() diff --git a/sound/tts/languages_dir.py b/sound/tts/languages_dir.py deleted file mode 100755 index 5e1fb1a75b..0000000000 --- a/sound/tts/languages_dir.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/python - -from __future__ import print_function -from optparse import OptionParser - -import os - - -def parse_args(): - opt_parser = OptionParser(usage="This tool creates directories for languages for twine." - + "All directory names shall be listed in languages file with space separator.\n" - + "Example: python %prog path_to_language_file.txt path_to_dir_with_json_files", - version="%prog 1.0") - - (options, args) = opt_parser.parse_args() - - if len(args) != 2: - opt_parser.error("Wrong number of arguments.") - return args - - -def run(): - langs_name, json_dir_name = parse_args() - - print ("Creating directories for languages in json.") - with open(langs_name, 'r') as langs_file: - for lang in langs_file.read().split(): - new_dir = json_dir_name + lang + '.json' - if not os.path.exists(new_dir): - os.makedirs(new_dir) - - -if __name__ == "__main__": - run() |