diff options
author | Lev Dragunov <lgardster@gmail.com> | 2015-10-15 15:49:31 +0300 |
---|---|---|
committer | Lev Dragunov <lgardster@gmail.com> | 2015-10-15 15:49:31 +0300 |
commit | b558d2449aff06613196785a42a0ac68358dbd4e (patch) | |
tree | 31f31a1d55c62b5522bd5415970b62e5b89c51bb /sound/tts | |
parent | 83fcafc3e932498fc25d961c4b4c3b320fa1a477 (diff) | |
parent | d320676ef8249d71bc6360fc1288671a5584b25a (diff) |
Merge pull request #250 from bykoianko/generating-cpp-list-of-supported-languages
Generating languages.hpp with TTS language supported by TTS while creating sounds.txt
Diffstat (limited to 'sound/tts')
-rwxr-xr-x | sound/tts/generate_sound_localizations.sh | 2 | ||||
-rw-r--r-- | sound/tts/languages.hpp | 49 | ||||
-rwxr-xr-x | sound/tts/languages.py | 67 | ||||
-rwxr-xr-x | sound/tts/languages_dir.py | 34 |
4 files changed, 117 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.hpp b/sound/tts/languages.hpp new file mode 100644 index 0000000000..fd15d10622 --- /dev/null +++ b/sound/tts/languages.hpp @@ -0,0 +1,49 @@ +#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, 28> const kLanguageList = +{{ + "en", + "ru", + "pl", + "sv", + "tr", + "fr", + "nl", + "de", + "ar", + "el", + "it", + "cs", + "hu", + "ro", + "ja", + "da", + "es", + "fi", + "hi", + "hr", + "in", + "ko", + "pt", + "sk", + "sw", + "th", + "zh-Hant", + "zh-Hans" +}}; +} // namespace sound +} // namespace turns +} // namespace routing 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() |