diff --git a/utils/addjson.py b/utils/addjson.py index 7fabe625e..013d14727 100755 --- a/utils/addjson.py +++ b/utils/addjson.py @@ -1,9 +1,7 @@ #!/usr/bin/env python3 # encoding: utf-8 - # Copyright 2018 Nagoya University (Tomoki Hayashi) # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) - from __future__ import print_function from __future__ import unicode_literals @@ -12,7 +10,6 @@ import codecs import json import logging import sys - from distutils.util import strtobool from espnet.utils.cli_utils import get_commandline_args @@ -23,17 +20,16 @@ is_python2 = sys.version_info[0] == 2 def get_parser(): parser = argparse.ArgumentParser( description="add multiple json values to an input or output value", - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - ) + formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument("jsons", type=str, nargs="+", help="json files") parser.add_argument( "-i", "--is-input", default=True, type=strtobool, - help="If true, add to input. If false, add to output", - ) - parser.add_argument("--verbose", "-V", default=0, type=int, help="Verbose option") + help="If true, add to input. If false, add to output", ) + parser.add_argument( + "--verbose", "-V", default=0, type=int, help="Verbose option") return parser @@ -121,7 +117,8 @@ if __name__ == "__main__": out_add_dic = {} # add shape if "odim" in adddic and "olen" in adddic: - out_add_dic["shape"] = [int(adddic["olen"]), int(adddic["odim"])] + out_add_dic[ + "shape"] = [int(adddic["olen"]), int(adddic["odim"])] elif "odim" in adddic: out_add_dic["shape"] = [int(adddic["odim"])] # add all other key value @@ -143,13 +140,13 @@ if __name__ == "__main__": # ensure "ensure_ascii=False", which is a bug jsonstring = json.dumps( - {"utts": new_dic}, + { + "utts": new_dic + }, indent=4, ensure_ascii=False, sort_keys=True, - separators=(",", ": "), - ) - sys.stdout = codecs.getwriter("utf-8")( - sys.stdout if is_python2 else sys.stdout.buffer - ) + separators=(",", ": "), ) + sys.stdout = codecs.getwriter("utf-8")(sys.stdout + if is_python2 else sys.stdout.buffer) print(jsonstring) diff --git a/utils/scp2json.py b/utils/scp2json.py index 8e8de3e08..e2a757665 100755 --- a/utils/scp2json.py +++ b/utils/scp2json.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 # encoding: utf-8 - # Copyright 2017 Johns Hopkins University (Shinji Watanabe) # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from __future__ import print_function @@ -17,8 +16,7 @@ is_python2 = sys.version_info[0] == 2 def get_parser(): parser = argparse.ArgumentParser( description="convert scp to json", - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - ) + formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument("--key", "-k", type=str, help="key") return parser @@ -28,10 +26,10 @@ if __name__ == "__main__": args = parser.parse_args() new_line = {} - sys.stdin = codecs.getreader("utf-8")(sys.stdin if is_python2 else sys.stdin.buffer) - sys.stdout = codecs.getwriter("utf-8")( - sys.stdout if is_python2 else sys.stdout.buffer - ) + sys.stdin = codecs.getreader("utf-8")(sys.stdin + if is_python2 else sys.stdin.buffer) + sys.stdout = codecs.getwriter("utf-8")(sys.stdout + if is_python2 else sys.stdout.buffer) line = sys.stdin.readline() while line: x = line.rstrip().split() @@ -43,6 +41,9 @@ if __name__ == "__main__": # ensure "ensure_ascii=False", which is a bug jsonstring = json.dumps( - all_l, indent=4, ensure_ascii=False, sort_keys=True, separators=(",", ": ") - ) + all_l, + indent=4, + ensure_ascii=False, + sort_keys=True, + separators=(",", ": ")) print(jsonstring)