From 1fe1f3d5a530585fd5aa2b01685d0d1b28cb2f53 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sun, 8 Mar 2020 21:56:07 +0800 Subject: [PATCH 1/8] Fix #89 Google Speech-to-Text API empty result response bug --- CHANGELOG.md | 9 +++ README.md | 2 +- autosub/cmdline_utils.py | 12 ++-- autosub/constants.py | 7 ++- autosub/core.py | 38 +++++++----- .../locale/zh_CN/LC_MESSAGES/autosub.core.po | 22 +++---- .../zh_CN/LC_MESSAGES/autosub.options.po | 61 ++++++++++--------- autosub/google_speech_api.py | 58 +++++++----------- autosub/options.py | 6 +- autosub/sub_utils.py | 2 +- docs/CHANGELOG.zh-Hans.md | 9 +++ docs/README.zh-Hans.md | 3 +- 12 files changed, 122 insertions(+), 107 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68459ed6..53551682 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## TOC +- [Unreleased](#unreleased) + - [Added](#addedunreleased) + - [Changed](#changedunreleased) - [0.5.5-alpha - 2020-03-04](#055-alpha---2020-03-04) - [Added](#added055-alpha) - [Changed](#changed055-alpha) @@ -34,6 +37,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Click up arrow to go back to TOC. +### [Unreleased] + +#### Changed(unreleased) + +- Fix Google Speech-to-Text API empty result response bug. [issue #89](https://github.com/BingLingGroup/autosub/issues/89) + ### [0.5.5-alpha] - 2020-03-04 #### Added(0.5.5-alpha) diff --git a/README.md b/README.md index 5baf81a8..0c83adc8 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ To solve this problem, autosub uses [langcodes](https://github.com/LuminosoInsig To manually match or see the full list of the lang codes, run the utility with the argument `-lsc`/`--list-speech-codes` and `-ltc`/ `--list-translation-codes`. Or open [constants.py](autosub/constants.py) and check. -To get a subtitles first line language, you can use `-dsl` to detect. +To get the language of the first line of the subtitles file, you can use `-dsl` to detect. - Currently, autosub allows to send the lang codes not from the `--list-speech-codes`, which means in this case the program won't stop. diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 346f92ff..7456d2f8 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -559,19 +559,19 @@ def fix_args(args): Check that the commandline arguments value passed to autosub are proper. """ if not args.ext_regions: - if args.min_region_size < constants.MIN_REGION_SIZE: + if args.min_region_size < constants.MIN_REGION_SIZE_LIMIT: print( _("Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}.").format(mrs0=args.min_region_size, - mrs=constants.MIN_REGION_SIZE)) - args.min_region_size = constants.MIN_REGION_SIZE + mrs=constants.MIN_REGION_SIZE_LIMIT)) + args.min_region_size = constants.MIN_REGION_SIZE_LIMIT - if args.max_region_size > constants.MAX_EXT_REGION_SIZE: + if args.max_region_size > constants.MAX_REGION_SIZE_LIMIT: print( _("Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}.").format(mrs0=args.max_region_size, - mrs=constants.MAX_EXT_REGION_SIZE)) - args.max_region_size = constants.MAX_EXT_REGION_SIZE + mrs=constants.MAX_REGION_SIZE_LIMIT)) + args.max_region_size = constants.MAX_REGION_SIZE_LIMIT if args.max_continuous_silence < 0: print( diff --git a/autosub/constants.py b/autosub/constants.py index 67f1e84e..afcfcbee 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -67,10 +67,11 @@ DEFAULT_SRC_LANGUAGE = 'en-US' DEFAULT_ENERGY_THRESHOLD = 45 -MAX_REGION_SIZE = 6.0 -MIN_REGION_SIZE = 0.5 +DEFAULT_MAX_REGION_SIZE = 6.0 +DEFAULT_MIN_REGION_SIZE = 1.0 +MIN_REGION_SIZE_LIMIT = 0.5 +MAX_REGION_SIZE_LIMIT = 12.0 DEFAULT_CONTINUOUS_SILENCE = 0.3 -MAX_EXT_REGION_SIZE = 10 # Maximum speech to text region length in milliseconds # when using external speech region control diff --git a/autosub/core.py b/autosub/core.py index 1fcba69c..140bf171 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -129,8 +129,8 @@ def encoding_to_extension( # pylint: disable=too-many-branches def auditok_gen_speech_regions( # pylint: disable=too-many-arguments audio_wav, energy_threshold=constants.DEFAULT_ENERGY_THRESHOLD, - min_region_size=constants.MIN_REGION_SIZE, - max_region_size=constants.MAX_REGION_SIZE, + min_region_size=constants.DEFAULT_MIN_REGION_SIZE, + max_region_size=constants.DEFAULT_MAX_REGION_SIZE, max_continuous_silence=constants.DEFAULT_CONTINUOUS_SILENCE, mode=auditok.StreamTokenizer.STRICT_MIN_LENGTH): """ @@ -252,13 +252,16 @@ def gsv2_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many # get full result and transcript else: for i, result in enumerate(pool.imap(recognizer, audio_fragments)): - result_list.append(result) - transcript = \ - google_speech_api.get_google_speech_v2_transcript(min_confidence, result) - if transcript: - text_list.append(transcript) + if result: + result_list.append(result) + transcript = \ + google_speech_api.get_google_speech_v2_transcript(min_confidence, result) + if transcript: + text_list.append(transcript) + continue else: - text_list.append("") + result_list.append("") + text_list.append("") gc.collect(0) pbar.update(i) pbar.finish() @@ -279,7 +282,7 @@ def gsv2_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many return text_list -def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many-branches,too-many-statements +def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many-branches,too-many-statements, too-many-nested-blocks audio_fragments, sample_rate, api_url=None, @@ -341,14 +344,17 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man # get full result and transcript else: for i, result in enumerate(pool.imap(recognizer, audio_fragments)): - result_list.append(result) - transcript = google_speech_api.get_gcsv1p1beta1_transcript( - min_confidence, - result) - if transcript: - text_list.append(transcript) + if result: + result_list.append(result) + transcript = google_speech_api.get_gcsv1p1beta1_transcript( + min_confidence, + result) + if transcript: + text_list.append(transcript) + continue else: - text_list.append("") + result_list.append("") + text_list.append("") pbar.update(i) else: diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po index b8732476..59d06e02 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-04 21:37+0800\n" +"POT-Creation-Date: 2020-03-08 21:50+0800\n" "PO-Revision-Date: 2020-02-03 16:38+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -37,11 +37,11 @@ msgstr "" "\n" "将短片段语音发送给Google Speech V2 API并得到识别结果。" -#: autosub/core.py:237 autosub/core.py:303 +#: autosub/core.py:237 autosub/core.py:306 msgid "Speech-to-Text: " msgstr "语音转文字中: " -#: autosub/core.py:275 autosub/core.py:418 +#: autosub/core.py:278 autosub/core.py:424 msgid "" "Error: Connection error happened too many times.\n" "All works done." @@ -49,7 +49,7 @@ msgstr "" "错误:过多连接错误。\n" "做完了。" -#: autosub/core.py:301 +#: autosub/core.py:304 msgid "" "\n" "Sending short-term fragments to Google Cloud Speech V1P1Beta1 API and " @@ -58,11 +58,11 @@ msgstr "" "\n" "将短片段语音发送给Google Cloud Speech V1P1Beta1 API并得到识别结果。" -#: autosub/core.py:426 +#: autosub/core.py:432 msgid "Receive something unexpected:" msgstr "收到未预期数据:" -#: autosub/core.py:449 +#: autosub/core.py:455 msgid "" "\n" "Translating text from \"{0}\" to \"{1}\"." @@ -70,24 +70,24 @@ msgstr "" "\n" "从\"{0}\"翻译为\"{1}\"。" -#: autosub/core.py:499 +#: autosub/core.py:505 msgid "Translation: " msgstr "翻译中: " -#: autosub/core.py:562 +#: autosub/core.py:568 msgid "Cancelling translation." msgstr "取消翻译。" -#: autosub/core.py:635 autosub/core.py:694 +#: autosub/core.py:641 autosub/core.py:700 msgid "Format \"{fmt}\" not supported. Use \"{default_fmt}\" instead." msgstr "不支持格式\"{fmt}\"。改用\"{default_fmt}\"。" -#: autosub/core.py:767 +#: autosub/core.py:773 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/core.py:770 +#: autosub/core.py:776 msgid "Input a new path (including directory and file name) for output file.\n" msgstr "为输出文件输入一个新的路径(包括路径和文件名)。\n" diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po index 94b1fbdc..248524a5 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-03 15:58+0800\n" +"POT-Creation-Date: 2020-03-08 21:07+0800\n" "PO-Revision-Date: 2020-03-03 15:58+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -169,7 +169,8 @@ msgstr "" "项提供的样式。更多信息详见\"-sn\"/\"--styles-name\"。(参数个数为0或1)" #: autosub/options.py:128 -msgid "style-name" +#, fuzzy +msgid "style_name" msgstr "样式名" #: autosub/options.py:129 @@ -197,8 +198,8 @@ msgstr "语言代码" msgid "" "Lang code/Lang tag for speech-to-text. Recommend using the Google Cloud " "Speech reference lang codes. WRONG INPUT WON'T STOP RUNNING. But use it at " -"your own risk. Ref: https://cloud.google.com/speech-to-text/docs/" -"languages(arg_num = 1) (default: %(default)s)" +"your own risk. Ref: https://cloud.google.com/speech-to-text/docs/languages" +"(arg_num = 1) (default: %(default)s)" msgstr "" "用于语音识别的语言代码/语言标识符。推荐使用Google Cloud Speech的参考语言代" "码。错误的输入不会终止程序。但是后果自负。参考:https://cloud.google.com/" @@ -214,8 +215,8 @@ msgid "" msgstr "" "用于翻译的源语言的语言代码/语言标识符。如果没有提供,会使用langcodes从列表里" "获取一个最佳匹配选项\"-S\"/\"--speech-language\"的语言代码。如果使用py-" -"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数" -"为%(default)s)" +"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数为%" +"(default)s)" #: autosub/options.py:164 #, python-format @@ -373,8 +374,8 @@ msgid "" msgstr "" "API用于识别可信度的回应参数。一个介于0和1之间的浮点数。可信度越高意味着结果越" "好。输入这个参数会导致所有低于这个结果的识别结果被删除。参考:https://github." -"com/BingLingGroup/google-speech-v2#response(参数个数为1)(默认参数" -"为%(default)s)" +"com/BingLingGroup/google-speech-v2#response(参数个数为1)(默认参数为%" +"(default)s)" #: autosub/options.py:306 msgid "Drop any regions without speech recognition result. (arg_num = 0)" @@ -399,8 +400,8 @@ msgid "" "(Experimental)Seconds to sleep between two translation requests. (arg_num = " "1) (default: %(default)s)" msgstr "" -"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数" -"为%(default)s)" +"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" +"(default)s)" #: autosub/options.py:330 msgid "" @@ -481,8 +482,8 @@ msgid "" msgstr "" "设置服务账号密钥的环境变量。应该是包含服务帐号凭据的JSON文件的文件路径。如果" "使用了,会被API密钥选项覆盖。参考:https://cloud.google.com/docs/" -"authentication/getting-started 当前支持:" -"gcsv1(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" +"authentication/getting-started 当前支持:gcsv1" +"(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" #: autosub/options.py:410 msgid "" @@ -532,13 +533,13 @@ msgstr "" #, python-format msgid "" "(Experimental)This arg will override the default audio conversion command. " -"\"[\", \"]\" are optional arguments meaning you can remove them. \"{{\", " -"\"}}\" are required arguments meaning you can't remove them. (arg_num = 1) " +"\"[\", \"]\" are optional arguments meaning you can remove them. \"{{\", \"}}" +"\" are required arguments meaning you can't remove them. (arg_num = 1) " "(default: %(default)s)" msgstr "" "(实验性)这个参数会取代默认的音频转换命令。\"[\", \"]\" 是可选参数,可以移" -"除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数" -"为%(default)s)" +"除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数为%(default)" +"s)" #: autosub/options.py:471 #, python-format @@ -559,8 +560,8 @@ msgid "" "(Experimental)This arg will override the default API audio suffix. (arg_num " "= 1) (default: %(default)s)" msgstr "" -"(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数" -"为%(default)s)" +"(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数为%(default)" +"s)" #: autosub/options.py:486 msgid "sample_rate" @@ -608,16 +609,16 @@ msgstr "" msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数" -"为%(default)s)" +"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" +"s)" #: autosub/options.py:526 #, python-format msgid "" "Maximum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数" -"为%(default)s)" +"最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" +"s)" #: autosub/options.py:535 #, python-format @@ -706,26 +707,26 @@ msgstr "" #~ "googletrans。(参数个数为1)" #~ msgid "" -#~ "Number of lines per Google Translate V2 request. (arg_num = 1) (default: " -#~ "%(default)s)" +#~ "Number of lines per Google Translate V2 request. (arg_num = 1) (default: %" +#~ "(default)s)" #~ msgstr "" -#~ "Google Translate V2请求的每行行数。(参数个数为1)(默认参数" -#~ "为%(default)s)" +#~ "Google Translate V2请求的每行行数。(参数个数为1)(默认参数为%(default)" +#~ "s)" #~ msgid "" #~ "Number of concurrent Google translate V2 API requests to make. (arg_num = " #~ "1) (default: %(default)s)" #~ msgstr "" -#~ "Google translate V2 API请求的并行数量。(参数个数为1)(默认参数" -#~ "为%(default)s)" +#~ "Google translate V2 API请求的并行数量。(参数个数为1)(默认参数为%" +#~ "(default)s)" #~ msgid "" #~ "Output more files. Available types: regions, src, dst, bilingual, all. (4 " #~ ">= arg_num >= 1) (default: %(default)s)" #~ msgstr "" #~ "输出更多的文件。可选种类:regions, src, dst, bilingual, all.(时间轴,源语" -#~ "言字幕,目标语言字幕,双语字幕,所有)(参数个数在4和1之间)(默认参数" -#~ "为%(default)s)" +#~ "言字幕,目标语言字幕,双语字幕,所有)(参数个数在4和1之间)(默认参数为%" +#~ "(default)s)" #~ msgid "" #~ "The Google Speech V2 API key to be used. If not provided, use free API " diff --git a/autosub/google_speech_api.py b/autosub/google_speech_api.py index feb50453..f38110c7 100644 --- a/autosub/google_speech_api.py +++ b/autosub/google_speech_api.py @@ -70,8 +70,12 @@ def get_gcsv1p1beta1_transcript( return None else: - raise exceptions.SpeechToTextException( - json.dumps(result_dict, indent=4, ensure_ascii=False)) + if not result_dict: + # if api returned empty json, don't throw the exception + return None + else: + raise exceptions.SpeechToTextException( + json.dumps(result_dict, indent=4, ensure_ascii=False)) if 'confidence' in result_dict: confidence = \ @@ -123,43 +127,27 @@ def __call__(self, filename): except requests.exceptions.ConnectionError: continue - if not self.is_full_result: - # receive several results delimited by LF - result_str = result.content.decode('utf-8').split("\n") - # get the one with valid content - for line in result_str: - try: - line_dict = json.loads(line) - transcript = get_google_speech_v2_transcript( - self.min_confidence, - line_dict) - if transcript: - # make sure it is the valid transcript + # receive several results delimited by LF + result_str = result.content.decode('utf-8').split("\n") + # get the one with valid content + for line in result_str: + try: + line_dict = json.loads(line) + transcript = get_google_speech_v2_transcript( + self.min_confidence, + line_dict) + if transcript: + # make sure it is the valid transcript + if not self.is_full_result: return transcript + return line_dict - except (ValueError, IndexError): - # no result - continue - - else: - result_str = result.content.decode('utf-8').split("\n") - for line in result_str: - try: - line_dict = json.loads(line) - transcript = get_google_speech_v2_transcript( - self.min_confidence, - line_dict) - if transcript: - # make sure it is the result with valid transcript - return line_dict - - except (ValueError, IndexError): - # no result - continue + except (ValueError, IndexError): + # no result + continue # Every line of the result can't be loaded to json - raise exceptions.SpeechToTextException( - result_str) + return None except KeyboardInterrupt: return None diff --git a/autosub/options.py b/autosub/options.py index 70083c7a..0710631f 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -125,7 +125,7 @@ def get_cmd_args(): # pylint: disable=too-many-statements input_group.add_argument( '-sn', '--styles-name', - nargs='*', metavar=_('style-name'), + nargs='*', metavar=_('style_name'), help=_("Valid when your output format is \"ass\"/\"ssa\" " "and \"-sty\"/\"--styles\" is given. " "Adds \"ass\"/\"ssa\" styles to your events. " @@ -513,7 +513,7 @@ def get_cmd_args(): # pylint: disable=too-many-statements '-mnrs', '--min-region-size', metavar=_('second'), type=float, - default=constants.MIN_REGION_SIZE, + default=constants.DEFAULT_MIN_REGION_SIZE, help=_("Minimum region size. " "Same docs above. " "(arg_num = 1) (default: %(default)s)")) @@ -522,7 +522,7 @@ def get_cmd_args(): # pylint: disable=too-many-statements '-mxrs', '--max-region-size', metavar=_('second'), type=float, - default=constants.MAX_REGION_SIZE, + default=constants.DEFAULT_MAX_REGION_SIZE, help=_("Maximum region size. " "Same docs above. " "(arg_num = 1) (default: %(default)s)")) diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 72a13ced..9168e7d6 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -18,7 +18,7 @@ def sub_to_speech_regions( audio_wav, sub_file, - ext_max_size_ms=constants.MAX_EXT_REGION_SIZE * 1000): + ext_max_size_ms=constants.MAX_REGION_SIZE_LIMIT * 1000): """ Give an input audio_wav file and subtitles file and generate proper speech regions. """ diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index bc21beae..b49cecb9 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -8,6 +8,9 @@ ## 目录 +- [未发布](#未发布) + - [添加](#添加未发布) + - [改动](#修改未发布) - [0.5.5-alpha - 2020-03-04](#055-alpha---2020-03-04) - [添加](#添加055-alpha) - [改动](#改动055-alpha) @@ -33,6 +36,12 @@ 点击上箭头以返回目录。 +### [未发布](未发布) + +#### 改动(未发布) + +- 修复Google Speech-to-Text API空结果返回bug。[issue #89](https://github.com/BingLingGroup/autosub/issues/89) + ### [0.5.5-alpha] - 2020-03-04 #### 添加(0.5.5-alpha) diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md index 27b330d7..24a36124 100644 --- a/docs/README.zh-Hans.md +++ b/docs/README.zh-Hans.md @@ -158,7 +158,7 @@ pip install autosub 建议:`Shift - 右键`是打开当前目录Powershell的快捷键。Powershell打开当前目录的exe需要输入这样的格式`.\autosub`。 - 发布包里没有pyinstaller后缀的是Nuitka编译的。它比pyinstaller的版本快,因为它是编译的,不同于pyinstaller只是把程序进行了打包。 -- ffmpeg和ffmpeg-normalize也在发布包内。原本ffmpeg-normalize没有独立运行的版本。这个独立运行的ffmpeg-normalize是另外构建的。代码在[这里]((https://github.com/BingLingGroup/ffmpeg-normalize))。 +- ffmpeg和ffmpeg-normalize也在发布包内。原本ffmpeg-normalize没有独立运行的版本。这个独立运行的ffmpeg-normalize是另外构建的。代码在[这里](https://github.com/BingLingGroup/ffmpeg-normalize)。 - 如果在使用发布包时遇到任何问题,或者包的大小太大或者遇到了什么烦人的事情,你依然可以采用下方所说的通过pip的方法进行安装。 或者通过choco来安装Python环境(如果你还没有),然后安装这个包。 @@ -297,6 +297,7 @@ OUTPUT_FORMAT = { DEFAULT_MODE_SET = { 'regions', 'src', + 'full-src', 'dst', 'bilingual', 'dst-lf-src', From 41b7c4ef49b6d1469c8f8fb7c6a04a22946e7035 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Thu, 12 Mar 2020 11:13:29 +0800 Subject: [PATCH 2/8] Fix translation codes detection prompt issue Update bug_report.md Remove requirements update in create_release.py --- .github/ISSUE_TEMPLATE/bug_report.md | 12 +-- .github/ISSUE_TEMPLATE/bug_report.zh-Hans.md | 10 ++- autosub/cmdline_utils.py | 18 ++-- autosub/constants.py | 4 +- .../LC_MESSAGES/autosub.cmdline_utils.po | 85 +++++++++++++------ .../zh_CN/LC_MESSAGES/autosub.options.po | 59 +++++++------ scripts/create_release.py | 28 +++--- 7 files changed, 126 insertions(+), 90 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 8f6630f2..92357f06 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -14,13 +14,14 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Command line arguments you are using. -2. A complete copy of command line output of the autosub. You can use `Ctrl-A` and `Ctrl-C` to copy all of them. Use the following markdown code block syntax is recommended. +2. A complete copy of command line output of the autosub. You can use `Ctrl-A` and `Ctrl-C` to copy all of them. Use the following markdown code block syntax is recommended. Copy them into the place between \`\`\`. ``` ``` -3. etc. +3. etc. **Expected behavior** A clear and concise description of what you expected to happen. @@ -29,9 +30,10 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. But it is not recommended using screenshots to demonstrate the commandline output unless you think it really matters. **Environment (please complete the following information):** - - OS: [e.g. windows] - - Python Version: [e.g. Python 2.7] - - Autosub Version: [e.g. 0.4.0] + +- OS: [e.g. windows] +- Python Version: [e.g. Python 2.7] +- Autosub Version: [e.g. 0.4.1-alpha/0.5.4-alpha Nuitka windows release] **Additional context** (Optional) Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/bug_report.zh-Hans.md b/.github/ISSUE_TEMPLATE/bug_report.zh-Hans.md index 0a1147e3..8ee53364 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.zh-Hans.md +++ b/.github/ISSUE_TEMPLATE/bug_report.zh-Hans.md @@ -14,8 +14,9 @@ assignees: '' **复现问题** 复现问题的步骤: + 1. 你使用的命令行参数。 -2. 一份完整的autosub命令行输出。你可以使用`Ctrl-A`和`Ctrl-C`去复制所有输出。推荐使用以下的代码块markdown语法。 +2. 一份完整的autosub命令行输出。你可以使用`Ctrl-A`和`Ctrl-C`去复制所有输出。推荐使用以下的代码块markdown语法,将代码块复制到\`\`\`和\`\`\`之间即可。 ``` ``` @@ -29,9 +30,10 @@ assignees: '' 合适的话可以提供用以描述问题的截图。但是不推荐用截图来展示命令行输出,除非你真的认为这很有必要。 **操作环境(请提供以下完整数据):** - - 操作系统: [譬如 windows] - - Python版本: [譬如 Python 2.7] - - Autosub版本: [譬如 0.4.0] + +- 操作系统: [譬如 windows] +- Python版本: [譬如 Python 2.7] +- Autosub版本: [譬如 0.4.1-alpha或0.5.4-alpha Nuitka windows发布版] **额外信息**(可选) 任何其他的能描述问题的信息。 diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 7456d2f8..1469e244 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -322,7 +322,7 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret if args.speech_language \ not in constants.SPEECH_TO_TEXT_LANGUAGE_CODES: print( - _("Warning: Speech language \"{src}\" not recommended. " + _("Warning: Speech language \"{src}\" is not recommended. " "Run with \"-lsc\"/\"--list-speech-codes\" " "to see all supported languages.").format(src=args.speech_language)) if args.best_match and 's' in args.best_match: @@ -378,8 +378,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret if not is_src_matched: if args.best_match and 'src' in args.best_match: print( - _("Warning: Source language \"{src}\" not supported. " - "Run with \"-lsc\"/\"--list-translation-codes\" " + _("Warning: Translation source language \"{src}\" is not supported. " + "Run with \"-ltc\"/\"--list-translation-codes\" " "to see all supported languages.").format(src=args.src_language)) best_result = lang_code_utils.match_print( dsr_lang=args.src_language, @@ -397,8 +397,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret else: raise exceptions.AutosubException( - _("Error: Source language \"{src}\" not supported. " - "Run with \"-lsc\"/\"--list-translation-codes\" " + _("Error: Translation source language \"{src}\" is not supported. " + "Run with \"-ltc\"/\"--list-translation-codes\" " "to see all supported languages. " "Or use \"-bm\"/\"--best-match\" to get a best match.").format( src=args.src_language)) @@ -406,8 +406,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret if not is_dst_matched: if args.best_match and 'd' in args.best_match: print( - _("Warning: Destination language \"{dst}\" not supported. " - "Run with \"-lsc\"/\"--list-translation-codes\" " + _("Warning: Translation destination language \"{dst}\" is not supported. " + "Run with \"-ltc\"/\"--list-translation-codes\" " "to see all supported languages.").format(dst=args.dst_language)) best_result = lang_code_utils.match_print( dsr_lang=args.dst_language, @@ -425,8 +425,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret else: raise exceptions.AutosubException( - _("Error: Destination language \"{dst}\" not supported. " - "Run with \"-lsc\"/\"--list-translation-codes\" " + _("Error: Translation destination language \"{dst}\" is not supported. " + "Run with \"-ltc\"/\"--list-translation-codes\" " "to see all supported languages. " "Or use \"-bm\"/\"--best-match\" to get a best match.").format( dst=args.dst_language)) diff --git a/autosub/constants.py b/autosub/constants.py index afcfcbee..f4af1899 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -27,8 +27,6 @@ } # Ref: https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html#Locale-Names -ENCODING = 'UTF-8' - if getattr(sys, 'frozen', False): # If the application is run as a bundle, the pyInstaller bootloader # extends the sys module by a flag frozen=True and sets the app @@ -67,7 +65,7 @@ DEFAULT_SRC_LANGUAGE = 'en-US' DEFAULT_ENERGY_THRESHOLD = 45 -DEFAULT_MAX_REGION_SIZE = 6.0 +DEFAULT_MAX_REGION_SIZE = 8.0 DEFAULT_MIN_REGION_SIZE = 1.0 MIN_REGION_SIZE_LIMIT = 0.5 MAX_REGION_SIZE_LIMIT = 12.0 diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po index 7e9b27cf..24efedd0 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-04 21:39+0800\n" -"PO-Revision-Date: 2020-03-04 21:39+0800\n" +"POT-Creation-Date: 2020-03-12 11:08+0800\n" +"PO-Revision-Date: 2020-03-12 11:10+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -140,7 +140,7 @@ msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" #: autosub/cmdline_utils.py:325 msgid "" -"Warning: Speech language \"{src}\" not recommended. Run with \"-lsc\"/\"--" +"Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" "list-speech-codes\" to see all supported languages." msgstr "" "警告:语音语言\"{src}\"不在推荐的清单里面。用\"-lsc\"/\"--list-speech-codes" @@ -176,46 +176,45 @@ msgstr "翻译目的语言未提供。只进行语音识别。" msgid "Source language not provided. Use Speech language instead." msgstr "翻译源语言未提供。改用语音语言。" -#: autosub/cmdline_utils.py:381 autosub/cmdline_utils.py:488 +#: autosub/cmdline_utils.py:381 msgid "" -"Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" -"translation-codes\" to see all supported languages." +"Warning: Translation source language \"{src}\" is not supported. Run with \"-" +"ltc\"/\"--list-translation-codes\" to see all supported languages." msgstr "" -"警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" -"codes\"选项运行来查看所有支持的语言。" +"警告:翻译源语言\"{src}\"不在推荐的清单里面。用 \"-ltc\"/\"--list-" +"translation-codes\"选项运行来查看所有支持的语言。" #: autosub/cmdline_utils.py:394 autosub/cmdline_utils.py:422 #: autosub/cmdline_utils.py:500 autosub/cmdline_utils.py:527 msgid "Match failed. Still using \"{lang_code}\". Program stopped." msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" -#: autosub/cmdline_utils.py:400 autosub/cmdline_utils.py:506 +#: autosub/cmdline_utils.py:400 msgid "" -"Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" -"translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" -"match\" to get a best match." +"Error: Translation source language \"{src}\" is not supported. Run with \"-" +"ltc\"/\"--list-translation-codes\" to see all supported languages. Or use \"-" +"bm\"/\"--best-match\" to get a best match." msgstr "" -"警告:源语言\"{src}\"不在推荐的清单里面。用\"-lsc\"/\"--list-translation-" +"警告:翻译源语言\"{src}\"不在推荐的清单里面。用\"-ltc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:409 autosub/cmdline_utils.py:515 +#: autosub/cmdline_utils.py:409 msgid "" -"Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" -"list-translation-codes\" to see all supported languages." +"Warning: Translation destination language \"{dst}\" is not supported. Run " +"with \"-ltc\"/\"--list-translation-codes\" to see all supported languages." msgstr "" -"警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" -"行来查看所有支持的语言。" +"警告:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" +"项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:428 autosub/cmdline_utils.py:533 +#: autosub/cmdline_utils.py:428 msgid "" -"Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" -"list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" -"best-match\" to get a best match." +"Error: Translation destination language \"{dst}\" is not supported. Run with " +"\"-ltc\"/\"--list-translation-codes\" to see all supported languages. Or use " +"\"-bm\"/\"--best-match\" to get a best match." msgstr "" -"错误:不支持输出的字幕格式\"{dst}\"。用\"-lf\"/\"--list-formats\"选项运行来查" -"看所有支持的格式。\n" -"或者使用ffmpeg或者SubtitleEdit来转换格式。" +"错误:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" +"项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最佳匹配。" #: autosub/cmdline_utils.py:437 msgid "" @@ -239,6 +238,42 @@ msgstr "错误:外部时间轴文件未提供。" msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" +#: autosub/cmdline_utils.py:488 +msgid "" +"Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" +"translation-codes\" to see all supported languages." +msgstr "" +"警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" +"codes\"选项运行来查看所有支持的语言。" + +#: autosub/cmdline_utils.py:506 +msgid "" +"Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" +"translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" +"match\" to get a best match." +msgstr "" +"警告:源语言\"{src}\"不在推荐的清单里面。用\"-lsc\"/\"--list-translation-" +"codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" +"佳匹配。" + +#: autosub/cmdline_utils.py:515 +msgid "" +"Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" +"list-translation-codes\" to see all supported languages." +msgstr "" +"警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" +"行来查看所有支持的语言。" + +#: autosub/cmdline_utils.py:533 +msgid "" +"Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" +"list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" +"best-match\" to get a best match." +msgstr "" +"错误:不支持输出的字幕格式\"{dst}\"。用\"-lf\"/\"--list-formats\"选项运行来查" +"看所有支持的格式。\n" +"或者使用ffmpeg或者SubtitleEdit来转换格式。" + #: autosub/cmdline_utils.py:541 msgid "Error: Source language is the same as the Destination language." msgstr "错误:源语言和目的语言一致。" diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po index 248524a5..f84a0068 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2020-03-08 21:07+0800\n" -"PO-Revision-Date: 2020-03-03 15:58+0800\n" +"PO-Revision-Date: 2020-03-09 17:27+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -169,7 +169,6 @@ msgstr "" "项提供的样式。更多信息详见\"-sn\"/\"--styles-name\"。(参数个数为0或1)" #: autosub/options.py:128 -#, fuzzy msgid "style_name" msgstr "样式名" @@ -198,8 +197,8 @@ msgstr "语言代码" msgid "" "Lang code/Lang tag for speech-to-text. Recommend using the Google Cloud " "Speech reference lang codes. WRONG INPUT WON'T STOP RUNNING. But use it at " -"your own risk. Ref: https://cloud.google.com/speech-to-text/docs/languages" -"(arg_num = 1) (default: %(default)s)" +"your own risk. Ref: https://cloud.google.com/speech-to-text/docs/" +"languages(arg_num = 1) (default: %(default)s)" msgstr "" "用于语音识别的语言代码/语言标识符。推荐使用Google Cloud Speech的参考语言代" "码。错误的输入不会终止程序。但是后果自负。参考:https://cloud.google.com/" @@ -215,8 +214,8 @@ msgid "" msgstr "" "用于翻译的源语言的语言代码/语言标识符。如果没有提供,会使用langcodes从列表里" "获取一个最佳匹配选项\"-S\"/\"--speech-language\"的语言代码。如果使用py-" -"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数为%" -"(default)s)" +"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数" +"为%(default)s)" #: autosub/options.py:164 #, python-format @@ -374,8 +373,8 @@ msgid "" msgstr "" "API用于识别可信度的回应参数。一个介于0和1之间的浮点数。可信度越高意味着结果越" "好。输入这个参数会导致所有低于这个结果的识别结果被删除。参考:https://github." -"com/BingLingGroup/google-speech-v2#response(参数个数为1)(默认参数为%" -"(default)s)" +"com/BingLingGroup/google-speech-v2#response(参数个数为1)(默认参数" +"为%(default)s)" #: autosub/options.py:306 msgid "Drop any regions without speech recognition result. (arg_num = 0)" @@ -400,8 +399,8 @@ msgid "" "(Experimental)Seconds to sleep between two translation requests. (arg_num = " "1) (default: %(default)s)" msgstr "" -"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" -"(default)s)" +"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数" +"为%(default)s)" #: autosub/options.py:330 msgid "" @@ -482,8 +481,8 @@ msgid "" msgstr "" "设置服务账号密钥的环境变量。应该是包含服务帐号凭据的JSON文件的文件路径。如果" "使用了,会被API密钥选项覆盖。参考:https://cloud.google.com/docs/" -"authentication/getting-started 当前支持:gcsv1" -"(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" +"authentication/getting-started 当前支持:" +"gcsv1(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" #: autosub/options.py:410 msgid "" @@ -533,13 +532,13 @@ msgstr "" #, python-format msgid "" "(Experimental)This arg will override the default audio conversion command. " -"\"[\", \"]\" are optional arguments meaning you can remove them. \"{{\", \"}}" -"\" are required arguments meaning you can't remove them. (arg_num = 1) " +"\"[\", \"]\" are optional arguments meaning you can remove them. \"{{\", " +"\"}}\" are required arguments meaning you can't remove them. (arg_num = 1) " "(default: %(default)s)" msgstr "" "(实验性)这个参数会取代默认的音频转换命令。\"[\", \"]\" 是可选参数,可以移" -"除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数为%(default)" -"s)" +"除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数" +"为%(default)s)" #: autosub/options.py:471 #, python-format @@ -560,8 +559,8 @@ msgid "" "(Experimental)This arg will override the default API audio suffix. (arg_num " "= 1) (default: %(default)s)" msgstr "" -"(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数为%(default)" -"s)" +"(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数" +"为%(default)s)" #: autosub/options.py:486 msgid "sample_rate" @@ -609,16 +608,16 @@ msgstr "" msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" -"s)" +"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数" +"为%(default)s)" #: autosub/options.py:526 #, python-format msgid "" "Maximum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" -"s)" +"最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数" +"为%(default)s)" #: autosub/options.py:535 #, python-format @@ -707,26 +706,26 @@ msgstr "" #~ "googletrans。(参数个数为1)" #~ msgid "" -#~ "Number of lines per Google Translate V2 request. (arg_num = 1) (default: %" -#~ "(default)s)" +#~ "Number of lines per Google Translate V2 request. (arg_num = 1) (default: " +#~ "%(default)s)" #~ msgstr "" -#~ "Google Translate V2请求的每行行数。(参数个数为1)(默认参数为%(default)" -#~ "s)" +#~ "Google Translate V2请求的每行行数。(参数个数为1)(默认参数" +#~ "为%(default)s)" #~ msgid "" #~ "Number of concurrent Google translate V2 API requests to make. (arg_num = " #~ "1) (default: %(default)s)" #~ msgstr "" -#~ "Google translate V2 API请求的并行数量。(参数个数为1)(默认参数为%" -#~ "(default)s)" +#~ "Google translate V2 API请求的并行数量。(参数个数为1)(默认参数" +#~ "为%(default)s)" #~ msgid "" #~ "Output more files. Available types: regions, src, dst, bilingual, all. (4 " #~ ">= arg_num >= 1) (default: %(default)s)" #~ msgstr "" #~ "输出更多的文件。可选种类:regions, src, dst, bilingual, all.(时间轴,源语" -#~ "言字幕,目标语言字幕,双语字幕,所有)(参数个数在4和1之间)(默认参数为%" -#~ "(default)s)" +#~ "言字幕,目标语言字幕,双语字幕,所有)(参数个数在4和1之间)(默认参数" +#~ "为%(default)s)" #~ msgid "" #~ "The Google Speech V2 API key to be used. If not provided, use free API " diff --git a/scripts/create_release.py b/scripts/create_release.py index e4f7b83e..4d00fb18 100644 --- a/scripts/create_release.py +++ b/scripts/create_release.py @@ -87,20 +87,20 @@ def copytree(src, if os.path.isdir(target_pyi): shutil.rmtree(target_pyi) os.makedirs(target_pyi) - command = "pipreqs --encoding=utf-8 --force --savepath requirements.txt {}".format(package_name) - print(command) - if sys.platform.startswith('win'): - args = command - else: - args = shlex.split(command) - p = subprocess.Popen(args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - out, err = p.communicate() - if out: - print(out.decode(sys.stdout.encoding)) - if err: - print(err.decode(sys.stdout.encoding)) + # command = "pipreqs --encoding=utf-8 --force --savepath requirements.txt {}".format(package_name) + # print(command) + # if sys.platform.startswith('win'): + # args = command + # else: + # args = shlex.split(command) + # p = subprocess.Popen(args, + # stdout=subprocess.PIPE, + # stderr=subprocess.PIPE) + # out, err = p.communicate() + # if out: + # print(out.decode(sys.stdout.encoding)) + # if err: + # print(err.decode(sys.stdout.encoding)) copytree(src=here, dst=target, exts=[".md", ".txt"]) target_docs = os.path.join(target, "docs") os.makedirs(target_docs) From 8ecbb045e30c00a841f4938861f2035bf8395aa3 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Thu, 12 Mar 2020 12:17:19 +0800 Subject: [PATCH 3/8] Refactor translation codes detection prompts --- README.md | 2 +- autosub/cmdline_utils.py | 66 +++--- .../LC_MESSAGES/autosub.cmdline_utils.po | 202 ++++++++++-------- docs/README.zh-Hans.md | 2 +- 4 files changed, 142 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index 0c83adc8..2019b88d 100644 --- a/README.md +++ b/README.md @@ -266,7 +266,7 @@ To get the language of the first line of the subtitles file, you can use `-dsl` - Though you can input the speech lang code whatever you want, need to point out that if not using the codes on the list but somehow the API accept it, [Google-Speech-v2](https://github.com/gillesdemey/google-speech-v2) recognizes your audio in the ways that depend on your IP address which is uncontrollable by yourself. This is a known issue and I ask for a [pull request](https://github.com/agermanidis/autosub/pull/136) in the original repo. -- On the other hand, [py-googletrans](https://github.com/ssut/py-googletrans) is stricter. When it receive a lang code not on its list, it will throw an exception. Of course it can be designed as a throw-catch code block and ask user to input once again but currently I don't add this support so an improper translation lang code input will stop the program running unless you use the best match method mentioned above. +- On the other hand, [py-googletrans](https://github.com/ssut/py-googletrans) is stricter. When it receive a lang code not on its list, it will throw an exception and stop translation. - Apart from the user input, another notable change is I split the `-S` option into two parts, `-S` and `-SRC`. `-S` option is for speech recognition lang code. `-SRC` is for translation source language. When not offering the arg of `-SRC`, autosub will automatically match the `-S` arg by using [langcodes](https://github.com/LuminosoInsight/langcodes) and get a best-match lang code for translation source language though [py-googletrans](https://github.com/ssut/py-googletrans) can auto-detect source language. Of course you can manually specify one by input `-SRC` option. `-D` is for translation destination language, still the same as before. diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 1469e244..03c7b8b8 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -89,7 +89,7 @@ def list_args(args): column_1=lang_code_utils.wjust(code, 18), column_2=language)) else: - print(_("Match Google Speech V2 lang codes.")) + print(_("Match Google Speech-to-Text lang codes.")) lang_code_utils.match_print( dsr_lang=args.list_speech_codes, match_list=list(constants.SPEECH_TO_TEXT_LANGUAGE_CODES.keys()), @@ -321,11 +321,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret args.speech_language = args.speech_language.lower() if args.speech_language \ not in constants.SPEECH_TO_TEXT_LANGUAGE_CODES: - print( - _("Warning: Speech language \"{src}\" is not recommended. " - "Run with \"-lsc\"/\"--list-speech-codes\" " - "to see all supported languages.").format(src=args.speech_language)) if args.best_match and 's' in args.best_match: + print(_("Let speech lang code to match Google Speech-to-Text lang codes.")) best_result = lang_code_utils.match_print( dsr_lang=args.speech_language, match_list=list(constants.SPEECH_TO_TEXT_LANGUAGE_CODES.keys()), @@ -336,9 +333,14 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret print(_("Use \"{lang_code}\" instead.").format( lang_code=args.speech_language)) else: - print( - _("Match failed. Still using \"{lang_code}\".").format( - lang_code=args.speech_language)) + print(_("Match failed. Still using \"{lang_code}\".").format( + lang_code=args.speech_language)) + else: + print(_("Warning: Speech language \"{src}\" is not recommended. " + "Run with \"-lsc\"/\"--list-speech-codes\" " + "to see all supported languages. " + "Or use \"-bm\"/\"--best-match\" to get a best match." + ).format(src=args.speech_language)) if args.min_confidence < 0.0 or args.min_confidence > 1.0: raise exceptions.AutosubException( @@ -349,15 +351,13 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret _("Error: Wrong API code.")) if args.dst_language is None: - print( - _("Destination language not provided. " - "Only performing speech recognition.")) + print(_("Translation destination language not provided. " + "Only performing speech recognition.")) else: if not args.src_language: - print( - _("Source language not provided. " - "Use Speech language instead.")) + print(_("Translation source language not provided. " + "Use speech language instead.")) args.src_language = args.speech_language if not args.best_match: args.best_match = {'src'} @@ -377,10 +377,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret if not is_src_matched: if args.best_match and 'src' in args.best_match: - print( - _("Warning: Translation source language \"{src}\" is not supported. " - "Run with \"-ltc\"/\"--list-translation-codes\" " - "to see all supported languages.").format(src=args.src_language)) + print(_("Let translation source lang code " + "to match py-googletrans lang codes.")) best_result = lang_code_utils.match_print( dsr_lang=args.src_language, match_list=list(googletrans.constants.LANGUAGES.keys()), @@ -390,11 +388,7 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret lang_code=best_result[0])) args.src_language = best_result[0] else: - raise exceptions.AutosubException( - _("Match failed. Still using \"{lang_code}\". " - "Program stopped.").format( - lang_code=args.src_language)) - + raise exceptions.AutosubException(_("Error: Match failed.")) else: raise exceptions.AutosubException( _("Error: Translation source language \"{src}\" is not supported. " @@ -405,10 +399,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret if not is_dst_matched: if args.best_match and 'd' in args.best_match: - print( - _("Warning: Translation destination language \"{dst}\" is not supported. " - "Run with \"-ltc\"/\"--list-translation-codes\" " - "to see all supported languages.").format(dst=args.dst_language)) + print(_("Let translation destination lang code " + "to match py-googletrans lang codes.")) best_result = lang_code_utils.match_print( dsr_lang=args.dst_language, match_list=list(googletrans.constants.LANGUAGES.keys()), @@ -418,11 +410,7 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret lang_code=best_result[0])) args.dst_language = best_result[0] else: - raise exceptions.AutosubException( - _("Match failed. Still using \"{lang_code}\". " - "Program stopped.").format( - lang_code=args.dst_language)) - + raise exceptions.AutosubException(_("Error: Match failed.")) else: raise exceptions.AutosubException( _("Error: Translation destination language \"{dst}\" is not supported. " @@ -433,9 +421,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret if args.dst_language == args.speech_language \ or args.src_language == args.dst_language: - print( - _("Speech language is the same as the Destination language. " - "Only performing speech recognition.")) + print(_("Speech language is the same as the destination language. " + "Only performing speech recognition.")) args.dst_language = None args.src_language = None @@ -447,9 +434,8 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret "No works done.")) else: - print( - _("Speech language not provided. " - "Only performing speech regions detection.")) + print(_("Speech language not provided. " + "Only performing speech regions detection.")) if args.styles == ' ': # when args.styles is used but without option @@ -538,11 +524,11 @@ def validate_sp_args(args): # pylint: disable=too-many-branches,too-many-return if args.dst_language == args.src_language: raise exceptions.AutosubException( - _("Error: Source language is the same as the Destination language.")) + _("Error: Translation source language is the same as the destination language.")) else: raise exceptions.AutosubException( - _("Error: Source language not provided.")) + _("Error: Translation source language is not provided.")) if args.styles == ' ': # when args.styles is used but without option diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po index 24efedd0..64707b48 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-12 11:08+0800\n" -"PO-Revision-Date: 2020-03-12 11:10+0800\n" +"POT-Creation-Date: 2020-03-12 12:10+0800\n" +"PO-Revision-Date: 2020-03-12 12:16+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -56,8 +56,8 @@ msgid "List of all lang codes for speech-to-text:\n" msgstr "列出所有语音转文字的语言代码:\n" #: autosub/cmdline_utils.py:92 -msgid "Match Google Speech V2 lang codes." -msgstr "匹配Google Speech V2的语言代码。" +msgid "Match Google Speech-to-Text lang codes." +msgstr "匹配Google Speech-to-Text的语言代码。" #: autosub/cmdline_utils.py:101 msgid "List of all lang codes for translation:\n" @@ -139,57 +139,60 @@ msgid "Error: \"-slp\"/\"--sleep-seconds\" arg is illegal." msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" #: autosub/cmdline_utils.py:325 -msgid "" -"Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" -"list-speech-codes\" to see all supported languages." -msgstr "" -"警告:语音语言\"{src}\"不在推荐的清单里面。用\"-lsc\"/\"--list-speech-codes" -"\"选项运行来查看所有支持的语言。" +msgid "Let speech lang code to match Google Speech-to-Text lang codes." +msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:334 +#: autosub/cmdline_utils.py:331 msgid "Use langcodes to standardize the result." msgstr "使用langcodes来标准化结果。" -#: autosub/cmdline_utils.py:336 autosub/cmdline_utils.py:389 -#: autosub/cmdline_utils.py:417 autosub/cmdline_utils.py:496 -#: autosub/cmdline_utils.py:523 +#: autosub/cmdline_utils.py:333 autosub/cmdline_utils.py:387 +#: autosub/cmdline_utils.py:409 autosub/cmdline_utils.py:482 +#: autosub/cmdline_utils.py:509 msgid "Use \"{lang_code}\" instead." msgstr "改用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:340 +#: autosub/cmdline_utils.py:336 msgid "Match failed. Still using \"{lang_code}\"." msgstr "匹配失败。仍在使用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:345 +#: autosub/cmdline_utils.py:339 +msgid "" +"Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" +"list-speech-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" +"match\" to get a best match." +msgstr "" +"警告:语音语言\"{src}\"不在推荐的清单里面。用\"-lsc\"/\"--list-translation-" +"codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" +"佳匹配。" + +#: autosub/cmdline_utils.py:347 msgid "Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal." msgstr "错误:\"-mnc\"/\"--min-confidence\"参数的值不合法。" -#: autosub/cmdline_utils.py:349 +#: autosub/cmdline_utils.py:351 msgid "Error: Wrong API code." msgstr "错误:错误的API代码。" -#: autosub/cmdline_utils.py:353 -msgid "Destination language not provided. Only performing speech recognition." +#: autosub/cmdline_utils.py:354 +msgid "" +"Translation destination language not provided. Only performing speech " +"recognition." msgstr "翻译目的语言未提供。只进行语音识别。" #: autosub/cmdline_utils.py:359 -msgid "Source language not provided. Use Speech language instead." +msgid "Translation source language not provided. Use speech language instead." msgstr "翻译源语言未提供。改用语音语言。" -#: autosub/cmdline_utils.py:381 -msgid "" -"Warning: Translation source language \"{src}\" is not supported. Run with \"-" -"ltc\"/\"--list-translation-codes\" to see all supported languages." -msgstr "" -"警告:翻译源语言\"{src}\"不在推荐的清单里面。用 \"-ltc\"/\"--list-" -"translation-codes\"选项运行来查看所有支持的语言。" +#: autosub/cmdline_utils.py:380 +msgid "Let translation source lang code to match py-googletrans lang codes." +msgstr "让翻译源语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:394 autosub/cmdline_utils.py:422 -#: autosub/cmdline_utils.py:500 autosub/cmdline_utils.py:527 -msgid "Match failed. Still using \"{lang_code}\". Program stopped." -msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" +#: autosub/cmdline_utils.py:391 autosub/cmdline_utils.py:413 +msgid "Error: Match failed." +msgstr "错误:匹配失败。" -#: autosub/cmdline_utils.py:400 +#: autosub/cmdline_utils.py:394 msgid "" "Error: Translation source language \"{src}\" is not supported. Run with \"-" "ltc\"/\"--list-translation-codes\" to see all supported languages. Or use \"-" @@ -199,15 +202,12 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:409 +#: autosub/cmdline_utils.py:402 msgid "" -"Warning: Translation destination language \"{dst}\" is not supported. Run " -"with \"-ltc\"/\"--list-translation-codes\" to see all supported languages." -msgstr "" -"警告:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" -"项运行来查看所有支持的语言。" +"Let translation destination lang code to match py-googletrans lang codes." +msgstr "让翻译目的语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:428 +#: autosub/cmdline_utils.py:416 msgid "" "Error: Translation destination language \"{dst}\" is not supported. Run with " "\"-ltc\"/\"--list-translation-codes\" to see all supported languages. Or use " @@ -216,29 +216,29 @@ msgstr "" "错误:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" "项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最佳匹配。" -#: autosub/cmdline_utils.py:437 +#: autosub/cmdline_utils.py:424 msgid "" -"Speech language is the same as the Destination language. Only performing " +"Speech language is the same as the destination language. Only performing " "speech recognition." msgstr "语音语言和目的语言一致。只进行语音识别。" -#: autosub/cmdline_utils.py:446 +#: autosub/cmdline_utils.py:433 msgid "You've already input times. No works done." msgstr "你已经输入了时间轴。啥都没做。" -#: autosub/cmdline_utils.py:451 +#: autosub/cmdline_utils.py:437 msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:459 autosub/cmdline_utils.py:552 +#: autosub/cmdline_utils.py:445 autosub/cmdline_utils.py:538 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" -#: autosub/cmdline_utils.py:472 +#: autosub/cmdline_utils.py:458 msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" -#: autosub/cmdline_utils.py:488 +#: autosub/cmdline_utils.py:474 msgid "" "Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages." @@ -246,7 +246,11 @@ msgstr "" "警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:506 +#: autosub/cmdline_utils.py:486 autosub/cmdline_utils.py:513 +msgid "Match failed. Still using \"{lang_code}\". Program stopped." +msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" + +#: autosub/cmdline_utils.py:492 msgid "" "Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -256,7 +260,7 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:515 +#: autosub/cmdline_utils.py:501 msgid "" "Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages." @@ -264,7 +268,7 @@ msgstr "" "警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" "行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:533 +#: autosub/cmdline_utils.py:519 msgid "" "Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" @@ -274,15 +278,16 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:541 -msgid "Error: Source language is the same as the Destination language." -msgstr "错误:源语言和目的语言一致。" +#: autosub/cmdline_utils.py:527 +msgid "" +"Error: Translation source language is the same as the destination language." +msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:545 -msgid "Error: Source language not provided." -msgstr "错误:源语言未提供。" +#: autosub/cmdline_utils.py:531 +msgid "Error: Translation source language is not provided." +msgstr "错误:翻译源语言未提供。" -#: autosub/cmdline_utils.py:564 +#: autosub/cmdline_utils.py:550 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -290,7 +295,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:571 +#: autosub/cmdline_utils.py:557 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -298,7 +303,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:578 +#: autosub/cmdline_utils.py:564 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -306,7 +311,7 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:611 autosub/cmdline_utils.py:877 +#: autosub/cmdline_utils.py:597 autosub/cmdline_utils.py:863 msgid "" "\n" "No works done. Check your \"-of\"/\"--output-files\" option." @@ -314,19 +319,19 @@ msgstr "" "\n" "啥都没做。检查你的\"-of\"/\"--output-files\"选项。" -#: autosub/cmdline_utils.py:644 autosub/cmdline_utils.py:1184 +#: autosub/cmdline_utils.py:630 autosub/cmdline_utils.py:1170 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:688 autosub/cmdline_utils.py:1223 +#: autosub/cmdline_utils.py:674 autosub/cmdline_utils.py:1209 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:692 autosub/cmdline_utils.py:744 -#: autosub/cmdline_utils.py:796 autosub/cmdline_utils.py:979 -#: autosub/cmdline_utils.py:1125 autosub/cmdline_utils.py:1167 -#: autosub/cmdline_utils.py:1227 autosub/cmdline_utils.py:1275 -#: autosub/cmdline_utils.py:1323 +#: autosub/cmdline_utils.py:678 autosub/cmdline_utils.py:730 +#: autosub/cmdline_utils.py:782 autosub/cmdline_utils.py:965 +#: autosub/cmdline_utils.py:1111 autosub/cmdline_utils.py:1153 +#: autosub/cmdline_utils.py:1213 autosub/cmdline_utils.py:1261 +#: autosub/cmdline_utils.py:1309 msgid "" "\n" "All works done." @@ -334,23 +339,23 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:740 autosub/cmdline_utils.py:1271 +#: autosub/cmdline_utils.py:726 autosub/cmdline_utils.py:1257 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:792 autosub/cmdline_utils.py:1319 +#: autosub/cmdline_utils.py:778 autosub/cmdline_utils.py:1305 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:835 autosub/cmdline_utils.py:1364 +#: autosub/cmdline_utils.py:821 autosub/cmdline_utils.py:1350 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:882 +#: autosub/cmdline_utils.py:868 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:918 +#: autosub/cmdline_utils.py:904 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -358,11 +363,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:928 +#: autosub/cmdline_utils.py:914 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:931 +#: autosub/cmdline_utils.py:917 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -370,7 +375,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:943 +#: autosub/cmdline_utils.py:929 msgid "" "\n" "\"{name}\" has been deleted." @@ -378,19 +383,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:947 +#: autosub/cmdline_utils.py:933 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:976 autosub/cmdline_utils.py:1431 +#: autosub/cmdline_utils.py:962 autosub/cmdline_utils.py:1417 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1000 +#: autosub/cmdline_utils.py:986 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1004 +#: autosub/cmdline_utils.py:990 msgid "" "Audio processing complete.\n" "All works done." @@ -398,11 +403,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1056 +#: autosub/cmdline_utils.py:1042 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1071 +#: autosub/cmdline_utils.py:1057 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -412,18 +417,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1076 +#: autosub/cmdline_utils.py:1062 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1090 +#: autosub/cmdline_utils.py:1076 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1102 +#: autosub/cmdline_utils.py:1088 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -431,11 +436,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1121 +#: autosub/cmdline_utils.py:1107 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1129 +#: autosub/cmdline_utils.py:1115 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -443,11 +448,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1163 autosub/cmdline_utils.py:1401 +#: autosub/cmdline_utils.py:1149 autosub/cmdline_utils.py:1387 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1373 +#: autosub/cmdline_utils.py:1359 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -455,7 +460,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1406 +#: autosub/cmdline_utils.py:1392 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output regions subtitles file only." @@ -463,6 +468,27 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出时间轴文件。" +#~ msgid "" +#~ "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/" +#~ "\"--list-speech-codes\" to see all supported languages." +#~ msgstr "" +#~ "警告:语音语言\"{src}\"不在推荐的清单里面。用\"-lsc\"/\"--list-speech-" +#~ "codes\"选项运行来查看所有支持的语言。" + +#~ msgid "" +#~ "Warning: Translation source language \"{src}\" is not supported. Run with " +#~ "\"-ltc\"/\"--list-translation-codes\" to see all supported languages." +#~ msgstr "" +#~ "警告:翻译源语言\"{src}\"不在推荐的清单里面。用 \"-ltc\"/\"--list-" +#~ "translation-codes\"选项运行来查看所有支持的语言。" + +#~ msgid "" +#~ "Warning: Translation destination language \"{dst}\" is not supported. Run " +#~ "with \"-ltc\"/\"--list-translation-codes\" to see all supported languages." +#~ msgstr "" +#~ "警告:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes" +#~ "\"选项运行来查看所有支持的语言。" + #~ msgid "Error: Currently doesn't support encoding \"{encoding}\"." #~ msgstr "错误:无法解码配置文件\"{filename}\"。" diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md index 24a36124..1d613458 100644 --- a/docs/README.zh-Hans.md +++ b/docs/README.zh-Hans.md @@ -266,7 +266,7 @@ Autosub使用Auditok来检测语音区域。通过语音区域来分割并转换 - 尽管你可以输入任何你想输入的语言代码,需要指出的是如果你使用了不在清单上的语言代码但是API接受了,[Google-Speech-v2](https://github.com/gillesdemey/google-speech-v2)可能会按照你的IP地址机型个性化识别,而这是不受你控制的。这是一个已知的问题,我已经在原仓库申请了[拉取请求](https://github.com/agermanidis/autosub/pull/136)。 -- 另外一方面,[py-googletrans](https://github.com/ssut/py-googletrans)更加严格。当它收到了一个不在它清单内的语言代码,它会直接抛出异常。当然这可以设计成一个抛出-捕获的代码块,并允许用户再次输入语言代码,不过我目前还没加入这个支持,所以不适合的翻译语言代码会终止程序运行,除非你使用前面提到的最佳匹配功能。 +- 另外一方面,[py-googletrans](https://github.com/ssut/py-googletrans)更加严格。当它收到了一个不在它清单内的语言代码,它会直接抛出异常。 - 除了用户输入的部分,另外一个显著的更改是我将`-S`选项分为了两部分,一个是`-S`一个是`-SRC`。`-S`选项是给语音识别的语言代码使用的。`-SRC`则是给翻译源语言代码使用的。如果不输入`-SRC`的参数时,autosub会使用[langcodes](https://github.com/LuminosoInsight/langcodes)来匹配`-S`的参数来获得其在翻译支持的语言代码清单中的最佳匹配,尽管[py-googletrans](https://github.com/ssut/py-googletrans)可以自动检测翻译源语言。当然你可以手动配置`-SRC`选项。而`-D`还是给目标翻译语言使用的,和之前一样。 From 510802bca3a06618a26f025de40395c895ea32bb Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Thu, 12 Mar 2020 15:58:31 +0800 Subject: [PATCH 4/8] Add (close #91) extra environment variables check when finding dependencies --- CHANGELOG.md | 6 +++++- README.md | 8 ++++++++ autosub/constants.py | 16 +++++++++++++--- docs/CHANGELOG.zh-Hans.md | 4 ++++ docs/README.zh-Hans.md | 8 ++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53551682..6feb740b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,11 @@ Click up arrow to go back to TOC. ### [Unreleased] -#### Changed(unreleased) +#### Added(Unreleased) + +- Add extra environment variables check when finding dependencies. [issue #91](https://github.com/BingLingGroup/autosub/issues/91) + +#### Changed(Unreleased) - Fix Google Speech-to-Text API empty result response bug. [issue #89](https://github.com/BingLingGroup/autosub/issues/89) diff --git a/README.md b/README.md index 2019b88d..6fbf5ca9 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ This repo has a different license from [the original repo](https://github.com/ag Autosub depends on these third party softwares or Python site-packages. Much appreciation to all of these projects. - [ffmpeg](https://ffmpeg.org/) +- [ffprobe](https://ffmpeg.org/ffprobe.html) - [auditok](https://github.com/amsehili/auditok) - [pysubs2](https://github.com/tkarabela/pysubs2) - [py-googletrans](https://github.com/ssut/py-googletrans) @@ -96,6 +97,13 @@ After autosub-0.4.0, all of the codes is compatible with both Python 2.7 and Pyt About the dependencies installation. If you install autosub by pip, ffmpeg and ffmpeg-normalize won't be installed together not like the Python site-packages already listed on the `setup.py` or `requirements.txt`. You need to install them separately. But of course they are optional. They aren't necessary if you only use autosub to translate your subtitles. +ffmpeg, ffprobe, ffmpeg-normalize need to be put on one of these places to let the autosub detect and use them. The following codes are in the [constants.py](autosub/constants.py). Priority is determined in order. + +1. Set the following environment variables before running the program: `FFMPEG_PATH`, `FFPROBE_PATH` and `FFMPEG_NORMALIZE_PATH`. It will override the ones located at the environment variable `PATH`. This will be helpful if you don't want to use the one in the `PATH`. +2. Add them to the environment variable `PATH`. No need to worry about if using package manager to install such as using pip to install ffmpeg-normalize and using chocolatey to install ffmpeg. +3. Add them to the same directory as the autosub executable. +4. Add them to the current command line working directory. + About the git installation. If you don't want to install git to use pip [VCS](https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support) support to install python package or just confused with git environment variables, you can manually click that clone and download button to download the source code and use pip to install the source code [locally](https://pip.pypa.io/en/stable/reference/pip_install/#description) by input these commands. ```batch diff --git a/autosub/constants.py b/autosub/constants.py index f4af1899..78b6e7e0 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -401,10 +401,20 @@ def get_cmd(program_name): return "" -FFMPEG_CMD = get_cmd("ffmpeg") -FFPROBE_CMD = get_cmd("ffprobe") -FFMPEG_NORMALIZE_CMD = get_cmd("ffmpeg-normalize") +if 'FFMPEG_PATH' in os.environ: + FFMPEG_CMD = os.environ['FFMPEG_PATH'] +else: + FFMPEG_CMD = get_cmd("ffmpeg") + +if 'FFPROBE_PATH' in os.environ: + FFPROBE_CMD = os.environ['FFPROBE_PATH'] +else: + FFPROBE_CMD = get_cmd("ffprobe") +if 'FFMPEG_NORMALIZE_PATH' in os.environ: + FFMPEG_NORMALIZE_CMD = os.environ['FFMPEG_NORMALIZE_PATH'] +else: + FFMPEG_NORMALIZE_CMD = get_cmd("ffmpeg-normalize") DEFAULT_AUDIO_PRCS = [ FFMPEG_CMD + " -hide_banner -i \"{in_}\" -af \"asplit[a],aphasemeter=video=0,\ diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index b49cecb9..74388b28 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -38,6 +38,10 @@ ### [未发布](未发布) +#### 添加(未发布) + +- 添加额外的环境变量检查在查找依赖时。[issue #91](https://github.com/BingLingGroup/autosub/issues/91) + #### 改动(未发布) - 修复Google Speech-to-Text API空结果返回bug。[issue #89](https://github.com/BingLingGroup/autosub/issues/89) diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md index 1d613458..40293e0f 100644 --- a/docs/README.zh-Hans.md +++ b/docs/README.zh-Hans.md @@ -76,6 +76,7 @@ Autosub是一个字幕自动生成工具。它能使用Auditok来自动检测语 Autosub依赖于这些第三方的软件或者Python的site-packages。非常感谢以下这些项目的工作。 - [ffmpeg](https://ffmpeg.org/) +- [ffprobe](https://ffmpeg.org/ffprobe.html) - [auditok](https://github.com/amsehili/auditok) - [pysubs2](https://github.com/tkarabela/pysubs2) - [py-googletrans](https://github.com/ssut/py-googletrans) @@ -96,6 +97,13 @@ Autosub依赖于这些第三方的软件或者Python的site-packages。非常感 至于依赖的安装,如果你是通过pip来安装的autosub,那么ffmpeg和ffmpeg-normalize不会被一块儿安装,不像site-packages那样列在`setup.py`或者`requirements.txt`里面自动安装了。你需要分别安装它们。当然安装是可选的,如果你只是翻译字幕,不需要安装这两个软件。 +ffmpeg, ffprobe, ffmpeg-normalize需要被放在以下位置之一来让autosub检测并使用。以下代码都在[constants.py](autosub/constants.py)里。优先级按照先后顺序确定。 + +1. 在运行程序前设置以下环境变量:`FFMPEG_PATH`,`FFPROBE_PATH`和 `FFMPEG_NORMALIZE_PATH`。它会替代环境变量`PATH`里的值。如果你不想使用`PATH`里的值,那么这会帮到你。 +2. 把它们加入环境变量`PATH`。如果使用的是包管理器进行的安装,那么就不需要关心这件事。用管理器进行安装是指使用pip安装ffmpeg-normalize或者chocolatey安装ffmpeg。 +3. 把它们放在和autosub的可执行文件的同一个目录下。 +4. 把它们放在当前命令行工作的文件夹下。 + 至于git的安装,如果你不想通过pip的[VCS](https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support)支持来安装python包或者只是不想碰git的环境变量这些东西,你可以手动点击clone and download来下载源码并在[本地](https://pip.pypa.io/en/stable/reference/pip_install/#description)进行安装。指令如下。 ```batch From 785b083b4ebdb783cf21f7277beec5ff9fc0f80f Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Thu, 12 Mar 2020 17:30:00 +0800 Subject: [PATCH 5/8] Add (close #92) arguments parser input when open it without arguments --- CHANGELOG.md | 1 + README.md | 2 + autosub/__init__.py | 31 ++++++++++----- .../data/locale/zh_CN/LC_MESSAGES/autosub.po | 38 ++++++++++++------- autosub/options.py | 6 +-- docs/CHANGELOG.zh-Hans.md | 1 + docs/README.zh-Hans.md | 2 + 7 files changed, 56 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6feb740b..a5fce7f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Click up arrow to go back to TOC. #### Added(Unreleased) - Add extra environment variables check when finding dependencies. [issue #91](https://github.com/BingLingGroup/autosub/issues/91) +- Add arguments parser input when open it without arguments. [issue #92](https://github.com/BingLingGroup/autosub/issues/92) #### Changed(Unreleased) diff --git a/README.md b/README.md index 6fbf5ca9..1c54b2c4 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,8 @@ You can just go to the [release page](https://github.com/BingLingGroup/autosub/r Tips: `Shift - Right Click` is the keyboard shortcut for opening a Powershell on current directory. To open an exe at current directory, the format is like `.\autosub`. +Or you can just directly open it and input the args manually though I don't recommend doing this due to its less efficiency. + - The one without pyinstaller suffix is compiled by Nuitka. It's faster than the pyinstaller due to its compiling feature different from pyinstaller which just bundles the application. - ffmpeg and ffmpeg-normalize are also in the package. The original ffmpeg-normalize doesn't have a standalone version. The standalone version of ffmpeg-normalize is built separately. Codes are [here](https://github.com/BingLingGroup/ffmpeg-normalize). - If there's anything wrong on the both releases, or the package size and any other things are annoying you, you can just use the traditional pip installation method below. diff --git a/autosub/__init__.py b/autosub/__init__.py index ac90c2e5..45b8d0c7 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -7,6 +7,8 @@ from __future__ import absolute_import, print_function, unicode_literals import os import gettext +import sys +import subprocess # Import third-party modules import pysubs2 @@ -35,7 +37,21 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- Run autosub as a command-line program. """ - args = options.get_cmd_args() + is_pause = False + + try: + input_main = raw_input + except NameError: + input_main = input + + option_parser = options.get_cmd_parser() + if len(sys.argv) > 1: + args = option_parser.parse_args() + else: + option_parser.print_help() + new_argv = input_main(_("\nInput args(without \"autosub\"): ")) + args = option_parser.parse_args(new_argv.split()) + is_pause = True if args.https_proxy: os.environ['https_proxy'] = args.https_proxy @@ -57,10 +73,7 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- raise exceptions.AutosubException(_("\nAll works done.")) if not args.yes: - try: - input_m = raw_input - except NameError: - input_m = input + input_m = input_main else: input_m = None @@ -155,15 +168,15 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- fps=fps, styles_list=None) + raise exceptions.AutosubException(_("\nAll works done.")) + except KeyboardInterrupt: print(_("\nKeyboardInterrupt. Works stopped.")) - return 1 except pysubs2.exceptions.Pysubs2Error: print(_("\nError: pysubs2.exceptions. Check your file format.")) - return 1 except exceptions.AutosubException as err_msg: print(err_msg) - return 0 - print(_("\nAll works done.")) + if is_pause: + input_main(_("Press Enter to exit...")) return 0 diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po index 9c622b08..44529496 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po @@ -7,17 +7,25 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-02-28 12:44+0800\n" -"PO-Revision-Date: 2020-02-03 21:31+0800\n" +"POT-Creation-Date: 2020-03-12 17:25+0800\n" +"PO-Revision-Date: 2020-03-12 17:25+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: zh_CN\n" -"X-Generator: Poedit 2.2.4\n" +"X-Generator: Poedit 2.3\n" -#: autosub/__init__.py:57 autosub/__init__.py:168 +#: autosub/__init__.py:52 +msgid "" +"\n" +"Input args(without \"autosub\"): " +msgstr "" +"\n" +"输入参数(不包含\"autosub\"): " + +#: autosub/__init__.py:73 autosub/__init__.py:171 msgid "" "\n" "All works done." @@ -25,15 +33,15 @@ msgstr "" "\n" "做完了。" -#: autosub/__init__.py:73 +#: autosub/__init__.py:86 msgid "Error: Dependency ffmpeg not found on this machine." msgstr "错误:依赖ffmpeg未在这台电脑上找到。" -#: autosub/__init__.py:77 +#: autosub/__init__.py:90 msgid "Error: Dependency ffprobe not found on this machine." msgstr "错误:依赖ffprobe未在这台电脑上找到。" -#: autosub/__init__.py:88 +#: autosub/__init__.py:101 msgid "" "Error: The args of \"-ap\"/\"--audio-process\" are wrong.\n" "No works done." @@ -41,11 +49,11 @@ msgstr "" "错误:\"-ap\"/\"--audio-process\"的参数有误。\n" "啥都没做。" -#: autosub/__init__.py:100 +#: autosub/__init__.py:113 msgid "No works done." msgstr "啥都没做。" -#: autosub/__init__.py:104 +#: autosub/__init__.py:117 msgid "" "Audio pre-processing complete.\n" "All works done." @@ -53,7 +61,7 @@ msgstr "" "音频预处理已完成。\n" "做完了。" -#: autosub/__init__.py:120 +#: autosub/__init__.py:133 msgid "" "Audio pre-processing failed.\n" "Use default method." @@ -61,11 +69,11 @@ msgstr "" "音频预处理失败。\n" "使用默认方法。" -#: autosub/__init__.py:124 +#: autosub/__init__.py:137 msgid "Audio pre-processing complete." msgstr "音频预处理已完成。" -#: autosub/__init__.py:159 +#: autosub/__init__.py:174 msgid "" "\n" "KeyboardInterrupt. Works stopped." @@ -73,7 +81,7 @@ msgstr "" "\n" "键盘中断。操作终止。" -#: autosub/__init__.py:162 +#: autosub/__init__.py:176 msgid "" "\n" "Error: pysubs2.exceptions. Check your file format." @@ -81,5 +89,9 @@ msgstr "" "\n" "错误:pysubs2异常。检查你的文件格式。" +#: autosub/__init__.py:181 +msgid "Press Enter to exit..." +msgstr "按回车以退出..." + #~ msgid "No extra check/conversion before the speech-to-text procedure." #~ msgstr "在语音转文字之前不会有多余的检查/格式转换。" diff --git a/autosub/options.py b/autosub/options.py index 0710631f..0cd748c2 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -34,9 +34,9 @@ M_ = META_TEXT.gettext -def get_cmd_args(): # pylint: disable=too-many-statements +def get_cmd_parser(): # pylint: disable=too-many-statements """ - Get command-line arguments. + Get command-line parser. """ parser = argparse.ArgumentParser( @@ -596,4 +596,4 @@ def get_cmd_args(): # pylint: disable=too-many-statements "Ref: https://cloud.google.com/speech-to-text/docs/languages " "(arg_num = 1) (default: %(default)s)")) - return parser.parse_args() + return parser diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 74388b28..7e9d98b3 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -41,6 +41,7 @@ #### 添加(未发布) - 添加额外的环境变量检查在查找依赖时。[issue #91](https://github.com/BingLingGroup/autosub/issues/91) +- 添加无参数启动时的请求输入参数解析功能。[issue #92](https://github.com/BingLingGroup/autosub/issues/92) #### 改动(未发布) diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md index 40293e0f..af6d60a8 100644 --- a/docs/README.zh-Hans.md +++ b/docs/README.zh-Hans.md @@ -165,6 +165,8 @@ pip install autosub 建议:`Shift - 右键`是打开当前目录Powershell的快捷键。Powershell打开当前目录的exe需要输入这样的格式`.\autosub`。 +或者你也可以直接打开它并手动输入参数,尽管我并不建议这样做,因为效率比较低。 + - 发布包里没有pyinstaller后缀的是Nuitka编译的。它比pyinstaller的版本快,因为它是编译的,不同于pyinstaller只是把程序进行了打包。 - ffmpeg和ffmpeg-normalize也在发布包内。原本ffmpeg-normalize没有独立运行的版本。这个独立运行的ffmpeg-normalize是另外构建的。代码在[这里](https://github.com/BingLingGroup/ffmpeg-normalize)。 - 如果在使用发布包时遇到任何问题,或者包的大小太大或者遇到了什么烦人的事情,你依然可以采用下方所说的通过pip的方法进行安装。 From 8bce23abf184bd96c00085110228bbf5050fa46c Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Thu, 19 Mar 2020 10:29:59 +0800 Subject: [PATCH 6/8] =?UTF-8?q?Change=20option=20=E2=80=9C-sml=E2=80=9D=20?= =?UTF-8?q?into=20=E2=80=9C-nsml=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 + autosub/__init__.py | 4 +- autosub/cmdline_utils.py | 8 +- autosub/constants.py | 10 +-- .../LC_MESSAGES/autosub.cmdline_utils.po | 56 ++++++------- .../zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po | 10 +-- .../zh_CN/LC_MESSAGES/autosub.options.po | 82 +++++++++++-------- autosub/ffmpeg_utils.py | 3 +- autosub/google_speech_api.py | 5 +- autosub/options.py | 6 +- autosub/sub_utils.py | 5 ++ docs/CHANGELOG.zh-Hans.md | 2 + 12 files changed, 105 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5fce7f6..3d1ac78d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ Click up arrow to go back to TOC. #### Changed(Unreleased) - Fix Google Speech-to-Text API empty result response bug. [issue #89](https://github.com/BingLingGroup/autosub/issues/89) +- Change option `-sml` into `-nsml`. +- Change defaults for Auditok. ### [0.5.5-alpha] - 2020-03-04 diff --git a/autosub/__init__.py b/autosub/__init__.py index 45b8d0c7..0cd7be45 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -8,7 +8,7 @@ import os import gettext import sys -import subprocess +import shlex # Import third-party modules import pysubs2 @@ -50,7 +50,7 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- else: option_parser.print_help() new_argv = input_main(_("\nInput args(without \"autosub\"): ")) - args = option_parser.parse_args(new_argv.split()) + args = option_parser.parse_args(shlex.split(new_argv)) is_pause = True if args.https_proxy: diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 03c7b8b8..8bdad2fa 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -886,12 +886,10 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen else: # use auditok_gen_speech_regions mode = 0 - if args.strict_min_length: + if not args.not_strict_min_length: mode = auditok.StreamTokenizer.STRICT_MIN_LENGTH - if args.drop_trailing_silence: - mode = mode | auditok.StreamTokenizer.DROP_TRAILING_SILENCE - elif args.drop_trailing_silence: - mode = auditok.StreamTokenizer.DROP_TRAILING_SILENCE + if args.drop_trailing_silence: + mode = mode | auditok.StreamTokenizer.DROP_TRAILING_SILENCE audio_wav_temp = tempfile.NamedTemporaryFile(suffix='.wav', delete=False) audio_wav = audio_wav_temp.name diff --git a/autosub/constants.py b/autosub/constants.py index 78b6e7e0..2a7783d0 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -64,12 +64,12 @@ DEFAULT_CONCURRENCY = 2 DEFAULT_SRC_LANGUAGE = 'en-US' -DEFAULT_ENERGY_THRESHOLD = 45 -DEFAULT_MAX_REGION_SIZE = 8.0 -DEFAULT_MIN_REGION_SIZE = 1.0 -MIN_REGION_SIZE_LIMIT = 0.5 +DEFAULT_ENERGY_THRESHOLD = 50 +DEFAULT_MAX_REGION_SIZE = 6.0 +DEFAULT_MIN_REGION_SIZE = 0.8 +MIN_REGION_SIZE_LIMIT = 0.6 MAX_REGION_SIZE_LIMIT = 12.0 -DEFAULT_CONTINUOUS_SILENCE = 0.3 +DEFAULT_CONTINUOUS_SILENCE = 0.2 # Maximum speech to text region length in milliseconds # when using external speech region control diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po index 64707b48..f640e2b8 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-12 12:10+0800\n" +"POT-Creation-Date: 2020-03-19 10:17+0800\n" "PO-Revision-Date: 2020-03-12 12:16+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -319,19 +319,19 @@ msgstr "" "\n" "啥都没做。检查你的\"-of\"/\"--output-files\"选项。" -#: autosub/cmdline_utils.py:630 autosub/cmdline_utils.py:1170 +#: autosub/cmdline_utils.py:630 autosub/cmdline_utils.py:1168 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:674 autosub/cmdline_utils.py:1209 +#: autosub/cmdline_utils.py:674 autosub/cmdline_utils.py:1207 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" #: autosub/cmdline_utils.py:678 autosub/cmdline_utils.py:730 -#: autosub/cmdline_utils.py:782 autosub/cmdline_utils.py:965 -#: autosub/cmdline_utils.py:1111 autosub/cmdline_utils.py:1153 -#: autosub/cmdline_utils.py:1213 autosub/cmdline_utils.py:1261 -#: autosub/cmdline_utils.py:1309 +#: autosub/cmdline_utils.py:782 autosub/cmdline_utils.py:963 +#: autosub/cmdline_utils.py:1109 autosub/cmdline_utils.py:1151 +#: autosub/cmdline_utils.py:1211 autosub/cmdline_utils.py:1259 +#: autosub/cmdline_utils.py:1307 msgid "" "\n" "All works done." @@ -339,15 +339,15 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:726 autosub/cmdline_utils.py:1257 +#: autosub/cmdline_utils.py:726 autosub/cmdline_utils.py:1255 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:778 autosub/cmdline_utils.py:1305 +#: autosub/cmdline_utils.py:778 autosub/cmdline_utils.py:1303 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:821 autosub/cmdline_utils.py:1350 +#: autosub/cmdline_utils.py:821 autosub/cmdline_utils.py:1348 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" @@ -355,7 +355,7 @@ msgstr "目的语言字幕文件创建在了\"{}\"。" msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:904 +#: autosub/cmdline_utils.py:902 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -363,11 +363,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:914 +#: autosub/cmdline_utils.py:912 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:917 +#: autosub/cmdline_utils.py:915 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -375,7 +375,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:929 +#: autosub/cmdline_utils.py:927 msgid "" "\n" "\"{name}\" has been deleted." @@ -383,19 +383,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:933 +#: autosub/cmdline_utils.py:931 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:962 autosub/cmdline_utils.py:1417 +#: autosub/cmdline_utils.py:960 autosub/cmdline_utils.py:1415 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:986 +#: autosub/cmdline_utils.py:984 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:990 +#: autosub/cmdline_utils.py:988 msgid "" "Audio processing complete.\n" "All works done." @@ -403,11 +403,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1042 +#: autosub/cmdline_utils.py:1040 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1057 +#: autosub/cmdline_utils.py:1055 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -417,18 +417,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1062 +#: autosub/cmdline_utils.py:1060 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1076 +#: autosub/cmdline_utils.py:1074 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1088 +#: autosub/cmdline_utils.py:1086 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -436,11 +436,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1107 +#: autosub/cmdline_utils.py:1105 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1115 +#: autosub/cmdline_utils.py:1113 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -448,11 +448,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1149 autosub/cmdline_utils.py:1387 +#: autosub/cmdline_utils.py:1147 autosub/cmdline_utils.py:1385 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1359 +#: autosub/cmdline_utils.py:1357 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -460,7 +460,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1392 +#: autosub/cmdline_utils.py:1390 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output regions subtitles file only." diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po index 42149cf4..bdc79174 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-02-03 21:36+0800\n" +"POT-Creation-Date: 2020-03-19 10:17+0800\n" "PO-Revision-Date: 2020-02-03 21:37+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -47,22 +47,22 @@ msgstr "" "\n" "使用ffprobe来检查转换结果。" -#: autosub/ffmpeg_utils.py:174 +#: autosub/ffmpeg_utils.py:173 msgid "" "Warning: Dependency ffmpeg-normalize not found on this machine. Try default " "method." msgstr "" "警告:依赖ffmpeg-normalize未在这台电脑上找到。尝试默认的方法去转换格式。" -#: autosub/ffmpeg_utils.py:186 +#: autosub/ffmpeg_utils.py:185 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/ffmpeg_utils.py:189 +#: autosub/ffmpeg_utils.py:188 msgid "Input a new path (including directory and file name) for output file.\n" msgstr "为输出文件输入一个新的路径(包括路径和文件名)。\n" -#: autosub/ffmpeg_utils.py:206 autosub/ffmpeg_utils.py:238 +#: autosub/ffmpeg_utils.py:205 autosub/ffmpeg_utils.py:237 msgid "Audio pre-processing failed. Try default method." msgstr "音频预处理失败。尝试默认的方法去转换格式。" diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po index f84a0068..47a8f641 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-08 21:07+0800\n" +"POT-Creation-Date: 2020-03-19 10:17+0800\n" "PO-Revision-Date: 2020-03-09 17:27+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -135,7 +135,7 @@ msgstr "列出所有可选参数。" #: autosub/options.py:97 autosub/options.py:106 autosub/options.py:115 #: autosub/options.py:197 autosub/options.py:273 autosub/options.py:398 -#: autosub/options.py:592 +#: autosub/options.py:594 msgid "path" msgstr "路径" @@ -188,7 +188,7 @@ msgstr "" "言行使用第二个。(参数个数为1或2)" #: autosub/options.py:142 autosub/options.py:153 autosub/options.py:163 -#: autosub/options.py:564 autosub/options.py:580 +#: autosub/options.py:566 autosub/options.py:582 msgid "lang_code" msgstr "语言代码" @@ -197,8 +197,8 @@ msgstr "语言代码" msgid "" "Lang code/Lang tag for speech-to-text. Recommend using the Google Cloud " "Speech reference lang codes. WRONG INPUT WON'T STOP RUNNING. But use it at " -"your own risk. Ref: https://cloud.google.com/speech-to-text/docs/" -"languages(arg_num = 1) (default: %(default)s)" +"your own risk. Ref: https://cloud.google.com/speech-to-text/docs/languages" +"(arg_num = 1) (default: %(default)s)" msgstr "" "用于语音识别的语言代码/语言标识符。推荐使用Google Cloud Speech的参考语言代" "码。错误的输入不会终止程序。但是后果自负。参考:https://cloud.google.com/" @@ -214,8 +214,8 @@ msgid "" msgstr "" "用于翻译的源语言的语言代码/语言标识符。如果没有提供,会使用langcodes从列表里" "获取一个最佳匹配选项\"-S\"/\"--speech-language\"的语言代码。如果使用py-" -"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数" -"为%(default)s)" +"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数为%" +"(default)s)" #: autosub/options.py:164 #, python-format @@ -373,8 +373,8 @@ msgid "" msgstr "" "API用于识别可信度的回应参数。一个介于0和1之间的浮点数。可信度越高意味着结果越" "好。输入这个参数会导致所有低于这个结果的识别结果被删除。参考:https://github." -"com/BingLingGroup/google-speech-v2#response(参数个数为1)(默认参数" -"为%(default)s)" +"com/BingLingGroup/google-speech-v2#response(参数个数为1)(默认参数为%" +"(default)s)" #: autosub/options.py:306 msgid "Drop any regions without speech recognition result. (arg_num = 0)" @@ -399,8 +399,8 @@ msgid "" "(Experimental)Seconds to sleep between two translation requests. (arg_num = " "1) (default: %(default)s)" msgstr "" -"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数" -"为%(default)s)" +"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" +"(default)s)" #: autosub/options.py:330 msgid "" @@ -481,8 +481,8 @@ msgid "" msgstr "" "设置服务账号密钥的环境变量。应该是包含服务帐号凭据的JSON文件的文件路径。如果" "使用了,会被API密钥选项覆盖。参考:https://cloud.google.com/docs/" -"authentication/getting-started 当前支持:" -"gcsv1(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" +"authentication/getting-started 当前支持:gcsv1" +"(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" #: autosub/options.py:410 msgid "" @@ -532,13 +532,13 @@ msgstr "" #, python-format msgid "" "(Experimental)This arg will override the default audio conversion command. " -"\"[\", \"]\" are optional arguments meaning you can remove them. \"{{\", " -"\"}}\" are required arguments meaning you can't remove them. (arg_num = 1) " +"\"[\", \"]\" are optional arguments meaning you can remove them. \"{{\", \"}}" +"\" are required arguments meaning you can't remove them. (arg_num = 1) " "(default: %(default)s)" msgstr "" "(实验性)这个参数会取代默认的音频转换命令。\"[\", \"]\" 是可选参数,可以移" -"除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数" -"为%(default)s)" +"除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数为%(default)" +"s)" #: autosub/options.py:471 #, python-format @@ -559,8 +559,8 @@ msgid "" "(Experimental)This arg will override the default API audio suffix. (arg_num " "= 1) (default: %(default)s)" msgstr "" -"(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数" -"为%(default)s)" +"(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数为%(default)" +"s)" #: autosub/options.py:486 msgid "sample_rate" @@ -608,16 +608,16 @@ msgstr "" msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数" -"为%(default)s)" +"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" +"s)" #: autosub/options.py:526 #, python-format msgid "" "Maximum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数" -"为%(default)s)" +"最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" +"s)" #: autosub/options.py:535 #, python-format @@ -628,7 +628,17 @@ msgstr "" "在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如" "上。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:542 autosub/options.py:548 +#: autosub/options.py:542 +#, fuzzy +msgid "" +"If not input this option, it will keep all regions strictly follow the " +"minimum region limit. Ref: https://auditok.readthedocs.io/en/latest/core." +"html#class-summary (arg_num = 0)" +msgstr "" +"参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" +"个数为0)" + +#: autosub/options.py:550 msgid "" "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)" @@ -636,7 +646,7 @@ msgstr "" "参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" "个数为0)" -#: autosub/options.py:554 +#: autosub/options.py:556 msgid "" "List all available subtitles formats. If your format is not supported, you " "can use ffmpeg or SubtitleEdit to convert the formats. You need to offer fps " @@ -647,7 +657,7 @@ msgstr "" "SubtitleEdit来对其进行转换。如果输出格式是\"sub\"且输入文件是音频无法获取到视" "频帧率时,你需要提供fps选项指定帧率。(参数个数为0)" -#: autosub/options.py:567 +#: autosub/options.py:569 msgid "" "List all recommended \"-S\"/\"--speech-language\" Google Speech-to-Text " "language codes. If no arg is given, list all. Or else will list a group of " @@ -665,7 +675,7 @@ msgstr "" "言)-扩展-私有(https://www.zhihu.com/question/21980689/answer/93615123)(参" "数个数为0或1)" -#: autosub/options.py:583 +#: autosub/options.py:585 msgid "" "List all available \"-SRC\"/\"--src-language\" py-googletrans translation " "language codes. Or else will list a group of \"good match\" of the arg. Same " @@ -675,7 +685,7 @@ msgstr "" "言代码。否则会给出一个“好的匹配”的清单。同样的参考文档如上。(参数个数为0或" "1)" -#: autosub/options.py:593 +#: autosub/options.py:595 #, python-format msgid "" "Use py-googletrans to detect a sub file's first line language. And list a " @@ -706,26 +716,26 @@ msgstr "" #~ "googletrans。(参数个数为1)" #~ msgid "" -#~ "Number of lines per Google Translate V2 request. (arg_num = 1) (default: " -#~ "%(default)s)" +#~ "Number of lines per Google Translate V2 request. (arg_num = 1) (default: %" +#~ "(default)s)" #~ msgstr "" -#~ "Google Translate V2请求的每行行数。(参数个数为1)(默认参数" -#~ "为%(default)s)" +#~ "Google Translate V2请求的每行行数。(参数个数为1)(默认参数为%(default)" +#~ "s)" #~ msgid "" #~ "Number of concurrent Google translate V2 API requests to make. (arg_num = " #~ "1) (default: %(default)s)" #~ msgstr "" -#~ "Google translate V2 API请求的并行数量。(参数个数为1)(默认参数" -#~ "为%(default)s)" +#~ "Google translate V2 API请求的并行数量。(参数个数为1)(默认参数为%" +#~ "(default)s)" #~ msgid "" #~ "Output more files. Available types: regions, src, dst, bilingual, all. (4 " #~ ">= arg_num >= 1) (default: %(default)s)" #~ msgstr "" #~ "输出更多的文件。可选种类:regions, src, dst, bilingual, all.(时间轴,源语" -#~ "言字幕,目标语言字幕,双语字幕,所有)(参数个数在4和1之间)(默认参数" -#~ "为%(default)s)" +#~ "言字幕,目标语言字幕,双语字幕,所有)(参数个数在4和1之间)(默认参数为%" +#~ "(default)s)" #~ msgid "" #~ "The Google Speech V2 API key to be used. If not provided, use free API " diff --git a/autosub/ffmpeg_utils.py b/autosub/ffmpeg_utils.py index 8b8ad8b7..5e19f25f 100644 --- a/autosub/ffmpeg_utils.py +++ b/autosub/ffmpeg_utils.py @@ -147,8 +147,7 @@ def ffprobe_check_file(filename): print(command) ffprobe_bytes = subprocess.check_output( constants.cmd_conversion(command), - stdin=open(os.devnull), - shell=False) + stdin=open(os.devnull)) ffprobe_str = ffprobe_bytes.decode(sys.stdout.encoding) print(ffprobe_str) bitrate_idx = ffprobe_str.find('bit_rate') diff --git a/autosub/google_speech_api.py b/autosub/google_speech_api.py index f38110c7..ae026beb 100644 --- a/autosub/google_speech_api.py +++ b/autosub/google_speech_api.py @@ -73,9 +73,8 @@ def get_gcsv1p1beta1_transcript( if not result_dict: # if api returned empty json, don't throw the exception return None - else: - raise exceptions.SpeechToTextException( - json.dumps(result_dict, indent=4, ensure_ascii=False)) + raise exceptions.SpeechToTextException( + json.dumps(result_dict, indent=4, ensure_ascii=False)) if 'confidence' in result_dict: confidence = \ diff --git a/autosub/options.py b/autosub/options.py index 0cd748c2..d56e00d5 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -537,9 +537,11 @@ def get_cmd_parser(): # pylint: disable=too-many-statements "(arg_num = 1) (default: %(default)s)")) auditok_group.add_argument( - '-sml', '--strict-min-length', + '-nsml', '--not-strict-min-length', action='store_true', - help=_("Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " + help=_("If not input this option, " + "it will keep all regions strictly follow the minimum region limit. " + "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)")) auditok_group.add_argument( diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 9168e7d6..5d115ae3 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -101,6 +101,7 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem event = pysubs2.SSAEvent() event.start = src_ssafile.events[i].start event.end = src_ssafile.events[i].end + event.is_comment = src_ssafile.events[i].is_comment event.text = text_list[i] event.style = style_name dst_ssafile.events.append(event) @@ -114,6 +115,7 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem event = pysubs2.SSAEvent() event.start = src_ssafile.events[i].start event.end = src_ssafile.events[i].end + event.is_comment = src_ssafile.events[i].is_comment event.text = \ text_list[i] + "\\N" + src_ssafile.events[i].text event.style = style_name @@ -125,6 +127,7 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem event = pysubs2.SSAEvent() event.start = src_ssafile.events[i].start event.end = src_ssafile.events[i].end + event.is_comment = src_ssafile.events[i].is_comment event.text = \ text_list[i] + \ "\\N{{\\r{style_name}}}".format( @@ -142,6 +145,7 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem event = pysubs2.SSAEvent() event.start = src_ssafile.events[i].start event.end = src_ssafile.events[i].end + event.is_comment = src_ssafile.events[i].is_comment event.text = \ src_ssafile.events[i].text + "\\N" + text_list[i] event.style = style_name @@ -153,6 +157,7 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem event = pysubs2.SSAEvent() event.start = src_ssafile.events[i].start event.end = src_ssafile.events[i].end + event.is_comment = src_ssafile.events[i].is_comment event.text = \ src_ssafile.events[i].text + \ "\\N{{\\r{style_name}}}".format( diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 7e9d98b3..59439209 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -46,6 +46,8 @@ #### 改动(未发布) - 修复Google Speech-to-Text API空结果返回bug。[issue #89](https://github.com/BingLingGroup/autosub/issues/89) +- 修改选项`-sml`为`-nsml`。 +- 修改Auditok默认参数。 ### [0.5.5-alpha] - 2020-03-04 From 473044f73928bbc23b60cf01910d39847e3c9b9a Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Thu, 19 Mar 2020 16:21:46 +0800 Subject: [PATCH 7/8] Add subtitles processing when not input "-SRC" --- CHANGELOG.md | 1 + autosub/__init__.py | 23 +++--- autosub/cmdline_utils.py | 57 ++++++++++++--- autosub/sub_utils.py | 143 ++++++++++++++++++++++++++++++++++++++ docs/CHANGELOG.zh-Hans.md | 1 + 5 files changed, 208 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d1ac78d..f23c41b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Click up arrow to go back to TOC. - Add extra environment variables check when finding dependencies. [issue #91](https://github.com/BingLingGroup/autosub/issues/91) - Add arguments parser input when open it without arguments. [issue #92](https://github.com/BingLingGroup/autosub/issues/92) +- Add subtitles processing when not input `-SRC`. #### Changed(Unreleased) diff --git a/autosub/__init__.py b/autosub/__init__.py index 0cd7be45..0d0eae1b 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -78,9 +78,9 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- input_m = None styles_list = [] - validate_result = cmdline_utils.validate_io(args, styles_list) + result = cmdline_utils.validate_io(args, styles_list) - if validate_result == 0: + if result: if not constants.FFMPEG_CMD: raise exceptions.AutosubException( _("Error: Dependency ffmpeg" @@ -160,13 +160,20 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- input_m=input_m, styles_list=styles_list) - elif validate_result == 1: - cmdline_utils.validate_sp_args(args) + else: + result = cmdline_utils.validate_sp_args(args) fps = cmdline_utils.get_fps(args=args, input_m=input_m) - cmdline_utils.sub_trans(args, - input_m=input_m, - fps=fps, - styles_list=None) + if result: + cmdline_utils.sub_trans(args, + input_m=input_m, + fps=fps, + styles_list=None) + else: + cmdline_utils.sub_conversion( + args, + input_m=input_m, + fps=fps + ) raise exceptions.AutosubException(_("\nAll works done.")) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 8bdad2fa..3d20390c 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -244,9 +244,9 @@ def validate_io( # pylint: disable=too-many-branches, too-many-statements if is_ass_input: print(_("Input is a subtitles file.")) - return 1 + return 0 - return 0 + return 1 def validate_config_args(args): # pylint: disable=too-many-branches, too-many-return-statements, too-many-statements @@ -527,8 +527,7 @@ def validate_sp_args(args): # pylint: disable=too-many-branches,too-many-return _("Error: Translation source language is the same as the destination language.")) else: - raise exceptions.AutosubException( - _("Error: Translation source language is not provided.")) + return 0 if args.styles == ' ': # when args.styles is used but without option @@ -539,6 +538,8 @@ def validate_sp_args(args): # pylint: disable=too-many-branches,too-many-return args.styles = args.ext_regions + return 1 + def fix_args(args): """ @@ -584,6 +585,49 @@ def get_timed_text( return timed_text +def sub_conversion( # pylint: disable=too-many-branches, too-many-statements, too-many-locals + args, + input_m=input, + fps=30.0): + """ + Give args and convert a subtitles file. + """ + src_sub = pysubs2.SSAFile.load(args.input) + try: + args.output_files.remove("dst-lf-src") + new_sub = sub_utils.merge_bilingual_assfile( + subtitles=src_sub + ) + sub_string = core.ssafile_to_sub_str( + ssafile=new_sub, + fps=fps, + subtitles_file_format=args.format) + + if args.format == 'mpl2': + extension = 'mpl2.txt' + else: + extension = args.format + + sub_name = "{base}.{nt}.{extension}".format( + base=args.output, + nt="combination", + extension=extension) + + subtitles_file_path = core.str_to_file( + str_=sub_string, + output=sub_name, + input_m=input_m) + # subtitles string to file + print(_("\"dst-lf-src\" subtitles file " + "created at \"{}\".").format(subtitles_file_path)) + + if not args.output_files: + raise exceptions.AutosubException(_("\nAll works done.")) + + except KeyError: + pass + + def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-many-locals args, input_m=input, @@ -592,11 +636,6 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma """ Give args and translate a subtitles file. """ - if not args.output_files: - raise exceptions.AutosubException( - _("\nNo works done." - " Check your \"-of\"/\"--output-files\" option.")) - src_sub = pysubs2.SSAFile.load(args.input) text_list = [] diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 5d115ae3..a921c0a1 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -294,3 +294,146 @@ def assfile_to_txt_str(subtitles): Serialize ASSFile as a newline-delimited string. """ return '\n'.join(event.text for event in subtitles.events) + + +def merge_bilingual_assfile( # pylint: disable=too-many-locals, too-many-branches, too-many-statements + subtitles, + order=1): + """ + Merge a bilingual subtitles file's events automatically. + """ + style_events = {} + event_pos = {} + + i = 0 + for event in subtitles.events: + if event.style not in style_events: + style_events[event.style] = [event] + event_pos[event.style] = i + else: + style_events[event.style].append(event) + i = i + 1 + + sorted_events_list = sorted(style_events.values(), key=len) + events_1 = sorted_events_list.pop() + events_2 = sorted_events_list.pop() + + dst_ssafile = pysubs2.SSAFile() + src_ssafile = pysubs2.SSAFile() + + if event_pos[events_1[0].style] > event_pos[events_2[0].style] and order: + # destination language events are behind source language events in a bilingual subtitles + dst_ssafile.events = events_1 + src_ssafile.events = events_2 + else: + dst_ssafile.events = events_2 + src_ssafile.events = events_1 + + dst_ssafile.sort() + src_ssafile.sort() + + new_ssafile = pysubs2.SSAFile() + new_ssafile.styles = subtitles.styles + new_ssafile.info = subtitles.info + + # default in dst-lf-src order + dst_length = len(dst_ssafile.events) + src_length = len(src_ssafile.events) + i = 0 + j = 0 + + start = 0 + end = 0 + + events_0 = [] + while i < dst_length and j < src_length: + if dst_ssafile.events[i].is_comment != src_ssafile.events[j].is_comment: + if dst_ssafile.events[i].is_comment: + events_0.append(dst_ssafile.events[i]) + i = i + 1 + continue + events_0.append(src_ssafile.events[j]) + j = j + 1 + continue + if dst_ssafile.events[i].start == src_ssafile.events[j].start or \ + dst_ssafile.events[i].end == src_ssafile.events[j].end: + start = dst_ssafile.events[i].start + end = dst_ssafile.events[i].end + elif dst_ssafile.events[i].start >= src_ssafile.events[j].end: + events_0.append(src_ssafile.events[j]) + j = j + 1 + continue + elif src_ssafile.events[j].start >= dst_ssafile.events[i].end: + events_0.append(dst_ssafile.events[i]) + i = i + 1 + continue + elif src_ssafile.events[j].start < dst_ssafile.events[i].start: + event = pysubs2.SSAEvent() + event.start = src_ssafile.events[j].start + event.end = dst_ssafile.events[i].start + event.is_comment = src_ssafile.events[j].is_comment + event.text = src_ssafile.events[j].text + event.style = src_ssafile.events[j].style + events_0.append(event) + start = dst_ssafile.events[i].start + + if src_ssafile.events[j].end > dst_ssafile.events[i].end: + event = pysubs2.SSAEvent() + event.start = dst_ssafile.events[i].end + event.end = src_ssafile.events[j].end + event.is_comment = src_ssafile.events[j].is_comment + event.text = src_ssafile.events[j].text + event.style = src_ssafile.events[j].style + events_0.append(event) + end = dst_ssafile.events[i].end + else: + end = src_ssafile.events[j].end + + elif dst_ssafile.events[i].start < src_ssafile.events[j].start: + event = pysubs2.SSAEvent() + event.start = dst_ssafile.events[i].start + event.end = src_ssafile.events[j].start + event.is_comment = dst_ssafile.events[i].is_comment + event.text = dst_ssafile.events[i].text + event.style = dst_ssafile.events[i].style + events_0.append(event) + start = src_ssafile.events[j].start + + if dst_ssafile.events[i].end > src_ssafile.events[j].end: + event = pysubs2.SSAEvent() + event.start = src_ssafile.events[j].end + event.end = dst_ssafile.events[i].end + event.is_comment = dst_ssafile.events[i].is_comment + event.text = dst_ssafile.events[i].text + event.style = dst_ssafile.events[i].style + events_0.append(event) + end = src_ssafile.events[j].end + else: + end = dst_ssafile.events[i].end + + event = pysubs2.SSAEvent() + event.start = start + event.end = end + event.is_comment = dst_ssafile.events[i].is_comment + event.text = \ + dst_ssafile.events[i].text + \ + "\\N{{\\r{style_name}}}".format( + style_name=src_ssafile.events[j].style) + \ + src_ssafile.events[j].text + event.style = dst_ssafile.events[i].style + new_ssafile.events.append(event) + i = i + 1 + j = j + 1 + + if i < dst_length: + new_ssafile.events = new_ssafile.events + events_0 + dst_ssafile.events[i:] + else: + new_ssafile.events = new_ssafile.events + events_0 + src_ssafile.events[j:] + + for events in sorted_events_list: + if event_pos[events[0].style] > event_pos[new_ssafile.events[0].style]: + new_ssafile.events = new_ssafile.events + events + else: + new_ssafile.events = events + new_ssafile.events + + return new_ssafile diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 59439209..6a701fc8 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -42,6 +42,7 @@ - 添加额外的环境变量检查在查找依赖时。[issue #91](https://github.com/BingLingGroup/autosub/issues/91) - 添加无参数启动时的请求输入参数解析功能。[issue #92](https://github.com/BingLingGroup/autosub/issues/92) +- 添加字幕处理功能,当不输入`-SRC`选项时。 #### 改动(未发布) From b1ae5a088b1112f858e5b99f74ab3a7e571d5091 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Fri, 20 Mar 2020 09:59:08 +0800 Subject: [PATCH 8/8] Docs update changelog --- CHANGELOG.md | 75 ++++++++++++++++++++++++++++----------- autosub/metadata.py | 2 +- docs/CHANGELOG.zh-Hans.md | 66 ++++++++++++++++++++++++---------- 3 files changed, 102 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f23c41b0..93ece95e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,28 +12,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Unreleased](#unreleased) - [Added](#addedunreleased) - [Changed](#changedunreleased) +- [0.5.6-alpha - 2020-03-20](#056-alpha---2020-03-20) + - [Added](#added056-alpha) + - [Changed](#changed056-alpha) + - [Deprecated](#deprecated056-alpha) + - [Fixed](#fixed056-alpha) - [0.5.5-alpha - 2020-03-04](#055-alpha---2020-03-04) - [Added](#added055-alpha) - - [Changed](#changed055-alpha) + - [Fixed](#fixed055-alpha) - [0.5.4-alpha - 2020-01-31](#054-alpha---2020-01-31) - [Added](#added054-alpha) - - [Changed](#changed054-alpha) + - [Removed](#removed054-alpha) + - [Fixed](#fixed054-alpha) - [0.5.3-alpha - 2019-12-30](#053-alpha---2019-12-30) - - [Changed](#changed053-alpha) + - [Fixed](#fixed053-alpha) - [0.5.2-alpha - 2019-11-05](#052-alpha---2019-11-05) - [Added](#added052-alpha) - - [Changed](#changed052-alpha) + - [Fixed](#fixed052-alpha) - [0.5.1-alpha - 2019-08-02](#051-alpha---2019-08-02) - [Added](#added051-alpha) - - [Changed](#changed051-alpha) + - [Fixed](#fixed051-alpha) - [0.5.0-alpha - 2019-07-27](#050-alpha---2019-07-27) - [Added](#added050-alpha) - [Changed](#changed050-alpha) + - [Fixed](#fixed050-alpha) - [0.4.1-alpha - 2019-07-11](#041-alpha---2019-07-11) - [Added](#added041-alpha) - [Changed](#changed041-alpha) + - [Fixed](#fixed041-alpha) - [0.4.0-alpha - 2019-02-17](#040-alpha---2019-02-17) - - [Changed](#changed040-alpha) + - [Fixed](#fixed040-alpha) Click up arrow to go back to TOC. @@ -41,16 +49,29 @@ Click up arrow to go back to TOC. #### Added(Unreleased) +#### Changed(Unreleased) + +### [0.5.6-alpha] - 2020-03-20 + +#### Added(0.5.6-alpha) + - Add extra environment variables check when finding dependencies. [issue #91](https://github.com/BingLingGroup/autosub/issues/91) - Add arguments parser input when open it without arguments. [issue #92](https://github.com/BingLingGroup/autosub/issues/92) - Add subtitles processing when not input `-SRC`. -#### Changed(Unreleased) +#### Changed(0.5.6-alpha) -- Fix Google Speech-to-Text API empty result response bug. [issue #89](https://github.com/BingLingGroup/autosub/issues/89) - Change option `-sml` into `-nsml`. - Change defaults for Auditok. +#### Fixed(0.5.6-alpha) + +- Fix Google Speech-to-Text API empty result response bug. [issue #89](https://github.com/BingLingGroup/autosub/issues/89) + +#### Deprecated(0.5.6-alpha) + +- Deprecate Python 2.7 support. + ### [0.5.5-alpha] - 2020-03-04 #### Added(0.5.5-alpha) @@ -60,12 +81,14 @@ Click up arrow to go back to TOC. - Add exception when receiving error from [Google-Speech-v2](https://github.com/gillesdemey/google-speech-v2). - Add Nuitka compatibility codes to stop program compiled by Nuitka when using Google Cloud service account credentials. [Nuitka pkg_resources.DistributionNotFound error](https://github.com/Nuitka/Nuitka/issues/146) -#### Changed(0.5.5-alpha) +#### Fixed(0.5.5-alpha) - Fix high memory/RAM usage partially by terminating child processes, lowering default multiprocessing counts and using `gc.collect(0)`. [issue #67](https://github.com/BingLingGroup/autosub/issues/67), [issue #74](https://github.com/BingLingGroup/autosub/issues/74) - Fix dependency finding issue. [issue #82](https://github.com/BingLingGroup/autosub/issues/82) - Fix ass override tags translation issue. [issue #79](https://github.com/BingLingGroup/autosub/issues/79) + ↑  + ### [0.5.4-alpha] - 2020-01-31 #### Added(0.5.4-alpha) @@ -73,16 +96,19 @@ Click up arrow to go back to TOC. - Add basic Google Cloud Speech-to-Text support. [issue #10](https://github.com/BingLingGroup/autosub/issues/10) - Add more bilingual subtitles formats output support. [issue #72](https://github.com/BingLingGroup/autosub/issues/72) -#### Changed(0.5.4-alpha) +#### Removed(0.5.4-alpha) -- Fix output format limits when input is a subtitles file. - Remove gtransv2 support. +#### Fixed(0.5.4-alpha) + +- Fix output format limits when input is a subtitles file. +  ↑  ### [0.5.3-alpha] - 2019-12-30 -#### Changed(0.5.3-alpha) +#### Fixed(0.5.3-alpha) - Fix excessive transcoding time issue. [pull request #66](https://github.com/BingLingGroup/autosub/pull/66) - Fix Auditok option issues. [issue #70](https://github.com/BingLingGroup/autosub/issues/70) @@ -96,7 +122,7 @@ Click up arrow to go back to TOC. - Add issue templates. -#### Changed(0.5.2-alpha) +#### Fixed(0.5.2-alpha) - Fix last row of empty translation text missing issue. [issue #62](https://github.com/BingLingGroup/autosub/issues/62) - Fix executable file detection problem in the current directory. @@ -109,7 +135,7 @@ Click up arrow to go back to TOC. - Add translation source lang code auto match. -#### Changed(0.5.1-alpha) +#### Fixed(0.5.1-alpha) - Fix method list_to_googletrans index error bug. [issue #48](https://github.com/BingLingGroup/autosub/issues/48) - Fix unix subprocess.check_output compatibility. [issue #47](https://github.com/BingLingGroup/autosub/issues/47) @@ -166,14 +192,17 @@ Click up arrow to go back to TOC. - Refactor internal regions unit to millisecond. [issue #23](https://github.com/BingLingGroup/autosub/issues/23) - Refactor speech regions detection by using auditok. [issue #27](https://github.com/BingLingGroup/autosub/issues/27) - Refactor generate_subtitles into 3 parts. [issue #24](https://github.com/BingLingGroup/autosub/issues/24) -- [issue #8](https://github.com/BingLingGroup/autosub/issues/8) - - Fix python3 compatibility issues. - - Fix Nuitka build after updating Nuitka to 0.6.4(Environment Anaconda2 python3.5). - Refactor api_gen_text to 2 parts. One is speech_to_text. Another is text_translation. [issue #33](https://github.com/BingLingGroup/autosub/issues/33) - Refactor txt output. Now txt can output regions. -- Fix vtt output replacing all commas to dots issues. - Refactor list_to_sub_str. [issue #37](https://github.com/BingLingGroup/autosub/issues/37) +#### Fixed(0.5.0-alpha) + +- Fix vtt output replacing all commas to dots issues. +- [issue #8](https://github.com/BingLingGroup/autosub/issues/8) + - Fix python3 compatibility issues. + - Fix Nuitka build after updating Nuitka to 0.6.4(Environment Anaconda2 python3.5). +  ↑  ### [0.4.1-alpha] - 2019-07-11 @@ -188,16 +217,19 @@ Click up arrow to go back to TOC. #### Changed(0.4.1-alpha) -- Fix vague language codes caused wrong recognition result. [agermanidis/autosub pull request #136](https://github.com/agermanidis/autosub/pull/136) - Change docs. +#### Fixed(0.4.1-alpha) + +- Fix vague language codes caused wrong recognition result. [agermanidis/autosub pull request #136](https://github.com/agermanidis/autosub/pull/136) +  ↑  ### [0.4.0-alpha] - 2019-02-17 [0.4.0-alpha release](https://github.com/BingLingGroup/autosub/releases/tag/0.4.0-alpha) -#### Changed(0.4.0-alpha) +#### Fixed(0.4.0-alpha) - Fix several issues. [agermanidis/autosub pull request #128](https://github.com/agermanidis/autosub/pull/128) by [@iWangJiaxiang](https://github.com/iWangJiaxiang) - Fix "ffmpeg.exe" causes "Dependency not found: ffmpeg" on Windows. @@ -207,7 +239,8 @@ Click up arrow to go back to TOC.  ↑  -[Unreleased]: https://github.com/BingLingGroup/autosub/compare/0.5.5-alpha...HEAD +[Unreleased]: https://github.com/BingLingGroup/autosub/compare/0.5.6-alpha...HEAD +[0.5.6-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.5-alpha...0.5.6-alpha [0.5.5-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.4-alpha...0.5.5-alpha [0.5.4-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.3-alpha...0.5.4-alpha [0.5.3-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.2-alpha...0.5.3-alpha diff --git a/autosub/metadata.py b/autosub/metadata.py index 73a42882..23df48dd 100644 --- a/autosub/metadata.py +++ b/autosub/metadata.py @@ -12,7 +12,7 @@ # For gettext po files NAME = 'autosub' -VERSION = '0.5.5-alpha' +VERSION = '0.5.6-alpha' DESCRIPTION = _('Auto-generate subtitles for video/audio/subtitles file.') LONG_DESCRIPTION = ( _('Autosub is an automatic subtitles generating utility. ' diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 6a701fc8..0551a773 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -11,28 +11,34 @@ - [未发布](#未发布) - [添加](#添加未发布) - [改动](#修改未发布) +- [0.5.6-alpha - 2020-03-20](#056-alpha---2020-03-20) + - [添加](#添加056-alpha) + - [即将删除](#即将删除056-alpha) + - [修复](#修复056-alpha) - [0.5.5-alpha - 2020-03-04](#055-alpha---2020-03-04) - [添加](#添加055-alpha) - - [改动](#改动055-alpha) + - [修复](#修复055-alpha) - [0.5.4-alpha - 2020-01-31](#054-alpha---2020-01-31) - [添加](#添加054-alpha) - - [改动](#改动054-alpha) + - [删除](#删除054-alpha) + - [修复](#修复054-alpha) - [0.5.3-alpha - 2019-12-30](#053-alpha---2019-12-30) - - [改动](#改动053-alpha) + - [修复](#修复053-alpha) - [0.5.2-alpha - 2019-11-05](#052-alpha---2019-11-05) - [添加](#添加052-alpha) - - [改动](#改动052-alpha) + - [修复](#修复052-alpha) - [0.5.1-alpha - 2019-08-02](#051-alpha---2019-08-02) - [添加](#添加051-alpha) - - [改动](#改动051-alpha) + - [修复](#修复051-alpha) - [0.5.0-alpha - 2019-07-27](#050-alpha---2019-07-27) - [添加](#添加050-alpha) - [改动](#改动050-alpha) + - [修复](#修复050-alpha) - [0.4.1-alpha - 2019-07-11](#041-alpha---2019-07-11) - [添加](#添加041-alpha) - [改动](#改动041-alpha) - [0.4.0-alpha - 2019-02-17](#040-alpha---2019-02-17) - - [改动](#改动040-alpha) + - [修复](#修复040-alpha) 点击上箭头以返回目录。 @@ -40,11 +46,21 @@ #### 添加(未发布) +#### 改动(未发布) + +### [0.5.6-alpha] - 2020-03-20 + +#### 添加(0.5.6-alpha) + - 添加额外的环境变量检查在查找依赖时。[issue #91](https://github.com/BingLingGroup/autosub/issues/91) - 添加无参数启动时的请求输入参数解析功能。[issue #92](https://github.com/BingLingGroup/autosub/issues/92) - 添加字幕处理功能,当不输入`-SRC`选项时。 -#### 改动(未发布) +#### 即将删除(0.5.6-alpha) + +- 即将删除Python 2.7支持。 + +#### 修复(0.5.6-alpha) - 修复Google Speech-to-Text API空结果返回bug。[issue #89](https://github.com/BingLingGroup/autosub/issues/89) - 修改选项`-sml`为`-nsml`。 @@ -59,12 +75,14 @@ - 添加[Google-Speech-v2](https://github.com/gillesdemey/google-speech-v2)识别错误的异常。 - 添加Nuitka兼容性代码,使得Nuitka编译版在使用Google Cloud服务账号凭据时终止运行。[Nuitka pkg_resources.DistributionNotFound错误](https://github.com/Nuitka/Nuitka/issues/146) -#### 改动(0.5.5-alpha) +#### 修复(0.5.5-alpha) - 修复部分高内存占用,通过终结子进程,减少默认多进程数量,使用`gc.collect(0)`。[issue #67](https://github.com/BingLingGroup/autosub/issues/67),[issue #74](https://github.com/BingLingGroup/autosub/issues/74) - 修复依赖查找问题。[issue #82](https://github.com/BingLingGroup/autosub/issues/82) - 修复ass标签翻译问题。[issue #79](https://github.com/BingLingGroup/autosub/issues/79) + ↑  + ### [0.5.4-alpha] - 2020-01-31 #### 添加(0.5.4-alpha) @@ -72,16 +90,19 @@ - 添加Google Cloud Speech-to-Text基础支持。[issue #10](https://github.com/BingLingGroup/autosub/issues/10) - 添加更多格式的双语字幕输出支持。[issue #72](https://github.com/BingLingGroup/autosub/issues/72) -#### 改动(0.5.4-alpha) +#### 删除(0.5.4-alpha) -- 修复输入是字幕文件时的输出格式限制。 - 删除gtransv2支持。 +#### 修复(0.5.4-alpha) + +- 修复输入是字幕文件时的输出格式限制。 +  ↑  ### [0.5.3-alpha] - 2019-12-30 -#### 改动(0.5.3-alpha) +#### 修复(0.5.3-alpha) - 修复ffmpeg参数导致的过长转码时间问题。[pull request #66](https://github.com/BingLingGroup/autosub/pull/66) - 修复Auditok选项问题。[issue #70](https://github.com/BingLingGroup/autosub/issues/70) @@ -95,7 +116,7 @@ - 添加问题模板。 -#### 改动(0.5.2-alpha) +#### 修复(0.5.2-alpha) - 修复最后一排空翻译丢行问题。[issue #62](https://github.com/BingLingGroup/autosub/issues/62) - 修复当前运行路径的可执行文件检测问题。 @@ -108,7 +129,7 @@ - 添加翻译源语言代码自动匹配功能。 -#### 改动(0.5.1-alpha) +#### 修复(0.5.1-alpha) - 修复方法list_to_googletrans的列表越界bug。[issue #48](https://github.com/BingLingGroup/autosub/issues/48) - 修复unix subprocess.check_output的兼容性问题。[issue #47](https://github.com/BingLingGroup/autosub/issues/47) @@ -163,13 +184,16 @@ - 修改内部音频处理的时间单位为毫秒。[issue #23](https://github.com/BingLingGroup/autosub/issues/23) - 修改内部时间轴/分句处理为auditok。[issue #27](https://github.com/BingLingGroup/autosub/issues/27) - 重构内部函数generate_subtitles为3个独立的部分。[issue #24](https://github.com/BingLingGroup/autosub/issues/24) +- 重构内部函数api_gen_text为两部分。一个是speech_to_text。另一个是text_translation。[issue #33](https://github.com/BingLingGroup/autosub/issues/33) +- 重构txt输出,现在可以用txt输出时间码。 +- 重构方法list_to_sub_str。[issue #37](https://github.com/BingLingGroup/autosub/issues/37) + +#### 修复(0.5.0-alpha) + - [issue #8](https://github.com/BingLingGroup/autosub/issues/8) - 修复python3兼容性问题。 - 修复Nuitka构建问题(Nuitka更新至0.6.4后解决,环境Anaconda2 python3.5)。 -- 重构内部函数api_gen_text为两部分。一个是speech_to_text。另一个是text_translation。[issue #33](https://github.com/BingLingGroup/autosub/issues/33) -- 重构txt输出,现在可以用txt输出时间码。 - 修复vtt输出模块替换所有逗号到句号的问题。 -- 重构方法list_to_sub_str。[issue #37](https://github.com/BingLingGroup/autosub/issues/37)  ↑  @@ -183,14 +207,17 @@ #### 改动(0.4.1-alpha) -- 修复因不确切的语言代码导致的错误识别结果。[agermanidis/autosub pull request #136](https://github.com/agermanidis/autosub/pull/136) - 修改文档。 +#### 修复(0.4.1-alpha) + +- 修复因不确切的语言代码导致的错误识别结果。[agermanidis/autosub pull request #136](https://github.com/agermanidis/autosub/pull/136) +  ↑  ### [0.4.0-alpha] - 2019-02-17 -#### 改动(0.4.0-alpha) +#### 修复(0.4.0-alpha) - 修复多个问题。[agermanidis/autosub pull request #128](https://github.com/agermanidis/autosub/pull/128) by [@iWangJiaxiang](https://github.com/iWangJiaxiang) - 修复Windows上ffmpeg依赖不存在问题。 @@ -200,7 +227,8 @@  ↑  -[未发布]: https://github.com/BingLingGroup/autosub/compare/0.5.5-alpha...HEAD +[未发布]: https://github.com/BingLingGroup/autosub/compare/0.5.6-alpha...HEAD +[0.5.6-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.5-alpha...0.5.6-alpha [0.5.5-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.4-alpha...0.5.5-alpha [0.5.4-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.3-alpha...0.5.4-alpha [0.5.3-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.2-alpha...0.5.3-alpha