From 8b160fb8d43e443d8dad9b5e4e5e830bd8829f4f Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Fri, 20 Mar 2020 17:54:38 +0800 Subject: [PATCH 01/26] Remove support for python 2.7 Add xfyun_api.py for Xfyun Speech-to-Text Websocket API --- autosub/__init__.py | 21 +- autosub/__main__.py | 3 +- autosub/cmdline_utils.py | 10 +- autosub/constants.py | 4 +- autosub/core.py | 32 +-- .../LC_MESSAGES/autosub.cmdline_utils.po | 102 ++++---- .../data/locale/zh_CN/LC_MESSAGES/autosub.po | 10 +- autosub/exceptions.py | 9 +- autosub/ffmpeg_utils.py | 11 +- .../{google_speech_api.py => google_api.py} | 13 +- autosub/lang_code_utils.py | 9 +- autosub/metadata.py | 6 +- autosub/options.py | 11 +- autosub/sub_utils.py | 3 +- autosub/xfyun_api.py | 223 ++++++++++++++++++ requirements.txt | 3 +- scripts/pyinstaller_build.spec | 3 +- scripts/xfyun_api_websockets.py | 192 +++++++++++++++ setup.py | 9 +- 19 files changed, 525 insertions(+), 149 deletions(-) rename autosub/{google_speech_api.py => google_api.py} (95%) create mode 100644 autosub/xfyun_api.py create mode 100644 scripts/xfyun_api_websockets.py diff --git a/autosub/__init__.py b/autosub/__init__.py index 0d0eae1b..0316f780 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines autosub's commandline entry point functionality. """ # Import built-in modules -from __future__ import absolute_import, print_function, unicode_literals import os import gettext import sys @@ -25,11 +24,7 @@ languages=[constants.CURRENT_LOCALE], fallback=True) -try: - _ = INIT_TEXT.ugettext -except AttributeError: - # Python 3 fallback - _ = INIT_TEXT.gettext +_ = INIT_TEXT.gettext def main(): # pylint: disable=too-many-branches, too-many-statements, too-many-locals @@ -39,17 +34,13 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- is_pause = False - try: - input_main = raw_input - except NameError: - input_main = input - + # todo1: move into constants to support locale and dependency 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\"): ")) + new_argv = input(_("\nInput args(without \"autosub\"): ")) args = option_parser.parse_args(shlex.split(new_argv)) is_pause = True @@ -73,7 +64,7 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- raise exceptions.AutosubException(_("\nAll works done.")) if not args.yes: - input_m = input_main + input_m = input else: input_m = None @@ -185,5 +176,5 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- print(err_msg) if is_pause: - input_main(_("Press Enter to exit...")) + input(_("Press Enter to exit...")) return 0 diff --git a/autosub/__main__.py b/autosub/__main__.py index 0c9eb900..0406f98f 100644 --- a/autosub/__main__.py +++ b/autosub/__main__.py @@ -1,11 +1,10 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines autosub's entry point. """ # Import built-in modules # pylint: disable=no-member, protected-access -from __future__ import absolute_import, print_function, unicode_literals import multiprocessing import sys diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 3d20390c..26a287c3 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -1,12 +1,10 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines autosub's command line functionality. """ # pylint: disable=too-many-lines # Import built-in modules -from __future__ import absolute_import, print_function, unicode_literals - import gettext import os import subprocess @@ -33,11 +31,7 @@ languages=[constants.CURRENT_LOCALE], fallback=True) -try: - _ = CMDLINE_UTILS_TEXT.ugettext -except AttributeError: - # Python 3 fallback - _ = CMDLINE_UTILS_TEXT.gettext +_ = CMDLINE_UTILS_TEXT.gettext def list_args(args): diff --git a/autosub/constants.py b/autosub/constants.py index 2a7783d0..524e099a 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines constants used by autosub. """ # Import built-in modules -from __future__ import absolute_import, print_function, unicode_literals import os import sys import shlex @@ -57,6 +56,7 @@ GOOGLE_SPEECH_V2_API_KEY = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" GOOGLE_SPEECH_V2_API_URL = \ "www.google.com/speech-api/v2/recognize?client=chromium&lang={lang}&key={key}" +XFYUN_SPEECH_WEBAPI_URL = "iat-api.xfyun.cn" if multiprocessing.cpu_count() > 3: DEFAULT_CONCURRENCY = multiprocessing.cpu_count() >> 1 diff --git a/autosub/core.py b/autosub/core.py index 140bf171..6090f9c7 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines autosub's core functionality. """ # Import built-in modules -from __future__ import absolute_import, print_function, unicode_literals import os import multiprocessing import time @@ -20,7 +19,7 @@ import wcwidth # Any changes to the path and your own modules -from autosub import google_speech_api +from autosub import google_api from autosub import sub_utils from autosub import constants from autosub import ffmpeg_utils @@ -36,11 +35,7 @@ languages=[constants.CURRENT_LOCALE], fallback=True) -try: - _ = CORE_TEXT.ugettext -except AttributeError: - # Python 3 fallback - _ = CORE_TEXT.gettext +_ = CORE_TEXT.gettext def extension_to_encoding( @@ -226,7 +221,7 @@ def gsv2_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many text_list = [] pool = multiprocessing.Pool(concurrency) - recognizer = google_speech_api.GoogleSpeechV2( + recognizer = google_api.GoogleSpeechV2( api_url=api_url, headers=headers, min_confidence=min_confidence, @@ -255,7 +250,7 @@ def gsv2_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many if result: result_list.append(result) transcript = \ - google_speech_api.get_google_speech_v2_transcript(min_confidence, result) + google_api.get_google_speech_v2_transcript(min_confidence, result) if transcript: text_list.append(transcript) continue @@ -322,10 +317,9 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man config = { "encoding": extension_to_encoding(audio_fragments[0]), "sampleRateHertz": sample_rate, - "languageCode": src_language, - } + "languageCode": src_language} - recognizer = google_speech_api.GCSV1P1Beta1URL( + recognizer = google_api.GCSV1P1Beta1URL( config=config, api_url=api_url, headers=headers, @@ -346,7 +340,7 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man for i, result in enumerate(pool.imap(recognizer, audio_fragments)): if result: result_list.append(result) - transcript = google_speech_api.get_gcsv1p1beta1_transcript( + transcript = google_api.get_gcsv1p1beta1_transcript( min_confidence, result) if transcript: @@ -370,11 +364,9 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man config = { "encoding": extension_to_encoding( extension=audio_fragments[0], - is_string=False - ), + is_string=False), "sample_rate_hertz": sample_rate, - "language_code": src_language, - } + "language_code": src_language} i = 0 tasks = [] @@ -382,7 +374,7 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man # google cloud speech-to-text client can't use multiprocessing.pool # based on class call, otherwise will receive pickling error tasks.append(pool.apply_async( - google_speech_api.gcsv1p1beta1_service_client, + google_api.gcsv1p1beta1_service_client, args=(filename, is_keep, config, min_confidence, result_list is not None))) gc.collect(0) @@ -401,7 +393,7 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man i = i + 1 result = task.get() result_list.append(result) - transcript = google_speech_api.get_gcsv1p1beta1_transcript( + transcript = google_api.get_gcsv1p1beta1_transcript( min_confidence, result) if transcript: 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 f640e2b8..95a491bc 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-19 10:17+0800\n" +"POT-Creation-Date: 2020-03-20 10:01+0800\n" "PO-Revision-Date: 2020-03-12 12:16+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -230,7 +230,7 @@ msgstr "你已经输入了时间轴。啥都没做。" msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:445 autosub/cmdline_utils.py:538 +#: autosub/cmdline_utils.py:445 autosub/cmdline_utils.py:537 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" @@ -283,11 +283,7 @@ msgid "" "Error: Translation source language is the same as the destination language." msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:531 -msgid "Error: Translation source language is not provided." -msgstr "错误:翻译源语言未提供。" - -#: autosub/cmdline_utils.py:550 +#: autosub/cmdline_utils.py:551 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -295,7 +291,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:557 +#: autosub/cmdline_utils.py:558 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -303,7 +299,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:564 +#: autosub/cmdline_utils.py:565 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -311,51 +307,52 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:597 autosub/cmdline_utils.py:863 +#: autosub/cmdline_utils.py:621 autosub/cmdline_utils.py:765 +#: autosub/cmdline_utils.py:1294 +msgid "\"dst-lf-src\" subtitles file created at \"{}\"." +msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" + +#: autosub/cmdline_utils.py:625 autosub/cmdline_utils.py:717 +#: autosub/cmdline_utils.py:769 autosub/cmdline_utils.py:821 +#: autosub/cmdline_utils.py:1002 autosub/cmdline_utils.py:1148 +#: autosub/cmdline_utils.py:1190 autosub/cmdline_utils.py:1250 +#: autosub/cmdline_utils.py:1298 autosub/cmdline_utils.py:1346 msgid "" "\n" -"No works done. Check your \"-of\"/\"--output-files\" option." +"All works done." msgstr "" "\n" -"啥都没做。检查你的\"-of\"/\"--output-files\"选项。" +"做完了。" -#: autosub/cmdline_utils.py:630 autosub/cmdline_utils.py:1168 +#: autosub/cmdline_utils.py:669 autosub/cmdline_utils.py:1207 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:674 autosub/cmdline_utils.py:1207 +#: autosub/cmdline_utils.py:713 autosub/cmdline_utils.py:1246 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: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." -msgstr "" -"\n" -"做完了。" - -#: 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:1303 +#: autosub/cmdline_utils.py:817 autosub/cmdline_utils.py:1342 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:821 autosub/cmdline_utils.py:1348 +#: autosub/cmdline_utils.py:860 autosub/cmdline_utils.py:1387 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:868 +#: autosub/cmdline_utils.py:902 +msgid "" +"\n" +"No works done. Check your \"-of\"/\"--output-files\" option." +msgstr "" +"\n" +"啥都没做。检查你的\"-of\"/\"--output-files\"选项。" + +#: autosub/cmdline_utils.py:907 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:902 +#: autosub/cmdline_utils.py:941 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -363,11 +360,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:912 +#: autosub/cmdline_utils.py:951 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:915 +#: autosub/cmdline_utils.py:954 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -375,7 +372,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:927 +#: autosub/cmdline_utils.py:966 msgid "" "\n" "\"{name}\" has been deleted." @@ -383,19 +380,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:931 +#: autosub/cmdline_utils.py:970 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:960 autosub/cmdline_utils.py:1415 +#: autosub/cmdline_utils.py:999 autosub/cmdline_utils.py:1454 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:984 +#: autosub/cmdline_utils.py:1023 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:988 +#: autosub/cmdline_utils.py:1027 msgid "" "Audio processing complete.\n" "All works done." @@ -403,11 +400,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1040 +#: autosub/cmdline_utils.py:1079 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1055 +#: autosub/cmdline_utils.py:1094 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -417,18 +414,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1060 +#: autosub/cmdline_utils.py:1099 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1074 +#: autosub/cmdline_utils.py:1113 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1086 +#: autosub/cmdline_utils.py:1125 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -436,11 +433,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1105 +#: autosub/cmdline_utils.py:1144 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1113 +#: autosub/cmdline_utils.py:1152 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -448,11 +445,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1147 autosub/cmdline_utils.py:1385 +#: autosub/cmdline_utils.py:1186 autosub/cmdline_utils.py:1424 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1357 +#: autosub/cmdline_utils.py:1396 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -460,7 +457,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1390 +#: autosub/cmdline_utils.py:1429 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output regions subtitles file only." @@ -468,6 +465,9 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出时间轴文件。" +#~ msgid "Error: Translation source language is not provided." +#~ msgstr "错误:翻译源语言未提供。" + #~ msgid "" #~ "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/" #~ "\"--list-speech-codes\" to see all supported languages." diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po index 44529496..70142e44 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-12 17:25+0800\n" +"POT-Creation-Date: 2020-03-20 10:01+0800\n" "PO-Revision-Date: 2020-03-12 17:25+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -25,7 +25,7 @@ msgstr "" "\n" "输入参数(不包含\"autosub\"): " -#: autosub/__init__.py:73 autosub/__init__.py:171 +#: autosub/__init__.py:73 autosub/__init__.py:178 msgid "" "\n" "All works done." @@ -73,7 +73,7 @@ msgstr "" msgid "Audio pre-processing complete." msgstr "音频预处理已完成。" -#: autosub/__init__.py:174 +#: autosub/__init__.py:181 msgid "" "\n" "KeyboardInterrupt. Works stopped." @@ -81,7 +81,7 @@ msgstr "" "\n" "键盘中断。操作终止。" -#: autosub/__init__.py:176 +#: autosub/__init__.py:183 msgid "" "\n" "Error: pysubs2.exceptions. Check your file format." @@ -89,7 +89,7 @@ msgstr "" "\n" "错误:pysubs2异常。检查你的文件格式。" -#: autosub/__init__.py:181 +#: autosub/__init__.py:188 msgid "Press Enter to exit..." msgstr "按回车以退出..." diff --git a/autosub/exceptions.py b/autosub/exceptions.py index bdbea96c..5ea1fc11 100644 --- a/autosub/exceptions.py +++ b/autosub/exceptions.py @@ -1,11 +1,10 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines exceptions used by autosub. """ # Import built-in modules -from __future__ import absolute_import, print_function, unicode_literals import sys # Import third-party modules @@ -41,3 +40,9 @@ class SpeechToTextException(AutosubException): """ Raised when speech-to-text failed. """ + + +class XfyunWebSocketClosedException(AutosubException): + """ + Raised when xfyun speech-to-text websocket closed. + """ diff --git a/autosub/ffmpeg_utils.py b/autosub/ffmpeg_utils.py index 5e19f25f..3ec5d8c2 100644 --- a/autosub/ffmpeg_utils.py +++ b/autosub/ffmpeg_utils.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines ffmpeg command line calling functionality. """ # Import built-in modules -from __future__ import absolute_import, print_function, unicode_literals import subprocess import tempfile import re @@ -24,14 +23,10 @@ languages=[constants.CURRENT_LOCALE], fallback=True) -try: - _ = FFMPEG_UTILS_TEXT.ugettext -except AttributeError: - # Python 3 fallback - _ = FFMPEG_UTILS_TEXT.gettext +_ = FFMPEG_UTILS_TEXT.gettext -class SplitIntoAudioPiece(object): # pylint: disable=too-few-public-methods +class SplitIntoAudioPiece: # pylint: disable=too-few-public-methods """ Class for converting a region of an input audio or video file into a short-term audio file """ diff --git a/autosub/google_speech_api.py b/autosub/google_api.py similarity index 95% rename from autosub/google_speech_api.py rename to autosub/google_api.py index ae026beb..9b251f33 100644 --- a/autosub/google_speech_api.py +++ b/autosub/google_api.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -Defines google speech api used by autosub. +Defines Google API used by autosub. """ # Import built-in modules -from __future__ import absolute_import, unicode_literals import os import base64 import json @@ -94,7 +93,7 @@ def get_gcsv1p1beta1_transcript( return result -class GoogleSpeechV2(object): # pylint: disable=too-few-public-methods +class GoogleSpeechV2: # pylint: disable=too-few-public-methods """ Class for performing speech-to-text using Google Speech V2 API for an input FLAC file. """ @@ -176,9 +175,9 @@ def gcsv1p1beta1_service_client( # https://cloud.google.com/speech-to-text/docs/reference/rpc/google.cloud.speech.v1p1beta1#google.cloud.speech.v1p1beta1.SpeechRecognitionResult client = speech_v1p1beta1.SpeechClient() audio_dict = {"content": audio_data} - recognize_reponse = client.recognize(config, audio_dict) + recognize_response = client.recognize(config, audio_dict) result_dict = MessageToDict( - recognize_reponse, + recognize_response, preserving_proto_field_name=True) if not is_full_result: @@ -189,7 +188,7 @@ def gcsv1p1beta1_service_client( return None -class GCSV1P1Beta1URL(object): # pylint: disable=too-few-public-methods +class GCSV1P1Beta1URL: # pylint: disable=too-few-public-methods """ Class for performing Speech-to-Text using Google Cloud Speech-to-Text V1P1Beta1 API URL for an input FLAC file. diff --git a/autosub/lang_code_utils.py b/autosub/lang_code_utils.py index 5760d6ef..83e1e348 100644 --- a/autosub/lang_code_utils.py +++ b/autosub/lang_code_utils.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines autosub's lang codes functionality. """ # Import built-in modules -from __future__ import absolute_import, print_function, unicode_literals import gettext # Import third-party modules @@ -19,11 +18,7 @@ languages=[constants.CURRENT_LOCALE], fallback=True) -try: - _ = LANG_CODE_TEXT.ugettext -except AttributeError: - # Python 3 fallback - _ = LANG_CODE_TEXT.gettext +_ = LANG_CODE_TEXT.gettext def better_match(desired_language, diff --git a/autosub/metadata.py b/autosub/metadata.py index 23df48dd..0f5b69ef 100644 --- a/autosub/metadata.py +++ b/autosub/metadata.py @@ -1,12 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines autosub's metadata. """ -# Import built-in modules -from __future__ import unicode_literals - -# Any changes to the path and your own modules _ = str # For gettext po files diff --git a/autosub/options.py b/autosub/options.py index d56e00d5..a9e3b187 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines autosub's command line options. @@ -25,13 +25,8 @@ languages=[constants.CURRENT_LOCALE], fallback=True) -try: - _ = OPTIONS_TEXT.ugettext - M_ = META_TEXT.ugettext -except AttributeError: - # Python 3 fallback - _ = OPTIONS_TEXT.gettext - M_ = META_TEXT.gettext +_ = OPTIONS_TEXT.gettext +M_ = META_TEXT.gettext def get_cmd_parser(): # pylint: disable=too-many-statements diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index a921c0a1..9453d747 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines subtitle formatters used by autosub. """ # Import built-in modules -from __future__ import absolute_import, unicode_literals import wave import json diff --git a/autosub/xfyun_api.py b/autosub/xfyun_api.py new file mode 100644 index 00000000..8d0dd977 --- /dev/null +++ b/autosub/xfyun_api.py @@ -0,0 +1,223 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Defines Xun Fei Yun API used by autosub. +""" +# Import built-in modules +import datetime +import hashlib +import base64 +import hmac +import json +from urllib.parse import urlencode +import ssl +from email.utils import formatdate +import time +from datetime import datetime +from time import mktime + +# Import third-party modules +import websocket +import _thread + +# Any changes to the path and your own modules +from autosub import constants +from autosub import exceptions + + +def create_xfyun_url( + api_key, + api_secret, + api_address=constants.XFYUN_SPEECH_WEBAPI_URL +): + """ + Function for creating authorization for Xun Fei Yun Speech-to-Text Websocket API. + """ + request_location = "/v2/iat" + result_url = "wss://" + api_address + request_location + now = datetime.now() + stamp = mktime(now.timetuple()) + date = formatdate(timeval=stamp, localtime=False, usegmt=True) + + signature_origin = "host: " + api_address + "\n" + signature_origin += "date: " + date + "\n" + signature_origin += "GET " + request_location + " HTTP/1.1" + signature_sha = hmac.new( + api_secret.encode('utf-8'), + signature_origin.encode('utf-8'), + digestmod=hashlib.sha256).digest() + + signature_sha = base64.b64encode(signature_sha).decode(encoding='utf-8') + authorization_origin = "api_key=\"{api_key}\", " \ + "algorithm=\"hmac-sha256\", " \ + "headers=\"host date request-line\", " \ + "signature=\"{sign}\"".format( + api_key=api_key, + sign=signature_sha) + authorization = base64.b64encode( + authorization_origin.encode('utf-8')).decode(encoding='utf-8') + verification = { + "authorization": authorization, + "date": date, + "host": api_address + } + result_url = result_url + '?' + urlencode(verification) + return result_url + + +def get_xfyun_transcript( + result_dict): + """ + Function for getting transcript from Xun Fei Yun Speech-to-Text Websocket API result dictionary. + Reference: https://www.xfyun.cn/doc/asr/voicedictation/API.html + """ + try: + code = result_dict["code"] + if code != 0: + raise exceptions.SpeechToTextException( + json.dumps(result_dict, indent=4, ensure_ascii=False)) + result = "" + for item in result_dict["data"]["result"]["ws"]: + result = result + item["cw"][0]["w"] + return result + except (KeyError, TypeError): + return "" + + +class XfyunWebSocketAPI: # pylint: disable=too-many-instance-attributes, too-many-arguments, unnecessary-lambda + """ + Class for performing speech-to-text using Xun Fei Yun Speech-to-Text Websocket API. + Reference: https://www.xfyun.cn/doc/asr/voicedictation/API.html + #%E6%8E%A5%E5%8F%A3%E8%B0%83%E7%94%A8%E6%B5%81%E7%A8%8B + https://stackoverflow.com/questions/26980966/using-a-websocket-client-as-a-class-in-python + """ + def __init__(self, + app_id, + api_key, + api_secret, + api_address, + business_args, + is_full_result=False): + self.common_args = {"app_id": app_id} + self.api_key = api_key + self.api_secret = api_secret + self.api_address = api_address + self.business_args = business_args + self.is_full_result = is_full_result + self.data = {"status": 0, + "format": "audio/L16;rate=16000", + "encoding": "raw", + "audio": ""} + self.transcript = "" + self.result_list = [] + self.filename = None + self.web_socket_app = None + + def __call__(self, filename): + if self.is_full_result: + self.result_list = [] + else: + self.transcript = "" + self.filename = filename + websocket.enableTrace(False) + self.web_socket_app = websocket.WebSocketApp( + create_xfyun_url( + api_key=self.api_key, + api_secret=self.api_secret, + api_address=self.api_address), + on_message=lambda web_socket, msg: self.on_message(web_socket, msg), + on_error=lambda web_socket, msg: self.on_error(web_socket, msg), + on_close=lambda web_socket: self.on_close(web_socket), + on_open=lambda web_socket: self.on_open(web_socket)) + self.web_socket_app.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}) + if self.is_full_result: + return self.result_list + return self.transcript + + def on_message(self, web_socket, result): # pylint: disable=unused-argument + """ + Process the message received from WebSocket. + """ + try: + web_socket_result = json.loads(result) + except ValueError: + return + if not self.is_full_result: + self.transcript = self.transcript + get_xfyun_transcript(web_socket_result) + else: + self.result_list.append(web_socket_result) + + def on_error(self, web_socket, error): # pylint: disable=no-self-use + """ + Process the error from WebSocket. + """ + raise exceptions.SpeechToTextException(error) + + def on_close(self, web_socket): # pylint: disable=no-self-use + """ + Process the connection close from WebSocket. + """ + raise exceptions.XfyunWebSocketClosedException("") + + def on_open(self, web_socket): + """ + Process the connection open from WebSocket. + """ + def run(): + frame_size = 8000 # 每一帧的音频大小 + interval = 0.04 # 发送音频间隔(单位:s) + status = 0 # 音频的状态信息,标识音频是第一帧,还是中间帧、最后一帧 + with open(self.filename, "rb") as audio_file: + while True: + buf = audio_file.read(frame_size) + # 文件结束 + if not buf: + status = 2 + self.data["audio"] = str(base64.b64encode(buf), "utf-8") + # 第一帧处理 + # 发送第一帧音频,带business 参数 + # appid 必须带上,只需第一帧发送 + if status == 0: + self.data["status"] = 0 + web_socket_data = { + "common": self.common_args, + "business": self.business_args, + "data": self.data} + status = 1 + # 中间帧处理 + elif status == 1: + self.data["status"] = 1 + web_socket_data = {"data": self.data} + # 最后一帧处理 + elif status == 2: + self.data["status"] = 2 + web_socket_data = {"data": self.data} + web_socket_json = json.dumps(web_socket_data) + web_socket.send(web_socket_json) + time.sleep(1) + break + + web_socket_json = json.dumps(web_socket_data) + web_socket.send(web_socket_json) + # 模拟音频采样间隔 + time.sleep(interval) + web_socket.close() + _thread.start_new_thread(run, ()) + + +# if __name__ == "__main__": +# # 测试时候在此处正确填写相关信息即可运行 +# time1 = datetime.now() +# web_socket_result_obj = XfyunWebSocketAPI( +# app_id="", +# api_key="", +# api_secret="", +# api_address=constants.XFYUN_SPEECH_WEBAPI_URL, +# business_args={"language": "zh_cn", +# "domain": "iat", +# "accent": "mandarin"}, +# is_full_result=False) +# +# print(web_socket_result_obj(filename=r"C:\userfile\Video\autosub\test\temp.pcm")) +# time2 = datetime.now() +# print(time2 - time1) diff --git a/requirements.txt b/requirements.txt index 409887d5..6283f8b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ pysubs2>=0.2.4 progressbar2>=3.34.3 auditok>=0.1.5 googletrans>=2.4.0 -langcodes-py2>=1.2.0 +langcodes>=1.2.0 wcwidth>=0.1.7 google-cloud-speech>=1.3.1 +websocket-client>=0.56.0 diff --git a/scripts/pyinstaller_build.spec b/scripts/pyinstaller_build.spec index 02b82c7e..9ff5540a 100644 --- a/scripts/pyinstaller_build.spec +++ b/scripts/pyinstaller_build.spec @@ -13,7 +13,8 @@ a = Analysis([r"..\autosub\__main__.py", r"..\autosub\lang_code_utils.py", r"..\autosub\metadata.py", r"..\autosub\options.py", - r"..\autosub\google_speech_api.py", + r"..\autosub\google_api.py", + r"..\autosub\xfyun_api.py" r"..\autosub\sub_utils.py",], pathex=[r'C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x64'], binaries=[], diff --git a/scripts/xfyun_api_websockets.py b/scripts/xfyun_api_websockets.py new file mode 100644 index 00000000..86d48f04 --- /dev/null +++ b/scripts/xfyun_api_websockets.py @@ -0,0 +1,192 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Defines xfyun API used by autosub. +""" + +# Import built-in modules +import datetime +import hashlib +import base64 +import hmac +import json +from urllib.parse import urlencode +from email.utils import formatdate +import time +import asyncio +from datetime import datetime +from time import mktime + +# Import third-party modules +import websockets + +# Any changes to the path and your own modules +from autosub import constants +from autosub import exceptions + +try: + import thread +except ImportError: + import _thread as thread + + +def get_xfyun_transcript( + result_dict): + try: + code = result_dict["code"] + if code != 0: + raise exceptions.SpeechToTextException( + json.dumps(result_dict, indent=4, ensure_ascii=False)) + else: + result = "" + for item in result_dict["data"]["result"]["ws"]: + result = result + item["cw"][0]["w"] + return result + except (KeyError, TypeError): + return "" + + +def create_xfyun_url( + api_key, + api_secret, + url=constants.XFYUN_SPEECH_WEBAPI_URL +): + request_location = "/v2/iat" + result_url = "wss://" + url + request_location + now = datetime.now() + stamp = mktime(now.timetuple()) + date = formatdate(timeval=stamp, localtime=False, usegmt=True) + + signature_origin = "host: " + url + "\n" + signature_origin += "date: " + date + "\n" + signature_origin += "GET " + request_location + " HTTP/1.1" + signature_sha = hmac.new( + api_secret.encode('utf-8'), + signature_origin.encode('utf-8'), + digestmod=hashlib.sha256).digest() + + signature_sha = base64.b64encode(signature_sha).decode(encoding='utf-8') + authorization_origin = "api_key=\"{api_key}\", " \ + "algorithm=\"hmac-sha256\", " \ + "headers=\"host date request-line\", " \ + "signature=\"{sign}\"".format( + api_key=api_key, + sign=signature_sha) + authorization = base64.b64encode( + authorization_origin.encode('utf-8')).decode(encoding='utf-8') + v = { + "authorization": authorization, + "date": date, + "host": url + } + result_url = result_url + '?' + urlencode(v) + return result_url + + +async def xfyun_speech_websocket( + url, + app_id, + filename, + business_args, + is_full_result=False): + data = {"status": 0, + "format": "audio/L16;rate=16000", + "encoding": "raw", + "audio": ""} + common_args = {"app_id": app_id} + business_args = business_args + + transcript = "" + result_list = [] + + try: + async with websockets.connect(url) as web_socket: + frame_size = 1280 # 每一帧的音频大小 + interval = 0.04 # 发送音频间隔(单位:s) + status = 0 # 音频的状态信息,标识音频是第一帧,还是中间帧、最后一帧 + with open(filename, "rb") as fp: + while True: + buf = fp.read(frame_size) + # 文件结束 + if not buf: + status = 2 + data["audio"] = str(base64.b64encode(buf), "utf-8") + # 第一帧处理 + # 发送第一帧音频,带business 参数 + # appid 必须带上,只需第一帧发送 + if status == 0: + data["status"] = 0 + web_socket_data = { + "common": common_args, + "business": business_args, + "data": data} + status = 1 + # 中间帧处理 + elif status == 1: + data["status"] = 1 + web_socket_data = {"data": data} + # 最后一帧处理 + elif status == 2: + data["status"] = 2 + web_socket_data = {"data": data} + web_socket_json = json.dumps(web_socket_data) + await web_socket.send(web_socket_json) + try: + result = await web_socket.recv() + print(result) + web_socket_result = json.loads(result) + print(web_socket_result) + except (websockets.exceptions.ConnectionClosedOK, ValueError): + raise exceptions.SpeechToTextException("") + + if not is_full_result: + transcript = transcript + get_xfyun_transcript( + web_socket_result) + else: + result_list.append(web_socket_result) + time.sleep(1) + break + + web_socket_json = json.dumps(web_socket_data) + await web_socket.send(web_socket_json) + try: + result = await web_socket.recv() + print(result) + web_socket_result = json.loads(result) + except websockets.exceptions.ConnectionClosedOK: + raise exceptions.SpeechToTextException("") + except ValueError: + continue + + if not is_full_result: + transcript = transcript + get_xfyun_transcript( + web_socket_result) + else: + result_list.append(web_socket_result) + # 模拟音频采样间隔 + time.sleep(interval) + + except websockets.exceptions.InvalidStatusCode: + raise exceptions.SpeechToTextException(websockets.exceptions.InvalidStatusCode) + + except exceptions.SpeechToTextException: + if not is_full_result: + return transcript + else: + return result_list + + +if __name__ == "__main__": + print(asyncio.get_event_loop().run_until_complete( + xfyun_speech_websocket( + url=create_xfyun_url(api_key="", + api_secret=""), + app_id="", + filename=r".pcm", + business_args={ + "language": "zh_cn", + "domain": "iat", + "accent": "mandarin" + } + ) + )) diff --git a/setup.py b/setup.py index 9a59fbf4..3307e2db 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python -from __future__ import unicode_literals - +#!/usr/bin/env python3 import os try: @@ -38,9 +36,10 @@ 'progressbar2>=3.34.3', 'auditok>=0.1.5', 'googletrans>=2.4.0', - 'langcodes-py2>=1.2.0', + 'langcodes>=1.2.0', 'wcwidth>=0.1.7', - 'google-cloud-speech>=1.3.1' + 'google-cloud-speech>=1.3.1', + 'websocket-client>=0.56.0' ], license=open(os.path.join(here, "LICENSE")).read() ) From ba90e48bd856b5f518a13bc443a8dfaf8034b8a0 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Fri, 20 Mar 2020 20:51:06 +0800 Subject: [PATCH 02/26] Add support for Xun Fei Yun Speech-to-Text WebSocket API --- .travis.yml | 2 +- CHANGELOG.md | 2 + autosub/__init__.py | 6 + autosub/cmdline_utils.py | 127 +++++++---- autosub/core.py | 88 ++++++++ .../LC_MESSAGES/autosub.cmdline_utils.po | 211 ++++++++++-------- .../locale/zh_CN/LC_MESSAGES/autosub.core.po | 40 ++-- .../zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po | 20 +- .../LC_MESSAGES/autosub.lang_code_utils.po | 16 +- .../zh_CN/LC_MESSAGES/autosub.metadata.po | 10 +- .../zh_CN/LC_MESSAGES/autosub.options.po | 202 +++++++++-------- .../data/locale/zh_CN/LC_MESSAGES/autosub.po | 26 +-- autosub/exceptions.py | 6 - autosub/options.py | 9 +- autosub/xfyun_api.py | 21 +- docs/CHANGELOG.zh-Hans.md | 2 + 16 files changed, 492 insertions(+), 296 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d65ed3e..e42bbef5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: python python: - - "2.7" + - "3.7" install: - pip install . - pip install pylint diff --git a/CHANGELOG.md b/CHANGELOG.md index 93ece95e..ca77eead 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,8 @@ Click up arrow to go back to TOC. #### Added(Unreleased) +- Add support for Xun Fei Yun Speech-to-Text WebSocket API. + #### Changed(Unreleased) ### [0.5.6-alpha] - 2020-03-20 diff --git a/autosub/__init__.py b/autosub/__init__.py index 0316f780..bba6557a 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -143,6 +143,12 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- args.audio_split_cmd.replace( "-vn", "-vn -c:a libopus") + elif args.api_suffix == ".pcm": + # raw pcm + args.audio_split_cmd = \ + args.audio_split_cmd.replace( + "-vn", + "-vn -c:a pcm_s16le -f s16le") cmdline_utils.validate_aovp_args(args) fps = cmdline_utils.get_fps(args=args, input_m=input_m) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 26a287c3..42758c1c 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -254,49 +254,87 @@ def validate_config_args(args): # pylint: disable=too-many-branches, too-many-r config_dict = json.load(config_file) except ValueError: raise exceptions.AutosubException( - _("Error: Can't decode config file \"{filename}\".").format( + _("Error: Can't decode speech config file \"{filename}\".").format( filename=args.speech_config)) else: raise exceptions.AutosubException( - _("Error: Config file \"{filename}\" doesn't exist.").format( + _("Error: Speech config file \"{filename}\" doesn't exist.").format( filename=args.speech_config)) - if "encoding" in config_dict and config_dict["encoding"]: - # https://cloud.google.com/speech-to-text/docs/quickstart-protocol - # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding - if config_dict["encoding"] == "FLAC": - args.api_suffix = ".flac" - elif config_dict["encoding"] == "MP3": - args.api_suffix = ".mp3" - elif config_dict["encoding"] == "LINEAR16": - args.api_suffix = ".wav" - elif config_dict["encoding"] == "OGG_OPUS": - args.api_suffix = ".ogg" - else: - # it's necessary to set default encoding - config_dict["encoding"] = core.extension_to_encoding(args.api_suffix) - - # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig - # https://googleapis.dev/python/speech/latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig - # In practice, the client API only accept the Snake case naming variable - # but the URL API accept the both - if "sample_rate_hertz" in config_dict and config_dict["sample_rate_hertz"]: - args.api_sample_rate = config_dict["sample_rate_hertz"] - elif "sampleRateHertz" in config_dict and config_dict["sampleRateHertz"]: - args.api_sample_rate = config_dict["sampleRateHertz"] - else: - # it's necessary to set sample_rate_hertz from option --api-sample-rate - config_dict["sample_rate_hertz"] = args.api_sample_rate + if args.speech_api == "gcsv1": + if "encoding" in config_dict and config_dict["encoding"]: + # https://cloud.google.com/speech-to-text/docs/quickstart-protocol + # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding + if config_dict["encoding"] == "FLAC": + args.api_suffix = ".flac" + elif config_dict["encoding"] == "MP3": + args.api_suffix = ".mp3" + elif config_dict["encoding"] == "LINEAR16": + args.api_suffix = ".wav" + elif config_dict["encoding"] == "OGG_OPUS": + args.api_suffix = ".ogg" + else: + # it's necessary to set default encoding + config_dict["encoding"] = core.extension_to_encoding(args.api_suffix) + + # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig + # https://googleapis.dev/python/speech/latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig + # In practice, the client API only accept the Snake case naming variable + # but the URL API accept the both + if "sample_rate_hertz" in config_dict and config_dict["sample_rate_hertz"]: + args.api_sample_rate = config_dict["sample_rate_hertz"] + elif "sampleRateHertz" in config_dict and config_dict["sampleRateHertz"]: + args.api_sample_rate = config_dict["sampleRateHertz"] + else: + # it's necessary to set sample_rate_hertz from option --api-sample-rate + config_dict["sample_rate_hertz"] = args.api_sample_rate + + if "audio_channel_count" in config_dict and config_dict["audio_channel_count"]: + args.api_audio_channel = config_dict["audio_channel_count"] + elif "audioChannelCount" in config_dict and config_dict["audioChannelCount"]: + args.api_audio_channel = config_dict["audioChannelCount"] + + if "language_code" in config_dict and config_dict["language_code"]: + args.speech_language = config_dict["language_code"] + elif "languageCode" in config_dict and config_dict["languageCode"]: + args.speech_language = config_dict["languageCode"] + + elif args.speech_api == "xfyun": + args.api_suffix = ".pcm" + args.api_sample_rate = 16000 + if "business" not in config_dict: + config_dict["business"] = { + "language": "zh_cn", + "domain": "iat", + "accent": "mandarin"} + + if "APPID" in config_dict: + config_dict["app_id"] = config_dict["APPID"] + elif "app_id" not in config_dict: + raise exceptions.AutosubException( + _("Error: No \"app_id\" found in speech config file \"{filename}\"." + ).format(filename=args.speech_config)) + + if "APIKey" in config_dict: + config_dict["api_key"] = config_dict["APIKey"] + elif "api_key" not in config_dict: + raise exceptions.AutosubException( + _("Error: No \"api_key\" found in speech config file \"{filename}\"." + ).format(filename=args.speech_config)) + + if "APISecret" in config_dict: + config_dict["api_secret"] = config_dict["APISecret"] + elif "api_secret" not in config_dict: + raise exceptions.AutosubException( + _("Error: No \"api_secret\" found in speech config file \"{filename}\"." + ).format(filename=args.speech_config)) - if "audio_channel_count" in config_dict and config_dict["audio_channel_count"]: - args.api_audio_channel = config_dict["audio_channel_count"] - elif "audioChannelCount" in config_dict and config_dict["audioChannelCount"]: - args.api_audio_channel = config_dict["audioChannelCount"] + if "language" not in config_dict["business"]: + raise exceptions.AutosubException( + _("Error: No \"language\" found in speech config file \"{filename}\"." + ).format(filename=args.speech_config)) - if "language_code" in config_dict and config_dict["language_code"]: - args.speech_language = config_dict["language_code"] - elif "languageCode" in config_dict and config_dict["languageCode"]: - args.speech_language = config_dict["languageCode"] + args.speech_language = config_dict["business"]["language"] args.speech_config = config_dict @@ -340,9 +378,11 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret raise exceptions.AutosubException( _("Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal.")) - else: - raise exceptions.AutosubException( - _("Error: Wrong API code.")) + elif args.speech_api == "xfyun": + if not args.speech_config: + raise exceptions.AutosubException( + _("Error: You must provide \"-sconf\", \"--speech-config\" option " + "when using Xun Fei Yun API.")) if args.dst_language is None: print(_("Translation destination language not provided. " @@ -1119,6 +1159,15 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen print(_("No available GOOGLE_APPLICATION_CREDENTIALS. " "Use \"-sa\"/\"--service-account\" to set one.")) text_list = None + + elif args.speech_api == "xfyun": + # Xun Fei Yun Speech-to-Text WebSocket API + text_list = core.xfyun_to_text( + audio_fragments=audio_fragments, + config=args.speech_config, + concurrency=constants.DEFAULT_CONCURRENCY, + is_keep=False, + result_list=result_list) else: text_list = None diff --git a/autosub/core.py b/autosub/core.py index 6090f9c7..896579f9 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -20,6 +20,7 @@ # Any changes to the path and your own modules from autosub import google_api +from autosub import xfyun_api from autosub import sub_utils from autosub import constants from autosub import ffmpeg_utils @@ -428,6 +429,93 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man return text_list +def xfyun_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many-branches,too-many-statements, too-many-nested-blocks + audio_fragments, + config, + concurrency=constants.DEFAULT_CONCURRENCY, + is_keep=False, + result_list=None): + """ + Give a list of short-term audio fragment files + and generate text_list from Google cloud speech-to-text V1P1Beta1 api. + """ + + text_list = [] + + if "api_address" in config: + api_address = config["api_address"] + else: + api_address = constants.XFYUN_SPEECH_WEBAPI_URL + + pool = multiprocessing.Pool(concurrency) + + print(_("\nSending short-term fragments to Xun Fei Yun WebSocket API" + " and getting result.")) + widgets = [_("Speech-to-Text: "), + progressbar.Percentage(), ' ', + progressbar.Bar(), ' ', + progressbar.ETA()] + pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(audio_fragments)).start() + + try: + recognizer = xfyun_api.XfyunWebSocketAPI( + app_id=config["app_id"], + api_key=config["api_key"], + api_secret=config["api_secret"], + api_address=api_address, + business_args=config["business"], + is_keep=is_keep, + is_full_result=result_list is not None) + + # get transcript + if result_list is None: + for i, transcript in enumerate(pool.imap(recognizer, audio_fragments)): + if transcript: + text_list.append(transcript) + else: + text_list.append("") + pbar.update(i) + # get full result and transcript + else: + for i, result in enumerate(pool.imap(recognizer, audio_fragments)): + if result: + result_list.append(result) + transcript = "" + for item in result: + transcript = transcript + xfyun_api.get_xfyun_transcript(item) + if transcript: + text_list.append(transcript) + continue + else: + result_list.append("") + text_list.append("") + pbar.update(i) + pbar.finish() + pool.terminate() + pool.join() + + except (KeyboardInterrupt, AttributeError) as error: + pbar.finish() + pool.terminate() + pool.join() + + if error == AttributeError: + print( + _("Error: Connection error happened too many times.\nAll works done.")) + + return None + + except exceptions.SpeechToTextException as err_msg: + pbar.finish() + pool.terminate() + pool.join() + print(_("Receive something unexpected:")) + print(err_msg) + return None + + return text_list + + def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, too-many-branches, too-many-statements text_list, src_language=constants.DEFAULT_SRC_LANGUAGE, 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 95a491bc..412a079b 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-20 10:01+0800\n" -"PO-Revision-Date: 2020-03-12 12:16+0800\n" +"POT-Creation-Date: 2020-03-20 20:42+0800\n" +"PO-Revision-Date: 2020-03-20 20:45+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -17,20 +17,20 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/cmdline_utils.py:48 +#: autosub/cmdline_utils.py:42 msgid "List of output formats:\n" msgstr "列出所有输出格式:\n" -#: autosub/cmdline_utils.py:50 autosub/cmdline_utils.py:58 +#: autosub/cmdline_utils.py:44 autosub/cmdline_utils.py:52 msgid "Format" msgstr "格式" -#: autosub/cmdline_utils.py:51 autosub/cmdline_utils.py:59 -#: autosub/cmdline_utils.py:86 autosub/cmdline_utils.py:104 +#: autosub/cmdline_utils.py:45 autosub/cmdline_utils.py:53 +#: autosub/cmdline_utils.py:80 autosub/cmdline_utils.py:98 msgid "Description" msgstr "描述" -#: autosub/cmdline_utils.py:56 +#: autosub/cmdline_utils.py:50 msgid "" "\n" "List of input formats:\n" @@ -38,36 +38,36 @@ msgstr "" "\n" "列出所有输入格式:\n" -#: autosub/cmdline_utils.py:67 +#: autosub/cmdline_utils.py:61 msgid "Use py-googletrans to detect a sub file's first line language." msgstr "使用py-googletrans来检测字幕文件第一行的语言。" -#: autosub/cmdline_utils.py:74 autosub/cmdline_utils.py:85 -#: autosub/cmdline_utils.py:103 +#: autosub/cmdline_utils.py:68 autosub/cmdline_utils.py:79 +#: autosub/cmdline_utils.py:97 msgid "Lang code" msgstr "语言代码" -#: autosub/cmdline_utils.py:75 +#: autosub/cmdline_utils.py:69 msgid "Confidence" msgstr "可信度" -#: autosub/cmdline_utils.py:83 +#: autosub/cmdline_utils.py:77 msgid "List of all lang codes for speech-to-text:\n" msgstr "列出所有语音转文字的语言代码:\n" -#: autosub/cmdline_utils.py:92 +#: autosub/cmdline_utils.py:86 msgid "Match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:101 +#: autosub/cmdline_utils.py:95 msgid "List of all lang codes for translation:\n" msgstr "列出所有翻译的语言代码:\n" -#: autosub/cmdline_utils.py:110 +#: autosub/cmdline_utils.py:104 msgid "Match py-googletrans lang codes." msgstr "匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:128 +#: autosub/cmdline_utils.py:122 msgid "" "Error: arg of \"-i\"/\"--input\": \"{path}\" isn't valid. You need to give a " "valid path." @@ -75,7 +75,7 @@ msgstr "" "错误:\"-i\"/\"--input\"的参数:\"{path}\"是无效的。你需要提供一个有效的路" "径。" -#: autosub/cmdline_utils.py:134 +#: autosub/cmdline_utils.py:128 msgid "" "Error: arg of \"-sty\"/\"--styles\": \"{path}\" isn't valid. You need to " "give a valid path." @@ -83,15 +83,15 @@ msgstr "" "错误:\"-sty\"/\"--styles\"的参数:\"{path}\"是无效的。你需要提供一个有效的路" "径。" -#: autosub/cmdline_utils.py:140 +#: autosub/cmdline_utils.py:134 msgid "Error: Too many \"-sn\"/\"--styles-name\" arguments." msgstr "错误:\"-sn\"/\"--styles-name\"的参数过多。" -#: autosub/cmdline_utils.py:152 autosub/cmdline_utils.py:159 +#: autosub/cmdline_utils.py:146 autosub/cmdline_utils.py:153 msgid "Error: \"-sn\"/\"--styles-name\" arguments aren't in \"{path}\"." msgstr "错误:\"-sn\"/\"--styles-name\"的参数不在 \"{path}\"文件内。" -#: autosub/cmdline_utils.py:164 +#: autosub/cmdline_utils.py:158 msgid "" "Error: arg of \"-er\"/\"--ext-regions\": \"{path}\" isn't valid. You need to " "give a valid path." @@ -99,16 +99,16 @@ msgstr "" "错误:\"-er\"/\"--ext-regions\"的参数:\"{path}\"是无效的。你需要提供一个有效" "的路径。" -#: autosub/cmdline_utils.py:181 autosub/cmdline_utils.py:199 +#: autosub/cmdline_utils.py:175 autosub/cmdline_utils.py:193 msgid "No output format specified. Use input format \"{fmt}\" for output." msgstr "没有指定输出格式。使用输入的格式\"{fmt}\"作为输出格式。" -#: autosub/cmdline_utils.py:193 +#: autosub/cmdline_utils.py:187 msgid "" "Your output is a directory not a file path. Now file path set to \"{new}\"." msgstr "你的输出路径是一个目录不是一个文件路径。现在输出路径设置为\"{new}\"。" -#: autosub/cmdline_utils.py:216 +#: autosub/cmdline_utils.py:210 msgid "" "Error: Output subtitles format \"{fmt}\" not supported. Run with \"-lf\"/\"--" "list-formats\" to see all supported formats.\n" @@ -118,45 +118,61 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:229 autosub/cmdline_utils.py:235 +#: autosub/cmdline_utils.py:223 autosub/cmdline_utils.py:229 msgid "Error: No valid \"-of\"/\"--output-files\" arguments." msgstr "错误:\"-of\"/\"--output-files\"参数无效。" -#: autosub/cmdline_utils.py:246 +#: autosub/cmdline_utils.py:240 msgid "Input is a subtitles file." msgstr "输入是一个字幕文件。" -#: autosub/cmdline_utils.py:263 -msgid "Error: Can't decode config file \"{filename}\"." -msgstr "错误:无法解码配置文件\"{filename}\"。" +#: autosub/cmdline_utils.py:257 +msgid "Error: Can't decode speech config file \"{filename}\"." +msgstr "错误:无法解码语音配置文件\"{filename}\"。" + +#: autosub/cmdline_utils.py:261 +msgid "Error: Speech config file \"{filename}\" doesn't exist." +msgstr "错误:语音配置文件\"{filename}\"不存在。" -#: autosub/cmdline_utils.py:267 -msgid "Error: Config file \"{filename}\" doesn't exist." -msgstr "错误:配置文件\"{filename}\"不存在。" +#: autosub/cmdline_utils.py:315 +msgid "Error: No \"app_id\" found in speech config file \"{filename}\"." +msgstr "错误:\"app_id\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:317 +#: autosub/cmdline_utils.py:322 +msgid "Error: No \"api_key\" found in speech config file \"{filename}\"." +msgstr "错误:\"api_key\"不在语音配置文件\"{filename}\"中。" + +#: autosub/cmdline_utils.py:329 +msgid "Error: No \"api_secret\" found in speech config file \"{filename}\"." +msgstr "错误:\"api_secret\"不在语音配置文件\"{filename}\"中。" + +#: autosub/cmdline_utils.py:334 +msgid "Error: No \"language\" found in speech config file \"{filename}\"." +msgstr "错误:\"language\"不在语音配置文件\"{filename}\"中。" + +#: autosub/cmdline_utils.py:349 msgid "Error: \"-slp\"/\"--sleep-seconds\" arg is illegal." msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" -#: autosub/cmdline_utils.py:325 +#: autosub/cmdline_utils.py:357 msgid "Let speech lang code to match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:331 +#: autosub/cmdline_utils.py:363 msgid "Use langcodes to standardize the result." msgstr "使用langcodes来标准化结果。" -#: 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 +#: autosub/cmdline_utils.py:365 autosub/cmdline_utils.py:421 +#: autosub/cmdline_utils.py:443 autosub/cmdline_utils.py:516 +#: autosub/cmdline_utils.py:543 msgid "Use \"{lang_code}\" instead." msgstr "改用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:336 +#: autosub/cmdline_utils.py:368 msgid "Match failed. Still using \"{lang_code}\"." msgstr "匹配失败。仍在使用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:339 +#: autosub/cmdline_utils.py:371 msgid "" "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" "list-speech-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -166,33 +182,35 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:347 +#: autosub/cmdline_utils.py:379 msgid "Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal." msgstr "错误:\"-mnc\"/\"--min-confidence\"参数的值不合法。" -#: autosub/cmdline_utils.py:351 -msgid "Error: Wrong API code." -msgstr "错误:错误的API代码。" +#: autosub/cmdline_utils.py:384 +msgid "" +"Error: You must provide \"-sconf\", \"--speech-config\" option when using " +"Xun Fei Yun API." +msgstr "错误:使用讯飞云API时,你必须提供\"-sconf\",\"--speech-config\"选项。" -#: autosub/cmdline_utils.py:354 +#: autosub/cmdline_utils.py:388 msgid "" "Translation destination language not provided. Only performing speech " "recognition." msgstr "翻译目的语言未提供。只进行语音识别。" -#: autosub/cmdline_utils.py:359 +#: autosub/cmdline_utils.py:393 msgid "Translation source language not provided. Use speech language instead." msgstr "翻译源语言未提供。改用语音语言。" -#: autosub/cmdline_utils.py:380 +#: autosub/cmdline_utils.py:414 msgid "Let translation source lang code to match py-googletrans lang codes." msgstr "让翻译源语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:391 autosub/cmdline_utils.py:413 +#: autosub/cmdline_utils.py:425 autosub/cmdline_utils.py:447 msgid "Error: Match failed." msgstr "错误:匹配失败。" -#: autosub/cmdline_utils.py:394 +#: autosub/cmdline_utils.py:428 msgid "" "Error: Translation source language \"{src}\" is not supported. Run with \"-" "ltc\"/\"--list-translation-codes\" to see all supported languages. Or use \"-" @@ -202,12 +220,12 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:402 +#: autosub/cmdline_utils.py:436 msgid "" "Let translation destination lang code to match py-googletrans lang codes." msgstr "让翻译目的语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:416 +#: autosub/cmdline_utils.py:450 msgid "" "Error: Translation destination language \"{dst}\" is not supported. Run with " "\"-ltc\"/\"--list-translation-codes\" to see all supported languages. Or use " @@ -216,29 +234,29 @@ msgstr "" "错误:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" "项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最佳匹配。" -#: autosub/cmdline_utils.py:424 +#: autosub/cmdline_utils.py:458 msgid "" "Speech language is the same as the destination language. Only performing " "speech recognition." msgstr "语音语言和目的语言一致。只进行语音识别。" -#: autosub/cmdline_utils.py:433 +#: autosub/cmdline_utils.py:467 msgid "You've already input times. No works done." msgstr "你已经输入了时间轴。啥都没做。" -#: autosub/cmdline_utils.py:437 +#: autosub/cmdline_utils.py:471 msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:445 autosub/cmdline_utils.py:537 +#: autosub/cmdline_utils.py:479 autosub/cmdline_utils.py:571 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" -#: autosub/cmdline_utils.py:458 +#: autosub/cmdline_utils.py:492 msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" -#: autosub/cmdline_utils.py:474 +#: autosub/cmdline_utils.py:508 msgid "" "Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages." @@ -246,11 +264,11 @@ msgstr "" "警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:486 autosub/cmdline_utils.py:513 +#: autosub/cmdline_utils.py:520 autosub/cmdline_utils.py:547 msgid "Match failed. Still using \"{lang_code}\". Program stopped." msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" -#: autosub/cmdline_utils.py:492 +#: autosub/cmdline_utils.py:526 msgid "" "Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -260,7 +278,7 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:501 +#: autosub/cmdline_utils.py:535 msgid "" "Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages." @@ -268,7 +286,7 @@ msgstr "" "警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" "行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:519 +#: autosub/cmdline_utils.py:553 msgid "" "Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" @@ -278,12 +296,12 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:527 +#: autosub/cmdline_utils.py:561 msgid "" "Error: Translation source language is the same as the destination language." msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:551 +#: autosub/cmdline_utils.py:585 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -291,7 +309,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:558 +#: autosub/cmdline_utils.py:592 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -299,7 +317,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:565 +#: autosub/cmdline_utils.py:599 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -307,16 +325,16 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:621 autosub/cmdline_utils.py:765 -#: autosub/cmdline_utils.py:1294 +#: autosub/cmdline_utils.py:655 autosub/cmdline_utils.py:799 +#: autosub/cmdline_utils.py:1337 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:625 autosub/cmdline_utils.py:717 -#: autosub/cmdline_utils.py:769 autosub/cmdline_utils.py:821 -#: autosub/cmdline_utils.py:1002 autosub/cmdline_utils.py:1148 -#: autosub/cmdline_utils.py:1190 autosub/cmdline_utils.py:1250 -#: autosub/cmdline_utils.py:1298 autosub/cmdline_utils.py:1346 +#: autosub/cmdline_utils.py:659 autosub/cmdline_utils.py:751 +#: autosub/cmdline_utils.py:803 autosub/cmdline_utils.py:855 +#: autosub/cmdline_utils.py:1036 autosub/cmdline_utils.py:1191 +#: autosub/cmdline_utils.py:1233 autosub/cmdline_utils.py:1293 +#: autosub/cmdline_utils.py:1341 autosub/cmdline_utils.py:1389 msgid "" "\n" "All works done." @@ -324,23 +342,23 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:669 autosub/cmdline_utils.py:1207 +#: autosub/cmdline_utils.py:703 autosub/cmdline_utils.py:1250 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:713 autosub/cmdline_utils.py:1246 +#: autosub/cmdline_utils.py:747 autosub/cmdline_utils.py:1289 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:817 autosub/cmdline_utils.py:1342 +#: autosub/cmdline_utils.py:851 autosub/cmdline_utils.py:1385 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:860 autosub/cmdline_utils.py:1387 +#: autosub/cmdline_utils.py:894 autosub/cmdline_utils.py:1430 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:902 +#: autosub/cmdline_utils.py:936 msgid "" "\n" "No works done. Check your \"-of\"/\"--output-files\" option." @@ -348,11 +366,11 @@ msgstr "" "\n" "啥都没做。检查你的\"-of\"/\"--output-files\"选项。" -#: autosub/cmdline_utils.py:907 +#: autosub/cmdline_utils.py:941 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:941 +#: autosub/cmdline_utils.py:975 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -360,11 +378,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:951 +#: autosub/cmdline_utils.py:985 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:954 +#: autosub/cmdline_utils.py:988 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -372,7 +390,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:966 +#: autosub/cmdline_utils.py:1000 msgid "" "\n" "\"{name}\" has been deleted." @@ -380,19 +398,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:970 +#: autosub/cmdline_utils.py:1004 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:999 autosub/cmdline_utils.py:1454 +#: autosub/cmdline_utils.py:1033 autosub/cmdline_utils.py:1497 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1023 +#: autosub/cmdline_utils.py:1057 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1027 +#: autosub/cmdline_utils.py:1061 msgid "" "Audio processing complete.\n" "All works done." @@ -400,11 +418,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1079 +#: autosub/cmdline_utils.py:1113 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1094 +#: autosub/cmdline_utils.py:1128 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -414,18 +432,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1099 +#: autosub/cmdline_utils.py:1133 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1113 +#: autosub/cmdline_utils.py:1147 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1125 +#: autosub/cmdline_utils.py:1159 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -433,11 +451,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1144 +#: autosub/cmdline_utils.py:1187 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1152 +#: autosub/cmdline_utils.py:1195 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -445,11 +463,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1186 autosub/cmdline_utils.py:1424 +#: autosub/cmdline_utils.py:1229 autosub/cmdline_utils.py:1467 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1396 +#: autosub/cmdline_utils.py:1439 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -457,7 +475,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1429 +#: autosub/cmdline_utils.py:1472 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output regions subtitles file only." @@ -465,6 +483,9 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出时间轴文件。" +#~ msgid "Error: Wrong API code." +#~ msgstr "错误:错误的API代码。" + #~ msgid "Error: Translation source language is not provided." #~ msgstr "错误:翻译源语言未提供。" 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 59d06e02..9fd0cc6e 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po @@ -7,17 +7,17 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-08 21:50+0800\n" -"PO-Revision-Date: 2020-02-03 16:38+0800\n" +"POT-Creation-Date: 2020-03-20 20:42+0800\n" +"PO-Revision-Date: 2020-03-20 20:46+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/core.py:190 +#: autosub/core.py:186 msgid "" "\n" "Converting speech regions to short-term fragments." @@ -25,11 +25,11 @@ msgstr "" "\n" "按照语音区域将音频转换为多个短语音片段。" -#: autosub/core.py:191 +#: autosub/core.py:187 msgid "Converting: " msgstr "转换中: " -#: autosub/core.py:236 +#: autosub/core.py:232 msgid "" "\n" "Sending short-term fragments to Google Speech V2 API and getting result." @@ -37,11 +37,11 @@ msgstr "" "\n" "将短片段语音发送给Google Speech V2 API并得到识别结果。" -#: autosub/core.py:237 autosub/core.py:306 +#: autosub/core.py:233 autosub/core.py:302 autosub/core.py:454 msgid "Speech-to-Text: " msgstr "语音转文字中: " -#: autosub/core.py:278 autosub/core.py:424 +#: autosub/core.py:274 autosub/core.py:417 autosub/core.py:504 msgid "" "Error: Connection error happened too many times.\n" "All works done." @@ -49,7 +49,7 @@ msgstr "" "错误:过多连接错误。\n" "做完了。" -#: autosub/core.py:304 +#: autosub/core.py:300 msgid "" "\n" "Sending short-term fragments to Google Cloud Speech V1P1Beta1 API and " @@ -58,11 +58,19 @@ msgstr "" "\n" "将短片段语音发送给Google Cloud Speech V1P1Beta1 API并得到识别结果。" -#: autosub/core.py:432 +#: autosub/core.py:425 autosub/core.py:512 msgid "Receive something unexpected:" msgstr "收到未预期数据:" -#: autosub/core.py:455 +#: autosub/core.py:452 +msgid "" +"\n" +"Sending short-term fragments to Xun Fei Yun WebSocket API and getting result." +msgstr "" +"\n" +"将短片段语音发送给讯飞云WebSocket API并得到识别结果。" + +#: autosub/core.py:535 msgid "" "\n" "Translating text from \"{0}\" to \"{1}\"." @@ -70,24 +78,24 @@ msgstr "" "\n" "从\"{0}\"翻译为\"{1}\"。" -#: autosub/core.py:505 +#: autosub/core.py:585 msgid "Translation: " msgstr "翻译中: " -#: autosub/core.py:568 +#: autosub/core.py:648 msgid "Cancelling translation." msgstr "取消翻译。" -#: autosub/core.py:641 autosub/core.py:700 +#: autosub/core.py:721 autosub/core.py:780 msgid "Format \"{fmt}\" not supported. Use \"{default_fmt}\" instead." msgstr "不支持格式\"{fmt}\"。改用\"{default_fmt}\"。" -#: autosub/core.py:773 +#: autosub/core.py:853 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/core.py:776 +#: autosub/core.py:856 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.ffmpeg_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po index bdc79174..50f53f0a 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-03-19 10:17+0800\n" +"POT-Creation-Date: 2020-03-20 20:42+0800\n" "PO-Revision-Date: 2020-02-03 21:37+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,12 +17,12 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.2.4\n" -#: autosub/ffmpeg_utils.py:98 +#: autosub/ffmpeg_utils.py:93 msgid "" "Error: ffmpeg can't split your file. Check your audio processing options." msgstr "错误:ffmpeg无法分割你的文件。检查一下你的音频处理选项。" -#: autosub/ffmpeg_utils.py:122 +#: autosub/ffmpeg_utils.py:117 msgid "" "ffprobe can't get video fps.\n" "It is necessary when output is \".sub\"." @@ -30,16 +30,16 @@ msgstr "" "ffprobe无法获取到视频的帧率。\n" "当输出格式是\".sub\"时,需要获取帧率。" -#: autosub/ffmpeg_utils.py:125 +#: autosub/ffmpeg_utils.py:120 msgid "" "Input your video fps. Any illegal input will regard as \".srt\" instead.\n" msgstr "输入你视频的帧率。任何非法的值会被当作\".srt\"格式处理。\n" -#: autosub/ffmpeg_utils.py:132 +#: autosub/ffmpeg_utils.py:127 msgid "Use \".srt\" instead." msgstr "改用\".srt\"格式。" -#: autosub/ffmpeg_utils.py:145 +#: autosub/ffmpeg_utils.py:140 msgid "" "\n" "Use ffprobe to check conversion result." @@ -47,22 +47,22 @@ msgstr "" "\n" "使用ffprobe来检查转换结果。" -#: autosub/ffmpeg_utils.py:173 +#: autosub/ffmpeg_utils.py:168 msgid "" "Warning: Dependency ffmpeg-normalize not found on this machine. Try default " "method." msgstr "" "警告:依赖ffmpeg-normalize未在这台电脑上找到。尝试默认的方法去转换格式。" -#: autosub/ffmpeg_utils.py:185 +#: autosub/ffmpeg_utils.py:180 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/ffmpeg_utils.py:188 +#: autosub/ffmpeg_utils.py:183 msgid "Input a new path (including directory and file name) for output file.\n" msgstr "为输出文件输入一个新的路径(包括路径和文件名)。\n" -#: autosub/ffmpeg_utils.py:205 autosub/ffmpeg_utils.py:237 +#: autosub/ffmpeg_utils.py:200 autosub/ffmpeg_utils.py:232 msgid "Audio pre-processing failed. Try default method." msgstr "音频预处理失败。尝试默认的方法去转换格式。" diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.po index 0d4a911e..d78f21a6 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-01-31 12:02+0800\n" +"POT-Creation-Date: 2020-03-20 20:42+0800\n" "PO-Revision-Date: 2019-07-27 15:24+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,30 +17,30 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.2.3\n" -#: autosub/lang_code_utils.py:110 +#: autosub/lang_code_utils.py:105 msgid "Now match lang codes." msgstr "现在匹配语言代码。" -#: autosub/lang_code_utils.py:113 +#: autosub/lang_code_utils.py:108 msgid "The value of arg of \"-mns\"/\"--min-score\" isn't legal." msgstr "\"-mns\"/\"--min-score\"的参数的值不合法。" -#: autosub/lang_code_utils.py:117 +#: autosub/lang_code_utils.py:112 msgid "Input:" msgstr "输入:" -#: autosub/lang_code_utils.py:121 +#: autosub/lang_code_utils.py:116 msgid "Score above:" msgstr "分数高于:" -#: autosub/lang_code_utils.py:129 +#: autosub/lang_code_utils.py:124 msgid "No lang codes been matched." msgstr "没有匹配到语言代码。" -#: autosub/lang_code_utils.py:133 +#: autosub/lang_code_utils.py:128 msgid "Match result" msgstr "匹配结果" -#: autosub/lang_code_utils.py:134 +#: autosub/lang_code_utils.py:129 msgid "Score (0-100)" msgstr "分数(0-100)" diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.metadata.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.metadata.po index 2945ad85..e59f5f54 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.metadata.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.metadata.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-01-31 16:05+0800\n" +"POT-Creation-Date: 2020-03-20 20:42+0800\n" "PO-Revision-Date: 2020-01-31 16:06+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,11 +17,11 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.2.4\n" -#: autosub/metadata.py:16 +#: autosub/metadata.py:12 msgid "Auto-generate subtitles for video/audio/subtitles file." msgstr "为视频/音频/字幕文件自动生成字幕。" -#: autosub/metadata.py:18 +#: autosub/metadata.py:14 msgid "" "Autosub is an automatic subtitles generating utility. It can detect speech " "regions automatically by using Auditok, split the audio files according to " @@ -29,5 +29,5 @@ msgid "" "translate the subtitles' text by using py-googletrans." msgstr "" "Autosub是一个字幕自动生成工具。它能使用Auditok来自动检测语音区域,通过ffmpeg" -"根据语音区域来切割音频,通过多种API将语音转为文字,以及通过py-googletrans将" -"字幕文本翻译。" +"根据语音区域来切割音频,通过多种API将语音转为文字,以及通过py-googletrans将字" +"幕文本翻译。" 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 47a8f641..333b28fb 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-19 10:17+0800\n" -"PO-Revision-Date: 2020-03-09 17:27+0800\n" +"POT-Creation-Date: 2020-03-20 20:50+0800\n" +"PO-Revision-Date: 2020-03-20 20:50+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -19,7 +19,7 @@ msgstr "" "Plural-Forms: nplurals=1; plural=0;\n" "Language: zh_CN\n" -#: autosub/options.py:44 +#: autosub/options.py:39 #, python-format msgid "" "\n" @@ -28,7 +28,7 @@ msgstr "" "\n" "用法:%(prog)s [-i 路径] [选项]" -#: autosub/options.py:46 +#: autosub/options.py:41 msgid "" "Make sure the argument with space is in quotes.\n" "The default value is used\n" @@ -48,98 +48,98 @@ msgstr "" "Email: {email}\n" "问题反馈: {homepage}\n" -#: autosub/options.py:61 +#: autosub/options.py:56 msgid "Input Options" msgstr "输入选项" -#: autosub/options.py:62 +#: autosub/options.py:57 msgid "Options to control input." msgstr "控制输入的选项。" -#: autosub/options.py:64 +#: autosub/options.py:59 msgid "Language Options" msgstr "语言选项" -#: autosub/options.py:65 +#: autosub/options.py:60 msgid "Options to control language." msgstr "控制语言的选项。" -#: autosub/options.py:67 +#: autosub/options.py:62 msgid "Output Options" msgstr "输出选项" -#: autosub/options.py:68 +#: autosub/options.py:63 msgid "Options to control output." msgstr "控制输出的选项。" -#: autosub/options.py:70 +#: autosub/options.py:65 msgid "Speech Options" msgstr "语音选项" -#: autosub/options.py:71 +#: autosub/options.py:66 msgid "" "Options to control speech-to-text. If Speech Options not given, it will only " "generate the times." msgstr "控制语音转文字的选项。" -#: autosub/options.py:74 +#: autosub/options.py:69 msgid "py-googletrans Options" msgstr "py-googletrans选项" -#: autosub/options.py:75 +#: autosub/options.py:70 msgid "" "Options to control translation. Default method to translate. Could be " "blocked at any time." msgstr "控制翻译的选项。同时也是默认的翻译方法。可能随时会被谷歌爸爸封。" -#: autosub/options.py:79 +#: autosub/options.py:74 msgid "Network Options" msgstr "网络选项" -#: autosub/options.py:80 +#: autosub/options.py:75 msgid "Options to control network." msgstr "控制网络的选项。" -#: autosub/options.py:82 +#: autosub/options.py:77 msgid "Other Options" msgstr "其他选项" -#: autosub/options.py:83 +#: autosub/options.py:78 msgid "Other options to control." msgstr "控制其他东西的选项。" -#: autosub/options.py:85 +#: autosub/options.py:80 msgid "Audio Processing Options" msgstr "音频处理选项" -#: autosub/options.py:86 +#: autosub/options.py:81 msgid "Options to control audio processing." msgstr "控制音频处理的选项。" -#: autosub/options.py:88 +#: autosub/options.py:83 msgid "Auditok Options" msgstr "Auditok的选项" -#: autosub/options.py:89 +#: autosub/options.py:84 msgid "" "Options to control Auditok when not using external speech regions control." msgstr "不使用外部语音区域控制时,用于控制Auditok的选项。" -#: autosub/options.py:92 +#: autosub/options.py:87 msgid "List Options" msgstr "列表选项" -#: autosub/options.py:93 +#: autosub/options.py:88 msgid "List all available arguments." 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:92 autosub/options.py:101 autosub/options.py:110 +#: autosub/options.py:192 autosub/options.py:271 autosub/options.py:398 #: autosub/options.py:594 msgid "path" msgstr "路径" -#: autosub/options.py:98 +#: autosub/options.py:93 msgid "" "The path to the video/audio/subtitles file that needs to generate subtitles. " "When it is a subtitles file, the program will only translate it. (arg_num = " @@ -148,7 +148,7 @@ msgstr "" "用于生成字幕文件的视频/音频/字幕文件。如果输入文件是字幕文件,程序仅会对其进" "行翻译。(参数个数为1)" -#: autosub/options.py:107 +#: autosub/options.py:102 msgid "" "Path to the subtitles file which provides external speech regions, which is " "one of the formats that pysubs2 supports and overrides the default method to " @@ -157,7 +157,7 @@ msgstr "" "提供外部语音区域(时间轴)的字幕文件。该字幕文件格式需要是pysubs2所支持的。使" "用后会替换掉默认的自动寻找语音区域(时间轴)的功能。(参数个数为1)" -#: autosub/options.py:117 +#: autosub/options.py:112 msgid "" "Valid when your output format is \"ass\"/\"ssa\". Path to the subtitles file " "which provides \"ass\"/\"ssa\" styles for your output. If the arg_num is 0, " @@ -168,11 +168,11 @@ msgstr "" "幕文件。如果不提供参数,它会使用来自\"-esr\"/\"--external-speech-regions\"选" "项提供的样式。更多信息详见\"-sn\"/\"--styles-name\"。(参数个数为0或1)" -#: autosub/options.py:128 +#: autosub/options.py:123 msgid "style_name" msgstr "样式名" -#: autosub/options.py:129 +#: autosub/options.py:124 msgid "" "Valid when your output format is \"ass\"/\"ssa\" and \"-sty\"/\"--styles\" " "is given. Adds \"ass\"/\"ssa\" styles to your events. If not provided, " @@ -187,24 +187,24 @@ msgstr "" "数作为样式名。如果参数个数为2,源语言字幕行会使用第一个参数作为样式名。目标语" "言行使用第二个。(参数个数为1或2)" -#: autosub/options.py:142 autosub/options.py:153 autosub/options.py:163 +#: autosub/options.py:137 autosub/options.py:148 autosub/options.py:158 #: autosub/options.py:566 autosub/options.py:582 msgid "lang_code" msgstr "语言代码" -#: autosub/options.py:143 +#: autosub/options.py:138 #, python-format 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/" "speech-to-text/docs/languages(参数个数为1)(默认参数: %(default)s)" -#: autosub/options.py:154 +#: autosub/options.py:149 #, python-format msgid "" "Lang code/Lang tag for translation source language. If not given, use " @@ -214,10 +214,10 @@ msgid "" msgstr "" "用于翻译的源语言的语言代码/语言标识符。如果没有提供,会使用langcodes从列表里" "获取一个最佳匹配选项\"-S\"/\"--speech-language\"的语言代码。如果使用py-" -"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数为%" -"(default)s)" +"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数" +"为%(default)s)" -#: autosub/options.py:164 +#: autosub/options.py:159 #, python-format msgid "" "Lang code/Lang tag for translation destination language. Same attention in " @@ -226,11 +226,11 @@ msgstr "" "用于翻译的目标语言的语言代码/语言标识符。同样的注意参考选项\"-SRC\"/\"--src-" "language\"。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:170 autosub/options.py:409 +#: autosub/options.py:165 autosub/options.py:409 msgid "mode" msgstr "模式" -#: autosub/options.py:172 +#: autosub/options.py:167 msgid "" "Allow langcodes to get a best matching lang code when your input is wrong. " "Only functional for py-googletrans and Google Speech V2. Available modes: s, " @@ -242,7 +242,7 @@ msgstr "" "\"-S\"/\"--speech-language\"。\"src\"指\"-SRC\"/\"--src-language\"。\"d\"指" "\"-D\"/\"--dst-language\"。(参数个数在1到3之间)" -#: autosub/options.py:186 +#: autosub/options.py:181 msgid "" "An integer between 0 and 100 to control the good match group of \"-lsc\"/\"--" "list-speech-codes\" or \"-ltc\"/\"--list-translation-codes\" or the match " @@ -254,7 +254,7 @@ msgstr "" "best-match\"选项中的最佳匹配结果。结果会是一组“好的匹配”,其分数需要超过这个" "参数的值。(参数个数为1)" -#: autosub/options.py:198 +#: autosub/options.py:193 msgid "" "The output path for subtitles file. (default: the \"input\" path combined " "with the proper name tails) (arg_num = 1)" @@ -262,11 +262,11 @@ msgstr "" "输出字幕文件的路径。(默认值是\"input\"路径和适当的文件名后缀的结合)(参数个" "数为1)" -#: autosub/options.py:204 +#: autosub/options.py:199 msgid "format" msgstr "格式" -#: autosub/options.py:205 +#: autosub/options.py:200 msgid "" "Destination subtitles format. If not provided, use the extension in the \"-o" "\"/\"--output\" arg. If \"-o\"/\"--output\" arg doesn't provide the " @@ -279,18 +279,18 @@ msgstr "" "果\"-i\"/\"--input\"的参数是一个字幕文件,那么使用和字幕文件相同的扩展名。" "(参数个数为1)(默认参数为{dft})" -#: autosub/options.py:218 +#: autosub/options.py:213 msgid "" "Prevent pauses and allow files to be overwritten. Stop the program when your " "args are wrong. (arg_num = 0)" msgstr "" "避免任何暂停和覆写文件的行为。如果参数有误,会直接停止程序。(参数个数为0)" -#: autosub/options.py:223 +#: autosub/options.py:218 msgid "type" msgstr "种类" -#: autosub/options.py:226 +#: autosub/options.py:221 #, python-format msgid "" "Output more files. Available types: regions, src, full-src, dst, bilingual, " @@ -308,7 +308,7 @@ msgstr "" "字幕行中,且目标语言先于源语言。src-lf-dst:源语言和目标语言在同一字幕行中," "且源语言先于目标语言。(参数个数在6和1之间)(默认参数为%(default)s)" -#: autosub/options.py:243 +#: autosub/options.py:238 msgid "" "Valid when your output format is \"sub\". If input, it will override the fps " "check on the input file. Ref: https://pysubs2.readthedocs.io/en/latest/api-" @@ -318,34 +318,37 @@ msgstr "" "查。参考:https://pysubs2.readthedocs.io/en/latest/api-reference." "html#supported-input-output-formats(参数个数为1)" -#: autosub/options.py:252 +#: autosub/options.py:247 msgid "API_code" msgstr "API代码" -#: autosub/options.py:254 +#: autosub/options.py:250 #, python-format msgid "" "Choose which Speech-to-Text API to use. Currently support: gsv2: Google " "Speech V2 (https://github.com/gillesdemey/google-speech-v2). gcsv1: Google " "Cloud Speech-to-Text V1P1Beta1 (https://cloud.google.com/speech-to-text/" -"docs). (arg_num = 1) (default: %(default)s)" +"docs). xfyun: Xun Fei Yun Speech-to-Text WebSocket API (https://www.xfyun.cn/" +"doc/asr/voicedictation/API.html).(arg_num = 1) (default: %(default)s)" msgstr "" "选择使用Speech-to-Text API。当前支持:gsv2:Google Speech V2 (https://" "github.com/gillesdemey/google-speech-v2)。 gcsv1:Google Cloud Speech-to-" -"Text V1P1Beta1 (https://cloud.google.com/speech-to-text/docs)。(参数个数为" -"1)(默认参数为%(default)s)" +"Text V1P1Beta1 (https://cloud.google.com/speech-to-text/docs)。xfyun:讯飞" +"开放平台语音听写(流式版)WebSocket API(https://www.xfyun.cn/doc/asr/" +"voicedictation/API.html)。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:264 +#: autosub/options.py:262 msgid "" -"The API key for Speech-to-Text API. (arg_num = 1) Currently support: gsv2: " -"The API key for gsv2. (default: Free API key) gcsv1: The API key for gcsv1. " -"(If used, override the credentials given by\"-sa\"/\"--service-account\")" +"The API key for Google Speech-to-Text API. (arg_num = 1) Currently support: " +"gsv2: The API key for gsv2. (default: Free API key) gcsv1: The API key for " +"gcsv1. (If used, override the credentials given by\"-sa\"/\"--service-account" +"\")" msgstr "" -"Speech-to-Text API的密钥。(参数个数为1)当前支持:gsv2:gsv2的API密钥。(默" -"认参数为免费API密钥)gcsv1:gcsv1的API密钥。(如果使用了,可以覆盖 \"-sa\"/" -"\"--service-account\"提供的服务账号凭据)" +"Google Speech-to-Text API的密钥。(参数个数为1)当前支持:gsv2:gsv2的API密" +"钥。(默认参数为免费API密钥)gcsv1:gcsv1的API密钥。(如果使用了,可以覆盖 " +"\"-sa\"/\"--service-account\"提供的服务账号凭据)" -#: autosub/options.py:275 +#: autosub/options.py:273 #, python-format msgid "" "Use Speech-to-Text recognition config file to send request. Override these " @@ -353,28 +356,32 @@ msgid "" "Cloud Speech-to-Text V1P1Beta1 API key config reference: https://cloud." "google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig " "Service account config reference: https://googleapis.dev/python/speech/" -"latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig If " -"arg_num is 0, use const path. (arg_num = 0 or 1) (const: %(const)s)" +"latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig " +"xfyun: Xun Fei Yun Speech-to-Text WebSocket API (https://console.xfyun.cn/" +"services/iat). If arg_num is 0, use const path. (arg_num = 0 or 1) (const: " +"%(const)s)" msgstr "" "使用语音转文字识别配置文件来发送请求。取代以下选项:\"-S\", \"-asr\", \"-asf" "\"。目前支持:gcsv1:Google Cloud Speech-to-Text V1P1Beta1 API密钥配置参考:" "https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/" "RecognitionConfig 服务账号配置参考:https://googleapis.dev/python/speech/" "latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig 。" -"如果参数个数是0,使用const路径。(参数个数为0或1)(const为%(const)s)" +"xfyun:讯飞开放平台语音听写(流式版)WebSocket API(https://console.xfyun.cn/" +"services/iat)。如果参数个数是0,使用const路径。(参数个数为0或1)(const" +"为%(const)s)" #: autosub/options.py:296 #, python-format msgid "" -"API response for text confidence. A float value between 0 and 1. Confidence " -"bigger means the result is better. Input this argument will drop any result " -"below it. Ref: https://github.com/BingLingGroup/google-speech-v2#response " -"(arg_num = 1) (default: %(default)s)" +"Google Speech-to-Text API response for text confidence. A float value " +"between 0 and 1. Confidence bigger means the result is better. Input this " +"argument will drop any result below it. Ref: https://github.com/" +"BingLingGroup/google-speech-v2#response (arg_num = 1) (default: %(default)s)" msgstr "" -"API用于识别可信度的回应参数。一个介于0和1之间的浮点数。可信度越高意味着结果越" -"好。输入这个参数会导致所有低于这个结果的识别结果被删除。参考:https://github." -"com/BingLingGroup/google-speech-v2#response(参数个数为1)(默认参数为%" -"(default)s)" +"Google Speech-to-Text API用于识别可信度的回应参数。一个介于0和1之间的浮点数。" +"可信度越高意味着结果越好。输入这个参数会导致所有低于这个结果的识别结果被删" +"除。参考:https://github.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 +406,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 +488,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 +539,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 +566,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 +615,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 @@ -629,14 +636,13 @@ msgstr "" "上。(参数个数为1)(默认参数为%(default)s)" #: 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)" +"如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://" +"auditok.readthedocs.io/en/latest/core.html#class-summary(参数个数为0)" #: autosub/options.py:550 msgid "" @@ -716,26 +722,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/data/locale/zh_CN/LC_MESSAGES/autosub.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po index 70142e44..b56d6db8 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-20 10:01+0800\n" +"POT-Creation-Date: 2020-03-20 20:43+0800\n" "PO-Revision-Date: 2020-03-12 17:25+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,7 +17,7 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/__init__.py:52 +#: autosub/__init__.py:43 msgid "" "\n" "Input args(without \"autosub\"): " @@ -25,7 +25,7 @@ msgstr "" "\n" "输入参数(不包含\"autosub\"): " -#: autosub/__init__.py:73 autosub/__init__.py:178 +#: autosub/__init__.py:64 autosub/__init__.py:175 msgid "" "\n" "All works done." @@ -33,15 +33,15 @@ msgstr "" "\n" "做完了。" -#: autosub/__init__.py:86 +#: autosub/__init__.py:77 msgid "Error: Dependency ffmpeg not found on this machine." msgstr "错误:依赖ffmpeg未在这台电脑上找到。" -#: autosub/__init__.py:90 +#: autosub/__init__.py:81 msgid "Error: Dependency ffprobe not found on this machine." msgstr "错误:依赖ffprobe未在这台电脑上找到。" -#: autosub/__init__.py:101 +#: autosub/__init__.py:92 msgid "" "Error: The args of \"-ap\"/\"--audio-process\" are wrong.\n" "No works done." @@ -49,11 +49,11 @@ msgstr "" "错误:\"-ap\"/\"--audio-process\"的参数有误。\n" "啥都没做。" -#: autosub/__init__.py:113 +#: autosub/__init__.py:104 msgid "No works done." msgstr "啥都没做。" -#: autosub/__init__.py:117 +#: autosub/__init__.py:108 msgid "" "Audio pre-processing complete.\n" "All works done." @@ -61,7 +61,7 @@ msgstr "" "音频预处理已完成。\n" "做完了。" -#: autosub/__init__.py:133 +#: autosub/__init__.py:124 msgid "" "Audio pre-processing failed.\n" "Use default method." @@ -69,11 +69,11 @@ msgstr "" "音频预处理失败。\n" "使用默认方法。" -#: autosub/__init__.py:137 +#: autosub/__init__.py:128 msgid "Audio pre-processing complete." msgstr "音频预处理已完成。" -#: autosub/__init__.py:181 +#: autosub/__init__.py:178 msgid "" "\n" "KeyboardInterrupt. Works stopped." @@ -81,7 +81,7 @@ msgstr "" "\n" "键盘中断。操作终止。" -#: autosub/__init__.py:183 +#: autosub/__init__.py:180 msgid "" "\n" "Error: pysubs2.exceptions. Check your file format." @@ -89,7 +89,7 @@ msgstr "" "\n" "错误:pysubs2异常。检查你的文件格式。" -#: autosub/__init__.py:188 +#: autosub/__init__.py:185 msgid "Press Enter to exit..." msgstr "按回车以退出..." diff --git a/autosub/exceptions.py b/autosub/exceptions.py index 5ea1fc11..0b3e83b3 100644 --- a/autosub/exceptions.py +++ b/autosub/exceptions.py @@ -40,9 +40,3 @@ class SpeechToTextException(AutosubException): """ Raised when speech-to-text failed. """ - - -class XfyunWebSocketClosedException(AutosubException): - """ - Raised when xfyun speech-to-text websocket closed. - """ diff --git a/autosub/options.py b/autosub/options.py index a9e3b187..d49c49ef 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -246,17 +246,20 @@ def get_cmd_parser(): # pylint: disable=too-many-statements '-sapi', '--speech-api', metavar=_('API_code'), default='gsv2', + choices=["gsv2", "gcsv1", "xfyun"], help=_("Choose which Speech-to-Text API to use. " "Currently support: " "gsv2: Google Speech V2 (https://github.com/gillesdemey/google-speech-v2). " "gcsv1: Google Cloud Speech-to-Text V1P1Beta1 " "(https://cloud.google.com/speech-to-text/docs). " + "xfyun: Xun Fei Yun Speech-to-Text WebSocket API " + "(https://www.xfyun.cn/doc/asr/voicedictation/API.html)." "(arg_num = 1) (default: %(default)s)")) speech_group.add_argument( '-skey', '--speech-key', metavar='key', - help=_("The API key for Speech-to-Text API. (arg_num = 1) " + help=_("The API key for Google Speech-to-Text API. (arg_num = 1) " "Currently support: " "gsv2: The API key for gsv2. (default: Free API key) " "gcsv1: The API key for gcsv1. " @@ -279,6 +282,8 @@ def get_cmd_parser(): # pylint: disable=too-many-statements "https://googleapis.dev/python/speech/latest" "/gapic/v1/types.html" "#google.cloud.speech_v1.types.RecognitionConfig " + "xfyun: Xun Fei Yun Speech-to-Text WebSocket API " + "(https://console.xfyun.cn/services/iat). " "If arg_num is 0, use const path. " "(arg_num = 0 or 1) (const: %(const)s)") ) @@ -288,7 +293,7 @@ def get_cmd_parser(): # pylint: disable=too-many-statements metavar='float', type=float, default=0.0, - help=_("API response for text confidence. " + help=_("Google Speech-to-Text API response for text confidence. " "A float value between 0 and 1. " "Confidence bigger means the result is better. " "Input this argument will drop any result below it. " diff --git a/autosub/xfyun_api.py b/autosub/xfyun_api.py index 8d0dd977..6665d4e3 100644 --- a/autosub/xfyun_api.py +++ b/autosub/xfyun_api.py @@ -4,6 +4,7 @@ Defines Xun Fei Yun API used by autosub. """ # Import built-in modules +import os import datetime import hashlib import base64 @@ -15,6 +16,7 @@ import time from datetime import datetime from time import mktime +import gettext # Import third-party modules import websocket @@ -25,6 +27,14 @@ from autosub import exceptions +XFYUN_API_TEXT = gettext.translation(domain=__name__, + localedir=constants.LOCALE_PATH, + languages=[constants.CURRENT_LOCALE], + fallback=True) + +_ = XFYUN_API_TEXT.gettext + + def create_xfyun_url( api_key, api_secret, @@ -97,12 +107,14 @@ def __init__(self, api_secret, api_address, business_args, + is_keep=False, is_full_result=False): self.common_args = {"app_id": app_id} self.api_key = api_key self.api_secret = api_secret self.api_address = api_address self.business_args = business_args + self.is_keep = is_keep self.is_full_result = is_full_result self.data = {"status": 0, "format": "audio/L16;rate=16000", @@ -130,6 +142,8 @@ def __call__(self, filename): on_close=lambda web_socket: self.on_close(web_socket), on_open=lambda web_socket: self.on_open(web_socket)) self.web_socket_app.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}) + if not self.is_keep: + os.remove(filename) if self.is_full_result: return self.result_list return self.transcript @@ -153,11 +167,11 @@ def on_error(self, web_socket, error): # pylint: disable=no-self-use """ raise exceptions.SpeechToTextException(error) - def on_close(self, web_socket): # pylint: disable=no-self-use + def on_close(self, web_socket): # pylint: disable=no-self-use, unused-argument """ Process the connection close from WebSocket. """ - raise exceptions.XfyunWebSocketClosedException("") + return def on_open(self, web_socket): """ @@ -216,7 +230,8 @@ def run(): # business_args={"language": "zh_cn", # "domain": "iat", # "accent": "mandarin"}, -# is_full_result=False) +# is_full_result=False, +# is_keep=True) # # print(web_socket_result_obj(filename=r"C:\userfile\Video\autosub\test\temp.pcm")) # time2 = datetime.now() diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 0551a773..d26b2067 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -46,6 +46,8 @@ #### 添加(未发布) +- 添加讯飞开放平台语音听写(流式版)WebSocket API支持。 + #### 改动(未发布) ### [0.5.6-alpha] - 2020-03-20 From 1944f301f347eda9245031d13ac1a66605bf11f5 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sat, 21 Mar 2020 10:07:16 +0800 Subject: [PATCH 03/26] Add chars filter for the transcript result in XfyunWebSocketAPI --- CHANGELOG.md | 4 + autosub/__init__.py | 26 ++-- autosub/cmdline_utils.py | 9 +- autosub/constants.py | 2 +- autosub/core.py | 34 +++-- .../LC_MESSAGES/autosub.cmdline_utils.po | 134 +++++++++--------- .../locale/zh_CN/LC_MESSAGES/autosub.core.po | 30 ++-- .../data/locale/zh_CN/LC_MESSAGES/autosub.po | 10 +- autosub/xfyun_api.py | 8 +- docs/CHANGELOG.zh-Hans.md | 4 + 10 files changed, 139 insertions(+), 122 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca77eead..befbebe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,9 +50,13 @@ Click up arrow to go back to TOC. #### Added(Unreleased) - Add support for Xun Fei Yun Speech-to-Text WebSocket API. +- Add chars filter for the transcript result in XfyunWebSocketAPI. #### Changed(Unreleased) +- Change the replacement condition of the audio_split_cmd only when the user doesn't modify it. +- Change the MAX_REGION_SIZE_LIMIT into 60 seconds. + ### [0.5.6-alpha] - 2020-03-20 #### Added(0.5.6-alpha) diff --git a/autosub/__init__.py b/autosub/__init__.py index bba6557a..fd1ae9bc 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -137,18 +137,20 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- "[sample_rate]", "{sample_rate}".format(sample_rate=args.api_sample_rate)) - if args.api_suffix == ".ogg": - # regard ogg as ogg_opus - args.audio_split_cmd = \ - args.audio_split_cmd.replace( - "-vn", - "-vn -c:a libopus") - elif args.api_suffix == ".pcm": - # raw pcm - args.audio_split_cmd = \ - args.audio_split_cmd.replace( - "-vn", - "-vn -c:a pcm_s16le -f s16le") + if args.audio_split_cmd == constants.DEFAULT_AUDIO_SPLT: + # if user doesn't modify the audio_split_cmd + if args.api_suffix == ".ogg": + # regard ogg as ogg_opus + args.audio_split_cmd = \ + args.audio_split_cmd.replace( + "-vn", + "-vn -c:a libopus") + elif args.api_suffix == ".pcm": + # raw pcm + args.audio_split_cmd = \ + args.audio_split_cmd.replace( + "-vn", + "-vn -c:a pcm_s16le -f s16le") cmdline_utils.validate_aovp_args(args) fps = cmdline_utils.get_fps(args=args, input_m=input_m) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 42758c1c..fa80e644 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -265,14 +265,7 @@ def validate_config_args(args): # pylint: disable=too-many-branches, too-many-r if "encoding" in config_dict and config_dict["encoding"]: # https://cloud.google.com/speech-to-text/docs/quickstart-protocol # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding - if config_dict["encoding"] == "FLAC": - args.api_suffix = ".flac" - elif config_dict["encoding"] == "MP3": - args.api_suffix = ".mp3" - elif config_dict["encoding"] == "LINEAR16": - args.api_suffix = ".wav" - elif config_dict["encoding"] == "OGG_OPUS": - args.api_suffix = ".ogg" + args.api_suffix = core.encoding_to_extension(config_dict["encoding"]) else: # it's necessary to set default encoding config_dict["encoding"] = core.extension_to_encoding(args.api_suffix) diff --git a/autosub/constants.py b/autosub/constants.py index 524e099a..b2e4d39d 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -68,7 +68,7 @@ DEFAULT_MAX_REGION_SIZE = 6.0 DEFAULT_MIN_REGION_SIZE = 0.8 MIN_REGION_SIZE_LIMIT = 0.6 -MAX_REGION_SIZE_LIMIT = 12.0 +MAX_REGION_SIZE_LIMIT = 60.0 DEFAULT_CONTINUOUS_SILENCE = 0.2 # 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 896579f9..d8875db3 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -45,36 +45,38 @@ def extension_to_encoding( """ File extension to audio encoding. """ - + ext = extension.lower() if is_string: - if extension.lower().endswith(".flac"): + if ext.endswith(".flac"): encoding = "FLAC" - elif extension.lower().endswith(".mp3"): + elif ext.endswith(".mp3"): encoding = "MP3" - elif extension.lower().endswith(".wav"): + elif ext.endswith(".wav")\ + or ext.endswith(".pcm"): # regard WAV as PCM encoding = "LINEAR16" - elif extension.lower().endswith(".ogg"): + elif ext.endswith(".ogg"): encoding = "OGG_OPUS" else: encoding = "" else: # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding - if extension.lower().endswith(".flac"): + if ext.endswith(".flac"): encoding = \ enums.RecognitionConfig.AudioEncoding.FLAC # encoding = 2 - elif extension.lower().endswith(".mp3"): + elif ext.endswith(".mp3"): encoding = \ enums.RecognitionConfig.AudioEncoding.MP3 # encoding = 8 - elif extension.lower().endswith(".wav"): + elif ext.endswith(".wav")\ + or extension.lower().endswith(".pcm"): # regard WAV as PCM encoding = \ enums.RecognitionConfig.AudioEncoding.LINEAR16 # encoding = 1 - elif extension.lower().endswith(".ogg"): + elif ext.endswith(".ogg"): encoding = \ enums.RecognitionConfig.AudioEncoding.OGG_OPUS # encoding = 6 @@ -101,7 +103,7 @@ def encoding_to_extension( # pylint: disable=too-many-branches elif encoding == "OGG_OPUS": extension = ".ogg" else: - extension = "" + extension = ".flac" elif isinstance(encoding, int): # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding @@ -114,10 +116,10 @@ def encoding_to_extension( # pylint: disable=too-many-branches elif encoding == 6: extension = ".ogg" else: - extension = "" + extension = ".flac" else: - extension = "" + extension = ".flac" return extension @@ -447,6 +449,11 @@ def xfyun_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man else: api_address = constants.XFYUN_SPEECH_WEBAPI_URL + if "delete_chars" in config: + delete_chars = config["delete_chars"] + else: + delete_chars = None + pool = multiprocessing.Pool(concurrency) print(_("\nSending short-term fragments to Xun Fei Yun WebSocket API" @@ -465,7 +472,8 @@ def xfyun_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man api_address=api_address, business_args=config["business"], is_keep=is_keep, - is_full_result=result_list is not None) + is_full_result=result_list is not None, + delete_chars=delete_chars) # get transcript if result_list is None: 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 412a079b..4aaed4c0 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-20 20:42+0800\n" +"POT-Creation-Date: 2020-03-21 09:55+0800\n" "PO-Revision-Date: 2020-03-20 20:45+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -134,45 +134,45 @@ msgstr "错误:无法解码语音配置文件\"{filename}\"。" msgid "Error: Speech config file \"{filename}\" doesn't exist." msgstr "错误:语音配置文件\"{filename}\"不存在。" -#: autosub/cmdline_utils.py:315 +#: autosub/cmdline_utils.py:308 msgid "Error: No \"app_id\" found in speech config file \"{filename}\"." msgstr "错误:\"app_id\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:322 +#: autosub/cmdline_utils.py:315 msgid "Error: No \"api_key\" found in speech config file \"{filename}\"." msgstr "错误:\"api_key\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:329 +#: autosub/cmdline_utils.py:322 msgid "Error: No \"api_secret\" found in speech config file \"{filename}\"." msgstr "错误:\"api_secret\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:334 +#: autosub/cmdline_utils.py:327 msgid "Error: No \"language\" found in speech config file \"{filename}\"." msgstr "错误:\"language\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:349 +#: autosub/cmdline_utils.py:342 msgid "Error: \"-slp\"/\"--sleep-seconds\" arg is illegal." msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" -#: autosub/cmdline_utils.py:357 +#: autosub/cmdline_utils.py:350 msgid "Let speech lang code to match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:363 +#: autosub/cmdline_utils.py:356 msgid "Use langcodes to standardize the result." msgstr "使用langcodes来标准化结果。" -#: autosub/cmdline_utils.py:365 autosub/cmdline_utils.py:421 -#: autosub/cmdline_utils.py:443 autosub/cmdline_utils.py:516 -#: autosub/cmdline_utils.py:543 +#: autosub/cmdline_utils.py:358 autosub/cmdline_utils.py:414 +#: autosub/cmdline_utils.py:436 autosub/cmdline_utils.py:509 +#: autosub/cmdline_utils.py:536 msgid "Use \"{lang_code}\" instead." msgstr "改用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:368 +#: autosub/cmdline_utils.py:361 msgid "Match failed. Still using \"{lang_code}\"." msgstr "匹配失败。仍在使用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:371 +#: autosub/cmdline_utils.py:364 msgid "" "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" "list-speech-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -182,35 +182,35 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:379 +#: autosub/cmdline_utils.py:372 msgid "Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal." msgstr "错误:\"-mnc\"/\"--min-confidence\"参数的值不合法。" -#: autosub/cmdline_utils.py:384 +#: autosub/cmdline_utils.py:377 msgid "" "Error: You must provide \"-sconf\", \"--speech-config\" option when using " "Xun Fei Yun API." msgstr "错误:使用讯飞云API时,你必须提供\"-sconf\",\"--speech-config\"选项。" -#: autosub/cmdline_utils.py:388 +#: autosub/cmdline_utils.py:381 msgid "" "Translation destination language not provided. Only performing speech " "recognition." msgstr "翻译目的语言未提供。只进行语音识别。" -#: autosub/cmdline_utils.py:393 +#: autosub/cmdline_utils.py:386 msgid "Translation source language not provided. Use speech language instead." msgstr "翻译源语言未提供。改用语音语言。" -#: autosub/cmdline_utils.py:414 +#: autosub/cmdline_utils.py:407 msgid "Let translation source lang code to match py-googletrans lang codes." msgstr "让翻译源语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:425 autosub/cmdline_utils.py:447 +#: autosub/cmdline_utils.py:418 autosub/cmdline_utils.py:440 msgid "Error: Match failed." msgstr "错误:匹配失败。" -#: autosub/cmdline_utils.py:428 +#: autosub/cmdline_utils.py:421 msgid "" "Error: Translation source language \"{src}\" is not supported. Run with \"-" "ltc\"/\"--list-translation-codes\" to see all supported languages. Or use \"-" @@ -220,12 +220,12 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:436 +#: autosub/cmdline_utils.py:429 msgid "" "Let translation destination lang code to match py-googletrans lang codes." msgstr "让翻译目的语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:450 +#: autosub/cmdline_utils.py:443 msgid "" "Error: Translation destination language \"{dst}\" is not supported. Run with " "\"-ltc\"/\"--list-translation-codes\" to see all supported languages. Or use " @@ -234,29 +234,29 @@ msgstr "" "错误:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" "项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最佳匹配。" -#: autosub/cmdline_utils.py:458 +#: autosub/cmdline_utils.py:451 msgid "" "Speech language is the same as the destination language. Only performing " "speech recognition." msgstr "语音语言和目的语言一致。只进行语音识别。" -#: autosub/cmdline_utils.py:467 +#: autosub/cmdline_utils.py:460 msgid "You've already input times. No works done." msgstr "你已经输入了时间轴。啥都没做。" -#: autosub/cmdline_utils.py:471 +#: autosub/cmdline_utils.py:464 msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:479 autosub/cmdline_utils.py:571 +#: autosub/cmdline_utils.py:472 autosub/cmdline_utils.py:564 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" -#: autosub/cmdline_utils.py:492 +#: autosub/cmdline_utils.py:485 msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" -#: autosub/cmdline_utils.py:508 +#: autosub/cmdline_utils.py:501 msgid "" "Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages." @@ -264,11 +264,11 @@ msgstr "" "警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:520 autosub/cmdline_utils.py:547 +#: autosub/cmdline_utils.py:513 autosub/cmdline_utils.py:540 msgid "Match failed. Still using \"{lang_code}\". Program stopped." msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" -#: autosub/cmdline_utils.py:526 +#: autosub/cmdline_utils.py:519 msgid "" "Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -278,7 +278,7 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:535 +#: autosub/cmdline_utils.py:528 msgid "" "Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages." @@ -286,7 +286,7 @@ msgstr "" "警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" "行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:553 +#: autosub/cmdline_utils.py:546 msgid "" "Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" @@ -296,12 +296,12 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:561 +#: autosub/cmdline_utils.py:554 msgid "" "Error: Translation source language is the same as the destination language." msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:585 +#: autosub/cmdline_utils.py:578 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -309,7 +309,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:592 +#: autosub/cmdline_utils.py:585 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -317,7 +317,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:599 +#: autosub/cmdline_utils.py:592 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -325,16 +325,16 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:655 autosub/cmdline_utils.py:799 -#: autosub/cmdline_utils.py:1337 +#: autosub/cmdline_utils.py:648 autosub/cmdline_utils.py:792 +#: autosub/cmdline_utils.py:1330 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:659 autosub/cmdline_utils.py:751 -#: autosub/cmdline_utils.py:803 autosub/cmdline_utils.py:855 -#: autosub/cmdline_utils.py:1036 autosub/cmdline_utils.py:1191 -#: autosub/cmdline_utils.py:1233 autosub/cmdline_utils.py:1293 -#: autosub/cmdline_utils.py:1341 autosub/cmdline_utils.py:1389 +#: autosub/cmdline_utils.py:652 autosub/cmdline_utils.py:744 +#: autosub/cmdline_utils.py:796 autosub/cmdline_utils.py:848 +#: autosub/cmdline_utils.py:1029 autosub/cmdline_utils.py:1184 +#: autosub/cmdline_utils.py:1226 autosub/cmdline_utils.py:1286 +#: autosub/cmdline_utils.py:1334 autosub/cmdline_utils.py:1382 msgid "" "\n" "All works done." @@ -342,23 +342,23 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:703 autosub/cmdline_utils.py:1250 +#: autosub/cmdline_utils.py:696 autosub/cmdline_utils.py:1243 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:747 autosub/cmdline_utils.py:1289 +#: autosub/cmdline_utils.py:740 autosub/cmdline_utils.py:1282 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:851 autosub/cmdline_utils.py:1385 +#: autosub/cmdline_utils.py:844 autosub/cmdline_utils.py:1378 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:894 autosub/cmdline_utils.py:1430 +#: autosub/cmdline_utils.py:887 autosub/cmdline_utils.py:1423 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:936 +#: autosub/cmdline_utils.py:929 msgid "" "\n" "No works done. Check your \"-of\"/\"--output-files\" option." @@ -366,11 +366,11 @@ msgstr "" "\n" "啥都没做。检查你的\"-of\"/\"--output-files\"选项。" -#: autosub/cmdline_utils.py:941 +#: autosub/cmdline_utils.py:934 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:975 +#: autosub/cmdline_utils.py:968 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -378,11 +378,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:985 +#: autosub/cmdline_utils.py:978 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:988 +#: autosub/cmdline_utils.py:981 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -390,7 +390,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:1000 +#: autosub/cmdline_utils.py:993 msgid "" "\n" "\"{name}\" has been deleted." @@ -398,19 +398,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:1004 +#: autosub/cmdline_utils.py:997 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1033 autosub/cmdline_utils.py:1497 +#: autosub/cmdline_utils.py:1026 autosub/cmdline_utils.py:1490 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1057 +#: autosub/cmdline_utils.py:1050 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1061 +#: autosub/cmdline_utils.py:1054 msgid "" "Audio processing complete.\n" "All works done." @@ -418,11 +418,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1113 +#: autosub/cmdline_utils.py:1106 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1128 +#: autosub/cmdline_utils.py:1121 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -432,18 +432,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1133 +#: autosub/cmdline_utils.py:1126 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1147 +#: autosub/cmdline_utils.py:1140 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1159 +#: autosub/cmdline_utils.py:1152 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -451,11 +451,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1187 +#: autosub/cmdline_utils.py:1180 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1195 +#: autosub/cmdline_utils.py:1188 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -463,11 +463,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1229 autosub/cmdline_utils.py:1467 +#: autosub/cmdline_utils.py:1222 autosub/cmdline_utils.py:1460 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1439 +#: autosub/cmdline_utils.py:1432 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -475,7 +475,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1472 +#: autosub/cmdline_utils.py:1465 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.core.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po index 9fd0cc6e..d5bff2f7 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-20 20:42+0800\n" +"POT-Creation-Date: 2020-03-21 09:55+0800\n" "PO-Revision-Date: 2020-03-20 20:46+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,7 +17,7 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/core.py:186 +#: autosub/core.py:188 msgid "" "\n" "Converting speech regions to short-term fragments." @@ -25,11 +25,11 @@ msgstr "" "\n" "按照语音区域将音频转换为多个短语音片段。" -#: autosub/core.py:187 +#: autosub/core.py:189 msgid "Converting: " msgstr "转换中: " -#: autosub/core.py:232 +#: autosub/core.py:234 msgid "" "\n" "Sending short-term fragments to Google Speech V2 API and getting result." @@ -37,11 +37,11 @@ msgstr "" "\n" "将短片段语音发送给Google Speech V2 API并得到识别结果。" -#: autosub/core.py:233 autosub/core.py:302 autosub/core.py:454 +#: autosub/core.py:235 autosub/core.py:304 autosub/core.py:461 msgid "Speech-to-Text: " msgstr "语音转文字中: " -#: autosub/core.py:274 autosub/core.py:417 autosub/core.py:504 +#: autosub/core.py:276 autosub/core.py:419 autosub/core.py:512 msgid "" "Error: Connection error happened too many times.\n" "All works done." @@ -49,7 +49,7 @@ msgstr "" "错误:过多连接错误。\n" "做完了。" -#: autosub/core.py:300 +#: autosub/core.py:302 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:425 autosub/core.py:512 +#: autosub/core.py:427 autosub/core.py:520 msgid "Receive something unexpected:" msgstr "收到未预期数据:" -#: autosub/core.py:452 +#: autosub/core.py:459 msgid "" "\n" "Sending short-term fragments to Xun Fei Yun WebSocket API and getting result." @@ -70,7 +70,7 @@ msgstr "" "\n" "将短片段语音发送给讯飞云WebSocket API并得到识别结果。" -#: autosub/core.py:535 +#: autosub/core.py:543 msgid "" "\n" "Translating text from \"{0}\" to \"{1}\"." @@ -78,24 +78,24 @@ msgstr "" "\n" "从\"{0}\"翻译为\"{1}\"。" -#: autosub/core.py:585 +#: autosub/core.py:593 msgid "Translation: " msgstr "翻译中: " -#: autosub/core.py:648 +#: autosub/core.py:656 msgid "Cancelling translation." msgstr "取消翻译。" -#: autosub/core.py:721 autosub/core.py:780 +#: autosub/core.py:729 autosub/core.py:788 msgid "Format \"{fmt}\" not supported. Use \"{default_fmt}\" instead." msgstr "不支持格式\"{fmt}\"。改用\"{default_fmt}\"。" -#: autosub/core.py:853 +#: autosub/core.py:861 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/core.py:856 +#: autosub/core.py:864 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.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po index b56d6db8..6eede4c5 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-20 20:43+0800\n" +"POT-Creation-Date: 2020-03-21 09:55+0800\n" "PO-Revision-Date: 2020-03-12 17:25+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -25,7 +25,7 @@ msgstr "" "\n" "输入参数(不包含\"autosub\"): " -#: autosub/__init__.py:64 autosub/__init__.py:175 +#: autosub/__init__.py:64 autosub/__init__.py:177 msgid "" "\n" "All works done." @@ -73,7 +73,7 @@ msgstr "" msgid "Audio pre-processing complete." msgstr "音频预处理已完成。" -#: autosub/__init__.py:178 +#: autosub/__init__.py:180 msgid "" "\n" "KeyboardInterrupt. Works stopped." @@ -81,7 +81,7 @@ msgstr "" "\n" "键盘中断。操作终止。" -#: autosub/__init__.py:180 +#: autosub/__init__.py:182 msgid "" "\n" "Error: pysubs2.exceptions. Check your file format." @@ -89,7 +89,7 @@ msgstr "" "\n" "错误:pysubs2异常。检查你的文件格式。" -#: autosub/__init__.py:185 +#: autosub/__init__.py:187 msgid "Press Enter to exit..." msgstr "按回车以退出..." diff --git a/autosub/xfyun_api.py b/autosub/xfyun_api.py index 6665d4e3..9d7a2bc5 100644 --- a/autosub/xfyun_api.py +++ b/autosub/xfyun_api.py @@ -108,7 +108,8 @@ def __init__(self, api_address, business_args, is_keep=False, - is_full_result=False): + is_full_result=False, + delete_chars=None): self.common_args = {"app_id": app_id} self.api_key = api_key self.api_secret = api_secret @@ -116,6 +117,7 @@ def __init__(self, self.business_args = business_args self.is_keep = is_keep self.is_full_result = is_full_result + self.delete_chars = delete_chars self.data = {"status": 0, "format": "audio/L16;rate=16000", "encoding": "raw", @@ -132,6 +134,8 @@ def __call__(self, filename): self.transcript = "" self.filename = filename websocket.enableTrace(False) + # Ref: https://stackoverflow.com/questions/26980966 + # /using-a-websocket-client-as-a-class-in-python self.web_socket_app = websocket.WebSocketApp( create_xfyun_url( api_key=self.api_key, @@ -146,6 +150,8 @@ def __call__(self, filename): os.remove(filename) if self.is_full_result: return self.result_list + if self.delete_chars: + self.transcript.translate(str.maketrans("", "", self.delete_chars)) return self.transcript def on_message(self, web_socket, result): # pylint: disable=unused-argument diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index d26b2067..584d6122 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -47,9 +47,13 @@ #### 添加(未发布) - 添加讯飞开放平台语音听写(流式版)WebSocket API支持。 +- 添加字符过滤器用于讯飞开放平台语音听写。 #### 改动(未发布) +- 修改音频分割指令的更换条件为仅当用户不修改它时。 +- 修改最长语音区域限制为60秒。 + ### [0.5.6-alpha] - 2020-03-20 #### 添加(0.5.6-alpha) From 2054ca0f33e80c7b115502596380f755363b1786 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sat, 21 Mar 2020 15:46:04 +0800 Subject: [PATCH 04/26] Add (close #68) support for Baidu Automatic Speech Recognition API --- CHANGELOG.md | 1 + autosub/__init__.py | 18 +- autosub/api_baidu.py | 161 +++++ autosub/{google_api.py => api_google.py} | 93 ++- autosub/{xfyun_api.py => api_xfyun.py} | 11 +- autosub/cmdline_utils.py | 77 ++- autosub/constants.py | 3 + autosub/core.py | 228 +++---- .../zh_CN/LC_MESSAGES/autosub.api_baidu.po | 22 + .../LC_MESSAGES/autosub.cmdline_utils.po | 184 +++--- .../locale/zh_CN/LC_MESSAGES/autosub.core.po | 62 +- .../zh_CN/LC_MESSAGES/autosub.options.po | 166 ++--- autosub/options.py | 6 +- docs/CHANGELOG.zh-Hans.md | 1 + pylintrc | 581 ++++++++++++++++++ 15 files changed, 1281 insertions(+), 333 deletions(-) create mode 100644 autosub/api_baidu.py rename autosub/{google_api.py => api_google.py} (76%) rename autosub/{xfyun_api.py => api_xfyun.py} (93%) create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po create mode 100644 pylintrc diff --git a/CHANGELOG.md b/CHANGELOG.md index befbebe1..1303cc52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Click up arrow to go back to TOC. #### Added(Unreleased) - Add support for Xun Fei Yun Speech-to-Text WebSocket API. +- Add support for Baidu Automatic Speech Recognition API. [issue #68](https://github.com/BingLingGroup/autosub/issues/68) - Add chars filter for the transcript result in XfyunWebSocketAPI. #### Changed(Unreleased) diff --git a/autosub/__init__.py b/autosub/__init__.py index fd1ae9bc..faf63b79 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -128,15 +128,6 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- print(_("Audio pre-processing complete.")) else: - args.audio_split_cmd = \ - args.audio_split_cmd.replace( - "[channel]", - "{channel}".format(channel=args.api_audio_channel)) - args.audio_split_cmd = \ - args.audio_split_cmd.replace( - "[sample_rate]", - "{sample_rate}".format(sample_rate=args.api_sample_rate)) - if args.audio_split_cmd == constants.DEFAULT_AUDIO_SPLT: # if user doesn't modify the audio_split_cmd if args.api_suffix == ".ogg": @@ -152,6 +143,15 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- "-vn", "-vn -c:a pcm_s16le -f s16le") + args.audio_split_cmd = \ + args.audio_split_cmd.replace( + "[channel]", + "{channel}".format(channel=args.api_audio_channel)) + args.audio_split_cmd = \ + args.audio_split_cmd.replace( + "[sample_rate]", + "{sample_rate}".format(sample_rate=args.api_sample_rate)) + cmdline_utils.validate_aovp_args(args) fps = cmdline_utils.get_fps(args=args, input_m=input_m) cmdline_utils.audio_or_video_prcs(args, diff --git a/autosub/api_baidu.py b/autosub/api_baidu.py new file mode 100644 index 00000000..dfaf4490 --- /dev/null +++ b/autosub/api_baidu.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Defines Baidu API used by autosub. +""" + +# Import built-in modules +from urllib.parse import urlencode +import json +import gettext +import os +import base64 + +# Import third-party modules +import requests + + +# Any changes to the path and your own modules +from autosub import constants +from autosub import exceptions + + +API_BAIDU_TEXT = gettext.translation(domain=__name__, + localedir=constants.LOCALE_PATH, + languages=[constants.CURRENT_LOCALE], + fallback=True) + +_ = API_BAIDU_TEXT.gettext + + +def baidu_dev_pid_to_lang_code( + dev_pid +): + if dev_pid == 1737: + return "en" + return "zh-cn" + + +def get_baidu_transcript( + result_dict): + """ + Function for getting transcript from Baidu ASR API result dictionary. + Reference: https://ai.baidu.com/ai-doc/SPEECH/ek38lxj1u + """ + try: + err_no = result_dict["err_no"] + if err_no != 0: + raise exceptions.SpeechToTextException( + json.dumps(result_dict, indent=4, ensure_ascii=False)) + return result_dict["result"][0] + except (KeyError, TypeError): + return "" + + +def get_baidu_token( + api_key, + api_secret, + token_url=constants.BAIDU_TOKEN_URL +): + """ + Function for getting Baidu ASR API token + """ + requests_params = {"grant_type": "client_credentials", + "client_id": api_key, + "client_secret": api_secret} + post_data = urlencode(requests_params).encode("utf-8") + result = requests.post(token_url, data=post_data) + result_str = result.content.decode("utf-8") + # get the one with valid content + try: + result_dict = json.loads(result_str) + if "access_token" in result_dict and "scope" in result_dict: + if "audio_voice_assistant_get" not in result_dict["scope"].split(" "): + raise exceptions.SpeechToTextException( + _("Error: Check you project if its ASR feature is enabled.")) + return result_dict["access_token"] + raise exceptions.SpeechToTextException( + json.dumps(result_dict, indent=4, ensure_ascii=False)) + except (ValueError, IndexError): + # no result + return "" + + +class BaiduASRAPI: # pylint: disable=too-few-public-methods + """ + Class for performing Speech-to-Text using Baidu ASR API. + """ + def __init__(self, + config, + api_url=constants.BAIDU_ASR_URL, + retries=3, + is_keep=False, + is_full_result=False, + delete_chars=None): + # pylint: disable=too-many-arguments + self.config = config + self.api_url = api_url + self.retries = retries + self.is_keep = is_keep + self.is_full_result = is_full_result + self.delete_chars = delete_chars + + def __call__(self, filename): + try: # pylint: disable=too-many-nested-blocks + audio_file = open(filename, mode="rb") + audio_data = audio_file.read() + audio_file.close() + if not self.is_keep: + os.remove(filename) + + for _ in range(self.retries): + # Reference: https://github.com/Baidu-AIP/speech-demo/blob/master + # /rest-api-asr/python/asr_json.py + self.config["speech"] = base64.b64encode(audio_data).decode('utf-8') + self.config["len"] = len(audio_data) + config_json = json.dumps(self.config, ensure_ascii=False) + try: + requests_result = \ + requests.post(self.api_url, data=config_json) + except requests.exceptions.ConnectionError: + continue + requests_result_json = requests_result.content.decode("utf-8") + try: + result_dict = json.loads(requests_result_json) + except ValueError: + # no result + continue + + if not self.is_full_result: + if self.delete_chars: + return get_baidu_transcript(result_dict).translate( + str.maketrans("", "", self.delete_chars)) + return get_baidu_transcript(result_dict) + return result_dict + + except KeyboardInterrupt: + return None + + return None + + +# if __name__ == "__main__": +# # 测试时候在此处正确填写相关信息即可运行 +# config = { +# 'dev_pid': 1537, +# 'format': "pcm", +# 'rate': "16000", +# 'token': get_baidu_token( +# api_key="", +# api_secret=""), +# 'cuid': "python", +# 'channel': 1, +# } +# +# baidu_asr_obj = BaiduASRAPI( +# api_url=constants.BAIDU_ASR_URL, +# config=config, +# is_full_result=False, +# is_keep=True) +# +# print(baidu_asr_obj(filename=r".pcm")) diff --git a/autosub/google_api.py b/autosub/api_google.py similarity index 76% rename from autosub/google_api.py rename to autosub/api_google.py index 9b251f33..1b05eb8b 100644 --- a/autosub/google_api.py +++ b/autosub/api_google.py @@ -18,9 +18,96 @@ if constants.IS_GOOGLECLOUDCLIENT: from google.cloud import speech_v1p1beta1 from google.protobuf.json_format import MessageToDict + from google.cloud.speech_v1p1beta1 import enums else: speech_v1p1beta1 = None # pylint: disable=invalid-name MessageToDict = None # pylint: disable=invalid-name + enums = None # pylint: disable=invalid-name + + +def google_ext_to_enc( + extension, + is_string=True): + """ + File extension to audio encoding. + """ + ext = extension.lower() + if is_string: + if ext.endswith(".flac"): + encoding = "FLAC" + elif ext.endswith(".mp3"): + encoding = "MP3" + elif ext.endswith(".wav")\ + or ext.endswith(".pcm"): + # regard WAV as PCM + encoding = "LINEAR16" + elif ext.endswith(".ogg"): + encoding = "OGG_OPUS" + else: + encoding = "" + + else: + # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding + if ext.endswith(".flac"): + encoding = \ + enums.RecognitionConfig.AudioEncoding.FLAC + # encoding = 2 + elif ext.endswith(".mp3"): + encoding = \ + enums.RecognitionConfig.AudioEncoding.MP3 + # encoding = 8 + elif ext.endswith(".wav")\ + or extension.lower().endswith(".pcm"): + # regard WAV as PCM + encoding = \ + enums.RecognitionConfig.AudioEncoding.LINEAR16 + # encoding = 1 + elif ext.endswith(".ogg"): + encoding = \ + enums.RecognitionConfig.AudioEncoding.OGG_OPUS + # encoding = 6 + else: + encoding = \ + enums.RecognitionConfig.AudioEncoding.ENCODING_UNSPECIFIED + # encoding = 0 + + return encoding + + +def google_enc_to_ext( # pylint: disable=too-many-branches + encoding): + """ + Audio encoding to file extension. + """ + if isinstance(encoding, str): + if encoding == "FLAC": + extension = ".flac" + elif encoding == "MP3": + extension = ".mp3" + elif encoding == "LINEAR16": + extension = ".wav" + elif encoding == "OGG_OPUS": + extension = ".ogg" + else: + extension = ".flac" + + elif isinstance(encoding, int): + # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding + if encoding == 2: + extension = ".flac" + elif encoding == 8: + extension = ".mp3" + elif encoding == 1: + extension = ".wav" + elif encoding == 6: + extension = ".ogg" + else: + extension = ".flac" + + else: + extension = ".flac" + + return extension def get_google_speech_v2_transcript( @@ -126,9 +213,9 @@ def __call__(self, filename): continue # receive several results delimited by LF - result_str = result.content.decode('utf-8').split("\n") + result_list = result.content.decode('utf-8').split("\n") # get the one with valid content - for line in result_str: + for line in result_list: try: line_dict = json.loads(line) transcript = get_google_speech_v2_transcript( @@ -188,7 +275,7 @@ def gcsv1p1beta1_service_client( return None -class GCSV1P1Beta1URL: # pylint: disable=too-few-public-methods +class GCSV1P1Beta1URL: # pylint: disable=too-few-public-methods, duplicate-code """ Class for performing Speech-to-Text using Google Cloud Speech-to-Text V1P1Beta1 API URL for an input FLAC file. diff --git a/autosub/xfyun_api.py b/autosub/api_xfyun.py similarity index 93% rename from autosub/xfyun_api.py rename to autosub/api_xfyun.py index 9d7a2bc5..907023ac 100644 --- a/autosub/xfyun_api.py +++ b/autosub/api_xfyun.py @@ -16,7 +16,6 @@ import time from datetime import datetime from time import mktime -import gettext # Import third-party modules import websocket @@ -27,14 +26,6 @@ from autosub import exceptions -XFYUN_API_TEXT = gettext.translation(domain=__name__, - localedir=constants.LOCALE_PATH, - languages=[constants.CURRENT_LOCALE], - fallback=True) - -_ = XFYUN_API_TEXT.gettext - - def create_xfyun_url( api_key, api_secret, @@ -239,6 +230,6 @@ def run(): # is_full_result=False, # is_keep=True) # -# print(web_socket_result_obj(filename=r"C:\userfile\Video\autosub\test\temp.pcm")) +# print(web_socket_result_obj(filename=r".pcm")) # time2 = datetime.now() # print(time2 - time1) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index fa80e644..7fa059a8 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -25,6 +25,8 @@ from autosub import ffmpeg_utils from autosub import lang_code_utils from autosub import sub_utils +from autosub import api_google +from autosub import api_baidu CMDLINE_UTILS_TEXT = gettext.translation(domain=__name__, localedir=constants.LOCALE_PATH, @@ -265,10 +267,10 @@ def validate_config_args(args): # pylint: disable=too-many-branches, too-many-r if "encoding" in config_dict and config_dict["encoding"]: # https://cloud.google.com/speech-to-text/docs/quickstart-protocol # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding - args.api_suffix = core.encoding_to_extension(config_dict["encoding"]) + args.api_suffix = api_google.google_enc_to_ext(config_dict["encoding"]) else: # it's necessary to set default encoding - config_dict["encoding"] = core.extension_to_encoding(args.api_suffix) + config_dict["encoding"] = api_google.google_ext_to_enc(args.api_suffix) # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig # https://googleapis.dev/python/speech/latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig @@ -292,17 +294,16 @@ def validate_config_args(args): # pylint: disable=too-many-branches, too-many-r elif "languageCode" in config_dict and config_dict["languageCode"]: args.speech_language = config_dict["languageCode"] - elif args.speech_api == "xfyun": + else: args.api_suffix = ".pcm" args.api_sample_rate = 16000 - if "business" not in config_dict: - config_dict["business"] = { - "language": "zh_cn", - "domain": "iat", - "accent": "mandarin"} if "APPID" in config_dict: config_dict["app_id"] = config_dict["APPID"] + del config_dict["APPID"] + elif "AppID" in config_dict: + config_dict["app_id"] = config_dict["AppID"] + del config_dict["AppID"] elif "app_id" not in config_dict: raise exceptions.AutosubException( _("Error: No \"app_id\" found in speech config file \"{filename}\"." @@ -310,6 +311,10 @@ def validate_config_args(args): # pylint: disable=too-many-branches, too-many-r if "APIKey" in config_dict: config_dict["api_key"] = config_dict["APIKey"] + del config_dict["APIKey"] + elif "API key" in config_dict: + config_dict["api_key"] = config_dict["API key"] + del config_dict["API key"] elif "api_key" not in config_dict: raise exceptions.AutosubException( _("Error: No \"api_key\" found in speech config file \"{filename}\"." @@ -317,17 +322,51 @@ def validate_config_args(args): # pylint: disable=too-many-branches, too-many-r if "APISecret" in config_dict: config_dict["api_secret"] = config_dict["APISecret"] + del config_dict["APISecret"] + elif "Secret Key" in config_dict: + config_dict["api_secret"] = config_dict["Secret Key"] + del config_dict["Secret Key"] elif "api_secret" not in config_dict: raise exceptions.AutosubException( _("Error: No \"api_secret\" found in speech config file \"{filename}\"." ).format(filename=args.speech_config)) - if "language" not in config_dict["business"]: - raise exceptions.AutosubException( - _("Error: No \"language\" found in speech config file \"{filename}\"." - ).format(filename=args.speech_config)) + if args.speech_api == "xfyun": + if "business" not in config_dict: + config_dict["business"] = { + "language": "zh_cn", + "domain": "iat", + "accent": "mandarin"} - args.speech_language = config_dict["business"]["language"] + if "language" not in config_dict["business"]: + raise exceptions.AutosubException( + _("Error: No \"language\" found in speech config file \"{filename}\"." + ).format(filename=args.speech_config)) + + args.speech_language = config_dict["business"]["language"] + + elif args.speech_api == "baidu": + if "config" not in config_dict: + config_dict["config"] = { + "format": "pcm", + "rate": 16000, + "channel": 1, + "cuid": "python", + "dev_pid": 1537 + } + + if "dev_pid" in config_dict["config"]: + args.speech_language = api_baidu.baidu_dev_pid_to_lang_code(config_dict["config"]["dev_pid"]) + else: + config_dict["config"]["dev_pid"] = 1537 + + if "disable_qps_limit" not in config_dict \ + or config_dict["disable_qps_limit"] is not True: + # Queries per second limit + if config_dict["config"]["dev_pid"] == 80001: + args.speech_concurrency = 1 + else: + args.speech_concurrency = 1 args.speech_config = config_dict @@ -1158,7 +1197,15 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen text_list = core.xfyun_to_text( audio_fragments=audio_fragments, config=args.speech_config, - concurrency=constants.DEFAULT_CONCURRENCY, + concurrency=args.speech_concurrency, + is_keep=False, + result_list=result_list) + elif args.speech_api == "baidu": + # Baidu ASR API + text_list = core.baidu_to_text( + audio_fragments=audio_fragments, + config=args.speech_config, + concurrency=args.speech_concurrency, is_keep=False, result_list=result_list) else: @@ -1166,7 +1213,7 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen gc.collect(0) - if result_list is not None: + if result_list and result_list is not None: timed_result = get_timed_text( is_empty_dropped=False, regions=regions, diff --git a/autosub/constants.py b/autosub/constants.py index b2e4d39d..011dd6d6 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -57,6 +57,9 @@ GOOGLE_SPEECH_V2_API_URL = \ "www.google.com/speech-api/v2/recognize?client=chromium&lang={lang}&key={key}" XFYUN_SPEECH_WEBAPI_URL = "iat-api.xfyun.cn" +BAIDU_ASR_URL = "http://vop.baidu.com/server_api" +BAIDU_PRO_ASR_URL = "http://vop.baidu.com/pro_api" +BAIDU_TOKEN_URL = "http://openapi.baidu.com/oauth/2.0/token" if multiprocessing.cpu_count() > 3: DEFAULT_CONCURRENCY = multiprocessing.cpu_count() >> 1 diff --git a/autosub/core.py b/autosub/core.py index d8875db3..6a0ea1dd 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -19,18 +19,14 @@ import wcwidth # Any changes to the path and your own modules -from autosub import google_api -from autosub import xfyun_api +from autosub import api_baidu +from autosub import api_google +from autosub import api_xfyun from autosub import sub_utils from autosub import constants from autosub import ffmpeg_utils from autosub import exceptions -if constants.IS_GOOGLECLOUDCLIENT: - from google.cloud.speech_v1p1beta1 import enums -else: - enums = None # pylint: disable=invalid-name - CORE_TEXT = gettext.translation(domain=__name__, localedir=constants.LOCALE_PATH, languages=[constants.CURRENT_LOCALE], @@ -39,91 +35,6 @@ _ = CORE_TEXT.gettext -def extension_to_encoding( - extension, - is_string=True): - """ - File extension to audio encoding. - """ - ext = extension.lower() - if is_string: - if ext.endswith(".flac"): - encoding = "FLAC" - elif ext.endswith(".mp3"): - encoding = "MP3" - elif ext.endswith(".wav")\ - or ext.endswith(".pcm"): - # regard WAV as PCM - encoding = "LINEAR16" - elif ext.endswith(".ogg"): - encoding = "OGG_OPUS" - else: - encoding = "" - - else: - # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding - if ext.endswith(".flac"): - encoding = \ - enums.RecognitionConfig.AudioEncoding.FLAC - # encoding = 2 - elif ext.endswith(".mp3"): - encoding = \ - enums.RecognitionConfig.AudioEncoding.MP3 - # encoding = 8 - elif ext.endswith(".wav")\ - or extension.lower().endswith(".pcm"): - # regard WAV as PCM - encoding = \ - enums.RecognitionConfig.AudioEncoding.LINEAR16 - # encoding = 1 - elif ext.endswith(".ogg"): - encoding = \ - enums.RecognitionConfig.AudioEncoding.OGG_OPUS - # encoding = 6 - else: - encoding = \ - enums.RecognitionConfig.AudioEncoding.ENCODING_UNSPECIFIED - # encoding = 0 - - return encoding - - -def encoding_to_extension( # pylint: disable=too-many-branches - encoding): - """ - Audio encoding to file extension. - """ - if isinstance(encoding, str): - if encoding == "FLAC": - extension = ".flac" - elif encoding == "MP3": - extension = ".mp3" - elif encoding == "LINEAR16": - extension = ".wav" - elif encoding == "OGG_OPUS": - extension = ".ogg" - else: - extension = ".flac" - - elif isinstance(encoding, int): - # https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig?hl=zh-cn#AudioEncoding - if encoding == 2: - extension = ".flac" - elif encoding == 8: - extension = ".mp3" - elif encoding == 1: - extension = ".wav" - elif encoding == 6: - extension = ".ogg" - else: - extension = ".flac" - - else: - extension = ".flac" - - return extension - - def auditok_gen_speech_regions( # pylint: disable=too-many-arguments audio_wav, energy_threshold=constants.DEFAULT_ENERGY_THRESHOLD, @@ -224,7 +135,7 @@ def gsv2_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many text_list = [] pool = multiprocessing.Pool(concurrency) - recognizer = google_api.GoogleSpeechV2( + recognizer = api_google.GoogleSpeechV2( api_url=api_url, headers=headers, min_confidence=min_confidence, @@ -253,7 +164,7 @@ def gsv2_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many if result: result_list.append(result) transcript = \ - google_api.get_google_speech_v2_transcript(min_confidence, result) + api_google.get_google_speech_v2_transcript(min_confidence, result) if transcript: text_list.append(transcript) continue @@ -318,11 +229,11 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man config["language_code"] = src_language else: config = { - "encoding": extension_to_encoding(audio_fragments[0]), + "encoding": api_google.google_ext_to_enc(audio_fragments[0]), "sampleRateHertz": sample_rate, "languageCode": src_language} - recognizer = google_api.GCSV1P1Beta1URL( + recognizer = api_google.GCSV1P1Beta1URL( config=config, api_url=api_url, headers=headers, @@ -343,7 +254,7 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man for i, result in enumerate(pool.imap(recognizer, audio_fragments)): if result: result_list.append(result) - transcript = google_api.get_gcsv1p1beta1_transcript( + transcript = api_google.get_gcsv1p1beta1_transcript( min_confidence, result) if transcript: @@ -358,14 +269,14 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man # https://googleapis.dev/python/speech/latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig if config: # Use the fixed arguments - config["encoding"] = extension_to_encoding( + config["encoding"] = api_google.google_ext_to_enc( extension=audio_fragments[0], is_string=False ) config["language_code"] = src_language else: config = { - "encoding": extension_to_encoding( + "encoding": api_google.google_ext_to_enc( extension=audio_fragments[0], is_string=False), "sample_rate_hertz": sample_rate, @@ -377,7 +288,7 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man # google cloud speech-to-text client can't use multiprocessing.pool # based on class call, otherwise will receive pickling error tasks.append(pool.apply_async( - google_api.gcsv1p1beta1_service_client, + api_google.gcsv1p1beta1_service_client, args=(filename, is_keep, config, min_confidence, result_list is not None))) gc.collect(0) @@ -396,7 +307,7 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man i = i + 1 result = task.get() result_list.append(result) - transcript = google_api.get_gcsv1p1beta1_transcript( + transcript = api_google.get_gcsv1p1beta1_transcript( min_confidence, result) if transcript: @@ -431,7 +342,8 @@ def gcsv1_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man return text_list -def xfyun_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-many-branches,too-many-statements, too-many-nested-blocks +def xfyun_to_text( # pylint: disable=too-many-locals, too-many-arguments, + # pylint: disable=too-many-branches, too-many-statements, too-many-nested-blocks audio_fragments, config, concurrency=constants.DEFAULT_CONCURRENCY, @@ -465,7 +377,7 @@ def xfyun_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(audio_fragments)).start() try: - recognizer = xfyun_api.XfyunWebSocketAPI( + recognizer = api_xfyun.XfyunWebSocketAPI( app_id=config["app_id"], api_key=config["api_key"], api_secret=config["api_secret"], @@ -490,9 +402,117 @@ def xfyun_to_text( # pylint: disable=too-many-locals,too-many-arguments,too-man result_list.append(result) transcript = "" for item in result: - transcript = transcript + xfyun_api.get_xfyun_transcript(item) + transcript = transcript + api_xfyun.get_xfyun_transcript(item) + if transcript: + text_list.append(transcript) + pbar.update(i) + continue + else: + result_list.append("") + text_list.append("") + pbar.update(i) + pbar.finish() + pool.terminate() + pool.join() + + except (KeyboardInterrupt, AttributeError) as error: + pbar.finish() + pool.terminate() + pool.join() + + if error == AttributeError: + print( + _("Error: Connection error happened too many times.\nAll works done.")) + + return None + + except exceptions.SpeechToTextException as err_msg: + pbar.finish() + pool.terminate() + pool.join() + print(_("Receive something unexpected:")) + print(err_msg) + return None + + return text_list + + +def baidu_to_text( # pylint: disable=too-many-locals, too-many-arguments, + # pylint: disable=too-many-branches, too-many-statements, too-many-nested-blocks + audio_fragments, + config, + concurrency=constants.DEFAULT_CONCURRENCY, + is_keep=False, + result_list=None): + """ + Give a list of short-term audio fragment files + and generate text_list from Google cloud speech-to-text V1P1Beta1 api. + """ + + text_list = [] + + if config["config"]["dev_pid"] == 80001: + # pro edition of baidu asr + api_url = constants.BAIDU_PRO_ASR_URL + print(_("\nSending short-term fragments to Baidu PRO ASR API" + " and getting result.")) + else: + print(_("\nSending short-term fragments to Baidu ASR API" + " and getting result.")) + api_url = constants.BAIDU_ASR_URL + + if "delete_chars" in config: + delete_chars = config["delete_chars"] + else: + delete_chars = None + + try: + if "token" not in config["config"]: + print(_("Get the token online.")) + config["config"]["token"] = \ + api_baidu.get_baidu_token(api_secret=config["api_secret"], + api_key=config["api_key"]) + else: + print(_("Use the token from the config.")) + + except exceptions.SpeechToTextException as err_msg: + print(_("Failed to get the token. Error message:")) + print(err_msg) + return None + + pool = multiprocessing.Pool(concurrency) + + widgets = [_("Speech-to-Text: "), + progressbar.Percentage(), ' ', + progressbar.Bar(), ' ', + progressbar.ETA()] + pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(audio_fragments)).start() + + try: + recognizer = api_baidu.BaiduASRAPI( + config=config["config"], + api_url=api_url, + is_keep=is_keep, + is_full_result=result_list is not None, + delete_chars=delete_chars) + + # get transcript + if result_list is None: + for i, transcript in enumerate(pool.imap(recognizer, audio_fragments)): + if transcript: + text_list.append(transcript) + else: + text_list.append("") + pbar.update(i) + # get full result and transcript + else: + for i, result in enumerate(pool.imap(recognizer, audio_fragments)): + if result: + result_list.append(result) + transcript = api_baidu.get_baidu_transcript(result) if transcript: text_list.append(transcript) + pbar.update(i) continue else: result_list.append("") diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po new file mode 100644 index 00000000..603a0291 --- /dev/null +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po @@ -0,0 +1,22 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-03-21 15:37+0800\n" +"PO-Revision-Date: 2020-03-21 15:38+0800\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: zh_CN\n" +"X-Generator: Poedit 2.3\n" + +#: autosub/api_baidu.py:75 +msgid "Error: Check you project if its ASR feature is enabled." +msgstr "错误:检查你的项目是否打开了语音识别功能。" 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 4aaed4c0..95cad272 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-21 09:55+0800\n" +"POT-Creation-Date: 2020-03-21 15:37+0800\n" "PO-Revision-Date: 2020-03-20 20:45+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,20 +17,20 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/cmdline_utils.py:42 +#: autosub/cmdline_utils.py:44 msgid "List of output formats:\n" msgstr "列出所有输出格式:\n" -#: autosub/cmdline_utils.py:44 autosub/cmdline_utils.py:52 +#: autosub/cmdline_utils.py:46 autosub/cmdline_utils.py:54 msgid "Format" msgstr "格式" -#: autosub/cmdline_utils.py:45 autosub/cmdline_utils.py:53 -#: autosub/cmdline_utils.py:80 autosub/cmdline_utils.py:98 +#: autosub/cmdline_utils.py:47 autosub/cmdline_utils.py:55 +#: autosub/cmdline_utils.py:82 autosub/cmdline_utils.py:100 msgid "Description" msgstr "描述" -#: autosub/cmdline_utils.py:50 +#: autosub/cmdline_utils.py:52 msgid "" "\n" "List of input formats:\n" @@ -38,36 +38,36 @@ msgstr "" "\n" "列出所有输入格式:\n" -#: autosub/cmdline_utils.py:61 +#: autosub/cmdline_utils.py:63 msgid "Use py-googletrans to detect a sub file's first line language." msgstr "使用py-googletrans来检测字幕文件第一行的语言。" -#: autosub/cmdline_utils.py:68 autosub/cmdline_utils.py:79 -#: autosub/cmdline_utils.py:97 +#: autosub/cmdline_utils.py:70 autosub/cmdline_utils.py:81 +#: autosub/cmdline_utils.py:99 msgid "Lang code" msgstr "语言代码" -#: autosub/cmdline_utils.py:69 +#: autosub/cmdline_utils.py:71 msgid "Confidence" msgstr "可信度" -#: autosub/cmdline_utils.py:77 +#: autosub/cmdline_utils.py:79 msgid "List of all lang codes for speech-to-text:\n" msgstr "列出所有语音转文字的语言代码:\n" -#: autosub/cmdline_utils.py:86 +#: autosub/cmdline_utils.py:88 msgid "Match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:95 +#: autosub/cmdline_utils.py:97 msgid "List of all lang codes for translation:\n" msgstr "列出所有翻译的语言代码:\n" -#: autosub/cmdline_utils.py:104 +#: autosub/cmdline_utils.py:106 msgid "Match py-googletrans lang codes." msgstr "匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:122 +#: autosub/cmdline_utils.py:124 msgid "" "Error: arg of \"-i\"/\"--input\": \"{path}\" isn't valid. You need to give a " "valid path." @@ -75,7 +75,7 @@ msgstr "" "错误:\"-i\"/\"--input\"的参数:\"{path}\"是无效的。你需要提供一个有效的路" "径。" -#: autosub/cmdline_utils.py:128 +#: autosub/cmdline_utils.py:130 msgid "" "Error: arg of \"-sty\"/\"--styles\": \"{path}\" isn't valid. You need to " "give a valid path." @@ -83,15 +83,15 @@ msgstr "" "错误:\"-sty\"/\"--styles\"的参数:\"{path}\"是无效的。你需要提供一个有效的路" "径。" -#: autosub/cmdline_utils.py:134 +#: autosub/cmdline_utils.py:136 msgid "Error: Too many \"-sn\"/\"--styles-name\" arguments." msgstr "错误:\"-sn\"/\"--styles-name\"的参数过多。" -#: autosub/cmdline_utils.py:146 autosub/cmdline_utils.py:153 +#: autosub/cmdline_utils.py:148 autosub/cmdline_utils.py:155 msgid "Error: \"-sn\"/\"--styles-name\" arguments aren't in \"{path}\"." msgstr "错误:\"-sn\"/\"--styles-name\"的参数不在 \"{path}\"文件内。" -#: autosub/cmdline_utils.py:158 +#: autosub/cmdline_utils.py:160 msgid "" "Error: arg of \"-er\"/\"--ext-regions\": \"{path}\" isn't valid. You need to " "give a valid path." @@ -99,16 +99,16 @@ msgstr "" "错误:\"-er\"/\"--ext-regions\"的参数:\"{path}\"是无效的。你需要提供一个有效" "的路径。" -#: autosub/cmdline_utils.py:175 autosub/cmdline_utils.py:193 +#: autosub/cmdline_utils.py:177 autosub/cmdline_utils.py:195 msgid "No output format specified. Use input format \"{fmt}\" for output." msgstr "没有指定输出格式。使用输入的格式\"{fmt}\"作为输出格式。" -#: autosub/cmdline_utils.py:187 +#: autosub/cmdline_utils.py:189 msgid "" "Your output is a directory not a file path. Now file path set to \"{new}\"." msgstr "你的输出路径是一个目录不是一个文件路径。现在输出路径设置为\"{new}\"。" -#: autosub/cmdline_utils.py:210 +#: autosub/cmdline_utils.py:212 msgid "" "Error: Output subtitles format \"{fmt}\" not supported. Run with \"-lf\"/\"--" "list-formats\" to see all supported formats.\n" @@ -118,61 +118,61 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:223 autosub/cmdline_utils.py:229 +#: autosub/cmdline_utils.py:225 autosub/cmdline_utils.py:231 msgid "Error: No valid \"-of\"/\"--output-files\" arguments." msgstr "错误:\"-of\"/\"--output-files\"参数无效。" -#: autosub/cmdline_utils.py:240 +#: autosub/cmdline_utils.py:242 msgid "Input is a subtitles file." msgstr "输入是一个字幕文件。" -#: autosub/cmdline_utils.py:257 +#: autosub/cmdline_utils.py:259 msgid "Error: Can't decode speech config file \"{filename}\"." msgstr "错误:无法解码语音配置文件\"{filename}\"。" -#: autosub/cmdline_utils.py:261 +#: autosub/cmdline_utils.py:263 msgid "Error: Speech config file \"{filename}\" doesn't exist." msgstr "错误:语音配置文件\"{filename}\"不存在。" -#: autosub/cmdline_utils.py:308 +#: autosub/cmdline_utils.py:309 msgid "Error: No \"app_id\" found in speech config file \"{filename}\"." msgstr "错误:\"app_id\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:315 +#: autosub/cmdline_utils.py:320 msgid "Error: No \"api_key\" found in speech config file \"{filename}\"." msgstr "错误:\"api_key\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:322 +#: autosub/cmdline_utils.py:331 msgid "Error: No \"api_secret\" found in speech config file \"{filename}\"." msgstr "错误:\"api_secret\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:327 +#: autosub/cmdline_utils.py:343 msgid "Error: No \"language\" found in speech config file \"{filename}\"." msgstr "错误:\"language\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:342 +#: autosub/cmdline_utils.py:381 msgid "Error: \"-slp\"/\"--sleep-seconds\" arg is illegal." msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" -#: autosub/cmdline_utils.py:350 +#: autosub/cmdline_utils.py:389 msgid "Let speech lang code to match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:356 +#: autosub/cmdline_utils.py:395 msgid "Use langcodes to standardize the result." msgstr "使用langcodes来标准化结果。" -#: autosub/cmdline_utils.py:358 autosub/cmdline_utils.py:414 -#: autosub/cmdline_utils.py:436 autosub/cmdline_utils.py:509 -#: autosub/cmdline_utils.py:536 +#: autosub/cmdline_utils.py:397 autosub/cmdline_utils.py:453 +#: autosub/cmdline_utils.py:475 autosub/cmdline_utils.py:548 +#: autosub/cmdline_utils.py:575 msgid "Use \"{lang_code}\" instead." msgstr "改用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:361 +#: autosub/cmdline_utils.py:400 msgid "Match failed. Still using \"{lang_code}\"." msgstr "匹配失败。仍在使用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:364 +#: autosub/cmdline_utils.py:403 msgid "" "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" "list-speech-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -182,35 +182,35 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:372 +#: autosub/cmdline_utils.py:411 msgid "Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal." msgstr "错误:\"-mnc\"/\"--min-confidence\"参数的值不合法。" -#: autosub/cmdline_utils.py:377 +#: autosub/cmdline_utils.py:416 msgid "" "Error: You must provide \"-sconf\", \"--speech-config\" option when using " "Xun Fei Yun API." msgstr "错误:使用讯飞云API时,你必须提供\"-sconf\",\"--speech-config\"选项。" -#: autosub/cmdline_utils.py:381 +#: autosub/cmdline_utils.py:420 msgid "" "Translation destination language not provided. Only performing speech " "recognition." msgstr "翻译目的语言未提供。只进行语音识别。" -#: autosub/cmdline_utils.py:386 +#: autosub/cmdline_utils.py:425 msgid "Translation source language not provided. Use speech language instead." msgstr "翻译源语言未提供。改用语音语言。" -#: autosub/cmdline_utils.py:407 +#: autosub/cmdline_utils.py:446 msgid "Let translation source lang code to match py-googletrans lang codes." msgstr "让翻译源语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:418 autosub/cmdline_utils.py:440 +#: autosub/cmdline_utils.py:457 autosub/cmdline_utils.py:479 msgid "Error: Match failed." msgstr "错误:匹配失败。" -#: autosub/cmdline_utils.py:421 +#: autosub/cmdline_utils.py:460 msgid "" "Error: Translation source language \"{src}\" is not supported. Run with \"-" "ltc\"/\"--list-translation-codes\" to see all supported languages. Or use \"-" @@ -220,12 +220,12 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:429 +#: autosub/cmdline_utils.py:468 msgid "" "Let translation destination lang code to match py-googletrans lang codes." msgstr "让翻译目的语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:443 +#: autosub/cmdline_utils.py:482 msgid "" "Error: Translation destination language \"{dst}\" is not supported. Run with " "\"-ltc\"/\"--list-translation-codes\" to see all supported languages. Or use " @@ -234,29 +234,29 @@ msgstr "" "错误:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" "项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最佳匹配。" -#: autosub/cmdline_utils.py:451 +#: autosub/cmdline_utils.py:490 msgid "" "Speech language is the same as the destination language. Only performing " "speech recognition." msgstr "语音语言和目的语言一致。只进行语音识别。" -#: autosub/cmdline_utils.py:460 +#: autosub/cmdline_utils.py:499 msgid "You've already input times. No works done." msgstr "你已经输入了时间轴。啥都没做。" -#: autosub/cmdline_utils.py:464 +#: autosub/cmdline_utils.py:503 msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:472 autosub/cmdline_utils.py:564 +#: autosub/cmdline_utils.py:511 autosub/cmdline_utils.py:603 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" -#: autosub/cmdline_utils.py:485 +#: autosub/cmdline_utils.py:524 msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" -#: autosub/cmdline_utils.py:501 +#: autosub/cmdline_utils.py:540 msgid "" "Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages." @@ -264,11 +264,11 @@ msgstr "" "警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:513 autosub/cmdline_utils.py:540 +#: autosub/cmdline_utils.py:552 autosub/cmdline_utils.py:579 msgid "Match failed. Still using \"{lang_code}\". Program stopped." msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" -#: autosub/cmdline_utils.py:519 +#: autosub/cmdline_utils.py:558 msgid "" "Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -278,7 +278,7 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:528 +#: autosub/cmdline_utils.py:567 msgid "" "Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages." @@ -286,7 +286,7 @@ msgstr "" "警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" "行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:546 +#: autosub/cmdline_utils.py:585 msgid "" "Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" @@ -296,12 +296,12 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:554 +#: autosub/cmdline_utils.py:593 msgid "" "Error: Translation source language is the same as the destination language." msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:578 +#: autosub/cmdline_utils.py:617 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -309,7 +309,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:585 +#: autosub/cmdline_utils.py:624 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -317,7 +317,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:592 +#: autosub/cmdline_utils.py:631 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -325,16 +325,16 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:648 autosub/cmdline_utils.py:792 -#: autosub/cmdline_utils.py:1330 +#: autosub/cmdline_utils.py:687 autosub/cmdline_utils.py:831 +#: autosub/cmdline_utils.py:1377 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:652 autosub/cmdline_utils.py:744 -#: autosub/cmdline_utils.py:796 autosub/cmdline_utils.py:848 -#: autosub/cmdline_utils.py:1029 autosub/cmdline_utils.py:1184 -#: autosub/cmdline_utils.py:1226 autosub/cmdline_utils.py:1286 -#: autosub/cmdline_utils.py:1334 autosub/cmdline_utils.py:1382 +#: autosub/cmdline_utils.py:691 autosub/cmdline_utils.py:783 +#: autosub/cmdline_utils.py:835 autosub/cmdline_utils.py:887 +#: autosub/cmdline_utils.py:1068 autosub/cmdline_utils.py:1231 +#: autosub/cmdline_utils.py:1273 autosub/cmdline_utils.py:1333 +#: autosub/cmdline_utils.py:1381 autosub/cmdline_utils.py:1429 msgid "" "\n" "All works done." @@ -342,23 +342,23 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:696 autosub/cmdline_utils.py:1243 +#: autosub/cmdline_utils.py:735 autosub/cmdline_utils.py:1290 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:740 autosub/cmdline_utils.py:1282 +#: autosub/cmdline_utils.py:779 autosub/cmdline_utils.py:1329 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:844 autosub/cmdline_utils.py:1378 +#: autosub/cmdline_utils.py:883 autosub/cmdline_utils.py:1425 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:887 autosub/cmdline_utils.py:1423 +#: autosub/cmdline_utils.py:926 autosub/cmdline_utils.py:1470 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:929 +#: autosub/cmdline_utils.py:968 msgid "" "\n" "No works done. Check your \"-of\"/\"--output-files\" option." @@ -366,11 +366,11 @@ msgstr "" "\n" "啥都没做。检查你的\"-of\"/\"--output-files\"选项。" -#: autosub/cmdline_utils.py:934 +#: autosub/cmdline_utils.py:973 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:968 +#: autosub/cmdline_utils.py:1007 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -378,11 +378,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:978 +#: autosub/cmdline_utils.py:1017 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:981 +#: autosub/cmdline_utils.py:1020 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -390,7 +390,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:993 +#: autosub/cmdline_utils.py:1032 msgid "" "\n" "\"{name}\" has been deleted." @@ -398,19 +398,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:997 +#: autosub/cmdline_utils.py:1036 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1026 autosub/cmdline_utils.py:1490 +#: autosub/cmdline_utils.py:1065 autosub/cmdline_utils.py:1537 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1050 +#: autosub/cmdline_utils.py:1089 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1054 +#: autosub/cmdline_utils.py:1093 msgid "" "Audio processing complete.\n" "All works done." @@ -418,11 +418,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1106 +#: autosub/cmdline_utils.py:1145 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1121 +#: autosub/cmdline_utils.py:1160 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -432,18 +432,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1126 +#: autosub/cmdline_utils.py:1165 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1140 +#: autosub/cmdline_utils.py:1179 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1152 +#: autosub/cmdline_utils.py:1191 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -451,11 +451,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1180 +#: autosub/cmdline_utils.py:1227 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1188 +#: autosub/cmdline_utils.py:1235 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -463,11 +463,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1222 autosub/cmdline_utils.py:1460 +#: autosub/cmdline_utils.py:1269 autosub/cmdline_utils.py:1507 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1432 +#: autosub/cmdline_utils.py:1479 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -475,7 +475,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1465 +#: autosub/cmdline_utils.py:1512 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.core.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po index d5bff2f7..328a10ed 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-21 09:55+0800\n" -"PO-Revision-Date: 2020-03-20 20:46+0800\n" +"POT-Creation-Date: 2020-03-21 15:37+0800\n" +"PO-Revision-Date: 2020-03-21 15:41+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -17,7 +17,7 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/core.py:188 +#: autosub/core.py:99 msgid "" "\n" "Converting speech regions to short-term fragments." @@ -25,11 +25,11 @@ msgstr "" "\n" "按照语音区域将音频转换为多个短语音片段。" -#: autosub/core.py:189 +#: autosub/core.py:100 msgid "Converting: " msgstr "转换中: " -#: autosub/core.py:234 +#: autosub/core.py:145 msgid "" "\n" "Sending short-term fragments to Google Speech V2 API and getting result." @@ -37,11 +37,13 @@ msgstr "" "\n" "将短片段语音发送给Google Speech V2 API并得到识别结果。" -#: autosub/core.py:235 autosub/core.py:304 autosub/core.py:461 +#: autosub/core.py:146 autosub/core.py:215 autosub/core.py:373 +#: autosub/core.py:485 msgid "Speech-to-Text: " msgstr "语音转文字中: " -#: autosub/core.py:276 autosub/core.py:419 autosub/core.py:512 +#: autosub/core.py:187 autosub/core.py:330 autosub/core.py:425 +#: autosub/core.py:532 msgid "" "Error: Connection error happened too many times.\n" "All works done." @@ -49,7 +51,7 @@ msgstr "" "错误:过多连接错误。\n" "做完了。" -#: autosub/core.py:302 +#: autosub/core.py:213 msgid "" "\n" "Sending short-term fragments to Google Cloud Speech V1P1Beta1 API and " @@ -58,11 +60,11 @@ msgstr "" "\n" "将短片段语音发送给Google Cloud Speech V1P1Beta1 API并得到识别结果。" -#: autosub/core.py:427 autosub/core.py:520 +#: autosub/core.py:338 autosub/core.py:433 autosub/core.py:540 msgid "Receive something unexpected:" msgstr "收到未预期数据:" -#: autosub/core.py:459 +#: autosub/core.py:371 msgid "" "\n" "Sending short-term fragments to Xun Fei Yun WebSocket API and getting result." @@ -70,7 +72,35 @@ msgstr "" "\n" "将短片段语音发送给讯飞云WebSocket API并得到识别结果。" -#: autosub/core.py:543 +#: autosub/core.py:457 +msgid "" +"\n" +"Sending short-term fragments to Baidu PRO ASR API and getting result." +msgstr "" +"\n" +"将短片段语音发送给百度短语音识别极速版API并得到识别结果。" + +#: autosub/core.py:460 +msgid "" +"\n" +"Sending short-term fragments to Baidu ASR API and getting result." +msgstr "" +"\n" +"将短片段语音发送给百度短语音识别API并得到识别结果。" + +#: autosub/core.py:471 +msgid "Get the token online." +msgstr "在线获取token。" + +#: autosub/core.py:476 +msgid "Use the token from the config." +msgstr "使用配置文件中的token。" + +#: autosub/core.py:479 +msgid "Failed to get the token. Error message:" +msgstr "无法获取token。错误信息:" + +#: autosub/core.py:563 msgid "" "\n" "Translating text from \"{0}\" to \"{1}\"." @@ -78,24 +108,24 @@ msgstr "" "\n" "从\"{0}\"翻译为\"{1}\"。" -#: autosub/core.py:593 +#: autosub/core.py:613 msgid "Translation: " msgstr "翻译中: " -#: autosub/core.py:656 +#: autosub/core.py:676 msgid "Cancelling translation." msgstr "取消翻译。" -#: autosub/core.py:729 autosub/core.py:788 +#: autosub/core.py:749 autosub/core.py:808 msgid "Format \"{fmt}\" not supported. Use \"{default_fmt}\" instead." msgstr "不支持格式\"{fmt}\"。改用\"{default_fmt}\"。" -#: autosub/core.py:861 +#: autosub/core.py:881 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/core.py:864 +#: autosub/core.py:884 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 333b28fb..d7a85cb3 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-20 20:50+0800\n" +"POT-Creation-Date: 2020-03-21 15:37+0800\n" "PO-Revision-Date: 2020-03-20 20:50+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -134,8 +134,8 @@ msgid "List all available arguments." msgstr "列出所有可选参数。" #: autosub/options.py:92 autosub/options.py:101 autosub/options.py:110 -#: autosub/options.py:192 autosub/options.py:271 autosub/options.py:398 -#: autosub/options.py:594 +#: autosub/options.py:192 autosub/options.py:273 autosub/options.py:400 +#: autosub/options.py:596 msgid "path" msgstr "路径" @@ -188,7 +188,7 @@ msgstr "" "言行使用第二个。(参数个数为1或2)" #: autosub/options.py:137 autosub/options.py:148 autosub/options.py:158 -#: autosub/options.py:566 autosub/options.py:582 +#: autosub/options.py:568 autosub/options.py:584 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:159 #, python-format @@ -226,7 +226,7 @@ msgstr "" "用于翻译的目标语言的语言代码/语言标识符。同样的注意参考选项\"-SRC\"/\"--src-" "language\"。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:165 autosub/options.py:409 +#: autosub/options.py:165 autosub/options.py:411 msgid "mode" msgstr "模式" @@ -323,13 +323,15 @@ msgid "API_code" msgstr "API代码" #: autosub/options.py:250 -#, python-format +#, fuzzy, python-format msgid "" "Choose which Speech-to-Text API to use. Currently support: gsv2: Google " "Speech V2 (https://github.com/gillesdemey/google-speech-v2). gcsv1: Google " "Cloud Speech-to-Text V1P1Beta1 (https://cloud.google.com/speech-to-text/" "docs). xfyun: Xun Fei Yun Speech-to-Text WebSocket API (https://www.xfyun.cn/" -"doc/asr/voicedictation/API.html).(arg_num = 1) (default: %(default)s)" +"doc/asr/voicedictation/API.html). baidu: Baidu Automatic Speech Recognition " +"API (https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) (arg_num = 1) (default: %" +"(default)s)" msgstr "" "选择使用Speech-to-Text API。当前支持:gsv2:Google Speech V2 (https://" "github.com/gillesdemey/google-speech-v2)。 gcsv1:Google Cloud Speech-to-" @@ -337,7 +339,7 @@ msgstr "" "开放平台语音听写(流式版)WebSocket API(https://www.xfyun.cn/doc/asr/" "voicedictation/API.html)。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:262 +#: autosub/options.py:264 msgid "" "The API key for Google Speech-to-Text API. (arg_num = 1) Currently support: " "gsv2: The API key for gsv2. (default: Free API key) gcsv1: The API key for " @@ -348,7 +350,7 @@ msgstr "" "钥。(默认参数为免费API密钥)gcsv1:gcsv1的API密钥。(如果使用了,可以覆盖 " "\"-sa\"/\"--service-account\"提供的服务账号凭据)" -#: autosub/options.py:273 +#: autosub/options.py:275 #, python-format msgid "" "Use Speech-to-Text recognition config file to send request. Override these " @@ -358,8 +360,8 @@ msgid "" "Service account config reference: https://googleapis.dev/python/speech/" "latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig " "xfyun: Xun Fei Yun Speech-to-Text WebSocket API (https://console.xfyun.cn/" -"services/iat). If arg_num is 0, use const path. (arg_num = 0 or 1) (const: " -"%(const)s)" +"services/iat). If arg_num is 0, use const path. (arg_num = 0 or 1) (const: %" +"(const)s)" msgstr "" "使用语音转文字识别配置文件来发送请求。取代以下选项:\"-S\", \"-asr\", \"-asf" "\"。目前支持:gcsv1:Google Cloud Speech-to-Text V1P1Beta1 API密钥配置参考:" @@ -367,10 +369,10 @@ msgstr "" "RecognitionConfig 服务账号配置参考:https://googleapis.dev/python/speech/" "latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig 。" "xfyun:讯飞开放平台语音听写(流式版)WebSocket API(https://console.xfyun.cn/" -"services/iat)。如果参数个数是0,使用const路径。(参数个数为0或1)(const" -"为%(const)s)" +"services/iat)。如果参数个数是0,使用const路径。(参数个数为0或1)(const为%" +"(const)s)" -#: autosub/options.py:296 +#: autosub/options.py:298 #, python-format msgid "" "Google Speech-to-Text API response for text confidence. A float value " @@ -383,11 +385,11 @@ msgstr "" "除。参考:https://github.com/BingLingGroup/google-speech-v2#response(参数个" "数为1)(默认参数为%(default)s)" -#: autosub/options.py:306 +#: autosub/options.py:308 msgid "Drop any regions without speech recognition result. (arg_num = 0)" msgstr "删除所有没有语音识别结果的空轴。(参数个数为0)" -#: autosub/options.py:314 +#: autosub/options.py:316 #, python-format msgid "" "Number of concurrent Speech-to-Text requests to make. (arg_num = 1) " @@ -395,21 +397,21 @@ msgid "" msgstr "" "用于Speech-to-Text请求的并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:319 autosub/options.py:514 autosub/options.py:523 -#: autosub/options.py:532 +#: autosub/options.py:321 autosub/options.py:516 autosub/options.py:525 +#: autosub/options.py:534 msgid "second" msgstr "秒" -#: autosub/options.py:322 +#: autosub/options.py:324 #, python-format 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 +#: autosub/options.py:332 msgid "" "(Experimental)Customize request urls. Ref: https://py-googletrans." "readthedocs.io/en/latest/ (arg_num >= 1)" @@ -417,24 +419,24 @@ msgstr "" "(实验性)自定义多个请求URL。参考:https://py-googletrans.readthedocs.io/en/" "latest/(参数个数大于等于1)" -#: autosub/options.py:337 +#: autosub/options.py:339 msgid "" "(Experimental)Customize User-Agent headers. Same docs above. (arg_num = 1)" msgstr "" "(实验性)自定义用户代理(User-Agent)头部。同样的参考文档如上。(参数个数为" "1)" -#: autosub/options.py:344 +#: autosub/options.py:346 msgid "" "Drop any .ass override codes in the text before translation. Only affect the " "translation result. (arg_num = 0)" msgstr "在翻译前删除所有文本中的ass特效标签。只影响翻译结果。(参数个数为0)" -#: autosub/options.py:351 +#: autosub/options.py:353 msgid "Change the Google Speech V2 API URL into the http one. (arg_num = 0)" msgstr "将Google Speech V2 API的URL改为http类型。(参数个数为0)" -#: autosub/options.py:359 +#: autosub/options.py:361 #, python-format msgid "" "Add https proxy by setting environment variables. If arg_num is 0, use const " @@ -443,7 +445,7 @@ msgstr "" "通过设置环境变量的方式添加https代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:367 +#: autosub/options.py:369 #, python-format msgid "" "Add http proxy by setting environment variables. If arg_num is 0, use const " @@ -452,33 +454,33 @@ msgstr "" "通过设置环境变量的方式添加http代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:373 +#: autosub/options.py:375 msgid "username" msgstr "用户名" -#: autosub/options.py:374 +#: autosub/options.py:376 msgid "Set proxy username. (arg_num = 1)" msgstr "设置代理用户名。(参数个数为1)" -#: autosub/options.py:379 +#: autosub/options.py:381 msgid "password" msgstr "密码" -#: autosub/options.py:380 +#: autosub/options.py:382 msgid "Set proxy password. (arg_num = 1)" msgstr "设置代理密码。(参数个数为1)" -#: autosub/options.py:386 +#: autosub/options.py:388 #, python-format msgid "Show %(prog)s help message and exit. (arg_num = 0)" msgstr "显示%(prog)s的帮助信息并退出。(参数个数为0)" -#: autosub/options.py:394 +#: autosub/options.py:396 #, python-format msgid "Show %(prog)s version and exit. (arg_num = 0)" msgstr "显示%(prog)s的版本信息并退出。(参数个数为0)" -#: autosub/options.py:399 +#: autosub/options.py:401 msgid "" "Set service account key environment variable. It should be the file path of " "the JSON file that contains your service account credentials. Can be " @@ -488,10 +490,10 @@ 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 +#: autosub/options.py:412 msgid "" "Option to control audio process. If not given the option, do normal " "conversion work. \"y\": pre-process the input first then start normal " @@ -510,15 +512,15 @@ msgstr "" "scripts/subgen.sh https://ffmpeg.org/ffmpeg-filters.html)(参数个数介于1和2" "之间)" -#: autosub/options.py:434 +#: autosub/options.py:436 msgid "Keep audio processing files to the output path. (arg_num = 0)" msgstr "将音频处理中产生的文件放在输出路径中。(参数个数为0)" -#: autosub/options.py:439 autosub/options.py:457 autosub/options.py:469 +#: autosub/options.py:441 autosub/options.py:459 autosub/options.py:471 msgid "command" msgstr "命令" -#: autosub/options.py:440 +#: autosub/options.py:442 msgid "" "This arg will override the default audio pre-process command. Every line of " "the commands need to be in quotes. Input file name is {in_}. Output file " @@ -527,7 +529,7 @@ msgstr "" "这个参数会取代默认的音频预处理命令。每行命令需要放在一个引号内。输入文件名写" "为{in_}。输出文件名写为{out_}。(参数个数大于1)" -#: autosub/options.py:452 +#: autosub/options.py:454 #, python-format msgid "" "Number of concurrent ffmpeg audio split process to make. (arg_num = 1) " @@ -535,19 +537,19 @@ msgid "" msgstr "" "用于ffmpeg音频切割的进程并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:459 +#: autosub/options.py:461 #, 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 +#: autosub/options.py:473 #, python-format msgid "" "(Experimental)This arg will override the default audio split command. Same " @@ -556,24 +558,24 @@ msgstr "" "(实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:478 +#: autosub/options.py:480 msgid "file_suffix" msgstr "文件名后缀" -#: autosub/options.py:480 +#: autosub/options.py:482 #, python-format 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 +#: autosub/options.py:488 msgid "sample_rate" msgstr "采样率" -#: autosub/options.py:489 +#: autosub/options.py:491 #, python-format msgid "" "(Experimental)This arg will override the default API audio sample rate(Hz). " @@ -582,11 +584,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频采样率(赫兹)。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:495 +#: autosub/options.py:497 msgid "channel_num" msgstr "声道数" -#: autosub/options.py:498 +#: autosub/options.py:500 #, python-format msgid "" "(Experimental)This arg will override the default API audio channel. (arg_num " @@ -595,11 +597,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频声道数量。(参数个数为1)(默认" "参数为%(default)s)" -#: autosub/options.py:504 +#: autosub/options.py:506 msgid "energy" msgstr "能量(相对值)" -#: autosub/options.py:507 +#: autosub/options.py:509 #, python-format msgid "" "The energy level which determines the region to be detected. Ref: https://" @@ -610,23 +612,23 @@ msgstr "" "latest/apitutorial.html#examples-using-real-audio-data(参数个数为1)(默认参" "数为%(default)s)" -#: autosub/options.py:517 +#: autosub/options.py:519 #, python-format msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数" -"为%(default)s)" +"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" +"s)" -#: autosub/options.py:526 +#: autosub/options.py:528 #, 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 +#: autosub/options.py:537 #, python-format msgid "" "Maximum length of a tolerated silence within a valid audio activity. Same " @@ -635,7 +637,7 @@ msgstr "" "在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如" "上。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:542 +#: autosub/options.py:544 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." @@ -644,7 +646,7 @@ msgstr "" "如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://" "auditok.readthedocs.io/en/latest/core.html#class-summary(参数个数为0)" -#: autosub/options.py:550 +#: autosub/options.py:552 msgid "" "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)" @@ -652,7 +654,7 @@ msgstr "" "参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" "个数为0)" -#: autosub/options.py:556 +#: autosub/options.py:558 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 " @@ -663,7 +665,7 @@ msgstr "" "SubtitleEdit来对其进行转换。如果输出格式是\"sub\"且输入文件是音频无法获取到视" "频帧率时,你需要提供fps选项指定帧率。(参数个数为0)" -#: autosub/options.py:569 +#: autosub/options.py:571 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 " @@ -681,7 +683,7 @@ msgstr "" "言)-扩展-私有(https://www.zhihu.com/question/21980689/answer/93615123)(参" "数个数为0或1)" -#: autosub/options.py:585 +#: autosub/options.py:587 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 " @@ -691,7 +693,7 @@ msgstr "" "言代码。否则会给出一个“好的匹配”的清单。同样的参考文档如上。(参数个数为0或" "1)" -#: autosub/options.py:595 +#: autosub/options.py:597 #, python-format msgid "" "Use py-googletrans to detect a sub file's first line language. And list a " @@ -722,26 +724,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/options.py b/autosub/options.py index d49c49ef..f56382f1 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -246,14 +246,16 @@ def get_cmd_parser(): # pylint: disable=too-many-statements '-sapi', '--speech-api', metavar=_('API_code'), default='gsv2', - choices=["gsv2", "gcsv1", "xfyun"], + choices=["gsv2", "gcsv1", "xfyun", "baidu"], help=_("Choose which Speech-to-Text API to use. " "Currently support: " "gsv2: Google Speech V2 (https://github.com/gillesdemey/google-speech-v2). " "gcsv1: Google Cloud Speech-to-Text V1P1Beta1 " "(https://cloud.google.com/speech-to-text/docs). " "xfyun: Xun Fei Yun Speech-to-Text WebSocket API " - "(https://www.xfyun.cn/doc/asr/voicedictation/API.html)." + "(https://www.xfyun.cn/doc/asr/voicedictation/API.html). " + "baidu: Baidu Automatic Speech Recognition API " + "(https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) " "(arg_num = 1) (default: %(default)s)")) speech_group.add_argument( diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 584d6122..006bcfa6 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -47,6 +47,7 @@ #### 添加(未发布) - 添加讯飞开放平台语音听写(流式版)WebSocket API支持。 +- 添加百度智能云语音识别/极速语音识别API支持。[issue #68](https://github.com/BingLingGroup/autosub/issues/68) - 添加字符过滤器用于讯飞开放平台语音听写。 #### 改动(未发布) diff --git a/pylintrc b/pylintrc new file mode 100644 index 00000000..adfb2142 --- /dev/null +++ b/pylintrc @@ -0,0 +1,581 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +extension-pkg-whitelist= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use. +jobs=1 + +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# List of plugins (as comma separated values of python module names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED. +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=print-statement, + parameter-unpacking, + unpacking-in-except, + old-raise-syntax, + backtick, + long-suffix, + old-ne-operator, + old-octal-literal, + import-star-module-level, + non-ascii-bytes-literal, + raw-checker-failed, + bad-inline-option, + locally-disabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + use-symbolic-message-instead, + apply-builtin, + basestring-builtin, + buffer-builtin, + cmp-builtin, + coerce-builtin, + execfile-builtin, + file-builtin, + long-builtin, + raw_input-builtin, + reduce-builtin, + standarderror-builtin, + unicode-builtin, + xrange-builtin, + coerce-method, + delslice-method, + getslice-method, + setslice-method, + no-absolute-import, + old-division, + dict-iter-method, + dict-view-method, + next-method-called, + metaclass-assignment, + indexing-exception, + raising-string, + reload-builtin, + oct-method, + hex-method, + nonzero-method, + cmp-method, + input-builtin, + round-builtin, + intern-builtin, + unichr-builtin, + map-builtin-not-iterating, + zip-builtin-not-iterating, + range-builtin-not-iterating, + filter-builtin-not-iterating, + using-cmp-argument, + eq-without-hash, + div-method, + idiv-method, + rdiv-method, + exception-message-attribute, + invalid-str-codec, + sys-max-int, + bad-python3-import, + deprecated-string-function, + deprecated-str-translate-call, + deprecated-itertools-function, + deprecated-types-field, + next-method-defined, + dict-items-not-iterating, + dict-keys-not-iterating, + dict-values-not-iterating, + deprecated-operator-function, + deprecated-urllib-function, + xreadlines-attribute, + deprecated-sys-function, + exception-escape, + comprehension-escape + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member + + +[REPORTS] + +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'error', 'warning', 'refactor', and 'convention' +# which contain the number of messages in each category, as well as 'statement' +# which is the total number of statements analyzed. This score is used by the +# global evaluation report (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages. +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=sys.exit + + +[BASIC] + +# Naming style matching correct argument names. +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style. +#argument-rgx= + +# Naming style matching correct attribute names. +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma. +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Naming style matching correct class attribute names. +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. +#class-attribute-rgx= + +# Naming style matching correct class names. +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming- +# style. +#class-rgx= + +# Naming style matching correct constant names. +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names. Overrides const-naming- +# style. +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names. +function-naming-style=snake_case + +# Regular expression matching correct function names. Overrides function- +# naming-style. +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma. +good-names=i, + j, + k, + ex, + Run, + _ + +# Include a hint for the correct naming format with invalid-name. +include-naming-hint=no + +# Naming style matching correct inline iteration names. +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. +#inlinevar-rgx= + +# Naming style matching correct method names. +method-naming-style=snake_case + +# Regular expression matching correct method names. Overrides method-naming- +# style. +#method-rgx= + +# Naming style matching correct module names. +module-naming-style=snake_case + +# Regular expression matching correct module names. Overrides module-naming- +# style. +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +# These decorators are taken in consideration only for invalid-name. +property-classes=abc.abstractproperty + +# Naming style matching correct variable names. +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style. +#variable-rgx= + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module. +max-module-lines=1000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma, + dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[LOGGING] + +# Format style used to check logging format string. `old` means using % +# formatting, `new` is for `{}` formatting,and `fstr` is for f-strings. +logging-format-style=old + +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules=logging + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=20 + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=4 + +# Spelling dictionary name. Available dictionaries: none. To make it work, +# install the python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains the private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to the private dictionary (see the +# --spelling-private-dict-file option) instead of raising a message. +spelling-store-unknown-words=no + + +[STRING] + +# This flag controls whether the implicit-str-concat-in-sequence should +# generate a warning on implicit string concatenation in sequences defined over +# several lines. +check-str-concat-over-line-jumps=no + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis). It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + +# List of decorators that change the signature of a decorated function. +signature-mutators= + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid defining new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore. +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp, + __post_init__ + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict, + _fields, + _replace, + _source, + _make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=cls + + +[DESIGN] + +# Maximum number of arguments for function / method. +max-args=5 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr=5 + +# Maximum number of branch for function / method body. +max-branches=12 + +# Maximum number of locals for function / method body. +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body. +max-returns=6 + +# Maximum number of statements in function / method body. +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[IMPORTS] + +# List of modules that can be imported at any level, not just the top level +# one. +allow-any-import-level= + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma. +deprecated-modules=optparse,tkinter.tix + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled). +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled). +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled). +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + +# Couples of modules and preferred modules, separated by a comma. +preferred-modules= + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "BaseException, Exception". +overgeneral-exceptions=BaseException, + Exception From 93bd00e13a472cafb0b2ea73ddb1d3998f0a4a18 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sat, 21 Mar 2020 17:14:33 +0800 Subject: [PATCH 05/26] Docs update readme and translations --- README.md | 166 +++++++++++++---- .../zh_CN/LC_MESSAGES/autosub.api_baidu.po | 6 +- .../zh_CN/LC_MESSAGES/autosub.options.po | 170 +++++++++--------- autosub/options.py | 2 + docs/README.zh-Hans.md | 133 +++++++++++--- 5 files changed, 329 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index 1c54b2c4..17edb223 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,10 @@ Color: [Solarized](https://en.wikipedia.org/wiki/Solarized_(color_scheme)#Colors - 6.1.4 [Transcribe Audio To Subtitles](#transcribe-audio-to-subtitles) - 6.1.4.1 [Google Speech V2](#google-speech-v2) - 6.1.4.2 [Google Cloud Speech-to-Text](#google-cloud-speech-to-text) - - 6.1.4.3 [Speech config](#speech-config) + - 6.1.4.3 [Google speech config](#google-speech-config) - 6.1.4.4 [Output API full response](#output-api-full-response) + - 6.1.4.5 [Xfyun speech config](#xfyun-speech-config) + - 6.1.4.6 [Baidu speech config](#baidu-speech-config) - 6.1.5 [Translate Subtitles](#translate-subtitles) - 6.2 [Options](#Options) - 6.3 [Internationalization](#internationalization) @@ -79,11 +81,15 @@ Autosub depends on these third party softwares or Python site-packages. Much app - [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) +- [wcwidth](https://github.com/jquast/wcwidth) +- [requests](https://github.com/psf/requests) - [langcodes](https://github.com/LuminosoInsight/langcodes) +- [progressbar2](https://github.com/WoLpH/python-progressbar) +- [websocket-client](https://github.com/websocket-client/websocket-client) +- [py-googletrans](https://github.com/ssut/py-googletrans) - [ffmpeg-normalize](https://github.com/slhck/ffmpeg-normalize) -Others see: [requirements.txt](requirements.txt). +[requirements.txt](requirements.txt). About how to install these dependencies, see [Download and Installation](#download-and-installation). @@ -229,6 +235,11 @@ Supported formats below: - MP3 - 16bit/mono PCM +[Xfyun Speech-to-Text WebSocket API](https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82)/[Baidu ASR API/Baidu ASR Pro API](https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) + +- Supported + - 16bit/16000Hz/mono PCM + Also, you can use the built-in audio pre-processing function though Google [doesn't recommend](https://cloud.google.com/speech-to-text/docs/best-practices) doing this. Honestly speaking, if your audio volume is not been standardized like too loud or too quiet, it's recommended to use some tools or just the built-in function to standardize it. The default [pre-processing commands](https://github.com/agermanidis/autosub/issues/40#issuecomment-509928060) depend on the ffmpeg-normalize and ffmpeg. The commands include three commands. The [first](https://trac.ffmpeg.org/wiki/AudioChannelManipulation) is for converting stereo to mono. The [second](https://superuser.com/questions/733061/reduce-background-noise-and-optimize-the-speech-from-an-audio-clip-using-ffmpeg) is for filtering out the sound not in the frequency of speech. The third is to normalize the audio to make sure it is not too loud or too quiet. If you are not satisfied with the default commands, you can also modified them yourself by input `-apc` option. Still, it currently only supports 24bit/44100Hz/mono FLAC format. If it is a subtitles file and you give the proper arguments, only translate it by py-googletrans. @@ -240,14 +251,18 @@ Audio length limits: [Google-Speech-v2](https://github.com/gillesdemey/google-speech-v2) - No longer than [10 to 15 seconds](https://github.com/gillesdemey/google-speech-v2#caveats). -- In autosub it is set as the [10-seconds-limit](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L61). +- In autosub it is set as the [60-seconds-limit](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L74). [Google Cloud Speech-to-Text API](https://cloud.google.com/speech-to-text/docs/encoding) - No longer than [1 minute](https://cloud.google.com/speech-to-text/docs/sync-recognize). -- In autosub it is currently set the same as the [10-seconds-limit](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L61). +- In autosub it is currently set the same as the [60-seconds-limit](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L74). - Currently only support sync-recognize means only short-term audio supported. +[Xfyun Speech-to-Text WebSocket API](https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82)/[Baidu ASR API](https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) + +- Same limit above. + Autosub uses Auditok to detect speech regions. And then use them to split as well as convert the video/audio into many audio fragments. Each fragment per region per API request. All these audio fragments are converted directly from input to avoid any extra quality loss. Or uses external regions from the file that pysubs2 supports like `.ass` or `.srt`. This will allow you to manually adjust the regions to get better recognition result. @@ -264,6 +279,8 @@ After Speech-to-Text, translates them to a different language. Combining multipl #### Speech-to-Text/Translation language support +Below is only for Google API language codes description. About other API: [Xfyun speech config](#xfyun-speech-config), [baidu speech config](#baidu-speech-config). + The Speech-to-Text lang codes are different from the Translation lang codes due to the difference between these two APIs. And of course, they are in *Google* formats, not following the iso standards, making users more confused to use. To solve this problem, autosub uses [langcodes](https://github.com/LuminosoInsight/langcodes) to detect input lang code and convert it to a best match according to the lang code lists. Default it won't be enabled. To enable it in different phases, use `-bm all` option. @@ -436,7 +453,7 @@ autosub -i input_file -sapi gcsv1 -asf .mp3 ...(other options)  ↑  -###### Speech config +###### Google Speech config Use customized [speech config file](https://googleapis.dev/python/speech/latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig) to send request to Google Cloud Speech API. If using the config file, override these options: `-S`, `-asr`, `-asf`. @@ -518,6 +535,70 @@ autosub -i input_file -sconf config_json_file -bm all -sapi gcsv1 -skey API_key  ↑  +##### Xfyun speech config + +For Xfyun Speech-to-Text WebSocket API usage, user must input its speech config. + +Example speech config file: + +```json +{ + "app_id": "", + "api_secret": "", + "api_key": "", + "business": { + "language": "zh_cn", + "domain": "iat", + "accent": "mandarin" + } +} +``` + +`"business"` field is the same as the [xfyun document](https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E4%B8%9A%E5%8A%A1%E5%8F%82%E6%95%B0) mentioned. + +When the file doesn't include the `"business"` field, autosub will use the above default content instead. + +command: + +``` +autosub -sapi xfyun -i input_file -sconf xfyun_speech_config ...(other options) +``` + +##### Baidu speech config + +For Baidu ASR API usage, user must input its speech config. + +Example speech config file: + +```json +{ + "AppID": "", + "API key": "", + "Secret Key": "", + "config": { + "format": "pcm", + "rate": 16000, + "channel": 1, + "cuid": "python", + "dev_pid": 1537 + } +} +``` + +`"config"` field is the same as the [Baidu ASR document](https://ai.baidu.com/ai-doc/SPEECH/ek38lxj1u) mentioned. + +If you want to use the Pro ASR API, change the value of `"cuid"` into `80001`. + +When the file doesn't include the `"config"` field, autosub will use the above default content instead. + +command: + +``` +autosub -sapi baidu -i input_file -sconf baidu_speech_config ...(other options) +``` + + ↑  + ##### Translate Subtitles Translate subtitles to another language. @@ -571,7 +652,7 @@ Input Options: for your output. If the arg_num is 0, it will use the styles from the : "-esr"/"--external-speech-regions". More info on "-sn"/"--styles-name". (arg_num = 0 or 1) - -sn [style-name [style-name ...]], --styles-name [style-name [style-name ...]] + -sn [style_name [style_name ...]], --styles-name [style_name [style_name ...]] Valid when your output format is "ass"/"ssa" and "-sty"/"--styles" is given. Adds "ass"/"ssa" styles to your events. If not provided, events will use the @@ -609,10 +690,10 @@ Language Options: language". (3 >= arg_num >= 1) -mns integer, --min-score integer An integer between 0 and 100 to control the good match - group of "-lsc"/"--list-speech-codes" or "-ltc - "/"--list-translation-codes" or the match result in - "-bm"/"--best-match". Result will be a group of "good - match" whose score is above this arg. (arg_num = 1) + group of "-lsc"/"--list-speech-codes" or "-ltc"/"-- + list-translation-codes" or the match result in "-bm"/" + --best-match". Result will be a group of "good match" + whose score is above this arg. (arg_num = 1) Output Options: Options to control output. @@ -640,7 +721,7 @@ Output Options: language in the same event. And dst is ahead of src. src-lf-dst: src language and dst language in the same event. And src is ahead of dst. (6 >= arg_num >= 1) - (default: [u'dst']) + (default: ['dst']) -fps float, --sub-fps float Valid when your output format is "sub". If input, it will override the fps check on the input file. Ref: @@ -656,14 +737,18 @@ Speech Options: support: gsv2: Google Speech V2 (https://github.com/gillesdemey/google-speech-v2). gcsv1: Google Cloud Speech-to-Text V1P1Beta1 - (https://cloud.google.com/speech-to-text/docs). + (https://cloud.google.com/speech-to-text/docs). xfyun: + Xun Fei Yun Speech-to-Text WebSocket API (https://www. + xfyun.cn/doc/asr/voicedictation/API.html). baidu: + Baidu Automatic Speech Recognition API + (https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) (arg_num = 1) (default: gsv2) -skey key, --speech-key key - The API key for Speech-to-Text API. (arg_num = 1) - Currently support: gsv2: The API key for gsv2. + The API key for Google Speech-to-Text API. (arg_num = + 1) Currently support: gsv2: The API key for gsv2. (default: Free API key) gcsv1: The API key for gcsv1. - (If used, override the credentials given by"-sa - "/"--service-account") + (If used, override the credentials given by"-sa"/"-- + service-account") -sconf [path], --speech-config [path] Use Speech-to-Text recognition config file to send request. Override these options below: "-S", "-asr", @@ -673,14 +758,19 @@ Speech Options: text/docs/reference/rest/v1p1beta1/RecognitionConfig Service account config reference: https://googleapis.d ev/python/speech/latest/gapic/v1/types.html#google.clo - ud.speech_v1.types.RecognitionConfig If arg_num is 0, - use const path. (arg_num = 0 or 1) (const: - config.json) + ud.speech_v1.types.RecognitionConfig xfyun: Xun Fei + Yun Speech-to-Text WebSocket API + (https://console.xfyun.cn/services/iat). baidu: Baidu + Automatic Speech Recognition API + (https://ai.baidu.com/ai-doc/SPEECH/ek38lxj1u). If + arg_num is 0, use const path. (arg_num = 0 or 1) + (const: config.json) -mnc float, --min-confidence float - API response for text confidence. A float value - between 0 and 1. Confidence bigger means the result is - better. Input this argument will drop any result below - it. Ref: https://github.com/BingLingGroup/google- + Google Speech-to-Text API response for text + confidence. A float value between 0 and 1. Confidence + bigger means the result is better. Input this argument + will drop any result below it. Ref: + https://github.com/BingLingGroup/google- speech-v2#response (arg_num = 1) (default: 0.0) -der, --drop-empty-regions Drop any regions without speech recognition result. @@ -758,7 +848,7 @@ Audio Processing Options: a]amix" -ac 1 -f flac "{out_}" | c:\programdata\chocolatey\bin\ffmpeg.exe -hide_banner -i "{in_}" -af lowpass=3000,highpass=200 "{out_}" | - C:\Python27\Scripts\ffmpeg-normalize.exe -v "{in_}" + C:\Python37\Scripts\ffmpeg-normalize.exe -v "{in_}" -ar 44100 -ofmt flac -c:a flac -pr -p -o "{out_}" (Ref: https://github.com/stevenj/autosub/blob/master/s cripts/subgen.sh https://ffmpeg.org/ffmpeg- @@ -804,25 +894,25 @@ Auditok Options: The energy level which determines the region to be detected. Ref: https://auditok.readthedocs.io/en/lates t/apitutorial.html#examples-using-real-audio-data - (arg_num = 1) (default: 45) + (arg_num = 1) (default: 50) -mnrs second, --min-region-size second Minimum region size. Same docs above. (arg_num = 1) - (default: 0.5) + (default: 0.8) -mxrs second, --max-region-size second Maximum region size. Same docs above. (arg_num = 1) (default: 6.0) -mxcs second, --max-continuous-silence second Maximum length of a tolerated silence within a valid audio activity. Same docs above. (arg_num = 1) - (default: 0.3) - -sml, --strict-min-length - Ref: - https://auditok.readthedocs.io/en/latest/core.html - #class-summary (arg_num = 0) + (default: 0.2) + -nsml, --not-strict-min-length + 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) -dts, --drop-trailing-silence - Ref: - https://auditok.readthedocs.io/en/latest/core.html - #class-summary (arg_num = 0) + Ref: https://auditok.readthedocs.io/en/latest/core.htm + l#class-summary (arg_num = 0) List Options: List all available arguments. @@ -851,9 +941,9 @@ List Options: Use py-googletrans to detect a sub file's first line language. And list a group of matched language in recommended "-S"/"--speech-language" Google Speech-to- - Text language codes. Ref: https://cloud.google.com - /speech-to-text/docs/languages (arg_num = 1) (default: - None) + Text language codes. Ref: + https://cloud.google.com/speech-to-text/docs/languages + (arg_num = 1) (default: None) Make sure the argument with space is in quotes. The default value is used diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po index 603a0291..45084983 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po @@ -7,13 +7,13 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-21 15:37+0800\n" +"POT-Creation-Date: 2020-03-21 17:10+0800\n" "PO-Revision-Date: 2020-03-21 15:38+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" -"Last-Translator: \n" -"Language-Team: \n" "Language: zh_CN\n" "X-Generator: Poedit 2.3\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 d7a85cb3..4dc423bf 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-21 15:37+0800\n" -"PO-Revision-Date: 2020-03-20 20:50+0800\n" +"POT-Creation-Date: 2020-03-21 17:10+0800\n" +"PO-Revision-Date: 2020-03-21 17:11+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -134,8 +134,8 @@ msgid "List all available arguments." msgstr "列出所有可选参数。" #: autosub/options.py:92 autosub/options.py:101 autosub/options.py:110 -#: autosub/options.py:192 autosub/options.py:273 autosub/options.py:400 -#: autosub/options.py:596 +#: autosub/options.py:192 autosub/options.py:273 autosub/options.py:402 +#: autosub/options.py:598 msgid "path" msgstr "路径" @@ -188,7 +188,7 @@ msgstr "" "言行使用第二个。(参数个数为1或2)" #: autosub/options.py:137 autosub/options.py:148 autosub/options.py:158 -#: autosub/options.py:568 autosub/options.py:584 +#: autosub/options.py:570 autosub/options.py:586 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:159 #, python-format @@ -226,7 +226,7 @@ msgstr "" "用于翻译的目标语言的语言代码/语言标识符。同样的注意参考选项\"-SRC\"/\"--src-" "language\"。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:165 autosub/options.py:411 +#: autosub/options.py:165 autosub/options.py:413 msgid "mode" msgstr "模式" @@ -323,21 +323,23 @@ msgid "API_code" msgstr "API代码" #: autosub/options.py:250 -#, fuzzy, python-format +#, python-format msgid "" "Choose which Speech-to-Text API to use. Currently support: gsv2: Google " "Speech V2 (https://github.com/gillesdemey/google-speech-v2). gcsv1: Google " "Cloud Speech-to-Text V1P1Beta1 (https://cloud.google.com/speech-to-text/" "docs). xfyun: Xun Fei Yun Speech-to-Text WebSocket API (https://www.xfyun.cn/" "doc/asr/voicedictation/API.html). baidu: Baidu Automatic Speech Recognition " -"API (https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) (arg_num = 1) (default: %" -"(default)s)" +"API (https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) (arg_num = 1) (default: " +"%(default)s)" msgstr "" "选择使用Speech-to-Text API。当前支持:gsv2:Google Speech V2 (https://" "github.com/gillesdemey/google-speech-v2)。 gcsv1:Google Cloud Speech-to-" "Text V1P1Beta1 (https://cloud.google.com/speech-to-text/docs)。xfyun:讯飞" "开放平台语音听写(流式版)WebSocket API(https://www.xfyun.cn/doc/asr/" -"voicedictation/API.html)。(参数个数为1)(默认参数为%(default)s)" +"voicedictation/API.html)。baidu: 百度短语音识别/短语音识别极速版(https://" +"ai.baidu.com/ai-doc/SPEECH/Vk38lxily)(参数个数为1)(默认参数" +"为%(default)s)" #: autosub/options.py:264 msgid "" @@ -360,8 +362,9 @@ msgid "" "Service account config reference: https://googleapis.dev/python/speech/" "latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig " "xfyun: Xun Fei Yun Speech-to-Text WebSocket API (https://console.xfyun.cn/" -"services/iat). If arg_num is 0, use const path. (arg_num = 0 or 1) (const: %" -"(const)s)" +"services/iat). baidu: Baidu Automatic Speech Recognition API (https://ai." +"baidu.com/ai-doc/SPEECH/ek38lxj1u). If arg_num is 0, use const path. " +"(arg_num = 0 or 1) (const: %(const)s)" msgstr "" "使用语音转文字识别配置文件来发送请求。取代以下选项:\"-S\", \"-asr\", \"-asf" "\"。目前支持:gcsv1:Google Cloud Speech-to-Text V1P1Beta1 API密钥配置参考:" @@ -369,10 +372,11 @@ msgstr "" "RecognitionConfig 服务账号配置参考:https://googleapis.dev/python/speech/" "latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig 。" "xfyun:讯飞开放平台语音听写(流式版)WebSocket API(https://console.xfyun.cn/" -"services/iat)。如果参数个数是0,使用const路径。(参数个数为0或1)(const为%" -"(const)s)" +"services/iat)。baidu: 百度短语音识别/短语音识别极速版(https://ai.baidu.com/" +"ai-doc/SPEECH/ek38lxj1u)。如果参数个数是0,使用const路径。(参数个数为0或1)" +"(const为%(const)s)" -#: autosub/options.py:298 +#: autosub/options.py:300 #, python-format msgid "" "Google Speech-to-Text API response for text confidence. A float value " @@ -385,11 +389,11 @@ msgstr "" "除。参考:https://github.com/BingLingGroup/google-speech-v2#response(参数个" "数为1)(默认参数为%(default)s)" -#: autosub/options.py:308 +#: autosub/options.py:310 msgid "Drop any regions without speech recognition result. (arg_num = 0)" msgstr "删除所有没有语音识别结果的空轴。(参数个数为0)" -#: autosub/options.py:316 +#: autosub/options.py:318 #, python-format msgid "" "Number of concurrent Speech-to-Text requests to make. (arg_num = 1) " @@ -397,21 +401,21 @@ msgid "" msgstr "" "用于Speech-to-Text请求的并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:321 autosub/options.py:516 autosub/options.py:525 -#: autosub/options.py:534 +#: autosub/options.py:323 autosub/options.py:518 autosub/options.py:527 +#: autosub/options.py:536 msgid "second" msgstr "秒" -#: autosub/options.py:324 +#: autosub/options.py:326 #, python-format 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:332 +#: autosub/options.py:334 msgid "" "(Experimental)Customize request urls. Ref: https://py-googletrans." "readthedocs.io/en/latest/ (arg_num >= 1)" @@ -419,24 +423,24 @@ msgstr "" "(实验性)自定义多个请求URL。参考:https://py-googletrans.readthedocs.io/en/" "latest/(参数个数大于等于1)" -#: autosub/options.py:339 +#: autosub/options.py:341 msgid "" "(Experimental)Customize User-Agent headers. Same docs above. (arg_num = 1)" msgstr "" "(实验性)自定义用户代理(User-Agent)头部。同样的参考文档如上。(参数个数为" "1)" -#: autosub/options.py:346 +#: autosub/options.py:348 msgid "" "Drop any .ass override codes in the text before translation. Only affect the " "translation result. (arg_num = 0)" msgstr "在翻译前删除所有文本中的ass特效标签。只影响翻译结果。(参数个数为0)" -#: autosub/options.py:353 +#: autosub/options.py:355 msgid "Change the Google Speech V2 API URL into the http one. (arg_num = 0)" msgstr "将Google Speech V2 API的URL改为http类型。(参数个数为0)" -#: autosub/options.py:361 +#: autosub/options.py:363 #, python-format msgid "" "Add https proxy by setting environment variables. If arg_num is 0, use const " @@ -445,7 +449,7 @@ msgstr "" "通过设置环境变量的方式添加https代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:369 +#: autosub/options.py:371 #, python-format msgid "" "Add http proxy by setting environment variables. If arg_num is 0, use const " @@ -454,33 +458,33 @@ msgstr "" "通过设置环境变量的方式添加http代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:375 +#: autosub/options.py:377 msgid "username" msgstr "用户名" -#: autosub/options.py:376 +#: autosub/options.py:378 msgid "Set proxy username. (arg_num = 1)" msgstr "设置代理用户名。(参数个数为1)" -#: autosub/options.py:381 +#: autosub/options.py:383 msgid "password" msgstr "密码" -#: autosub/options.py:382 +#: autosub/options.py:384 msgid "Set proxy password. (arg_num = 1)" msgstr "设置代理密码。(参数个数为1)" -#: autosub/options.py:388 +#: autosub/options.py:390 #, python-format msgid "Show %(prog)s help message and exit. (arg_num = 0)" msgstr "显示%(prog)s的帮助信息并退出。(参数个数为0)" -#: autosub/options.py:396 +#: autosub/options.py:398 #, python-format msgid "Show %(prog)s version and exit. (arg_num = 0)" msgstr "显示%(prog)s的版本信息并退出。(参数个数为0)" -#: autosub/options.py:401 +#: autosub/options.py:403 msgid "" "Set service account key environment variable. It should be the file path of " "the JSON file that contains your service account credentials. Can be " @@ -490,10 +494,10 @@ 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:412 +#: autosub/options.py:414 msgid "" "Option to control audio process. If not given the option, do normal " "conversion work. \"y\": pre-process the input first then start normal " @@ -512,15 +516,15 @@ msgstr "" "scripts/subgen.sh https://ffmpeg.org/ffmpeg-filters.html)(参数个数介于1和2" "之间)" -#: autosub/options.py:436 +#: autosub/options.py:438 msgid "Keep audio processing files to the output path. (arg_num = 0)" msgstr "将音频处理中产生的文件放在输出路径中。(参数个数为0)" -#: autosub/options.py:441 autosub/options.py:459 autosub/options.py:471 +#: autosub/options.py:443 autosub/options.py:461 autosub/options.py:473 msgid "command" msgstr "命令" -#: autosub/options.py:442 +#: autosub/options.py:444 msgid "" "This arg will override the default audio pre-process command. Every line of " "the commands need to be in quotes. Input file name is {in_}. Output file " @@ -529,7 +533,7 @@ msgstr "" "这个参数会取代默认的音频预处理命令。每行命令需要放在一个引号内。输入文件名写" "为{in_}。输出文件名写为{out_}。(参数个数大于1)" -#: autosub/options.py:454 +#: autosub/options.py:456 #, python-format msgid "" "Number of concurrent ffmpeg audio split process to make. (arg_num = 1) " @@ -537,19 +541,19 @@ msgid "" msgstr "" "用于ffmpeg音频切割的进程并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:461 +#: autosub/options.py:463 #, 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:473 +#: autosub/options.py:475 #, python-format msgid "" "(Experimental)This arg will override the default audio split command. Same " @@ -558,24 +562,24 @@ msgstr "" "(实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:480 +#: autosub/options.py:482 msgid "file_suffix" msgstr "文件名后缀" -#: autosub/options.py:482 +#: autosub/options.py:484 #, python-format 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:488 +#: autosub/options.py:490 msgid "sample_rate" msgstr "采样率" -#: autosub/options.py:491 +#: autosub/options.py:493 #, python-format msgid "" "(Experimental)This arg will override the default API audio sample rate(Hz). " @@ -584,11 +588,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频采样率(赫兹)。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:497 +#: autosub/options.py:499 msgid "channel_num" msgstr "声道数" -#: autosub/options.py:500 +#: autosub/options.py:502 #, python-format msgid "" "(Experimental)This arg will override the default API audio channel. (arg_num " @@ -597,11 +601,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频声道数量。(参数个数为1)(默认" "参数为%(default)s)" -#: autosub/options.py:506 +#: autosub/options.py:508 msgid "energy" msgstr "能量(相对值)" -#: autosub/options.py:509 +#: autosub/options.py:511 #, python-format msgid "" "The energy level which determines the region to be detected. Ref: https://" @@ -612,23 +616,23 @@ msgstr "" "latest/apitutorial.html#examples-using-real-audio-data(参数个数为1)(默认参" "数为%(default)s)" -#: autosub/options.py:519 +#: autosub/options.py:521 #, python-format msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" -"s)" +"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数" +"为%(default)s)" -#: autosub/options.py:528 +#: autosub/options.py:530 #, 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:537 +#: autosub/options.py:539 #, python-format msgid "" "Maximum length of a tolerated silence within a valid audio activity. Same " @@ -637,7 +641,7 @@ msgstr "" "在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如" "上。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:544 +#: autosub/options.py:546 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." @@ -646,7 +650,7 @@ msgstr "" "如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://" "auditok.readthedocs.io/en/latest/core.html#class-summary(参数个数为0)" -#: autosub/options.py:552 +#: autosub/options.py:554 msgid "" "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)" @@ -654,7 +658,7 @@ msgstr "" "参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" "个数为0)" -#: autosub/options.py:558 +#: autosub/options.py:560 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 " @@ -665,7 +669,7 @@ msgstr "" "SubtitleEdit来对其进行转换。如果输出格式是\"sub\"且输入文件是音频无法获取到视" "频帧率时,你需要提供fps选项指定帧率。(参数个数为0)" -#: autosub/options.py:571 +#: autosub/options.py:573 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 " @@ -683,7 +687,7 @@ msgstr "" "言)-扩展-私有(https://www.zhihu.com/question/21980689/answer/93615123)(参" "数个数为0或1)" -#: autosub/options.py:587 +#: autosub/options.py:589 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 " @@ -693,7 +697,7 @@ msgstr "" "言代码。否则会给出一个“好的匹配”的清单。同样的参考文档如上。(参数个数为0或" "1)" -#: autosub/options.py:597 +#: autosub/options.py:599 #, python-format msgid "" "Use py-googletrans to detect a sub file's first line language. And list a " @@ -724,26 +728,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/options.py b/autosub/options.py index f56382f1..32b118ca 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -286,6 +286,8 @@ def get_cmd_parser(): # pylint: disable=too-many-statements "#google.cloud.speech_v1.types.RecognitionConfig " "xfyun: Xun Fei Yun Speech-to-Text WebSocket API " "(https://console.xfyun.cn/services/iat). " + "baidu: Baidu Automatic Speech Recognition API " + "(https://ai.baidu.com/ai-doc/SPEECH/ek38lxj1u). " "If arg_num is 0, use const path. " "(arg_num = 0 or 1) (const: %(const)s)") ) diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md index af6d60a8..1a4bb558 100644 --- a/docs/README.zh-Hans.md +++ b/docs/README.zh-Hans.md @@ -41,8 +41,10 @@ - 6.1.4 [语音转录为字幕](#语音转录为字幕) - 6.1.4.1 [Google Speech V2](#google-speech-v2) - 6.1.4.2 [Google Cloud Speech-to-Text](#google-cloud-speech-to-text) - - 6.1.4.3 [语音识别配置](#语音识别配置) + - 6.1.4.3 [Google语音识别配置](#Google语音识别配置) - 6.1.4.4 [输出API完整响应](#输出API完整响应) + - 6.1.4.5 [讯飞云语音识别配置](#讯飞云语音识别配置) + - 6.1.4.6 [百度语音识别配置](#百度语音识别配置) - 6.1.5 [翻译字幕](#翻译字幕) - 6.2 [选项](#选项) - 6.3 [国际化](#国际化) @@ -79,13 +81,16 @@ Autosub依赖于这些第三方的软件或者Python的site-packages。非常感 - [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) +- [wcwidth](https://github.com/jquast/wcwidth) - [langcodes](https://github.com/LuminosoInsight/langcodes) +- [progressbar2](https://github.com/WoLpH/python-progressbar) +- [websocket-client](https://github.com/websocket-client/websocket-client) +- [py-googletrans](https://github.com/ssut/py-googletrans) - [ffmpeg-normalize](https://github.com/slhck/ffmpeg-normalize) -其他的依赖项目参见:[requirements.txt](requirements.txt)。 +[requirements.txt](requirements.txt)。 -以及如何安装这些依赖,参见[下载和安装](#下载和安装)。 +如何安装这些依赖,参见[下载和安装](#下载和安装)。  ↑  @@ -229,6 +234,11 @@ PyPI的版本(autosub-0.3.12)不推荐在windows上使用,因为它无法 - MP3 - 16bit/单声道 PCM +[讯飞语音听写(流式版)WebSocket API](https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82)/[百度短语音识别/短语音识别极速版API](https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) + +- 支持 + - 16bit/16000Hz/单声道 PCM + 你也可以使用自带的音频预处理功能,尽管谷歌并不[如此推荐](https://cloud.google.com/speech-to-text/docs/best-practices)。实话讲,如果你音频的音量没有被标准化,譬如音量太大或者太小,建议你使用一些工具或者只是自带的音频预处理功能去将其音量标准化。默认的[音频预处理指令](https://github.com/agermanidis/autosub/issues/40)同时依赖于ffmpeg和ffmpeg-normalize。这些命令包含三个子命令。[第一个](https://trac.ffmpeg.org/wiki/AudioChannelManipulation)是用来把双声道的音频转换为单声道的。[第二个](https://superuser.com/questions/733061/reduce-background-noise-and-optimize-the-speech-from-an-audio-clip-using-ffmpeg)是通过人声的频率范围来过滤噪音的。第三个则是正常化音频的音量来确保它的音量不是太大或者太小。如果你对默认指令的效果不满意,你也可以通过输入`-apc`选项来自行修改。当然,它仍然只支持24bit/44100Hz/单声道 FLAC格式。 如果输入是字幕文件,同时你提供的参数适合,程序仅会将其通过py-googletrans来翻译。 @@ -240,14 +250,18 @@ PyPI的版本(autosub-0.3.12)不推荐在windows上使用,因为它无法 [Google-Speech-v2](https://github.com/gillesdemey/google-speech-v2) - 不超过[10到15秒](https://github.com/gillesdemey/google-speech-v2#caveats)。 -- 在autosub里面,按照[10秒](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L61)来限制。 +- 在autosub里面,按照[60秒](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L74)来限制。 [Google Cloud Speech-to-Text API](https://cloud.google.com/speech-to-text/docs/encoding) - 不超过[1分钟](https://cloud.google.com/speech-to-text/docs/sync-recognize)。 -- 在autosub里面,同样按照[10秒](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L61)来限制。 +- 在autosub里面,同样按照[60秒](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L74)来限制。 - 现在只支持同步语言识别意味着只支持短语音识别。 +[讯飞语音听写(流式版)WebSocket API](https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82)/[百度短语音识别/短语音识别极速版API](https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) + +- 限制同上。 + Autosub使用Auditok来检测语音区域。通过语音区域来分割并转换视频/音频为许多短语音片段。每个区域对应一个片段一个API请求。所有这些片段都是直接从输入转换的,避免任何多余的损失。 或者使用外部文件提供的时间码来作为语音区域输入,支持pysubs2支持的文件格式,如`.ass`或者`.srt`。这样你就可以使用外部工具先制作时间轴然后让程序使用并得到精确度更高的识别结果。 @@ -264,6 +278,8 @@ Autosub使用Auditok来检测语音区域。通过语音区域来分割并转换 #### 语音转文字/翻译语言支持 +以下是Google API的预言代码说明,关于其他API的使用方法,详见:[讯飞云语音识别配置](#讯飞云语音识别配置),[百度语音识别配置](#百度语音识别配置)。 + 语音转文字的语言代码和翻译的语言代码是不一样的,因为这俩API并不相同。当然啦,这些语言代码的格式是*谷歌化*的,和iso标准不一样,会导致用户使用时很迷惑。 为了解决这个问题,autosub使用[langcodes](https://github.com/LuminosoInsight/langcodes)来检测输入的语言代码并在语言代码清单中找到与其最匹配的一项来使用。默认并不会启用这个功能。需要在不同的阶段都启动这个功能,可以使用选项`-bm all`。 @@ -436,7 +452,7 @@ autosub -i 输入文件 -sapi gcsv1 -asf .mp3 ...(其他选项)  ↑  -###### 语音识别配置 +###### Google语音识别配置 使用定制的[语音识别配置文件](https://googleapis.dev/python/speech/latest/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig)来发送请求给Google Cloud Speech API。如果使用配置文件,就会替代这些选项:`-S`, `-asr`, `-asf`。 @@ -483,7 +499,7 @@ autosub -i 输入文件 -sconf json格式配置文件 -bm all -sapi gcsv1 -skey ###### 输出API完整响应 -现在autosub不能处理API返回的语音识别结果里的很多[高级领域](https://cloud.google.com/speech-to-text/docs/reference/rpc/google.cloud.speech.v1p1beta1#google.cloud.speech.v1p1beta1.SpeechRecognitionResult),特别是从Google Cloud Speech-to-Text API中返回的。配合复杂的[语音识别配置](#speech-config)输入和选项`-of full-src`,语音识别结果就会被输出到json格式的文件中,所以你能定制化并在autosub外部处理这些数据。 +现在autosub不能处理API返回的语音识别结果里的很多[高级属性](https://cloud.google.com/speech-to-text/docs/reference/rpc/google.cloud.speech.v1p1beta1#google.cloud.speech.v1p1beta1.SpeechRecognitionResult),特别是从Google Cloud Speech-to-Text API中返回的。配合复杂的[语音识别配置](#speech-config)输入和选项`-of full-src`,语音识别结果就会被输出到json格式的文件中,所以你能定制化并在autosub外部处理这些数据。 示例json格式输出: @@ -518,6 +534,68 @@ autosub -i 输入文件 -sconf json格式配置文件 -bm all -sapi gcsv1 -skey  ↑  +##### 讯飞云语音识别配置 + +对于讯飞开放平台语音听写(流式版)WebAPI的使用,用户必须输入它的语音识别配置文件。 + +示例语音识别配置文件: + +```json +{ + "app_id": "", + "api_secret": "", + "api_key": "", + "business": { + "language": "zh_cn", + "domain": "iat", + "accent": "mandarin" + } +} +``` + +`"business"`属性和[讯飞文档](https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E4%B8%9A%E5%8A%A1%E5%8F%82%E6%95%B0)里所说的一样。 + +当文件中不包含`"business"`属性时,autosub会使用如上的默认内容。 + +命令: + +``` +autosub -sapi xfyun -i 输入文件 -sconf 讯飞云语音配置文件 ...(其他选项) +``` + +##### 百度语音识别配置 + +对于百度短语音识别/短语音识别极速版的使用,用户必须输入它的语音识别配置文件。 + +示例语音识别配置文件: + +```json +{ + "AppID": "", + "API key": "", + "Secret Key": "", + "config": { + "format": "pcm", + "rate": 16000, + "channel": 1, + "cuid": "python", + "dev_pid": 1537 + } +} +``` + +`"config"`属性和[百度短语音识别文档](https://ai.baidu.com/ai-doc/SPEECH/ek38lxj1u)里所说的一样。 + +如果你要使用短语音识别极速版,把`"cuid"`改为`80001`即可。 + +如果文件中不包含`"config"`属性,autosub会使用如上的默认内容。 + +命令: + +``` +autosub -sapi baidu -i 输入文件 -sconf 百度语音配置文件 ...(其他选项) +``` + ##### 翻译字幕 将字幕翻译为别的语言。 @@ -624,11 +702,14 @@ usage: (https://github.com/gillesdemey/google-speech-v2)。 gcsv1:Google Cloud Speech-to-Text V1P1Beta1 (https://cloud.google.com/speech-to- - text/docs)。(参数个数为1)(默认参数为gsv2) + text/docs)。xfyun:讯飞开放平台语音听写(流式版)WebSocket API(https:// + www.xfyun.cn/doc/asr/voicedictation/API.html)。baidu: + 百度短语音识别/短语音识别极速版(https://ai.baidu.com/ai- + doc/SPEECH/Vk38lxily)(参数个数为1)(默认参数为gsv2) -skey key, --speech-key key - Speech-to-Text API的密钥。(参数个数为1)当前支持:gsv2:gsv2的API密钥。(默认 - 参数为免费API密钥)gcsv1:gcsv1的API密钥。(如果使用了,可以覆盖 "-sa"/"-- - service-account"提供的服务账号凭据) + Google Speech-to-Text API的密钥。(参数个数为1)当前支持:gsv2:gsv2的AP + I密钥。(默认参数为免费API密钥)gcsv1:gcsv1的API密钥。(如果使用了,可以覆盖 + "-sa"/"--service-account"提供的服务账号凭据) -sconf [路径], --speech-config [路径] 使用语音转文字识别配置文件来发送请求。取代以下选项:"-S", "-asr", "-asf"。目前支持:gcsv1:Google Cloud Speech-to-Text @@ -637,12 +718,16 @@ usage: text/docs/reference/rest/v1p1beta1/RecognitionConfig 服 务账号配置参考:https://googleapis.dev/python/speech/latest/ga pic/v1/types.html#google.cloud.speech_v1.types.Recogni - tionConfig - 。如果参数个数是0,使用const路径。(参数个数为0或1)(const为config.json) + tionConfig 。xfyun:讯飞开放平台语音听写(流式版)WebSocket + API(https://console.xfyun.cn/services/iat)。baidu: + 百度短语音识别/短语音识别极速版(https://ai.baidu.com/ai-doc/SPEECH/ek + 38lxj1u)。如果参数个数是0,使用const路径。(参数个数为0或1)(const为config.js + on) -mnc float, --min-confidence float - API用于识别可信度的回应参数。一个介于0和1之间的浮点数。可信度越高意味着结果越好。输入这个参数会导致所有 - 低于这个结果的识别结果被删除。参考:https://github.com/BingLingGroup/goo - gle-speech-v2#response(参数个数为1)(默认参数为0.0) + Google Speech-to-Text API用于识别可信度的回应参数。一个介于0和1之间的浮点数。可信 + 度越高意味着结果越好。输入这个参数会导致所有低于这个结果的识别结果被删除。参考:https://github + .com/BingLingGroup/google- + speech-v2#response(参数个数为1)(默认参数为0.0) -der, --drop-empty-regions 删除所有没有语音识别结果的空轴。(参数个数为0) -sc integer, --speech-concurrency integer @@ -702,7 +787,7 @@ py-googletrans选项: first_pts=0,[a]amix" -ac 1 -f flac "{out_}" | c:\programdata\chocolatey\bin\ffmpeg.exe -hide_banner -i "{in_}" -af lowpass=3000,highpass=200 "{out_}" | - C:\Python27\Scripts\ffmpeg-normalize.exe -v "{in_}" + C:\Python37\Scripts\ffmpeg-normalize.exe -v "{in_}" -ar 44100 -ofmt flac -c:a flac -pr -p -o "{out_}"(参考:h ttps://github.com/stevenj/autosub/blob/master/scripts/ subgen.sh https://ffmpeg.org/ffmpeg- @@ -736,17 +821,17 @@ Auditok的选项: -et 能量(相对值), --energy-threshold 能量(相对值) 用于检测是否是语音区域的能量水平。参考:https://auditok.readthedocs.io/en/ latest/apitutorial.html#examples-using-real-audio- - data(参数个数为1)(默认参数为45) + data(参数个数为1)(默认参数为50) -mnrs 秒, --min-region-size 秒 - 最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为0.5) + 最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为0.8) -mxrs 秒, --max-region-size 秒 最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数为6.0) -mxcs 秒, --max-continuous-silence 秒 在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如上。(参数个数为1)(默认参数为0 - .3) - -sml, --strict-min-length - 参考:https://auditok.readthedocs.io/en/latest/core.html# - class-summary(参数个数为0) + .2) + -nsml, --not-strict-min-length + 如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://auditok.readthe + docs.io/en/latest/core.html#class-summary(参数个数为0) -dts, --drop-trailing-silence 参考:https://auditok.readthedocs.io/en/latest/core.html# class-summary(参数个数为0) From bc76a20d54fa73e292323dd83c1d6dbd673d3bdb Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sat, 21 Mar 2020 20:03:22 +0800 Subject: [PATCH 06/26] Fix delete_chars issue --- README.md | 8 +++++++- autosub/api_baidu.py | 9 +++++++-- autosub/api_xfyun.py | 4 +++- autosub/cmdline_utils.py | 8 +++----- docs/README.zh-Hans.md | 12 +++++++++++- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 17edb223..c81d753d 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,7 @@ Audio length limits: - In autosub it is currently set the same as the [60-seconds-limit](https://github.com/BingLingGroup/autosub/blob/dev/autosub/constants.py#L74). - Currently only support sync-recognize means only short-term audio supported. -[Xfyun Speech-to-Text WebSocket API](https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82)/[Baidu ASR API](https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) +[Xfyun Speech-to-Text WebSocket API](https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E6%8E%A5%E5%8F%A3%E8%A6%81%E6%B1%82)/[Baidu ASR API/Baidu ASR Pro API](https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) - Same limit above. @@ -558,6 +558,8 @@ Example speech config file: When the file doesn't include the `"business"` field, autosub will use the above default content instead. +If you add `"delete_chars": ",。"` in the configuration file (In this example, full-width comma and period are the punctuations to be deleted), autosub will automatically replace the specific punctuation with a space when receiving the transcript, and strip the space at the end of each sentence. + command: ``` @@ -591,6 +593,10 @@ If you want to use the Pro ASR API, change the value of `"cuid"` into `80001`. When the file doesn't include the `"config"` field, autosub will use the above default content instead. +Same `"delete_chars"` function above. + +Practical speaking, since Baidu ASR/ASR Pro API doesn't allow concurrency by default, concurrency will be limited to 1. If you need to lift the limit, please add `"disable_qps_limit": true,` to the config file. If so, the concurrency will be set by the option `-sc`. + command: ``` diff --git a/autosub/api_baidu.py b/autosub/api_baidu.py index dfaf4490..e836bfe5 100644 --- a/autosub/api_baidu.py +++ b/autosub/api_baidu.py @@ -31,6 +31,9 @@ def baidu_dev_pid_to_lang_code( dev_pid ): + """ + Get lang code from a baidu_dev_pid. + """ if dev_pid == 1737: return "en" return "zh-cn" @@ -128,8 +131,10 @@ def __call__(self, filename): if not self.is_full_result: if self.delete_chars: - return get_baidu_transcript(result_dict).translate( - str.maketrans("", "", self.delete_chars)) + transcript = get_baidu_transcript(result_dict).translate( + str.maketrans(self.delete_chars, " " * len(self.delete_chars))) + transcript = transcript.rstrip(" ") + return transcript return get_baidu_transcript(result_dict) return result_dict diff --git a/autosub/api_xfyun.py b/autosub/api_xfyun.py index 907023ac..b70bc2b0 100644 --- a/autosub/api_xfyun.py +++ b/autosub/api_xfyun.py @@ -142,7 +142,9 @@ def __call__(self, filename): if self.is_full_result: return self.result_list if self.delete_chars: - self.transcript.translate(str.maketrans("", "", self.delete_chars)) + self.transcript.translate( + str.maketrans(self.delete_chars, " " * len(self.delete_chars))) + self.transcript = self.transcript.rstrip(" ") return self.transcript def on_message(self, web_socket, result): # pylint: disable=unused-argument diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 7fa059a8..8837d314 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -356,17 +356,15 @@ def validate_config_args(args): # pylint: disable=too-many-branches, too-many-r } if "dev_pid" in config_dict["config"]: - args.speech_language = api_baidu.baidu_dev_pid_to_lang_code(config_dict["config"]["dev_pid"]) + args.speech_language = \ + api_baidu.baidu_dev_pid_to_lang_code(config_dict["config"]["dev_pid"]) else: config_dict["config"]["dev_pid"] = 1537 if "disable_qps_limit" not in config_dict \ or config_dict["disable_qps_limit"] is not True: # Queries per second limit - if config_dict["config"]["dev_pid"] == 80001: - args.speech_concurrency = 1 - else: - args.speech_concurrency = 1 + args.speech_concurrency = 1 args.speech_config = config_dict diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md index 1a4bb558..771e1c8e 100644 --- a/docs/README.zh-Hans.md +++ b/docs/README.zh-Hans.md @@ -105,7 +105,7 @@ Autosub依赖于这些第三方的软件或者Python的site-packages。非常感 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。 +2. 把它们加入环境变量`PATH`。如果使用的是包管理器进行的安装,那么就不需要关心这件事。用包管理器进行安装是指使用pip安装ffmpeg-normalize或者chocolatey安装ffmpeg。 3. 把它们放在和autosub的可执行文件的同一个目录下。 4. 把它们放在当前命令行工作的文件夹下。 @@ -557,12 +557,16 @@ autosub -i 输入文件 -sconf json格式配置文件 -bm all -sapi gcsv1 -skey 当文件中不包含`"business"`属性时,autosub会使用如上的默认内容。 +如果在配置文件中添加`"delete_chars": ",。"`(逗号和句号是需要删除的标点符号),autosub会在接收到识别结果时自动将指定符号替换为空格,并消除每句末尾空格。 + 命令: ``` autosub -sapi xfyun -i 输入文件 -sconf 讯飞云语音配置文件 ...(其他选项) ``` + ↑  + ##### 百度语音识别配置 对于百度短语音识别/短语音识别极速版的使用,用户必须输入它的语音识别配置文件。 @@ -590,12 +594,18 @@ autosub -sapi xfyun -i 输入文件 -sconf 讯飞云语音配置文件 ...(其 如果文件中不包含`"config"`属性,autosub会使用如上的默认内容。 +同样可以使用上文所说的`"delete_chars"`功能。 + +实测由于百度短语音识别/短语音识别极速版默认不允许并发,所以并发会被限制为1,如果需要解除限制,请在配置文件中添加`"disable_qps_limit": true,`,解除后并发即为选项`-sc`所设置的。 + 命令: ``` autosub -sapi baidu -i 输入文件 -sconf 百度语音配置文件 ...(其他选项) ``` + ↑  + ##### 翻译字幕 将字幕翻译为别的语言。 From a47bc5d65d3850ba419874a21a6254c92aaf181b Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Mon, 23 Mar 2020 19:35:34 +0800 Subject: [PATCH 07/26] Fix the size count bug when the last line been split in list_to_googletrans --- CHANGELOG.md | 9 ++ autosub/constants.py | 2 +- autosub/core.py | 27 ++-- .../zh_CN/LC_MESSAGES/autosub.api_baidu.po | 4 +- .../LC_MESSAGES/autosub.cmdline_utils.po | 126 +++++++++--------- .../locale/zh_CN/LC_MESSAGES/autosub.core.po | 12 +- docs/CHANGELOG.zh-Hans.md | 12 +- 7 files changed, 109 insertions(+), 83 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1303cc52..08576fd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Unreleased](#unreleased) - [Added](#addedunreleased) - [Changed](#changedunreleased) + - [Fixed](#fixedunreleased) - [0.5.6-alpha - 2020-03-20](#056-alpha---2020-03-20) - [Added](#added056-alpha) - [Changed](#changed056-alpha) @@ -58,6 +59,14 @@ Click up arrow to go back to TOC. - Change the replacement condition of the audio_split_cmd only when the user doesn't modify it. - Change the MAX_REGION_SIZE_LIMIT into 60 seconds. +#### Fixed(Unreleased) + +- Fix the size count bug when the last line been split in list_to_googletrans. + +#### Removed(Unreleased) + +- Remove Python 2.7 support. + ### [0.5.6-alpha] - 2020-03-20 #### Added(0.5.6-alpha) diff --git a/autosub/constants.py b/autosub/constants.py index 011dd6d6..76631165 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -67,7 +67,7 @@ DEFAULT_CONCURRENCY = 2 DEFAULT_SRC_LANGUAGE = 'en-US' -DEFAULT_ENERGY_THRESHOLD = 50 +DEFAULT_ENERGY_THRESHOLD = 45 DEFAULT_MAX_REGION_SIZE = 6.0 DEFAULT_MIN_REGION_SIZE = 0.8 MIN_REGION_SIZE_LIMIT = 0.6 diff --git a/autosub/core.py b/autosub/core.py index 6a0ea1dd..5870280d 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -569,14 +569,15 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, partial_index = [] valid_index = [] is_last = "" - for text in text_list: - if text: + text_list_length = len(text_list) + while i < text_list_length: + if text_list[i]: if not is_last: - is_last = text + is_last = text_list[i] valid_index.append(i) # valid_index for valid text position start - wcswidth_text = wcwidth.wcswidth(text) - if wcswidth_text * 10 / len(text) >= 10: + wcswidth_text = wcwidth.wcswidth(text_list[i]) + if wcswidth_text * 10 / len(text_list[i]) >= 10: # If text contains full-wide char, # count its length about 4 times than the ordinary text. # Avoid weird problem when text has full-wide char. @@ -586,17 +587,21 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, # Causing a googletrans internal jsondecode error. size = size + wcswidth_text * 2 else: - size = size + len(text) + size = size + len(text_list[i]) if size > size_per_trans: # use size_per_trans to split the list partial_index.append(i) size = 0 + continue + # stay at this line of text + # in case if it's the last one else: if is_last: - is_last = text + is_last = text_list[i] valid_index.append(i) # valid_index for valid text position end i = i + 1 + if size: partial_index.append(i) # python sequence @@ -633,7 +638,7 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, translation = translator.translate(text=content_to_trans, dest=dst_language, src=src_language) - result_text = translation.text.replace('’', '\'') + result_text = translation.text.translate(str.maketrans('’', '\'')) result_list = result_text.split('\n') k = 0 len_result_list = len(result_list) @@ -649,7 +654,8 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, # and then continue translated_text.append("") i = i + 1 - pbar.update(i) + if i % 20 == 5: + pbar.update(i) continue if i < valid_index[j + 1]: # if text is valid, append it @@ -658,7 +664,8 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, i = i + 1 else: j = j + 2 - pbar.update(i) + if i % 20 == 5: + pbar.update(i) if len(partial_index) > 1: time.sleep(sleep_seconds) diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po index 45084983..ed01d801 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-21 17:10+0800\n" +"POT-Creation-Date: 2020-03-23 19:35+0800\n" "PO-Revision-Date: 2020-03-21 15:38+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,6 +17,6 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/api_baidu.py:75 +#: autosub/api_baidu.py:78 msgid "Error: Check you project if its ASR feature is enabled." msgstr "错误:检查你的项目是否打开了语音识别功能。" 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 95cad272..b7dec35e 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-21 15:37+0800\n" +"POT-Creation-Date: 2020-03-23 19:35+0800\n" "PO-Revision-Date: 2020-03-20 20:45+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -150,29 +150,29 @@ msgstr "错误:\"api_secret\"不在语音配置文件\"{filename}\"中。" msgid "Error: No \"language\" found in speech config file \"{filename}\"." msgstr "错误:\"language\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:381 +#: autosub/cmdline_utils.py:379 msgid "Error: \"-slp\"/\"--sleep-seconds\" arg is illegal." msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" -#: autosub/cmdline_utils.py:389 +#: autosub/cmdline_utils.py:387 msgid "Let speech lang code to match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:395 +#: autosub/cmdline_utils.py:393 msgid "Use langcodes to standardize the result." msgstr "使用langcodes来标准化结果。" -#: autosub/cmdline_utils.py:397 autosub/cmdline_utils.py:453 -#: autosub/cmdline_utils.py:475 autosub/cmdline_utils.py:548 -#: autosub/cmdline_utils.py:575 +#: autosub/cmdline_utils.py:395 autosub/cmdline_utils.py:451 +#: autosub/cmdline_utils.py:473 autosub/cmdline_utils.py:546 +#: autosub/cmdline_utils.py:573 msgid "Use \"{lang_code}\" instead." msgstr "改用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:400 +#: autosub/cmdline_utils.py:398 msgid "Match failed. Still using \"{lang_code}\"." msgstr "匹配失败。仍在使用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:403 +#: autosub/cmdline_utils.py:401 msgid "" "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" "list-speech-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -182,35 +182,35 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:411 +#: autosub/cmdline_utils.py:409 msgid "Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal." msgstr "错误:\"-mnc\"/\"--min-confidence\"参数的值不合法。" -#: autosub/cmdline_utils.py:416 +#: autosub/cmdline_utils.py:414 msgid "" "Error: You must provide \"-sconf\", \"--speech-config\" option when using " "Xun Fei Yun API." msgstr "错误:使用讯飞云API时,你必须提供\"-sconf\",\"--speech-config\"选项。" -#: autosub/cmdline_utils.py:420 +#: autosub/cmdline_utils.py:418 msgid "" "Translation destination language not provided. Only performing speech " "recognition." msgstr "翻译目的语言未提供。只进行语音识别。" -#: autosub/cmdline_utils.py:425 +#: autosub/cmdline_utils.py:423 msgid "Translation source language not provided. Use speech language instead." msgstr "翻译源语言未提供。改用语音语言。" -#: autosub/cmdline_utils.py:446 +#: autosub/cmdline_utils.py:444 msgid "Let translation source lang code to match py-googletrans lang codes." msgstr "让翻译源语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:457 autosub/cmdline_utils.py:479 +#: autosub/cmdline_utils.py:455 autosub/cmdline_utils.py:477 msgid "Error: Match failed." msgstr "错误:匹配失败。" -#: autosub/cmdline_utils.py:460 +#: autosub/cmdline_utils.py:458 msgid "" "Error: Translation source language \"{src}\" is not supported. Run with \"-" "ltc\"/\"--list-translation-codes\" to see all supported languages. Or use \"-" @@ -220,12 +220,12 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:468 +#: autosub/cmdline_utils.py:466 msgid "" "Let translation destination lang code to match py-googletrans lang codes." msgstr "让翻译目的语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:482 +#: autosub/cmdline_utils.py:480 msgid "" "Error: Translation destination language \"{dst}\" is not supported. Run with " "\"-ltc\"/\"--list-translation-codes\" to see all supported languages. Or use " @@ -234,29 +234,29 @@ msgstr "" "错误:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" "项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最佳匹配。" -#: autosub/cmdline_utils.py:490 +#: autosub/cmdline_utils.py:488 msgid "" "Speech language is the same as the destination language. Only performing " "speech recognition." msgstr "语音语言和目的语言一致。只进行语音识别。" -#: autosub/cmdline_utils.py:499 +#: autosub/cmdline_utils.py:497 msgid "You've already input times. No works done." msgstr "你已经输入了时间轴。啥都没做。" -#: autosub/cmdline_utils.py:503 +#: autosub/cmdline_utils.py:501 msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:511 autosub/cmdline_utils.py:603 +#: autosub/cmdline_utils.py:509 autosub/cmdline_utils.py:601 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" -#: autosub/cmdline_utils.py:524 +#: autosub/cmdline_utils.py:522 msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" -#: autosub/cmdline_utils.py:540 +#: autosub/cmdline_utils.py:538 msgid "" "Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages." @@ -264,11 +264,11 @@ msgstr "" "警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:552 autosub/cmdline_utils.py:579 +#: autosub/cmdline_utils.py:550 autosub/cmdline_utils.py:577 msgid "Match failed. Still using \"{lang_code}\". Program stopped." msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" -#: autosub/cmdline_utils.py:558 +#: autosub/cmdline_utils.py:556 msgid "" "Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -278,7 +278,7 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:567 +#: autosub/cmdline_utils.py:565 msgid "" "Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages." @@ -286,7 +286,7 @@ msgstr "" "警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" "行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:585 +#: autosub/cmdline_utils.py:583 msgid "" "Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" @@ -296,12 +296,12 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:593 +#: autosub/cmdline_utils.py:591 msgid "" "Error: Translation source language is the same as the destination language." msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:617 +#: autosub/cmdline_utils.py:615 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -309,7 +309,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:624 +#: autosub/cmdline_utils.py:622 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -317,7 +317,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:631 +#: autosub/cmdline_utils.py:629 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -325,16 +325,16 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:687 autosub/cmdline_utils.py:831 -#: autosub/cmdline_utils.py:1377 +#: autosub/cmdline_utils.py:685 autosub/cmdline_utils.py:829 +#: autosub/cmdline_utils.py:1375 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:691 autosub/cmdline_utils.py:783 -#: autosub/cmdline_utils.py:835 autosub/cmdline_utils.py:887 -#: autosub/cmdline_utils.py:1068 autosub/cmdline_utils.py:1231 -#: autosub/cmdline_utils.py:1273 autosub/cmdline_utils.py:1333 -#: autosub/cmdline_utils.py:1381 autosub/cmdline_utils.py:1429 +#: autosub/cmdline_utils.py:689 autosub/cmdline_utils.py:781 +#: autosub/cmdline_utils.py:833 autosub/cmdline_utils.py:885 +#: autosub/cmdline_utils.py:1066 autosub/cmdline_utils.py:1229 +#: autosub/cmdline_utils.py:1271 autosub/cmdline_utils.py:1331 +#: autosub/cmdline_utils.py:1379 autosub/cmdline_utils.py:1427 msgid "" "\n" "All works done." @@ -342,23 +342,23 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:735 autosub/cmdline_utils.py:1290 +#: autosub/cmdline_utils.py:733 autosub/cmdline_utils.py:1288 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:779 autosub/cmdline_utils.py:1329 +#: autosub/cmdline_utils.py:777 autosub/cmdline_utils.py:1327 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:883 autosub/cmdline_utils.py:1425 +#: autosub/cmdline_utils.py:881 autosub/cmdline_utils.py:1423 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:926 autosub/cmdline_utils.py:1470 +#: autosub/cmdline_utils.py:924 autosub/cmdline_utils.py:1468 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:968 +#: autosub/cmdline_utils.py:966 msgid "" "\n" "No works done. Check your \"-of\"/\"--output-files\" option." @@ -366,11 +366,11 @@ msgstr "" "\n" "啥都没做。检查你的\"-of\"/\"--output-files\"选项。" -#: autosub/cmdline_utils.py:973 +#: autosub/cmdline_utils.py:971 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:1007 +#: autosub/cmdline_utils.py:1005 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -378,11 +378,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:1017 +#: autosub/cmdline_utils.py:1015 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:1020 +#: autosub/cmdline_utils.py:1018 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -390,7 +390,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:1032 +#: autosub/cmdline_utils.py:1030 msgid "" "\n" "\"{name}\" has been deleted." @@ -398,19 +398,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:1036 +#: autosub/cmdline_utils.py:1034 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1065 autosub/cmdline_utils.py:1537 +#: autosub/cmdline_utils.py:1063 autosub/cmdline_utils.py:1535 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1089 +#: autosub/cmdline_utils.py:1087 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1093 +#: autosub/cmdline_utils.py:1091 msgid "" "Audio processing complete.\n" "All works done." @@ -418,11 +418,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1145 +#: autosub/cmdline_utils.py:1143 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1160 +#: autosub/cmdline_utils.py:1158 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -432,18 +432,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1165 +#: autosub/cmdline_utils.py:1163 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1179 +#: autosub/cmdline_utils.py:1177 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1191 +#: autosub/cmdline_utils.py:1189 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -451,11 +451,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1227 +#: autosub/cmdline_utils.py:1225 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1235 +#: autosub/cmdline_utils.py:1233 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -463,11 +463,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1269 autosub/cmdline_utils.py:1507 +#: autosub/cmdline_utils.py:1267 autosub/cmdline_utils.py:1505 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1479 +#: autosub/cmdline_utils.py:1477 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -475,7 +475,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1512 +#: autosub/cmdline_utils.py:1510 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.core.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po index 328a10ed..c4d6f006 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-21 15:37+0800\n" +"POT-Creation-Date: 2020-03-23 19:35+0800\n" "PO-Revision-Date: 2020-03-21 15:41+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -108,24 +108,24 @@ msgstr "" "\n" "从\"{0}\"翻译为\"{1}\"。" -#: autosub/core.py:613 +#: autosub/core.py:618 msgid "Translation: " msgstr "翻译中: " -#: autosub/core.py:676 +#: autosub/core.py:683 msgid "Cancelling translation." msgstr "取消翻译。" -#: autosub/core.py:749 autosub/core.py:808 +#: autosub/core.py:756 autosub/core.py:815 msgid "Format \"{fmt}\" not supported. Use \"{default_fmt}\" instead." msgstr "不支持格式\"{fmt}\"。改用\"{default_fmt}\"。" -#: autosub/core.py:881 +#: autosub/core.py:888 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/core.py:884 +#: autosub/core.py:891 msgid "Input a new path (including directory and file name) for output file.\n" msgstr "为输出文件输入一个新的路径(包括路径和文件名)。\n" diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 006bcfa6..3a9002bc 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -10,7 +10,9 @@ - [未发布](#未发布) - [添加](#添加未发布) - - [改动](#修改未发布) + - [改动](#改动未发布) + - [修复](#修复未发布) + - [删除](#删除未发布) - [0.5.6-alpha - 2020-03-20](#056-alpha---2020-03-20) - [添加](#添加056-alpha) - [即将删除](#即将删除056-alpha) @@ -55,6 +57,14 @@ - 修改音频分割指令的更换条件为仅当用户不修改它时。 - 修改最长语音区域限制为60秒。 +#### 修复(未发布) + +- 修复list_to_googletrans中当最后一行是需要被分割时的长度计算问题。 + +#### 删除(未发布) + +- 删除Python 2.7支持。 + ### [0.5.6-alpha] - 2020-03-20 #### 添加(0.5.6-alpha) From 451049c01977e10342174034124064d8d064dd2b Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Wed, 25 Mar 2020 19:56:23 +0800 Subject: [PATCH 08/26] Add delete_chars in method list_to_googletrans. --- CHANGELOG.md | 3 + autosub/api_baidu.py | 14 +-- autosub/api_xfyun.py | 16 ++-- autosub/cmdline_utils.py | 12 ++- autosub/constants.py | 2 +- autosub/core.py | 14 ++- .../zh_CN/LC_MESSAGES/autosub.api_baidu.po | 4 +- .../LC_MESSAGES/autosub.cmdline_utils.po | 64 ++++++------- .../locale/zh_CN/LC_MESSAGES/autosub.core.po | 32 +++---- .../zh_CN/LC_MESSAGES/autosub.options.po | 94 ++++++++++--------- autosub/options.py | 9 ++ docs/CHANGELOG.zh-Hans.md | 3 + scripts/create_release.py | 2 +- scripts/pyinstaller_build.spec | 5 +- setup.py | 2 +- 15 files changed, 160 insertions(+), 116 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08576fd6..5626e673 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,15 +53,18 @@ Click up arrow to go back to TOC. - Add support for Xun Fei Yun Speech-to-Text WebSocket API. - Add support for Baidu Automatic Speech Recognition API. [issue #68](https://github.com/BingLingGroup/autosub/issues/68) - Add chars filter for the transcript result in XfyunWebSocketAPI. +- Add delete_chars in method list_to_googletrans. #### Changed(Unreleased) - Change the replacement condition of the audio_split_cmd only when the user doesn't modify it. - Change the MAX_REGION_SIZE_LIMIT into 60 seconds. +- Change all text file input decoding into "utf-8". #### Fixed(Unreleased) - Fix the size count bug when the last line been split in list_to_googletrans. +- Fix delete_chars issue when using `-of full-src`. #### Removed(Unreleased) diff --git a/autosub/api_baidu.py b/autosub/api_baidu.py index e836bfe5..5e9abaec 100644 --- a/autosub/api_baidu.py +++ b/autosub/api_baidu.py @@ -40,7 +40,8 @@ def baidu_dev_pid_to_lang_code( def get_baidu_transcript( - result_dict): + result_dict, + delete_chars=None): """ Function for getting transcript from Baidu ASR API result dictionary. Reference: https://ai.baidu.com/ai-doc/SPEECH/ek38lxj1u @@ -50,6 +51,10 @@ def get_baidu_transcript( if err_no != 0: raise exceptions.SpeechToTextException( json.dumps(result_dict, indent=4, ensure_ascii=False)) + if delete_chars: + result = result_dict["result"][0].translate( + str.maketrans(delete_chars, " " * len(delete_chars))) + return result.rstrip(" ") return result_dict["result"][0] except (KeyError, TypeError): return "" @@ -130,12 +135,7 @@ def __call__(self, filename): continue if not self.is_full_result: - if self.delete_chars: - transcript = get_baidu_transcript(result_dict).translate( - str.maketrans(self.delete_chars, " " * len(self.delete_chars))) - transcript = transcript.rstrip(" ") - return transcript - return get_baidu_transcript(result_dict) + return get_baidu_transcript(result_dict, self.delete_chars) return result_dict except KeyboardInterrupt: diff --git a/autosub/api_xfyun.py b/autosub/api_xfyun.py index b70bc2b0..f2bc78f4 100644 --- a/autosub/api_xfyun.py +++ b/autosub/api_xfyun.py @@ -67,7 +67,8 @@ def create_xfyun_url( def get_xfyun_transcript( - result_dict): + result_dict, + delete_chars=None): """ Function for getting transcript from Xun Fei Yun Speech-to-Text Websocket API result dictionary. Reference: https://www.xfyun.cn/doc/asr/voicedictation/API.html @@ -80,6 +81,10 @@ def get_xfyun_transcript( result = "" for item in result_dict["data"]["result"]["ws"]: result = result + item["cw"][0]["w"] + if delete_chars: + result = result.translate( + str.maketrans(delete_chars, " " * len(delete_chars))) + return result.rstrip(" ") return result except (KeyError, TypeError): return "" @@ -141,10 +146,6 @@ def __call__(self, filename): os.remove(filename) if self.is_full_result: return self.result_list - if self.delete_chars: - self.transcript.translate( - str.maketrans(self.delete_chars, " " * len(self.delete_chars))) - self.transcript = self.transcript.rstrip(" ") return self.transcript def on_message(self, web_socket, result): # pylint: disable=unused-argument @@ -156,7 +157,10 @@ def on_message(self, web_socket, result): # pylint: disable=unused-argument except ValueError: return if not self.is_full_result: - self.transcript = self.transcript + get_xfyun_transcript(web_socket_result) + self.transcript = self.transcript + \ + get_xfyun_transcript( + result_dict=web_socket_result, + delete_chars=self.delete_chars) else: self.result_list.append(web_socket_result) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 8837d314..16d2e608 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -251,7 +251,7 @@ def validate_config_args(args): # pylint: disable=too-many-branches, too-many-r for audio or video processing. """ if os.path.isfile(args.speech_config): - with open(args.speech_config, 'r') as config_file: + with open(args.speech_config, encoding='utf-8') as config_file: try: config_dict = json.load(config_file) except ValueError: @@ -726,7 +726,8 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma sleep_seconds=args.sleep_seconds, user_agent=args.user_agent, service_urls=args.service_urls, - drop_override_codes=args.drop_override_codes) + drop_override_codes=args.drop_override_codes, + delete_chars=args.gt_delete_chars) if not translated_text or len(translated_text) != len(text_list): raise exceptions.AutosubException( @@ -736,6 +737,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma args.output_files.remove("bilingual") bilingual_sub = pysubs2.SSAFile() bilingual_sub.styles = src_sub.styles + bilingual_sub.info = src_sub.info bilingual_sub.events = src_sub.events[:] if args.styles and \ len(styles_list) == 2 and \ @@ -787,6 +789,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma args.output_files.remove("dst-lf-src") bilingual_sub = pysubs2.SSAFile() bilingual_sub.styles = src_sub.styles + bilingual_sub.info = src_sub.info if args.styles and \ len(styles_list) == 2 and \ (args.format == 'ass' or @@ -839,6 +842,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma args.output_files.remove("src-lf-dst") bilingual_sub = pysubs2.SSAFile() bilingual_sub.styles = src_sub.styles + bilingual_sub.info = src_sub.info if args.styles and \ len(styles_list) == 2 and \ (args.format == 'ass' or @@ -891,6 +895,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma args.output_files.remove("dst") dst_sub = pysubs2.SSAFile() dst_sub.styles = src_sub.styles + dst_sub.info = src_sub.info if len(styles_list) == 2: sub_utils.pysubs2_ssa_event_add( src_ssafile=src_sub, @@ -1281,7 +1286,8 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen sleep_seconds=args.sleep_seconds, user_agent=args.user_agent, service_urls=args.service_urls, - drop_override_codes=args.drop_override_codes) + drop_override_codes=args.drop_override_codes, + delete_chars=args.gt_delete_chars) if not translated_text or len(translated_text) != len(regions): raise exceptions.AutosubException( diff --git a/autosub/constants.py b/autosub/constants.py index 76631165..571e2325 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -43,7 +43,7 @@ EXT_LOCALE = os.path.abspath(os.path.join(os.getcwd(), "locale")) if os.path.isfile(EXT_LOCALE): - with open(EXT_LOCALE, "r") as in_file: + with open(EXT_LOCALE, encoding='utf-8') as in_file: LINE = in_file.readline() LINE_LIST = LINE.split() if LINE_LIST[0] in SUPPORTED_LOCALE: diff --git a/autosub/core.py b/autosub/core.py index 5870280d..f74d3340 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -402,7 +402,9 @@ def xfyun_to_text( # pylint: disable=too-many-locals, too-many-arguments, result_list.append(result) transcript = "" for item in result: - transcript = transcript + api_xfyun.get_xfyun_transcript(item) + transcript = transcript + api_xfyun.get_xfyun_transcript( + result_dict=item, + delete_chars=delete_chars) if transcript: text_list.append(transcript) pbar.update(i) @@ -509,7 +511,8 @@ def baidu_to_text( # pylint: disable=too-many-locals, too-many-arguments, for i, result in enumerate(pool.imap(recognizer, audio_fragments)): if result: result_list.append(result) - transcript = api_baidu.get_baidu_transcript(result) + transcript = api_baidu.get_baidu_transcript( + result, delete_chars) if transcript: text_list.append(transcript) pbar.update(i) @@ -552,7 +555,8 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, sleep_seconds=constants.DEFAULT_SLEEP_SECONDS, user_agent=None, service_urls=None, - drop_override_codes=False): + drop_override_codes=False, + delete_chars=None): """ Give a text list, generate translated text list from GoogleTranslatorV2 api. """ @@ -659,6 +663,10 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, continue if i < valid_index[j + 1]: # if text is valid, append it + if delete_chars: + result_list[k] = result_list[k].translate( + str.maketrans(delete_chars, " " * len(delete_chars))) + result_list[k] = result_list[k].rstrip(" ") translated_text.append(result_list[k]) k = k + 1 i = i + 1 diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po index ed01d801..a927f4c7 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-23 19:35+0800\n" +"POT-Creation-Date: 2020-03-25 19:51+0800\n" "PO-Revision-Date: 2020-03-21 15:38+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,6 +17,6 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/api_baidu.py:78 +#: autosub/api_baidu.py:83 msgid "Error: Check you project if its ASR feature is enabled." msgstr "错误:检查你的项目是否打开了语音识别功能。" 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 b7dec35e..cc9efcc5 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-23 19:35+0800\n" +"POT-Creation-Date: 2020-03-24 11:50+0800\n" "PO-Revision-Date: 2020-03-20 20:45+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -325,16 +325,16 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:685 autosub/cmdline_utils.py:829 -#: autosub/cmdline_utils.py:1375 +#: autosub/cmdline_utils.py:685 autosub/cmdline_utils.py:832 +#: autosub/cmdline_utils.py:1381 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:689 autosub/cmdline_utils.py:781 -#: autosub/cmdline_utils.py:833 autosub/cmdline_utils.py:885 -#: autosub/cmdline_utils.py:1066 autosub/cmdline_utils.py:1229 -#: autosub/cmdline_utils.py:1271 autosub/cmdline_utils.py:1331 -#: autosub/cmdline_utils.py:1379 autosub/cmdline_utils.py:1427 +#: autosub/cmdline_utils.py:689 autosub/cmdline_utils.py:783 +#: autosub/cmdline_utils.py:836 autosub/cmdline_utils.py:889 +#: autosub/cmdline_utils.py:1071 autosub/cmdline_utils.py:1234 +#: autosub/cmdline_utils.py:1276 autosub/cmdline_utils.py:1337 +#: autosub/cmdline_utils.py:1385 autosub/cmdline_utils.py:1433 msgid "" "\n" "All works done." @@ -342,23 +342,23 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:733 autosub/cmdline_utils.py:1288 +#: autosub/cmdline_utils.py:734 autosub/cmdline_utils.py:1294 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:777 autosub/cmdline_utils.py:1327 +#: autosub/cmdline_utils.py:779 autosub/cmdline_utils.py:1333 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:881 autosub/cmdline_utils.py:1423 +#: autosub/cmdline_utils.py:885 autosub/cmdline_utils.py:1429 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:924 autosub/cmdline_utils.py:1468 +#: autosub/cmdline_utils.py:929 autosub/cmdline_utils.py:1474 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:966 +#: autosub/cmdline_utils.py:971 msgid "" "\n" "No works done. Check your \"-of\"/\"--output-files\" option." @@ -366,11 +366,11 @@ msgstr "" "\n" "啥都没做。检查你的\"-of\"/\"--output-files\"选项。" -#: autosub/cmdline_utils.py:971 +#: autosub/cmdline_utils.py:976 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:1005 +#: autosub/cmdline_utils.py:1010 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -378,11 +378,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:1015 +#: autosub/cmdline_utils.py:1020 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:1018 +#: autosub/cmdline_utils.py:1023 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -390,7 +390,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:1030 +#: autosub/cmdline_utils.py:1035 msgid "" "\n" "\"{name}\" has been deleted." @@ -398,19 +398,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:1034 +#: autosub/cmdline_utils.py:1039 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1063 autosub/cmdline_utils.py:1535 +#: autosub/cmdline_utils.py:1068 autosub/cmdline_utils.py:1541 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1087 +#: autosub/cmdline_utils.py:1092 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1091 +#: autosub/cmdline_utils.py:1096 msgid "" "Audio processing complete.\n" "All works done." @@ -418,11 +418,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1143 +#: autosub/cmdline_utils.py:1148 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1158 +#: autosub/cmdline_utils.py:1163 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -432,18 +432,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1163 +#: autosub/cmdline_utils.py:1168 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1177 +#: autosub/cmdline_utils.py:1182 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1189 +#: autosub/cmdline_utils.py:1194 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -451,11 +451,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1225 +#: autosub/cmdline_utils.py:1230 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1233 +#: autosub/cmdline_utils.py:1238 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -463,11 +463,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1267 autosub/cmdline_utils.py:1505 +#: autosub/cmdline_utils.py:1272 autosub/cmdline_utils.py:1511 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1477 +#: autosub/cmdline_utils.py:1483 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -475,7 +475,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1510 +#: autosub/cmdline_utils.py:1516 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.core.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po index c4d6f006..85692e20 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-23 19:35+0800\n" +"POT-Creation-Date: 2020-03-25 19:51+0800\n" "PO-Revision-Date: 2020-03-21 15:41+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -38,12 +38,12 @@ msgstr "" "将短片段语音发送给Google Speech V2 API并得到识别结果。" #: autosub/core.py:146 autosub/core.py:215 autosub/core.py:373 -#: autosub/core.py:485 +#: autosub/core.py:487 msgid "Speech-to-Text: " msgstr "语音转文字中: " -#: autosub/core.py:187 autosub/core.py:330 autosub/core.py:425 -#: autosub/core.py:532 +#: autosub/core.py:187 autosub/core.py:330 autosub/core.py:427 +#: autosub/core.py:535 msgid "" "Error: Connection error happened too many times.\n" "All works done." @@ -60,7 +60,7 @@ msgstr "" "\n" "将短片段语音发送给Google Cloud Speech V1P1Beta1 API并得到识别结果。" -#: autosub/core.py:338 autosub/core.py:433 autosub/core.py:540 +#: autosub/core.py:338 autosub/core.py:435 autosub/core.py:543 msgid "Receive something unexpected:" msgstr "收到未预期数据:" @@ -72,7 +72,7 @@ msgstr "" "\n" "将短片段语音发送给讯飞云WebSocket API并得到识别结果。" -#: autosub/core.py:457 +#: autosub/core.py:459 msgid "" "\n" "Sending short-term fragments to Baidu PRO ASR API and getting result." @@ -80,7 +80,7 @@ msgstr "" "\n" "将短片段语音发送给百度短语音识别极速版API并得到识别结果。" -#: autosub/core.py:460 +#: autosub/core.py:462 msgid "" "\n" "Sending short-term fragments to Baidu ASR API and getting result." @@ -88,19 +88,19 @@ msgstr "" "\n" "将短片段语音发送给百度短语音识别API并得到识别结果。" -#: autosub/core.py:471 +#: autosub/core.py:473 msgid "Get the token online." msgstr "在线获取token。" -#: autosub/core.py:476 +#: autosub/core.py:478 msgid "Use the token from the config." msgstr "使用配置文件中的token。" -#: autosub/core.py:479 +#: autosub/core.py:481 msgid "Failed to get the token. Error message:" msgstr "无法获取token。错误信息:" -#: autosub/core.py:563 +#: autosub/core.py:567 msgid "" "\n" "Translating text from \"{0}\" to \"{1}\"." @@ -108,24 +108,24 @@ msgstr "" "\n" "从\"{0}\"翻译为\"{1}\"。" -#: autosub/core.py:618 +#: autosub/core.py:622 msgid "Translation: " msgstr "翻译中: " -#: autosub/core.py:683 +#: autosub/core.py:691 msgid "Cancelling translation." msgstr "取消翻译。" -#: autosub/core.py:756 autosub/core.py:815 +#: autosub/core.py:764 autosub/core.py:823 msgid "Format \"{fmt}\" not supported. Use \"{default_fmt}\" instead." msgstr "不支持格式\"{fmt}\"。改用\"{default_fmt}\"。" -#: autosub/core.py:888 +#: autosub/core.py:896 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/core.py:891 +#: autosub/core.py:899 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 4dc423bf..a48c20a8 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-21 17:10+0800\n" -"PO-Revision-Date: 2020-03-21 17:11+0800\n" +"POT-Creation-Date: 2020-03-24 11:50+0800\n" +"PO-Revision-Date: 2020-03-24 11:52+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -134,8 +134,8 @@ msgid "List all available arguments." msgstr "列出所有可选参数。" #: autosub/options.py:92 autosub/options.py:101 autosub/options.py:110 -#: autosub/options.py:192 autosub/options.py:273 autosub/options.py:402 -#: autosub/options.py:598 +#: autosub/options.py:192 autosub/options.py:273 autosub/options.py:411 +#: autosub/options.py:607 msgid "path" msgstr "路径" @@ -188,7 +188,7 @@ msgstr "" "言行使用第二个。(参数个数为1或2)" #: autosub/options.py:137 autosub/options.py:148 autosub/options.py:158 -#: autosub/options.py:570 autosub/options.py:586 +#: autosub/options.py:579 autosub/options.py:595 msgid "lang_code" msgstr "语言代码" @@ -226,7 +226,7 @@ msgstr "" "用于翻译的目标语言的语言代码/语言标识符。同样的注意参考选项\"-SRC\"/\"--src-" "language\"。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:165 autosub/options.py:413 +#: autosub/options.py:165 autosub/options.py:422 msgid "mode" msgstr "模式" @@ -401,8 +401,8 @@ msgid "" msgstr "" "用于Speech-to-Text请求的并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:323 autosub/options.py:518 autosub/options.py:527 -#: autosub/options.py:536 +#: autosub/options.py:323 autosub/options.py:527 autosub/options.py:536 +#: autosub/options.py:545 msgid "second" msgstr "秒" @@ -436,11 +436,21 @@ msgid "" "translation result. (arg_num = 0)" msgstr "在翻译前删除所有文本中的ass特效标签。只影响翻译结果。(参数个数为0)" -#: autosub/options.py:355 +#: autosub/options.py:356 +#, python-format +msgid "" +"Replace the specific chars with a space after translation, and strip the " +"space at the end of each sentence. Only affect the translation result. " +"(arg_num = 0 or 1) (const: %(const)s)" +msgstr "" +"将指定字符替换为空格,并消除每句末尾空格。只会影响翻译结果。(参数个数为0或" +"1)(const为%(const)s)" + +#: autosub/options.py:364 msgid "Change the Google Speech V2 API URL into the http one. (arg_num = 0)" msgstr "将Google Speech V2 API的URL改为http类型。(参数个数为0)" -#: autosub/options.py:363 +#: autosub/options.py:372 #, python-format msgid "" "Add https proxy by setting environment variables. If arg_num is 0, use const " @@ -449,7 +459,7 @@ msgstr "" "通过设置环境变量的方式添加https代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:371 +#: autosub/options.py:380 #, python-format msgid "" "Add http proxy by setting environment variables. If arg_num is 0, use const " @@ -458,33 +468,33 @@ msgstr "" "通过设置环境变量的方式添加http代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:377 +#: autosub/options.py:386 msgid "username" msgstr "用户名" -#: autosub/options.py:378 +#: autosub/options.py:387 msgid "Set proxy username. (arg_num = 1)" msgstr "设置代理用户名。(参数个数为1)" -#: autosub/options.py:383 +#: autosub/options.py:392 msgid "password" msgstr "密码" -#: autosub/options.py:384 +#: autosub/options.py:393 msgid "Set proxy password. (arg_num = 1)" msgstr "设置代理密码。(参数个数为1)" -#: autosub/options.py:390 +#: autosub/options.py:399 #, python-format msgid "Show %(prog)s help message and exit. (arg_num = 0)" msgstr "显示%(prog)s的帮助信息并退出。(参数个数为0)" -#: autosub/options.py:398 +#: autosub/options.py:407 #, python-format msgid "Show %(prog)s version and exit. (arg_num = 0)" msgstr "显示%(prog)s的版本信息并退出。(参数个数为0)" -#: autosub/options.py:403 +#: autosub/options.py:412 msgid "" "Set service account key environment variable. It should be the file path of " "the JSON file that contains your service account credentials. Can be " @@ -497,7 +507,7 @@ msgstr "" "authentication/getting-started 当前支持:" "gcsv1(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" -#: autosub/options.py:414 +#: autosub/options.py:423 msgid "" "Option to control audio process. If not given the option, do normal " "conversion work. \"y\": pre-process the input first then start normal " @@ -516,15 +526,15 @@ msgstr "" "scripts/subgen.sh https://ffmpeg.org/ffmpeg-filters.html)(参数个数介于1和2" "之间)" -#: autosub/options.py:438 +#: autosub/options.py:447 msgid "Keep audio processing files to the output path. (arg_num = 0)" msgstr "将音频处理中产生的文件放在输出路径中。(参数个数为0)" -#: autosub/options.py:443 autosub/options.py:461 autosub/options.py:473 +#: autosub/options.py:452 autosub/options.py:470 autosub/options.py:482 msgid "command" msgstr "命令" -#: autosub/options.py:444 +#: autosub/options.py:453 msgid "" "This arg will override the default audio pre-process command. Every line of " "the commands need to be in quotes. Input file name is {in_}. Output file " @@ -533,7 +543,7 @@ msgstr "" "这个参数会取代默认的音频预处理命令。每行命令需要放在一个引号内。输入文件名写" "为{in_}。输出文件名写为{out_}。(参数个数大于1)" -#: autosub/options.py:456 +#: autosub/options.py:465 #, python-format msgid "" "Number of concurrent ffmpeg audio split process to make. (arg_num = 1) " @@ -541,7 +551,7 @@ msgid "" msgstr "" "用于ffmpeg音频切割的进程并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:463 +#: autosub/options.py:472 #, python-format msgid "" "(Experimental)This arg will override the default audio conversion command. " @@ -553,7 +563,7 @@ msgstr "" "除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数" "为%(default)s)" -#: autosub/options.py:475 +#: autosub/options.py:484 #, python-format msgid "" "(Experimental)This arg will override the default audio split command. Same " @@ -562,11 +572,11 @@ msgstr "" "(实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:482 +#: autosub/options.py:491 msgid "file_suffix" msgstr "文件名后缀" -#: autosub/options.py:484 +#: autosub/options.py:493 #, python-format msgid "" "(Experimental)This arg will override the default API audio suffix. (arg_num " @@ -575,11 +585,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数" "为%(default)s)" -#: autosub/options.py:490 +#: autosub/options.py:499 msgid "sample_rate" msgstr "采样率" -#: autosub/options.py:493 +#: autosub/options.py:502 #, python-format msgid "" "(Experimental)This arg will override the default API audio sample rate(Hz). " @@ -588,11 +598,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频采样率(赫兹)。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:499 +#: autosub/options.py:508 msgid "channel_num" msgstr "声道数" -#: autosub/options.py:502 +#: autosub/options.py:511 #, python-format msgid "" "(Experimental)This arg will override the default API audio channel. (arg_num " @@ -601,11 +611,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频声道数量。(参数个数为1)(默认" "参数为%(default)s)" -#: autosub/options.py:508 +#: autosub/options.py:517 msgid "energy" msgstr "能量(相对值)" -#: autosub/options.py:511 +#: autosub/options.py:520 #, python-format msgid "" "The energy level which determines the region to be detected. Ref: https://" @@ -616,7 +626,7 @@ msgstr "" "latest/apitutorial.html#examples-using-real-audio-data(参数个数为1)(默认参" "数为%(default)s)" -#: autosub/options.py:521 +#: autosub/options.py:530 #, python-format msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" @@ -624,7 +634,7 @@ msgstr "" "最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数" "为%(default)s)" -#: autosub/options.py:530 +#: autosub/options.py:539 #, python-format msgid "" "Maximum region size. Same docs above. (arg_num = 1) (default: %(default)s)" @@ -632,7 +642,7 @@ msgstr "" "最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数" "为%(default)s)" -#: autosub/options.py:539 +#: autosub/options.py:548 #, python-format msgid "" "Maximum length of a tolerated silence within a valid audio activity. Same " @@ -641,7 +651,7 @@ msgstr "" "在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如" "上。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:546 +#: autosub/options.py:555 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." @@ -650,7 +660,7 @@ msgstr "" "如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://" "auditok.readthedocs.io/en/latest/core.html#class-summary(参数个数为0)" -#: autosub/options.py:554 +#: autosub/options.py:563 msgid "" "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)" @@ -658,7 +668,7 @@ msgstr "" "参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" "个数为0)" -#: autosub/options.py:560 +#: autosub/options.py:569 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 " @@ -669,7 +679,7 @@ msgstr "" "SubtitleEdit来对其进行转换。如果输出格式是\"sub\"且输入文件是音频无法获取到视" "频帧率时,你需要提供fps选项指定帧率。(参数个数为0)" -#: autosub/options.py:573 +#: autosub/options.py:582 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 " @@ -687,7 +697,7 @@ msgstr "" "言)-扩展-私有(https://www.zhihu.com/question/21980689/answer/93615123)(参" "数个数为0或1)" -#: autosub/options.py:589 +#: autosub/options.py:598 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 " @@ -697,7 +707,7 @@ msgstr "" "言代码。否则会给出一个“好的匹配”的清单。同样的参考文档如上。(参数个数为0或" "1)" -#: autosub/options.py:599 +#: autosub/options.py:608 #, python-format msgid "" "Use py-googletrans to detect a sub file's first line language. And list a " diff --git a/autosub/options.py b/autosub/options.py index 32b118ca..7e553868 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -349,6 +349,15 @@ def get_cmd_parser(): # pylint: disable=too-many-statements "Only affect the translation result. " "(arg_num = 0)")) + pygt_group.add_argument( + '-gt-dc', '--gt-delete-chars', + nargs='?', metavar="chars", + const=",。!", + help=_("Replace the specific chars with a space after translation, " + "and strip the space at the end of each sentence. " + "Only affect the translation result. " + "(arg_num = 0 or 1) (const: %(const)s)")) + network_group.add_argument( '-hsa', '--http-speech-api', action='store_true', diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 3a9002bc..94619377 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -51,15 +51,18 @@ - 添加讯飞开放平台语音听写(流式版)WebSocket API支持。 - 添加百度智能云语音识别/极速语音识别API支持。[issue #68](https://github.com/BingLingGroup/autosub/issues/68) - 添加字符过滤器用于讯飞开放平台语音听写。 +- 添加delete_chars功能到方法list_to_googletrans里。 #### 改动(未发布) - 修改音频分割指令的更换条件为仅当用户不修改它时。 - 修改最长语音区域限制为60秒。 +- 修改所有文本文件输入编码为"utf-8"。 #### 修复(未发布) - 修复list_to_googletrans中当最后一行是需要被分割时的长度计算问题。 +- 修复delete_chars问题当使用`-of full-src`时。 #### 删除(未发布) diff --git a/scripts/create_release.py b/scripts/create_release.py index 4d00fb18..059446ba 100644 --- a/scripts/create_release.py +++ b/scripts/create_release.py @@ -73,7 +73,7 @@ def copytree(src, os.makedirs(dist_path) metadata = {} - with open(os.path.join(here, package_name, "metadata.py")) as metafile: + with open(os.path.join(here, package_name, "metadata.py"), encoding='utf-8') as metafile: exec(metafile.read(), metadata) target = os.path.join(here, ".release", package_name) diff --git a/scripts/pyinstaller_build.spec b/scripts/pyinstaller_build.spec index 9ff5540a..2672cc2e 100644 --- a/scripts/pyinstaller_build.spec +++ b/scripts/pyinstaller_build.spec @@ -13,8 +13,9 @@ a = Analysis([r"..\autosub\__main__.py", r"..\autosub\lang_code_utils.py", r"..\autosub\metadata.py", r"..\autosub\options.py", - r"..\autosub\google_api.py", - r"..\autosub\xfyun_api.py" + r"..\autosub\api_google.py", + r"..\autosub\api_xfyun.py", + r"..\autosub\api_baidu.py", r"..\autosub\sub_utils.py",], pathex=[r'C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x64'], binaries=[], diff --git a/setup.py b/setup.py index 3307e2db..784f06b9 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ NAME = "autosub" -with open(os.path.join(here, NAME, "metadata.py")) as metafile: +with open(os.path.join(here, NAME, "metadata.py"), encoding='utf-8') as metafile: exec(metafile.read(), metadata) setup( From fed650998e32220aad23aed377603856328ec686 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Thu, 26 Mar 2020 15:26:02 +0800 Subject: [PATCH 09/26] Add merge_src_assfile method --- CHANGELOG.md | 1 + autosub/__init__.py | 5 + autosub/cmdline_utils.py | 84 +++++- autosub/constants.py | 3 + .../LC_MESSAGES/autosub.cmdline_utils.po | 169 +++++------ .../zh_CN/LC_MESSAGES/autosub.options.po | 263 ++++++++++-------- .../data/locale/zh_CN/LC_MESSAGES/autosub.po | 16 +- .../zh_CN/LC_MESSAGES/autosub.sub_utils.po | 22 ++ autosub/options.py | 26 ++ autosub/sub_utils.py | 74 +++++ docs/CHANGELOG.zh-Hans.md | 1 + 11 files changed, 453 insertions(+), 211 deletions(-) create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po diff --git a/CHANGELOG.md b/CHANGELOG.md index 5626e673..736dff28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Click up arrow to go back to TOC. - Add support for Baidu Automatic Speech Recognition API. [issue #68](https://github.com/BingLingGroup/autosub/issues/68) - Add chars filter for the transcript result in XfyunWebSocketAPI. - Add delete_chars in method list_to_googletrans. +- Add merge_src_assfile method. #### Changed(Unreleased) diff --git a/autosub/__init__.py b/autosub/__init__.py index faf63b79..9718da1f 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -163,6 +163,11 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- result = cmdline_utils.validate_sp_args(args) fps = cmdline_utils.get_fps(args=args, input_m=input_m) if result: + args.output_files = args.output_files & \ + constants.DEFAULT_SUB_MODE_SET + if not args.output_files: + raise exceptions.AutosubException( + _("Error: No valid \"-of\"/\"--output-files\" arguments.")) cmdline_utils.sub_trans(args, input_m=input_m, fps=fps, diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 16d2e608..a8c2fd7e 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -223,12 +223,6 @@ def validate_io( # pylint: disable=too-many-branches, too-many-statements if not args.output_files: raise exceptions.AutosubException( _("Error: No valid \"-of\"/\"--output-files\" arguments.")) - else: - args.output_files = args.output_files & \ - constants.DEFAULT_SUB_MODE_SET - if not args.output_files: - raise exceptions.AutosubException( - _("Error: No valid \"-of\"/\"--output-files\" arguments.")) if args.best_match: args.best_match = {k.lower() for k in args.best_match} @@ -691,6 +685,78 @@ def sub_conversion( # pylint: disable=too-many-branches, too-many-statements, t except KeyError: pass + try: + args.output_files.remove("src-lf-dst") + new_sub = sub_utils.merge_bilingual_assfile( + subtitles=src_sub, + order=0 + ) + 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.2", + extension=extension) + + subtitles_file_path = core.str_to_file( + str_=sub_string, + output=sub_name, + input_m=input_m) + # subtitles string to file + print(_("\"src-lf-dst\" subtitles file " + "created at \"{}\".").format(subtitles_file_path)) + + if not args.output_files: + raise exceptions.AutosubException(_("\nAll works done.")) + + except KeyError: + pass + + try: + args.output_files.remove("join-events") + new_sub = sub_utils.merge_src_assfile( + subtitles=src_sub, + max_join_size=args.max_join_size, + max_delta_time=int(args.max_delta_time * 1000), + delimiters=args.delimiters + ) + 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="join", + extension=extension) + + subtitles_file_path = core.str_to_file( + str_=sub_string, + output=sub_name, + input_m=input_m) + # subtitles string to file + print(_("\"join-events\" 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, @@ -965,12 +1031,6 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen """ Give args and process an input audio or video file. """ - - if not args.output_files: - raise exceptions.AutosubException( - _("\nNo works done." - " Check your \"-of\"/\"--output-files\" option.")) - if args.ext_regions: # use external speech regions print(_("Use external speech regions.")) diff --git a/autosub/constants.py b/autosub/constants.py index 571e2325..c923b825 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -80,6 +80,9 @@ DEFAULT_SIZE_PER_TRANS = 4000 DEFAULT_SLEEP_SECONDS = 5 +DEFAULT_MAX_SIZE_PER_EVENT = 100 +DEFAULT_EVENT_DELIMITER = r"!()*,-.:;?[\]^_`~" + DEFAULT_SUBTITLES_FORMAT = 'srt' DEFAULT_MODE_SET = \ 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 cc9efcc5..7d103344 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-24 11:50+0800\n" -"PO-Revision-Date: 2020-03-20 20:45+0800\n" +"POT-Creation-Date: 2020-03-26 15:15+0800\n" +"PO-Revision-Date: 2020-03-26 14:48+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -118,61 +118,61 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:225 autosub/cmdline_utils.py:231 +#: autosub/cmdline_utils.py:225 msgid "Error: No valid \"-of\"/\"--output-files\" arguments." msgstr "错误:\"-of\"/\"--output-files\"参数无效。" -#: autosub/cmdline_utils.py:242 +#: autosub/cmdline_utils.py:236 msgid "Input is a subtitles file." msgstr "输入是一个字幕文件。" -#: autosub/cmdline_utils.py:259 +#: autosub/cmdline_utils.py:253 msgid "Error: Can't decode speech config file \"{filename}\"." msgstr "错误:无法解码语音配置文件\"{filename}\"。" -#: autosub/cmdline_utils.py:263 +#: autosub/cmdline_utils.py:257 msgid "Error: Speech config file \"{filename}\" doesn't exist." msgstr "错误:语音配置文件\"{filename}\"不存在。" -#: autosub/cmdline_utils.py:309 +#: autosub/cmdline_utils.py:303 msgid "Error: No \"app_id\" found in speech config file \"{filename}\"." msgstr "错误:\"app_id\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:320 +#: autosub/cmdline_utils.py:314 msgid "Error: No \"api_key\" found in speech config file \"{filename}\"." msgstr "错误:\"api_key\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:331 +#: autosub/cmdline_utils.py:325 msgid "Error: No \"api_secret\" found in speech config file \"{filename}\"." msgstr "错误:\"api_secret\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:343 +#: autosub/cmdline_utils.py:337 msgid "Error: No \"language\" found in speech config file \"{filename}\"." msgstr "错误:\"language\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:379 +#: autosub/cmdline_utils.py:373 msgid "Error: \"-slp\"/\"--sleep-seconds\" arg is illegal." msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" -#: autosub/cmdline_utils.py:387 +#: autosub/cmdline_utils.py:381 msgid "Let speech lang code to match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:393 +#: autosub/cmdline_utils.py:387 msgid "Use langcodes to standardize the result." msgstr "使用langcodes来标准化结果。" -#: autosub/cmdline_utils.py:395 autosub/cmdline_utils.py:451 -#: autosub/cmdline_utils.py:473 autosub/cmdline_utils.py:546 -#: autosub/cmdline_utils.py:573 +#: autosub/cmdline_utils.py:389 autosub/cmdline_utils.py:445 +#: autosub/cmdline_utils.py:467 autosub/cmdline_utils.py:540 +#: autosub/cmdline_utils.py:567 msgid "Use \"{lang_code}\" instead." msgstr "改用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:398 +#: autosub/cmdline_utils.py:392 msgid "Match failed. Still using \"{lang_code}\"." msgstr "匹配失败。仍在使用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:401 +#: autosub/cmdline_utils.py:395 msgid "" "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" "list-speech-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -182,35 +182,35 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:409 +#: autosub/cmdline_utils.py:403 msgid "Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal." msgstr "错误:\"-mnc\"/\"--min-confidence\"参数的值不合法。" -#: autosub/cmdline_utils.py:414 +#: autosub/cmdline_utils.py:408 msgid "" "Error: You must provide \"-sconf\", \"--speech-config\" option when using " "Xun Fei Yun API." msgstr "错误:使用讯飞云API时,你必须提供\"-sconf\",\"--speech-config\"选项。" -#: autosub/cmdline_utils.py:418 +#: autosub/cmdline_utils.py:412 msgid "" "Translation destination language not provided. Only performing speech " "recognition." msgstr "翻译目的语言未提供。只进行语音识别。" -#: autosub/cmdline_utils.py:423 +#: autosub/cmdline_utils.py:417 msgid "Translation source language not provided. Use speech language instead." msgstr "翻译源语言未提供。改用语音语言。" -#: autosub/cmdline_utils.py:444 +#: autosub/cmdline_utils.py:438 msgid "Let translation source lang code to match py-googletrans lang codes." msgstr "让翻译源语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:455 autosub/cmdline_utils.py:477 +#: autosub/cmdline_utils.py:449 autosub/cmdline_utils.py:471 msgid "Error: Match failed." msgstr "错误:匹配失败。" -#: autosub/cmdline_utils.py:458 +#: autosub/cmdline_utils.py:452 msgid "" "Error: Translation source language \"{src}\" is not supported. Run with \"-" "ltc\"/\"--list-translation-codes\" to see all supported languages. Or use \"-" @@ -220,12 +220,12 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:466 +#: autosub/cmdline_utils.py:460 msgid "" "Let translation destination lang code to match py-googletrans lang codes." msgstr "让翻译目的语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:480 +#: autosub/cmdline_utils.py:474 msgid "" "Error: Translation destination language \"{dst}\" is not supported. Run with " "\"-ltc\"/\"--list-translation-codes\" to see all supported languages. Or use " @@ -234,29 +234,29 @@ msgstr "" "错误:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" "项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最佳匹配。" -#: autosub/cmdline_utils.py:488 +#: autosub/cmdline_utils.py:482 msgid "" "Speech language is the same as the destination language. Only performing " "speech recognition." msgstr "语音语言和目的语言一致。只进行语音识别。" -#: autosub/cmdline_utils.py:497 +#: autosub/cmdline_utils.py:491 msgid "You've already input times. No works done." msgstr "你已经输入了时间轴。啥都没做。" -#: autosub/cmdline_utils.py:501 +#: autosub/cmdline_utils.py:495 msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:509 autosub/cmdline_utils.py:601 +#: autosub/cmdline_utils.py:503 autosub/cmdline_utils.py:595 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" -#: autosub/cmdline_utils.py:522 +#: autosub/cmdline_utils.py:516 msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" -#: autosub/cmdline_utils.py:538 +#: autosub/cmdline_utils.py:532 msgid "" "Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages." @@ -264,11 +264,11 @@ msgstr "" "警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:550 autosub/cmdline_utils.py:577 +#: autosub/cmdline_utils.py:544 autosub/cmdline_utils.py:571 msgid "Match failed. Still using \"{lang_code}\". Program stopped." msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" -#: autosub/cmdline_utils.py:556 +#: autosub/cmdline_utils.py:550 msgid "" "Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -278,7 +278,7 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:565 +#: autosub/cmdline_utils.py:559 msgid "" "Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages." @@ -286,7 +286,7 @@ msgstr "" "警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" "行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:583 +#: autosub/cmdline_utils.py:577 msgid "" "Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" @@ -296,12 +296,12 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:591 +#: autosub/cmdline_utils.py:585 msgid "" "Error: Translation source language is the same as the destination language." msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:615 +#: autosub/cmdline_utils.py:609 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -309,7 +309,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:622 +#: autosub/cmdline_utils.py:616 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -317,7 +317,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:629 +#: autosub/cmdline_utils.py:623 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -325,16 +325,17 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:685 autosub/cmdline_utils.py:832 -#: autosub/cmdline_utils.py:1381 +#: autosub/cmdline_utils.py:679 autosub/cmdline_utils.py:898 +#: autosub/cmdline_utils.py:1441 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:689 autosub/cmdline_utils.py:783 -#: autosub/cmdline_utils.py:836 autosub/cmdline_utils.py:889 -#: autosub/cmdline_utils.py:1071 autosub/cmdline_utils.py:1234 -#: autosub/cmdline_utils.py:1276 autosub/cmdline_utils.py:1337 -#: autosub/cmdline_utils.py:1385 autosub/cmdline_utils.py:1433 +#: autosub/cmdline_utils.py:683 autosub/cmdline_utils.py:718 +#: autosub/cmdline_utils.py:755 autosub/cmdline_utils.py:849 +#: autosub/cmdline_utils.py:902 autosub/cmdline_utils.py:955 +#: autosub/cmdline_utils.py:1131 autosub/cmdline_utils.py:1294 +#: autosub/cmdline_utils.py:1336 autosub/cmdline_utils.py:1397 +#: autosub/cmdline_utils.py:1445 autosub/cmdline_utils.py:1493 msgid "" "\n" "All works done." @@ -342,35 +343,32 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:734 autosub/cmdline_utils.py:1294 +#: autosub/cmdline_utils.py:714 autosub/cmdline_utils.py:951 +#: autosub/cmdline_utils.py:1489 +msgid "\"src-lf-dst\" subtitles file created at \"{}\"." +msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" + +#: autosub/cmdline_utils.py:751 +msgid "\"join-events\" subtitles file created at \"{}\"." +msgstr "\"join-events\"字幕创建在了\"{}\"。" + +#: autosub/cmdline_utils.py:800 autosub/cmdline_utils.py:1354 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:779 autosub/cmdline_utils.py:1333 +#: autosub/cmdline_utils.py:845 autosub/cmdline_utils.py:1393 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:885 autosub/cmdline_utils.py:1429 -msgid "\"src-lf-dst\" subtitles file created at \"{}\"." -msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" - -#: autosub/cmdline_utils.py:929 autosub/cmdline_utils.py:1474 +#: autosub/cmdline_utils.py:995 autosub/cmdline_utils.py:1534 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:971 -msgid "" -"\n" -"No works done. Check your \"-of\"/\"--output-files\" option." -msgstr "" -"\n" -"啥都没做。检查你的\"-of\"/\"--output-files\"选项。" - -#: autosub/cmdline_utils.py:976 +#: autosub/cmdline_utils.py:1036 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:1010 +#: autosub/cmdline_utils.py:1070 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -378,11 +376,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:1020 +#: autosub/cmdline_utils.py:1080 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:1023 +#: autosub/cmdline_utils.py:1083 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -390,7 +388,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:1035 +#: autosub/cmdline_utils.py:1095 msgid "" "\n" "\"{name}\" has been deleted." @@ -398,19 +396,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:1039 +#: autosub/cmdline_utils.py:1099 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1068 autosub/cmdline_utils.py:1541 +#: autosub/cmdline_utils.py:1128 autosub/cmdline_utils.py:1601 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1092 +#: autosub/cmdline_utils.py:1152 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1096 +#: autosub/cmdline_utils.py:1156 msgid "" "Audio processing complete.\n" "All works done." @@ -418,11 +416,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1148 +#: autosub/cmdline_utils.py:1208 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1163 +#: autosub/cmdline_utils.py:1223 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -432,18 +430,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1168 +#: autosub/cmdline_utils.py:1228 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1182 +#: autosub/cmdline_utils.py:1242 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1194 +#: autosub/cmdline_utils.py:1254 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -451,11 +449,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1230 +#: autosub/cmdline_utils.py:1290 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1238 +#: autosub/cmdline_utils.py:1298 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -463,11 +461,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1272 autosub/cmdline_utils.py:1511 +#: autosub/cmdline_utils.py:1332 autosub/cmdline_utils.py:1571 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1483 +#: autosub/cmdline_utils.py:1543 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -475,7 +473,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1516 +#: autosub/cmdline_utils.py:1576 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output regions subtitles file only." @@ -483,6 +481,13 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出时间轴文件。" +#~ msgid "" +#~ "\n" +#~ "No works done. Check your \"-of\"/\"--output-files\" option." +#~ msgstr "" +#~ "\n" +#~ "啥都没做。检查你的\"-of\"/\"--output-files\"选项。" + #~ msgid "Error: Wrong API code." #~ msgstr "错误:错误的API代码。" 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 a48c20a8..73758465 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-24 11:50+0800\n" +"POT-Creation-Date: 2020-03-26 15:14+0800\n" "PO-Revision-Date: 2020-03-24 11:52+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -93,53 +93,63 @@ msgid "" msgstr "控制翻译的选项。同时也是默认的翻译方法。可能随时会被谷歌爸爸封。" #: autosub/options.py:74 +#, fuzzy +msgid "Subtitles Conversion Options" +msgstr "音频处理选项" + +#: autosub/options.py:75 +#, fuzzy +msgid "Options to control subtitles conversions.(Experimental)" +msgstr "控制音频处理的选项。" + +#: autosub/options.py:77 msgid "Network Options" msgstr "网络选项" -#: autosub/options.py:75 +#: autosub/options.py:78 msgid "Options to control network." msgstr "控制网络的选项。" -#: autosub/options.py:77 +#: autosub/options.py:80 msgid "Other Options" msgstr "其他选项" -#: autosub/options.py:78 +#: autosub/options.py:81 msgid "Other options to control." msgstr "控制其他东西的选项。" -#: autosub/options.py:80 +#: autosub/options.py:83 msgid "Audio Processing Options" msgstr "音频处理选项" -#: autosub/options.py:81 +#: autosub/options.py:84 msgid "Options to control audio processing." msgstr "控制音频处理的选项。" -#: autosub/options.py:83 +#: autosub/options.py:86 msgid "Auditok Options" msgstr "Auditok的选项" -#: autosub/options.py:84 +#: autosub/options.py:87 msgid "" "Options to control Auditok when not using external speech regions control." msgstr "不使用外部语音区域控制时,用于控制Auditok的选项。" -#: autosub/options.py:87 +#: autosub/options.py:90 msgid "List Options" msgstr "列表选项" -#: autosub/options.py:88 +#: autosub/options.py:91 msgid "List all available arguments." msgstr "列出所有可选参数。" -#: autosub/options.py:92 autosub/options.py:101 autosub/options.py:110 -#: autosub/options.py:192 autosub/options.py:273 autosub/options.py:411 -#: autosub/options.py:607 +#: autosub/options.py:95 autosub/options.py:104 autosub/options.py:113 +#: autosub/options.py:195 autosub/options.py:276 autosub/options.py:437 +#: autosub/options.py:633 msgid "path" msgstr "路径" -#: autosub/options.py:93 +#: autosub/options.py:96 msgid "" "The path to the video/audio/subtitles file that needs to generate subtitles. " "When it is a subtitles file, the program will only translate it. (arg_num = " @@ -148,7 +158,7 @@ msgstr "" "用于生成字幕文件的视频/音频/字幕文件。如果输入文件是字幕文件,程序仅会对其进" "行翻译。(参数个数为1)" -#: autosub/options.py:102 +#: autosub/options.py:105 msgid "" "Path to the subtitles file which provides external speech regions, which is " "one of the formats that pysubs2 supports and overrides the default method to " @@ -157,7 +167,7 @@ msgstr "" "提供外部语音区域(时间轴)的字幕文件。该字幕文件格式需要是pysubs2所支持的。使" "用后会替换掉默认的自动寻找语音区域(时间轴)的功能。(参数个数为1)" -#: autosub/options.py:112 +#: autosub/options.py:115 msgid "" "Valid when your output format is \"ass\"/\"ssa\". Path to the subtitles file " "which provides \"ass\"/\"ssa\" styles for your output. If the arg_num is 0, " @@ -168,11 +178,11 @@ msgstr "" "幕文件。如果不提供参数,它会使用来自\"-esr\"/\"--external-speech-regions\"选" "项提供的样式。更多信息详见\"-sn\"/\"--styles-name\"。(参数个数为0或1)" -#: autosub/options.py:123 +#: autosub/options.py:126 msgid "style_name" msgstr "样式名" -#: autosub/options.py:124 +#: autosub/options.py:127 msgid "" "Valid when your output format is \"ass\"/\"ssa\" and \"-sty\"/\"--styles\" " "is given. Adds \"ass\"/\"ssa\" styles to your events. If not provided, " @@ -187,24 +197,24 @@ msgstr "" "数作为样式名。如果参数个数为2,源语言字幕行会使用第一个参数作为样式名。目标语" "言行使用第二个。(参数个数为1或2)" -#: autosub/options.py:137 autosub/options.py:148 autosub/options.py:158 -#: autosub/options.py:579 autosub/options.py:595 +#: autosub/options.py:140 autosub/options.py:151 autosub/options.py:161 +#: autosub/options.py:605 autosub/options.py:621 msgid "lang_code" msgstr "语言代码" -#: autosub/options.py:138 +#: autosub/options.py:141 #, python-format 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/" "speech-to-text/docs/languages(参数个数为1)(默认参数: %(default)s)" -#: autosub/options.py:149 +#: autosub/options.py:152 #, python-format msgid "" "Lang code/Lang tag for translation source language. If not given, use " @@ -214,10 +224,10 @@ msgid "" msgstr "" "用于翻译的源语言的语言代码/语言标识符。如果没有提供,会使用langcodes从列表里" "获取一个最佳匹配选项\"-S\"/\"--speech-language\"的语言代码。如果使用py-" -"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数" -"为%(default)s)" +"googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数为%" +"(default)s)" -#: autosub/options.py:159 +#: autosub/options.py:162 #, python-format msgid "" "Lang code/Lang tag for translation destination language. Same attention in " @@ -226,11 +236,11 @@ msgstr "" "用于翻译的目标语言的语言代码/语言标识符。同样的注意参考选项\"-SRC\"/\"--src-" "language\"。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:165 autosub/options.py:422 +#: autosub/options.py:168 autosub/options.py:448 msgid "mode" msgstr "模式" -#: autosub/options.py:167 +#: autosub/options.py:170 msgid "" "Allow langcodes to get a best matching lang code when your input is wrong. " "Only functional for py-googletrans and Google Speech V2. Available modes: s, " @@ -242,7 +252,7 @@ msgstr "" "\"-S\"/\"--speech-language\"。\"src\"指\"-SRC\"/\"--src-language\"。\"d\"指" "\"-D\"/\"--dst-language\"。(参数个数在1到3之间)" -#: autosub/options.py:181 +#: autosub/options.py:184 msgid "" "An integer between 0 and 100 to control the good match group of \"-lsc\"/\"--" "list-speech-codes\" or \"-ltc\"/\"--list-translation-codes\" or the match " @@ -254,7 +264,7 @@ msgstr "" "best-match\"选项中的最佳匹配结果。结果会是一组“好的匹配”,其分数需要超过这个" "参数的值。(参数个数为1)" -#: autosub/options.py:193 +#: autosub/options.py:196 msgid "" "The output path for subtitles file. (default: the \"input\" path combined " "with the proper name tails) (arg_num = 1)" @@ -262,11 +272,11 @@ msgstr "" "输出字幕文件的路径。(默认值是\"input\"路径和适当的文件名后缀的结合)(参数个" "数为1)" -#: autosub/options.py:199 +#: autosub/options.py:202 msgid "format" msgstr "格式" -#: autosub/options.py:200 +#: autosub/options.py:203 msgid "" "Destination subtitles format. If not provided, use the extension in the \"-o" "\"/\"--output\" arg. If \"-o\"/\"--output\" arg doesn't provide the " @@ -279,18 +289,18 @@ msgstr "" "果\"-i\"/\"--input\"的参数是一个字幕文件,那么使用和字幕文件相同的扩展名。" "(参数个数为1)(默认参数为{dft})" -#: autosub/options.py:213 +#: autosub/options.py:216 msgid "" "Prevent pauses and allow files to be overwritten. Stop the program when your " "args are wrong. (arg_num = 0)" msgstr "" "避免任何暂停和覆写文件的行为。如果参数有误,会直接停止程序。(参数个数为0)" -#: autosub/options.py:218 +#: autosub/options.py:221 msgid "type" msgstr "种类" -#: autosub/options.py:221 +#: autosub/options.py:224 #, python-format msgid "" "Output more files. Available types: regions, src, full-src, dst, bilingual, " @@ -308,7 +318,7 @@ msgstr "" "字幕行中,且目标语言先于源语言。src-lf-dst:源语言和目标语言在同一字幕行中," "且源语言先于目标语言。(参数个数在6和1之间)(默认参数为%(default)s)" -#: autosub/options.py:238 +#: autosub/options.py:241 msgid "" "Valid when your output format is \"sub\". If input, it will override the fps " "check on the input file. Ref: https://pysubs2.readthedocs.io/en/latest/api-" @@ -318,11 +328,11 @@ msgstr "" "查。参考:https://pysubs2.readthedocs.io/en/latest/api-reference." "html#supported-input-output-formats(参数个数为1)" -#: autosub/options.py:247 +#: autosub/options.py:250 msgid "API_code" msgstr "API代码" -#: autosub/options.py:250 +#: autosub/options.py:253 #, python-format msgid "" "Choose which Speech-to-Text API to use. Currently support: gsv2: Google " @@ -330,18 +340,18 @@ msgid "" "Cloud Speech-to-Text V1P1Beta1 (https://cloud.google.com/speech-to-text/" "docs). xfyun: Xun Fei Yun Speech-to-Text WebSocket API (https://www.xfyun.cn/" "doc/asr/voicedictation/API.html). baidu: Baidu Automatic Speech Recognition " -"API (https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) (arg_num = 1) (default: " -"%(default)s)" +"API (https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) (arg_num = 1) (default: %" +"(default)s)" msgstr "" "选择使用Speech-to-Text API。当前支持:gsv2:Google Speech V2 (https://" "github.com/gillesdemey/google-speech-v2)。 gcsv1:Google Cloud Speech-to-" "Text V1P1Beta1 (https://cloud.google.com/speech-to-text/docs)。xfyun:讯飞" "开放平台语音听写(流式版)WebSocket API(https://www.xfyun.cn/doc/asr/" "voicedictation/API.html)。baidu: 百度短语音识别/短语音识别极速版(https://" -"ai.baidu.com/ai-doc/SPEECH/Vk38lxily)(参数个数为1)(默认参数" -"为%(default)s)" +"ai.baidu.com/ai-doc/SPEECH/Vk38lxily)(参数个数为1)(默认参数为%(default)" +"s)" -#: autosub/options.py:264 +#: autosub/options.py:267 msgid "" "The API key for Google Speech-to-Text API. (arg_num = 1) Currently support: " "gsv2: The API key for gsv2. (default: Free API key) gcsv1: The API key for " @@ -352,7 +362,7 @@ msgstr "" "钥。(默认参数为免费API密钥)gcsv1:gcsv1的API密钥。(如果使用了,可以覆盖 " "\"-sa\"/\"--service-account\"提供的服务账号凭据)" -#: autosub/options.py:275 +#: autosub/options.py:278 #, python-format msgid "" "Use Speech-to-Text recognition config file to send request. Override these " @@ -376,7 +386,7 @@ msgstr "" "ai-doc/SPEECH/ek38lxj1u)。如果参数个数是0,使用const路径。(参数个数为0或1)" "(const为%(const)s)" -#: autosub/options.py:300 +#: autosub/options.py:303 #, python-format msgid "" "Google Speech-to-Text API response for text confidence. A float value " @@ -389,11 +399,11 @@ msgstr "" "除。参考:https://github.com/BingLingGroup/google-speech-v2#response(参数个" "数为1)(默认参数为%(default)s)" -#: autosub/options.py:310 +#: autosub/options.py:313 msgid "Drop any regions without speech recognition result. (arg_num = 0)" msgstr "删除所有没有语音识别结果的空轴。(参数个数为0)" -#: autosub/options.py:318 +#: autosub/options.py:321 #, python-format msgid "" "Number of concurrent Speech-to-Text requests to make. (arg_num = 1) " @@ -401,21 +411,21 @@ msgid "" msgstr "" "用于Speech-to-Text请求的并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:323 autosub/options.py:527 autosub/options.py:536 -#: autosub/options.py:545 +#: autosub/options.py:326 autosub/options.py:374 autosub/options.py:553 +#: autosub/options.py:562 autosub/options.py:571 msgid "second" msgstr "秒" -#: autosub/options.py:326 +#: autosub/options.py:329 #, python-format 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:334 +#: autosub/options.py:337 msgid "" "(Experimental)Customize request urls. Ref: https://py-googletrans." "readthedocs.io/en/latest/ (arg_num >= 1)" @@ -423,20 +433,20 @@ msgstr "" "(实验性)自定义多个请求URL。参考:https://py-googletrans.readthedocs.io/en/" "latest/(参数个数大于等于1)" -#: autosub/options.py:341 +#: autosub/options.py:344 msgid "" "(Experimental)Customize User-Agent headers. Same docs above. (arg_num = 1)" msgstr "" "(实验性)自定义用户代理(User-Agent)头部。同样的参考文档如上。(参数个数为" "1)" -#: autosub/options.py:348 +#: autosub/options.py:351 msgid "" "Drop any .ass override codes in the text before translation. Only affect the " "translation result. (arg_num = 0)" msgstr "在翻译前删除所有文本中的ass特效标签。只影响翻译结果。(参数个数为0)" -#: autosub/options.py:356 +#: autosub/options.py:359 #, python-format msgid "" "Replace the specific chars with a space after translation, and strip the " @@ -446,11 +456,42 @@ msgstr "" "将指定字符替换为空格,并消除每句末尾空格。只会影响翻译结果。(参数个数为0或" "1)(const为%(const)s)" -#: autosub/options.py:364 +#: autosub/options.py:369 +#, fuzzy, python-format +msgid "" +"(Experimental)Max length to join two events. (arg_num = 1) (default: %" +"(default)s)" +msgstr "" +"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" +"(default)s)" + +#: autosub/options.py:377 +#, fuzzy, python-format +msgid "" +"(Experimental)Max delta time to join two events. (arg_num = 1) (default: %" +"(default)s)" +msgstr "" +"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" +"(default)s)" + +#: autosub/options.py:382 +msgid "string" +msgstr "" + +#: autosub/options.py:384 +#, fuzzy, python-format +msgid "" +"(Experimental)Delimiters not to join two events. (arg_num = 1) (default: %" +"(default)s)" +msgstr "" +"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" +"(default)s)" + +#: autosub/options.py:390 msgid "Change the Google Speech V2 API URL into the http one. (arg_num = 0)" msgstr "将Google Speech V2 API的URL改为http类型。(参数个数为0)" -#: autosub/options.py:372 +#: autosub/options.py:398 #, python-format msgid "" "Add https proxy by setting environment variables. If arg_num is 0, use const " @@ -459,7 +500,7 @@ msgstr "" "通过设置环境变量的方式添加https代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:380 +#: autosub/options.py:406 #, python-format msgid "" "Add http proxy by setting environment variables. If arg_num is 0, use const " @@ -468,33 +509,33 @@ msgstr "" "通过设置环境变量的方式添加http代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:386 +#: autosub/options.py:412 msgid "username" msgstr "用户名" -#: autosub/options.py:387 +#: autosub/options.py:413 msgid "Set proxy username. (arg_num = 1)" msgstr "设置代理用户名。(参数个数为1)" -#: autosub/options.py:392 +#: autosub/options.py:418 msgid "password" msgstr "密码" -#: autosub/options.py:393 +#: autosub/options.py:419 msgid "Set proxy password. (arg_num = 1)" msgstr "设置代理密码。(参数个数为1)" -#: autosub/options.py:399 +#: autosub/options.py:425 #, python-format msgid "Show %(prog)s help message and exit. (arg_num = 0)" msgstr "显示%(prog)s的帮助信息并退出。(参数个数为0)" -#: autosub/options.py:407 +#: autosub/options.py:433 #, python-format msgid "Show %(prog)s version and exit. (arg_num = 0)" msgstr "显示%(prog)s的版本信息并退出。(参数个数为0)" -#: autosub/options.py:412 +#: autosub/options.py:438 msgid "" "Set service account key environment variable. It should be the file path of " "the JSON file that contains your service account credentials. Can be " @@ -504,10 +545,10 @@ 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:423 +#: autosub/options.py:449 msgid "" "Option to control audio process. If not given the option, do normal " "conversion work. \"y\": pre-process the input first then start normal " @@ -526,15 +567,15 @@ msgstr "" "scripts/subgen.sh https://ffmpeg.org/ffmpeg-filters.html)(参数个数介于1和2" "之间)" -#: autosub/options.py:447 +#: autosub/options.py:473 msgid "Keep audio processing files to the output path. (arg_num = 0)" msgstr "将音频处理中产生的文件放在输出路径中。(参数个数为0)" -#: autosub/options.py:452 autosub/options.py:470 autosub/options.py:482 +#: autosub/options.py:478 autosub/options.py:496 autosub/options.py:508 msgid "command" msgstr "命令" -#: autosub/options.py:453 +#: autosub/options.py:479 msgid "" "This arg will override the default audio pre-process command. Every line of " "the commands need to be in quotes. Input file name is {in_}. Output file " @@ -543,7 +584,7 @@ msgstr "" "这个参数会取代默认的音频预处理命令。每行命令需要放在一个引号内。输入文件名写" "为{in_}。输出文件名写为{out_}。(参数个数大于1)" -#: autosub/options.py:465 +#: autosub/options.py:491 #, python-format msgid "" "Number of concurrent ffmpeg audio split process to make. (arg_num = 1) " @@ -551,19 +592,19 @@ msgid "" msgstr "" "用于ffmpeg音频切割的进程并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:472 +#: autosub/options.py:498 #, 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:484 +#: autosub/options.py:510 #, python-format msgid "" "(Experimental)This arg will override the default audio split command. Same " @@ -572,24 +613,24 @@ msgstr "" "(实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:491 +#: autosub/options.py:517 msgid "file_suffix" msgstr "文件名后缀" -#: autosub/options.py:493 +#: autosub/options.py:519 #, python-format 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:499 +#: autosub/options.py:525 msgid "sample_rate" msgstr "采样率" -#: autosub/options.py:502 +#: autosub/options.py:528 #, python-format msgid "" "(Experimental)This arg will override the default API audio sample rate(Hz). " @@ -598,11 +639,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频采样率(赫兹)。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:508 +#: autosub/options.py:534 msgid "channel_num" msgstr "声道数" -#: autosub/options.py:511 +#: autosub/options.py:537 #, python-format msgid "" "(Experimental)This arg will override the default API audio channel. (arg_num " @@ -611,11 +652,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频声道数量。(参数个数为1)(默认" "参数为%(default)s)" -#: autosub/options.py:517 +#: autosub/options.py:543 msgid "energy" msgstr "能量(相对值)" -#: autosub/options.py:520 +#: autosub/options.py:546 #, python-format msgid "" "The energy level which determines the region to be detected. Ref: https://" @@ -626,23 +667,23 @@ msgstr "" "latest/apitutorial.html#examples-using-real-audio-data(参数个数为1)(默认参" "数为%(default)s)" -#: autosub/options.py:530 +#: autosub/options.py:556 #, python-format msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数" -"为%(default)s)" +"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" +"s)" -#: autosub/options.py:539 +#: autosub/options.py:565 #, 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:548 +#: autosub/options.py:574 #, python-format msgid "" "Maximum length of a tolerated silence within a valid audio activity. Same " @@ -651,7 +692,7 @@ msgstr "" "在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如" "上。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:555 +#: autosub/options.py:581 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." @@ -660,7 +701,7 @@ msgstr "" "如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://" "auditok.readthedocs.io/en/latest/core.html#class-summary(参数个数为0)" -#: autosub/options.py:563 +#: autosub/options.py:589 msgid "" "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)" @@ -668,7 +709,7 @@ msgstr "" "参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" "个数为0)" -#: autosub/options.py:569 +#: autosub/options.py:595 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 " @@ -679,7 +720,7 @@ msgstr "" "SubtitleEdit来对其进行转换。如果输出格式是\"sub\"且输入文件是音频无法获取到视" "频帧率时,你需要提供fps选项指定帧率。(参数个数为0)" -#: autosub/options.py:582 +#: autosub/options.py:608 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 " @@ -697,7 +738,7 @@ msgstr "" "言)-扩展-私有(https://www.zhihu.com/question/21980689/answer/93615123)(参" "数个数为0或1)" -#: autosub/options.py:598 +#: autosub/options.py:624 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 " @@ -707,7 +748,7 @@ msgstr "" "言代码。否则会给出一个“好的匹配”的清单。同样的参考文档如上。(参数个数为0或" "1)" -#: autosub/options.py:608 +#: autosub/options.py:634 #, python-format msgid "" "Use py-googletrans to detect a sub file's first line language. And list a " @@ -738,26 +779,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/data/locale/zh_CN/LC_MESSAGES/autosub.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po index 6eede4c5..93350765 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-21 09:55+0800\n" -"PO-Revision-Date: 2020-03-12 17:25+0800\n" +"POT-Creation-Date: 2020-03-26 11:26+0800\n" +"PO-Revision-Date: 2020-03-26 14:46+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -25,7 +25,7 @@ msgstr "" "\n" "输入参数(不包含\"autosub\"): " -#: autosub/__init__.py:64 autosub/__init__.py:177 +#: autosub/__init__.py:64 autosub/__init__.py:182 msgid "" "\n" "All works done." @@ -73,7 +73,11 @@ msgstr "" msgid "Audio pre-processing complete." msgstr "音频预处理已完成。" -#: autosub/__init__.py:180 +#: autosub/__init__.py:170 +msgid "Error: No valid \"-of\"/\"--output-files\" arguments." +msgstr "错误:\"-of\"/\"--output-files\"参数无效。" + +#: autosub/__init__.py:185 msgid "" "\n" "KeyboardInterrupt. Works stopped." @@ -81,7 +85,7 @@ msgstr "" "\n" "键盘中断。操作终止。" -#: autosub/__init__.py:182 +#: autosub/__init__.py:187 msgid "" "\n" "Error: pysubs2.exceptions. Check your file format." @@ -89,7 +93,7 @@ msgstr "" "\n" "错误:pysubs2异常。检查你的文件格式。" -#: autosub/__init__.py:187 +#: autosub/__init__.py:192 msgid "Press Enter to exit..." msgstr "按回车以退出..." diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po new file mode 100644 index 00000000..b3a9cceb --- /dev/null +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po @@ -0,0 +1,22 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-03-26 15:24+0800\n" +"PO-Revision-Date: 2020-03-26 14:45+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.3\n" + +#: autosub/sub_utils.py:510 +msgid "Merge {count} lines of events." +msgstr "合并了{count}行字幕。" diff --git a/autosub/options.py b/autosub/options.py index 7e553868..2f71f284 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -70,6 +70,9 @@ def get_cmd_parser(): # pylint: disable=too-many-statements _('Options to control translation. ' 'Default method to translate. ' 'Could be blocked at any time.')) + conversion_group = parser.add_argument_group( + _('Subtitles Conversion Options'), + _('Options to control subtitles conversions.(Experimental)')) network_group = parser.add_argument_group( _('Network Options'), _('Options to control network.')) @@ -358,6 +361,29 @@ def get_cmd_parser(): # pylint: disable=too-many-statements "Only affect the translation result. " "(arg_num = 0 or 1) (const: %(const)s)")) + conversion_group.add_argument( + '-mjs', '--max-join-size', + metavar='integer', + type=int, + default=constants.DEFAULT_MAX_SIZE_PER_EVENT, + help=_("(Experimental)Max length to join two events. " + "(arg_num = 1) (default: %(default)s)")) + + conversion_group.add_argument( + '-mdt', '--max-delta-time', + metavar=_('second'), + type=float, + default=constants.DEFAULT_CONTINUOUS_SILENCE, + help=_("(Experimental)Max delta time to join two events. " + "(arg_num = 1) (default: %(default)s)")) + + conversion_group.add_argument( + '-dms', '--delimiters', + metavar=_('string'), + default=constants.DEFAULT_EVENT_DELIMITER, + help=_("(Experimental)Delimiters not to join two events. " + "(arg_num = 1) (default: %(default)s)")) + network_group.add_argument( '-hsa', '--http-speech-api', action='store_true', diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 9453d747..1c016374 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -6,6 +6,7 @@ # Import built-in modules import wave import json +import gettext # Import third-party modules import pysubs2 @@ -14,6 +15,14 @@ from autosub import constants +SUB_UTILS_TEXT = gettext.translation(domain=__name__, + localedir=constants.LOCALE_PATH, + languages=[constants.CURRENT_LOCALE], + fallback=True) + +_ = SUB_UTILS_TEXT.gettext + + def sub_to_speech_regions( audio_wav, sub_file, @@ -436,3 +445,68 @@ def merge_bilingual_assfile( # pylint: disable=too-many-locals, too-many-branch new_ssafile.events = events + new_ssafile.events return new_ssafile + + +def merge_src_assfile( + subtitles, + max_join_size=constants.DEFAULT_MAX_SIZE_PER_EVENT, + max_delta_time=int(constants.DEFAULT_CONTINUOUS_SILENCE * 1000), + delimiters=constants.DEFAULT_EVENT_DELIMITER +): + """ + Merge a source subtitles file's events automatically. + """ + new_ssafile = pysubs2.SSAFile() + new_ssafile.styles = subtitles.styles + new_ssafile.info = subtitles.info + style_events = {} + + for event in subtitles.events: + if event.style not in style_events: + style_events[event.style] = [event] + else: + style_events[event.style].append(event) + + sorted_events_list = sorted(style_events.values(), key=len) + events_1 = sorted_events_list.pop() + + temp_ssafile = pysubs2.SSAFile() + temp_ssafile.events = events_1 + temp_ssafile.sort() + + sub_length = len(temp_ssafile.events) + i = 0 + j = 0 + + while i < sub_length - 1: + if len(temp_ssafile.events[i].text) < max_join_size: + if not temp_ssafile.events[i].is_comment and not temp_ssafile.events[i + 1].is_comment: + if len(temp_ssafile.events[i].text) + \ + len(temp_ssafile.events[i + 1].text) < max_join_size \ + and temp_ssafile.events[i].style == temp_ssafile.events[i + 1].style \ + and temp_ssafile.events[i].text.rstrip(" ")[-1] not in delimiters \ + and temp_ssafile.events[i + 1].start - \ + temp_ssafile.events[i].end < max_delta_time: + event = pysubs2.SSAEvent() + event.start = temp_ssafile.events[i].start + event.end = temp_ssafile.events[i + 1].end + if temp_ssafile.events[i].text[-1] != " ": + event.text = temp_ssafile.events[i].text + " " + \ + temp_ssafile.events[i + 1].text + else: + event.text = temp_ssafile.events[i].text + temp_ssafile.events[i + 1].text + event.style = temp_ssafile.events[i].style + new_ssafile.events.append(event) + i = i + 2 + j = j + 1 + continue + + new_ssafile.events.append(temp_ssafile.events[i]) + i = i + 1 + + for events in sorted_events_list: + new_ssafile.events = events + new_ssafile.events + + print(_("Merge {count} lines of events.").format(count=j)) + + return new_ssafile diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 94619377..cb8fb36b 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -52,6 +52,7 @@ - 添加百度智能云语音识别/极速语音识别API支持。[issue #68](https://github.com/BingLingGroup/autosub/issues/68) - 添加字符过滤器用于讯飞开放平台语音听写。 - 添加delete_chars功能到方法list_to_googletrans里。 +- 添加方法merge_src_assfile。 #### 改动(未发布) From 92ec7d3d3e5f8f5505351e24f23a69d7c13b8662 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sat, 28 Mar 2020 19:30:16 +0800 Subject: [PATCH 10/26] Add stop words to split events in merge_src_assfile method. --- CHANGELOG.md | 3 +- autosub/constants.py | 9 ++ .../zh_CN/LC_MESSAGES/autosub.sub_utils.po | 14 +- autosub/sub_utils.py | 130 +++++++++++++++--- docs/CHANGELOG.zh-Hans.md | 3 +- 5 files changed, 133 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 736dff28..bd63a67f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,8 @@ Click up arrow to go back to TOC. - Add support for Baidu Automatic Speech Recognition API. [issue #68](https://github.com/BingLingGroup/autosub/issues/68) - Add chars filter for the transcript result in XfyunWebSocketAPI. - Add delete_chars in method list_to_googletrans. -- Add merge_src_assfile method. +- Add merge_src_assfile, merge_bilingual_assfile methods. +- Add stop words to split events in merge_src_assfile method. #### Changed(Unreleased) diff --git a/autosub/constants.py b/autosub/constants.py index c923b825..761ab0a0 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -443,3 +443,12 @@ def get_cmd(program_name): "v:0 -show_entries stream=r_frame_rate \"{in_}\"" DEFAULT_CHECK_CMD = FFPROBE_CMD + " {in_} -show_format -pretty -loglevel quiet" + +DEFAULT_ENGLISH_STOP_WORDS_SET = \ + {'about', 'above', 'after', 'against', 'and', 'any', 'are', 'as', 'at', 'be', 'because', 'been', + 'before', 'being', 'below', 'between', 'both', 'but', 'by', 'down', 'during', 'each', 'few', + 'for', 'from', 'further', 'how', 'if', 'into', 'is', 'just', 'on', 'once', 'only', 'or', 'out', + 'over', 'so', 'some', 'such', 'than', 'that', 'the', 'then', 'there', 'these', 'this', 'those', + 'through', 'to', 'under', 'until', 'up', 'was', 'were', 'what', 'when', 'where', 'which', + 'while', 'who', 'whom', 'why', 'with'} +# Reference: https://gist.github.com/sebleier/554280 diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po index b3a9cceb..9e4a5cca 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-26 15:24+0800\n" -"PO-Revision-Date: 2020-03-26 14:45+0800\n" +"POT-Creation-Date: 2020-03-28 19:22+0800\n" +"PO-Revision-Date: 2020-03-28 19:23+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -17,6 +17,14 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/sub_utils.py:510 +#: autosub/sub_utils.py:536 msgid "Merge {count} lines of events." msgstr "合并了{count}行字幕。" + +#: autosub/sub_utils.py:537 +msgid "Split {count} lines of events." +msgstr "分割了{count}行字幕。" + +#: autosub/sub_utils.py:538 +msgid "Reduce {count} lines of events." +msgstr "减少了{count}行字幕。" diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 1c016374..3ac02021 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -447,7 +447,8 @@ def merge_bilingual_assfile( # pylint: disable=too-many-locals, too-many-branch return new_ssafile -def merge_src_assfile( +def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-blocks, + # pylint: disable=too-many-statements, too-many-branches subtitles, max_join_size=constants.DEFAULT_MAX_SIZE_PER_EVENT, max_delta_time=int(constants.DEFAULT_CONTINUOUS_SILENCE * 1000), @@ -475,31 +476,56 @@ def merge_src_assfile( temp_ssafile.sort() sub_length = len(temp_ssafile.events) - i = 0 + i = 1 j = 0 + k = 0 + + new_ssafile.events.append(temp_ssafile.events[0]) while i < sub_length - 1: - if len(temp_ssafile.events[i].text) < max_join_size: - if not temp_ssafile.events[i].is_comment and not temp_ssafile.events[i + 1].is_comment: - if len(temp_ssafile.events[i].text) + \ - len(temp_ssafile.events[i + 1].text) < max_join_size \ - and temp_ssafile.events[i].style == temp_ssafile.events[i + 1].style \ - and temp_ssafile.events[i].text.rstrip(" ")[-1] not in delimiters \ - and temp_ssafile.events[i + 1].start - \ - temp_ssafile.events[i].end < max_delta_time: - event = pysubs2.SSAEvent() - event.start = temp_ssafile.events[i].start - event.end = temp_ssafile.events[i + 1].end - if temp_ssafile.events[i].text[-1] != " ": - event.text = temp_ssafile.events[i].text + " " + \ - temp_ssafile.events[i + 1].text + if len(new_ssafile.events[-1].text) < max_join_size: + if not new_ssafile.events[-1].is_comment and not temp_ssafile.events[i].is_comment\ + and new_ssafile.events[-1].style == temp_ssafile.events[i].style\ + and temp_ssafile.events[i].start\ + - new_ssafile.events[-1].end < max_delta_time \ + and new_ssafile.events[-1].text.rstrip(" ")[-1] not in delimiters: + if len(new_ssafile.events[-1].text) + \ + len(temp_ssafile.events[i].text) < max_join_size: + new_ssafile.events[-1].end = temp_ssafile.events[i].end + if new_ssafile.events[-1].text[-1] != " ": + new_ssafile.events[-1].text = new_ssafile.events[-1].text + " " + \ + temp_ssafile.events[i].text else: - event.text = temp_ssafile.events[i].text + temp_ssafile.events[i + 1].text - event.style = temp_ssafile.events[i].style - new_ssafile.events.append(event) - i = i + 2 + new_ssafile.events[-1].text = \ + new_ssafile.events[-1].text + temp_ssafile.events[i].text j = j + 1 - continue + + else: + combination = new_ssafile.events[-1].text + " " + temp_ssafile.events[i].text + min_range = int(len(combination) * 0) + max_range = len(combination) - min_range + half_pos = int(len(combination) / 2) + word_dict = get_word_pos_dict(combination) + combination_set = set(word_dict.keys()) + stop_word_set = constants.DEFAULT_ENGLISH_STOP_WORDS_SET & combination_set + last_index = 0 + last_delta = half_pos - last_index + if stop_word_set: + for stop_word in stop_word_set: + for index in word_dict[stop_word]: + if min_range < index < max_range: + delta = abs(index - half_pos) + if delta < last_delta: + last_index = index + last_delta = delta + if last_index and last_index < max_join_size: + joint_event = join_event(new_ssafile.events[-1], temp_ssafile.events[i]) + new_ssafile.events.pop() + new_ssafile.events.extend(split_event(joint_event, last_index)) + k = k + 1 + + i = i + 1 + continue new_ssafile.events.append(temp_ssafile.events[i]) i = i + 1 @@ -508,5 +534,67 @@ def merge_src_assfile( new_ssafile.events = events + new_ssafile.events print(_("Merge {count} lines of events.").format(count=j)) + print(_("Split {count} lines of events.").format(count=k)) + print(_("Reduce {count} lines of events.").format(count=j - k)) return new_ssafile + + +def get_word_pos_dict( + sentence +): + """ + Get word position dictionary from sentence. + """ + i = 0 + j = 0 + result_dict = {} + length = len(sentence) + while i < length: + if sentence[i] == " ": + if i != j and sentence[j:i].strip(" "): + index = result_dict.get(sentence[j:i]) + if not index: + result_dict[sentence[j:i]] = [j] + else: + result_dict[sentence[j:i]].append(j) + j = i + 1 + i = i + 1 + + return result_dict + + +def join_event( + event1, + event2 +): + """ + Join two events. + """ + joint_event = event1.copy() + joint_event.start = event1.start + joint_event.end = event2.end + joint_event.text = event1.text + " " + event2.text + + return joint_event + + +def split_event( + event, + position +): + """ + Split an event based on position. + """ + ratio = position / len(event.text) + first_event = event.copy() + first_event.start = event.start + first_event.end = int((event.end - event.start) * ratio) + event.start + first_event.text = event.text[:position].rstrip(" ") + + second_event = event.copy() + second_event.end = event.end + second_event.start = first_event.end + second_event.text = event.text[position:] + + return [first_event, second_event] diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index cb8fb36b..f0bf5f73 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -52,7 +52,8 @@ - 添加百度智能云语音识别/极速语音识别API支持。[issue #68](https://github.com/BingLingGroup/autosub/issues/68) - 添加字符过滤器用于讯飞开放平台语音听写。 - 添加delete_chars功能到方法list_to_googletrans里。 -- 添加方法merge_src_assfile。 +- 添加方法merge_src_assfile,merge_bilingual_assfile。 +- 添加停用词用于merge_src_assfile方法里的断句。 #### 改动(未发布) From 9edd60bfec20143edea98af7e2405a4697e2428b Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sat, 28 Mar 2020 20:21:07 +0800 Subject: [PATCH 11/26] Add punctuations split in merge_src_assfile method. --- CHANGELOG.md | 1 + autosub/constants.py | 2 +- .../zh_CN/LC_MESSAGES/autosub.sub_utils.po | 8 ++++---- autosub/sub_utils.py | 16 ++++++++++------ docs/CHANGELOG.zh-Hans.md | 1 + 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd63a67f..a779ea2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Click up arrow to go back to TOC. - Add delete_chars in method list_to_googletrans. - Add merge_src_assfile, merge_bilingual_assfile methods. - Add stop words to split events in merge_src_assfile method. +- Add punctuations split in merge_src_assfile method. #### Changed(Unreleased) diff --git a/autosub/constants.py b/autosub/constants.py index 761ab0a0..e99981b9 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -81,7 +81,7 @@ DEFAULT_SLEEP_SECONDS = 5 DEFAULT_MAX_SIZE_PER_EVENT = 100 -DEFAULT_EVENT_DELIMITER = r"!()*,-.:;?[\]^_`~" +DEFAULT_EVENT_DELIMITER = r"!()*,.:;?[\]^_`~" DEFAULT_SUBTITLES_FORMAT = 'srt' diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po index 9e4a5cca..11f48352 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-28 19:22+0800\n" +"POT-Creation-Date: 2020-03-28 20:18+0800\n" "PO-Revision-Date: 2020-03-28 19:23+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,14 +17,14 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/sub_utils.py:536 +#: autosub/sub_utils.py:539 msgid "Merge {count} lines of events." msgstr "合并了{count}行字幕。" -#: autosub/sub_utils.py:537 +#: autosub/sub_utils.py:540 msgid "Split {count} lines of events." msgstr "分割了{count}行字幕。" -#: autosub/sub_utils.py:538 +#: autosub/sub_utils.py:541 msgid "Reduce {count} lines of events." msgstr "减少了{count}行字幕。" diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 3ac02021..05156eaa 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -505,9 +505,12 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block min_range = int(len(combination) * 0) max_range = len(combination) - min_range half_pos = int(len(combination) / 2) - word_dict = get_word_pos_dict(combination) - combination_set = set(word_dict.keys()) - stop_word_set = constants.DEFAULT_ENGLISH_STOP_WORDS_SET & combination_set + word_dict = get_slice_pos_dict(combination, delimiters=delimiters) + # use punctuations to split the sentence first + if len(word_dict) <= 1: + word_dict = get_slice_pos_dict(combination) + word_set = set(word_dict.keys()) + stop_word_set = constants.DEFAULT_ENGLISH_STOP_WORDS_SET & word_set last_index = 0 last_delta = half_pos - last_index if stop_word_set: @@ -540,8 +543,9 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block return new_ssafile -def get_word_pos_dict( - sentence +def get_slice_pos_dict( + sentence, + delimiters=" " ): """ Get word position dictionary from sentence. @@ -551,7 +555,7 @@ def get_word_pos_dict( result_dict = {} length = len(sentence) while i < length: - if sentence[i] == " ": + if sentence[i] in delimiters: if i != j and sentence[j:i].strip(" "): index = result_dict.get(sentence[j:i]) if not index: diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index f0bf5f73..ea101cd5 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -54,6 +54,7 @@ - 添加delete_chars功能到方法list_to_googletrans里。 - 添加方法merge_src_assfile,merge_bilingual_assfile。 - 添加停用词用于merge_src_assfile方法里的断句。 +- 添加标点符号分割功能在merge_src_assfile方法里。 #### 改动(未发布) From df2e9ad4f660efd804b255af13cd0444de2acbe8 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sun, 29 Mar 2020 12:18:41 +0800 Subject: [PATCH 12/26] Refactor merge_src_assfile method --- autosub/constants.py | 2 +- .../zh_CN/LC_MESSAGES/autosub.sub_utils.po | 28 ++- autosub/sub_utils.py | 163 ++++++++++++------ 3 files changed, 128 insertions(+), 65 deletions(-) diff --git a/autosub/constants.py b/autosub/constants.py index e99981b9..3fcc3177 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -81,7 +81,7 @@ DEFAULT_SLEEP_SECONDS = 5 DEFAULT_MAX_SIZE_PER_EVENT = 100 -DEFAULT_EVENT_DELIMITER = r"!()*,.:;?[\]^_`~" +DEFAULT_EVENT_DELIMITER = r"!()*,.:;?[]^_`~" DEFAULT_SUBTITLES_FORMAT = 'srt' diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po index 11f48352..f2f4961d 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-28 20:18+0800\n" -"PO-Revision-Date: 2020-03-28 19:23+0800\n" +"POT-Creation-Date: 2020-03-29 11:48+0800\n" +"PO-Revision-Date: 2020-03-29 11:48+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -17,14 +17,24 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/sub_utils.py:539 -msgid "Merge {count} lines of events." -msgstr "合并了{count}行字幕。" +#: autosub/sub_utils.py:554 +msgid "Merge {count} times." +msgstr "合并了{count}次。" -#: autosub/sub_utils.py:540 -msgid "Split {count} lines of events." -msgstr "分割了{count}行字幕。" +#: autosub/sub_utils.py:555 +msgid "Split {count} times." +msgstr "分割了{count}次。" -#: autosub/sub_utils.py:541 +#: autosub/sub_utils.py:558 msgid "Reduce {count} lines of events." msgstr "减少了{count}行字幕。" + +#: autosub/sub_utils.py:560 +msgid "Add {count} lines of events." +msgstr "增加了{count}行字幕。" + +#~ msgid "Merge {count} lines of events." +#~ msgstr "合并了{count}行字幕。" + +#~ msgid "Split {count} lines of events." +#~ msgstr "分割了{count}行字幕。" diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 05156eaa..53247413 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -452,7 +452,8 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block subtitles, max_join_size=constants.DEFAULT_MAX_SIZE_PER_EVENT, max_delta_time=int(constants.DEFAULT_CONTINUOUS_SILENCE * 1000), - delimiters=constants.DEFAULT_EVENT_DELIMITER + delimiters=constants.DEFAULT_EVENT_DELIMITER, + avoid_split=False ): """ Merge a source subtitles file's events automatically. @@ -476,73 +477,116 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block temp_ssafile.sort() sub_length = len(temp_ssafile.events) - i = 1 - j = 0 - k = 0 + event_count = 1 + merge_count = 0 + split_count = 0 new_ssafile.events.append(temp_ssafile.events[0]) - while i < sub_length - 1: + while event_count < sub_length: if len(new_ssafile.events[-1].text) < max_join_size: - if not new_ssafile.events[-1].is_comment and not temp_ssafile.events[i].is_comment\ - and new_ssafile.events[-1].style == temp_ssafile.events[i].style\ - and temp_ssafile.events[i].start\ + if not new_ssafile.events[-1].is_comment \ + and not temp_ssafile.events[event_count].is_comment\ + and new_ssafile.events[-1].style == temp_ssafile.events[event_count].style\ + and temp_ssafile.events[event_count].start\ - new_ssafile.events[-1].end < max_delta_time \ and new_ssafile.events[-1].text.rstrip(" ")[-1] not in delimiters: if len(new_ssafile.events[-1].text) + \ - len(temp_ssafile.events[i].text) < max_join_size: - new_ssafile.events[-1].end = temp_ssafile.events[i].end + len(temp_ssafile.events[event_count].text) < max_join_size: + new_ssafile.events[-1].end = temp_ssafile.events[event_count].end if new_ssafile.events[-1].text[-1] != " ": new_ssafile.events[-1].text = new_ssafile.events[-1].text + " " + \ - temp_ssafile.events[i].text + temp_ssafile.events[event_count].text else: new_ssafile.events[-1].text = \ - new_ssafile.events[-1].text + temp_ssafile.events[i].text - j = j + 1 - - else: - combination = new_ssafile.events[-1].text + " " + temp_ssafile.events[i].text - min_range = int(len(combination) * 0) - max_range = len(combination) - min_range - half_pos = int(len(combination) / 2) - word_dict = get_slice_pos_dict(combination, delimiters=delimiters) - # use punctuations to split the sentence first - if len(word_dict) <= 1: - word_dict = get_slice_pos_dict(combination) - word_set = set(word_dict.keys()) - stop_word_set = constants.DEFAULT_ENGLISH_STOP_WORDS_SET & word_set - last_index = 0 - last_delta = half_pos - last_index - if stop_word_set: - for stop_word in stop_word_set: - for index in word_dict[stop_word]: - if min_range < index < max_range: - delta = abs(index - half_pos) - if delta < last_delta: - last_index = index - last_delta = delta - if last_index and last_index < max_join_size: - joint_event = join_event(new_ssafile.events[-1], temp_ssafile.events[i]) - new_ssafile.events.pop() - new_ssafile.events.extend(split_event(joint_event, last_index)) - k = k + 1 - - i = i + 1 - continue - - new_ssafile.events.append(temp_ssafile.events[i]) - i = i + 1 + new_ssafile.events[-1].text + temp_ssafile.events[event_count].text + merge_count = merge_count + 1 + event_count = event_count + 1 + continue + + if not avoid_split: + joint_event = join_event(new_ssafile.events[-1], + temp_ssafile.events[event_count]) + event_list = [] + while True: + word_dict = get_slice_pos_dict(joint_event.text, delimiters=delimiters) + total_length = len(joint_event.text) + # use punctuations to split the sentence first + if len(word_dict) < 2: + word_dict = get_slice_pos_dict(joint_event.text) + stop_word_set = constants.DEFAULT_ENGLISH_STOP_WORDS_SET & \ + set(word_dict.keys()) + else: + stop_word_set = set(word_dict.keys()) + + last_index = find_split_index( + total_length=total_length, + stop_word_set=stop_word_set, + word_dict=word_dict, + min_range_ratio=0.1, + ) + + if 0 < last_index < max_join_size: + if total_length - last_index < max_join_size: + new_ssafile.events.pop() + event_list.extend(split_event(joint_event, last_index)) + new_ssafile.events.extend(event_list) + merge_count = merge_count + 1 + split_count = split_count + len(event_list) + last_index = -1 + break + split_events = split_event(joint_event, last_index) + event_list.append(split_events[0]) + joint_event = split_events[1] + else: + break + + if last_index == -1: + event_count = event_count + 1 + continue + + new_ssafile.events.append(temp_ssafile.events[event_count]) + event_count = event_count + 1 for events in sorted_events_list: new_ssafile.events = events + new_ssafile.events - print(_("Merge {count} lines of events.").format(count=j)) - print(_("Split {count} lines of events.").format(count=k)) - print(_("Reduce {count} lines of events.").format(count=j - k)) + print(_("Merge {count} times.").format(count=merge_count)) + print(_("Split {count} times.").format(count=split_count)) + delta = len(subtitles.events) - len(new_ssafile.events) + if delta > 0: + print(_("Reduce {count} lines of events.").format(count=delta)) + else: + print(_("Add {count} lines of events.").format(count=-delta)) return new_ssafile +def find_split_index( + total_length, + stop_word_set, + word_dict, + min_range_ratio +): + """ + Find index to split. + """ + half_pos = int(total_length / 2) + min_range = int(min_range_ratio * total_length) + max_range = total_length - min_range + last_index = 0 + last_delta = half_pos - last_index + if stop_word_set: + for stop_word in stop_word_set: + for index in word_dict[stop_word]: + if min_range < index < max_range: + delta = abs(index - half_pos) + if delta < last_delta: + last_index = index + last_delta = delta + return last_index + + def get_slice_pos_dict( sentence, delimiters=" " @@ -557,11 +601,12 @@ def get_slice_pos_dict( while i < length: if sentence[i] in delimiters: if i != j and sentence[j:i].strip(" "): - index = result_dict.get(sentence[j:i]) + slice_ = sentence[j:i].lstrip(" ") + index = result_dict.get(slice_) if not index: - result_dict[sentence[j:i]] = [j] + result_dict[slice_] = [j] else: - result_dict[sentence[j:i]].append(j) + result_dict[slice_].append(j) j = i + 1 i = i + 1 @@ -585,7 +630,8 @@ def join_event( def split_event( event, - position + position, + without_mark=False ): """ Split an event based on position. @@ -594,11 +640,18 @@ def split_event( first_event = event.copy() first_event.start = event.start first_event.end = int((event.end - event.start) * ratio) + event.start - first_event.text = event.text[:position].rstrip(" ") second_event = event.copy() second_event.end = event.end second_event.start = first_event.end - second_event.text = event.text[position:] + if not without_mark: + if not first_event.text.startswith("{\\r}"): + first_event.text = "{\\r}" + event.text[:position].rstrip(" ") + else: + first_event.text = event.text[:position].rstrip(" ") + if not second_event.text.startswith("{\\r}"): + second_event.text = "{\\r}" + event.text[position:].lstrip(" ") + else: + second_event.text = event.text[position:].lstrip(" ") return [first_event, second_event] From b82b2cdebf845ecb6d3ed04141a47827babef3b1 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sun, 29 Mar 2020 16:35:25 +0800 Subject: [PATCH 13/26] Fix merge_src_assfile method --- autosub/cmdline_utils.py | 16 +- autosub/constants.py | 32 +++- .../LC_MESSAGES/autosub.cmdline_utils.po | 66 ++++----- .../zh_CN/LC_MESSAGES/autosub.options.po | 106 +++++++++----- .../zh_CN/LC_MESSAGES/autosub.sub_utils.po | 10 +- autosub/options.py | 20 ++- autosub/sub_utils.py | 138 +++++++++++------- 7 files changed, 251 insertions(+), 137 deletions(-) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index a8c2fd7e..cafe9949 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -722,11 +722,25 @@ def sub_conversion( # pylint: disable=too-many-branches, too-many-statements, t try: args.output_files.remove("join-events") + if args.stop_words_1: + stop_words_1 = args.stop_words_1.split(" ") + stop_words_set_1 = set(stop_words_1) + else: + stop_words_set_1 = constants.DEFAULT_ENGLISH_STOP_WORDS_SET_1 + if args.stop_words_2: + stop_words_2 = args.stop_words_2.split(" ") + stop_words_set_2 = set(stop_words_2) + else: + stop_words_set_2 = constants.DEFAULT_ENGLISH_STOP_WORDS_SET_2 + new_sub = sub_utils.merge_src_assfile( subtitles=src_sub, max_join_size=args.max_join_size, max_delta_time=int(args.max_delta_time * 1000), - delimiters=args.delimiters + delimiters=args.delimiters, + stop_words_set_1=stop_words_set_1, + stop_words_set_2=stop_words_set_2, + avoid_split=args.dont_split ) sub_string = core.ssafile_to_sub_str( ssafile=new_sub, diff --git a/autosub/constants.py b/autosub/constants.py index 3fcc3177..2f976268 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -81,7 +81,7 @@ DEFAULT_SLEEP_SECONDS = 5 DEFAULT_MAX_SIZE_PER_EVENT = 100 -DEFAULT_EVENT_DELIMITER = r"!()*,.:;?[]^_`~" +DEFAULT_EVENT_DELIMITERS = r"!()*,.:;?[]^_`~" DEFAULT_SUBTITLES_FORMAT = 'srt' @@ -444,11 +444,27 @@ def get_cmd(program_name): DEFAULT_CHECK_CMD = FFPROBE_CMD + " {in_} -show_format -pretty -loglevel quiet" -DEFAULT_ENGLISH_STOP_WORDS_SET = \ - {'about', 'above', 'after', 'against', 'and', 'any', 'are', 'as', 'at', 'be', 'because', 'been', - 'before', 'being', 'below', 'between', 'both', 'but', 'by', 'down', 'during', 'each', 'few', - 'for', 'from', 'further', 'how', 'if', 'into', 'is', 'just', 'on', 'once', 'only', 'or', 'out', - 'over', 'so', 'some', 'such', 'than', 'that', 'the', 'then', 'there', 'these', 'this', 'those', - 'through', 'to', 'under', 'until', 'up', 'was', 'were', 'what', 'when', 'where', 'which', - 'while', 'who', 'whom', 'why', 'with'} +DEFAULT_ENGLISH_STOP_WORDS_SET_1 = \ + {'after', 'and', 'as', 'because', 'before', 'between', 'but', 'for', 'how', 'if', 'or', 'so', + 'that', "that'll", 'until', 'what', 'when', 'where', 'which', 'while', 'who', 'whom', 'why', + 'with'} + +DEFAULT_ENGLISH_STOP_WORDS_SET_2 = \ + {'a', 'about', 'above', 'after', 'again', 'against', 'ain', 'all', 'am', 'an', 'and', 'any', + 'are', 'aren', "aren't", 'as', 'at', 'be', 'because', 'been', 'before', 'being', 'below', + 'between', 'both', 'but', 'by', 'can', 'couldn', "couldn't", 'd', 'did', 'didn', "didn't", + 'do', 'does', 'doesn', "doesn't", 'doing', 'don', "don't", 'down', 'during', 'each', 'few', + 'for', 'from', 'further', 'had', 'hadn', "hadn't", 'has', 'hasn', "hasn't", 'have', 'haven', + "haven't", 'having', 'he', 'her', 'here', 'hers', 'herself', 'him', 'himself', 'his', 'how', + 'i', 'if', 'in', 'into', 'is', 'isn', "isn't", 'it', "it's", 'its', 'itself', 'just', 'll', + 'm', 'ma', 'me', 'mightn', "mightn't", 'more', 'most', 'mustn', "mustn't", 'my', 'myself', + 'needn', "needn't", 'no', 'nor', 'not', 'now', 'o', 'of', 'off', 'on', 'once', 'only', 'or', + 'other', 'our', 'ours', 'ourselves', 'out', 'over', 'own', 're', 's', 'same', 'shan', "shan't", + 'she', "she's", 'should', "should've", 'shouldn', "shouldn't", 'so', 'some', 'such', 't', + 'than', 'that', "that'll", 'the', 'their', 'theirs', 'them', 'themselves', 'then', 'there', + 'these', 'they', 'this', 'those', 'through', 'to', 'too', 'under', 'until', 'up', 've', 'very', + 'was', 'wasn', "wasn't", 'we', 'were', 'weren', "weren't", 'what', 'when', 'where', 'which', + 'while', 'who', 'whom', 'why', 'will', 'with', 'won', "won't", 'wouldn', "wouldn't", 'y', + 'you', "you'd", "you'll", "you're", "you've", 'your', 'yours', 'yourself', 'yourselves' + } # Reference: https://gist.github.com/sebleier/554280 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 7d103344..50c5b314 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-26 15:15+0800\n" +"POT-Creation-Date: 2020-03-29 16:29+0800\n" "PO-Revision-Date: 2020-03-26 14:48+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -325,17 +325,17 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:679 autosub/cmdline_utils.py:898 -#: autosub/cmdline_utils.py:1441 +#: autosub/cmdline_utils.py:679 autosub/cmdline_utils.py:912 +#: autosub/cmdline_utils.py:1455 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" #: autosub/cmdline_utils.py:683 autosub/cmdline_utils.py:718 -#: autosub/cmdline_utils.py:755 autosub/cmdline_utils.py:849 -#: autosub/cmdline_utils.py:902 autosub/cmdline_utils.py:955 -#: autosub/cmdline_utils.py:1131 autosub/cmdline_utils.py:1294 -#: autosub/cmdline_utils.py:1336 autosub/cmdline_utils.py:1397 -#: autosub/cmdline_utils.py:1445 autosub/cmdline_utils.py:1493 +#: autosub/cmdline_utils.py:769 autosub/cmdline_utils.py:863 +#: autosub/cmdline_utils.py:916 autosub/cmdline_utils.py:969 +#: autosub/cmdline_utils.py:1145 autosub/cmdline_utils.py:1308 +#: autosub/cmdline_utils.py:1350 autosub/cmdline_utils.py:1411 +#: autosub/cmdline_utils.py:1459 autosub/cmdline_utils.py:1507 msgid "" "\n" "All works done." @@ -343,32 +343,32 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:714 autosub/cmdline_utils.py:951 -#: autosub/cmdline_utils.py:1489 +#: autosub/cmdline_utils.py:714 autosub/cmdline_utils.py:965 +#: autosub/cmdline_utils.py:1503 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:751 +#: autosub/cmdline_utils.py:765 msgid "\"join-events\" subtitles file created at \"{}\"." msgstr "\"join-events\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:800 autosub/cmdline_utils.py:1354 +#: autosub/cmdline_utils.py:814 autosub/cmdline_utils.py:1368 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:845 autosub/cmdline_utils.py:1393 +#: autosub/cmdline_utils.py:859 autosub/cmdline_utils.py:1407 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:995 autosub/cmdline_utils.py:1534 +#: autosub/cmdline_utils.py:1009 autosub/cmdline_utils.py:1548 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1036 +#: autosub/cmdline_utils.py:1050 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:1070 +#: autosub/cmdline_utils.py:1084 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -376,11 +376,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:1080 +#: autosub/cmdline_utils.py:1094 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:1083 +#: autosub/cmdline_utils.py:1097 msgid "" "Conversion complete.\n" "Use Auditok to detect speech regions." @@ -388,7 +388,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:1095 +#: autosub/cmdline_utils.py:1109 msgid "" "\n" "\"{name}\" has been deleted." @@ -396,19 +396,19 @@ msgstr "" "\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:1099 +#: autosub/cmdline_utils.py:1113 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1128 autosub/cmdline_utils.py:1601 +#: autosub/cmdline_utils.py:1142 autosub/cmdline_utils.py:1615 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1152 +#: autosub/cmdline_utils.py:1166 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1156 +#: autosub/cmdline_utils.py:1170 msgid "" "Audio processing complete.\n" "All works done." @@ -416,11 +416,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1208 +#: autosub/cmdline_utils.py:1222 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1223 +#: autosub/cmdline_utils.py:1237 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -430,18 +430,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1228 +#: autosub/cmdline_utils.py:1242 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1242 +#: autosub/cmdline_utils.py:1256 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1254 +#: autosub/cmdline_utils.py:1268 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -449,11 +449,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1290 +#: autosub/cmdline_utils.py:1304 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1298 +#: autosub/cmdline_utils.py:1312 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -461,11 +461,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1332 autosub/cmdline_utils.py:1571 +#: autosub/cmdline_utils.py:1346 autosub/cmdline_utils.py:1585 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1543 +#: autosub/cmdline_utils.py:1557 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -473,7 +473,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1576 +#: autosub/cmdline_utils.py:1590 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.options.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po index 73758465..2469cead 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-26 15:14+0800\n" +"POT-Creation-Date: 2020-03-29 16:29+0800\n" "PO-Revision-Date: 2020-03-24 11:52+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -144,8 +144,8 @@ msgid "List all available arguments." msgstr "列出所有可选参数。" #: autosub/options.py:95 autosub/options.py:104 autosub/options.py:113 -#: autosub/options.py:195 autosub/options.py:276 autosub/options.py:437 -#: autosub/options.py:633 +#: autosub/options.py:195 autosub/options.py:276 autosub/options.py:455 +#: autosub/options.py:651 msgid "path" msgstr "路径" @@ -198,7 +198,7 @@ msgstr "" "言行使用第二个。(参数个数为1或2)" #: autosub/options.py:140 autosub/options.py:151 autosub/options.py:161 -#: autosub/options.py:605 autosub/options.py:621 +#: autosub/options.py:623 autosub/options.py:639 msgid "lang_code" msgstr "语言代码" @@ -236,7 +236,7 @@ msgstr "" "用于翻译的目标语言的语言代码/语言标识符。同样的注意参考选项\"-SRC\"/\"--src-" "language\"。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:168 autosub/options.py:448 +#: autosub/options.py:168 autosub/options.py:466 msgid "mode" msgstr "模式" @@ -411,8 +411,8 @@ msgid "" msgstr "" "用于Speech-to-Text请求的并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:326 autosub/options.py:374 autosub/options.py:553 -#: autosub/options.py:562 autosub/options.py:571 +#: autosub/options.py:326 autosub/options.py:374 autosub/options.py:571 +#: autosub/options.py:580 autosub/options.py:589 msgid "second" msgstr "秒" @@ -487,11 +487,37 @@ msgstr "" "(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" "(default)s)" +#: autosub/options.py:389 autosub/options.py:395 +msgid "words_delimited_by_space" +msgstr "" + #: autosub/options.py:390 +#, fuzzy, python-format +msgid "" +"(Experimental)First set of Stop words to split two events. (arg_num = 1) " +"(default: %(default)s)" +msgstr "" +"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" +"(default)s)" + +#: autosub/options.py:396 +#, fuzzy, python-format +msgid "" +"(Experimental)Second set of Stop words to split two events. (arg_num = 1) " +"(default: %(default)s)" +msgstr "" +"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" +"(default)s)" + +#: autosub/options.py:402 +msgid "(Experimental)Don't Split just merge. (arg_num = 0)" +msgstr "" + +#: autosub/options.py:408 msgid "Change the Google Speech V2 API URL into the http one. (arg_num = 0)" msgstr "将Google Speech V2 API的URL改为http类型。(参数个数为0)" -#: autosub/options.py:398 +#: autosub/options.py:416 #, python-format msgid "" "Add https proxy by setting environment variables. If arg_num is 0, use const " @@ -500,7 +526,7 @@ msgstr "" "通过设置环境变量的方式添加https代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:406 +#: autosub/options.py:424 #, python-format msgid "" "Add http proxy by setting environment variables. If arg_num is 0, use const " @@ -509,33 +535,33 @@ msgstr "" "通过设置环境变量的方式添加http代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:412 +#: autosub/options.py:430 msgid "username" msgstr "用户名" -#: autosub/options.py:413 +#: autosub/options.py:431 msgid "Set proxy username. (arg_num = 1)" msgstr "设置代理用户名。(参数个数为1)" -#: autosub/options.py:418 +#: autosub/options.py:436 msgid "password" msgstr "密码" -#: autosub/options.py:419 +#: autosub/options.py:437 msgid "Set proxy password. (arg_num = 1)" msgstr "设置代理密码。(参数个数为1)" -#: autosub/options.py:425 +#: autosub/options.py:443 #, python-format msgid "Show %(prog)s help message and exit. (arg_num = 0)" msgstr "显示%(prog)s的帮助信息并退出。(参数个数为0)" -#: autosub/options.py:433 +#: autosub/options.py:451 #, python-format msgid "Show %(prog)s version and exit. (arg_num = 0)" msgstr "显示%(prog)s的版本信息并退出。(参数个数为0)" -#: autosub/options.py:438 +#: autosub/options.py:456 msgid "" "Set service account key environment variable. It should be the file path of " "the JSON file that contains your service account credentials. Can be " @@ -548,7 +574,7 @@ msgstr "" "authentication/getting-started 当前支持:gcsv1" "(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" -#: autosub/options.py:449 +#: autosub/options.py:467 msgid "" "Option to control audio process. If not given the option, do normal " "conversion work. \"y\": pre-process the input first then start normal " @@ -567,15 +593,15 @@ msgstr "" "scripts/subgen.sh https://ffmpeg.org/ffmpeg-filters.html)(参数个数介于1和2" "之间)" -#: autosub/options.py:473 +#: autosub/options.py:491 msgid "Keep audio processing files to the output path. (arg_num = 0)" msgstr "将音频处理中产生的文件放在输出路径中。(参数个数为0)" -#: autosub/options.py:478 autosub/options.py:496 autosub/options.py:508 +#: autosub/options.py:496 autosub/options.py:514 autosub/options.py:526 msgid "command" msgstr "命令" -#: autosub/options.py:479 +#: autosub/options.py:497 msgid "" "This arg will override the default audio pre-process command. Every line of " "the commands need to be in quotes. Input file name is {in_}. Output file " @@ -584,7 +610,7 @@ msgstr "" "这个参数会取代默认的音频预处理命令。每行命令需要放在一个引号内。输入文件名写" "为{in_}。输出文件名写为{out_}。(参数个数大于1)" -#: autosub/options.py:491 +#: autosub/options.py:509 #, python-format msgid "" "Number of concurrent ffmpeg audio split process to make. (arg_num = 1) " @@ -592,7 +618,7 @@ msgid "" msgstr "" "用于ffmpeg音频切割的进程并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:498 +#: autosub/options.py:516 #, python-format msgid "" "(Experimental)This arg will override the default audio conversion command. " @@ -604,7 +630,7 @@ msgstr "" "除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数为%(default)" "s)" -#: autosub/options.py:510 +#: autosub/options.py:528 #, python-format msgid "" "(Experimental)This arg will override the default audio split command. Same " @@ -613,11 +639,11 @@ msgstr "" "(实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:517 +#: autosub/options.py:535 msgid "file_suffix" msgstr "文件名后缀" -#: autosub/options.py:519 +#: autosub/options.py:537 #, python-format msgid "" "(Experimental)This arg will override the default API audio suffix. (arg_num " @@ -626,11 +652,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数为%(default)" "s)" -#: autosub/options.py:525 +#: autosub/options.py:543 msgid "sample_rate" msgstr "采样率" -#: autosub/options.py:528 +#: autosub/options.py:546 #, python-format msgid "" "(Experimental)This arg will override the default API audio sample rate(Hz). " @@ -639,11 +665,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频采样率(赫兹)。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:534 +#: autosub/options.py:552 msgid "channel_num" msgstr "声道数" -#: autosub/options.py:537 +#: autosub/options.py:555 #, python-format msgid "" "(Experimental)This arg will override the default API audio channel. (arg_num " @@ -652,11 +678,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频声道数量。(参数个数为1)(默认" "参数为%(default)s)" -#: autosub/options.py:543 +#: autosub/options.py:561 msgid "energy" msgstr "能量(相对值)" -#: autosub/options.py:546 +#: autosub/options.py:564 #, python-format msgid "" "The energy level which determines the region to be detected. Ref: https://" @@ -667,7 +693,7 @@ msgstr "" "latest/apitutorial.html#examples-using-real-audio-data(参数个数为1)(默认参" "数为%(default)s)" -#: autosub/options.py:556 +#: autosub/options.py:574 #, python-format msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" @@ -675,7 +701,7 @@ msgstr "" "最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" "s)" -#: autosub/options.py:565 +#: autosub/options.py:583 #, python-format msgid "" "Maximum region size. Same docs above. (arg_num = 1) (default: %(default)s)" @@ -683,7 +709,7 @@ msgstr "" "最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" "s)" -#: autosub/options.py:574 +#: autosub/options.py:592 #, python-format msgid "" "Maximum length of a tolerated silence within a valid audio activity. Same " @@ -692,7 +718,7 @@ msgstr "" "在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如" "上。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:581 +#: autosub/options.py:599 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." @@ -701,7 +727,7 @@ msgstr "" "如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://" "auditok.readthedocs.io/en/latest/core.html#class-summary(参数个数为0)" -#: autosub/options.py:589 +#: autosub/options.py:607 msgid "" "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)" @@ -709,7 +735,7 @@ msgstr "" "参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" "个数为0)" -#: autosub/options.py:595 +#: autosub/options.py:613 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 " @@ -720,7 +746,7 @@ msgstr "" "SubtitleEdit来对其进行转换。如果输出格式是\"sub\"且输入文件是音频无法获取到视" "频帧率时,你需要提供fps选项指定帧率。(参数个数为0)" -#: autosub/options.py:608 +#: autosub/options.py:626 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 " @@ -738,7 +764,7 @@ msgstr "" "言)-扩展-私有(https://www.zhihu.com/question/21980689/answer/93615123)(参" "数个数为0或1)" -#: autosub/options.py:624 +#: autosub/options.py:642 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 " @@ -748,7 +774,7 @@ msgstr "" "言代码。否则会给出一个“好的匹配”的清单。同样的参考文档如上。(参数个数为0或" "1)" -#: autosub/options.py:634 +#: autosub/options.py:652 #, python-format msgid "" "Use py-googletrans to detect a sub file's first line language. And list a " diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po index f2f4961d..f95128da 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-29 11:48+0800\n" +"POT-Creation-Date: 2020-03-29 16:29+0800\n" "PO-Revision-Date: 2020-03-29 11:48+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,19 +17,19 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/sub_utils.py:554 +#: autosub/sub_utils.py:585 msgid "Merge {count} times." msgstr "合并了{count}次。" -#: autosub/sub_utils.py:555 +#: autosub/sub_utils.py:586 msgid "Split {count} times." msgstr "分割了{count}次。" -#: autosub/sub_utils.py:558 +#: autosub/sub_utils.py:589 msgid "Reduce {count} lines of events." msgstr "减少了{count}行字幕。" -#: autosub/sub_utils.py:560 +#: autosub/sub_utils.py:591 msgid "Add {count} lines of events." msgstr "增加了{count}行字幕。" diff --git a/autosub/options.py b/autosub/options.py index 2f71f284..11a563aa 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -380,10 +380,28 @@ def get_cmd_parser(): # pylint: disable=too-many-statements conversion_group.add_argument( '-dms', '--delimiters', metavar=_('string'), - default=constants.DEFAULT_EVENT_DELIMITER, + default=constants.DEFAULT_EVENT_DELIMITERS, help=_("(Experimental)Delimiters not to join two events. " "(arg_num = 1) (default: %(default)s)")) + conversion_group.add_argument( + '-sw1', '--stop-words-1', + metavar=_('words_delimited_by_space'), + help=_("(Experimental)First set of Stop words to split two events. " + "(arg_num = 1) (default: %(default)s)")) + + conversion_group.add_argument( + '-sw2', '--stop-words-2', + metavar=_('words_delimited_by_space'), + help=_("(Experimental)Second set of Stop words to split two events. " + "(arg_num = 1) (default: %(default)s)")) + + conversion_group.add_argument( + '-ds', '--dont-split', + action='store_true', + help=_("(Experimental)Don't Split just merge. " + "(arg_num = 0)")) + network_group.add_argument( '-hsa', '--http-speech-api', action='store_true', diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 53247413..b74597d2 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -448,13 +448,14 @@ def merge_bilingual_assfile( # pylint: disable=too-many-locals, too-many-branch def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-blocks, - # pylint: disable=too-many-statements, too-many-branches + # pylint: disable=too-many-statements, too-many-branches, too-many-arguments subtitles, + stop_words_set_1, + stop_words_set_2, max_join_size=constants.DEFAULT_MAX_SIZE_PER_EVENT, max_delta_time=int(constants.DEFAULT_CONTINUOUS_SILENCE * 1000), - delimiters=constants.DEFAULT_EVENT_DELIMITER, - avoid_split=False -): + delimiters=constants.DEFAULT_EVENT_DELIMITERS, + avoid_split=False): """ Merge a source subtitles file's events automatically. """ @@ -484,66 +485,96 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block new_ssafile.events.append(temp_ssafile.events[0]) while event_count < sub_length: - if len(new_ssafile.events[-1].text) < max_join_size: - if not new_ssafile.events[-1].is_comment \ - and not temp_ssafile.events[event_count].is_comment\ - and new_ssafile.events[-1].style == temp_ssafile.events[event_count].style\ - and temp_ssafile.events[event_count].start\ - - new_ssafile.events[-1].end < max_delta_time \ - and new_ssafile.events[-1].text.rstrip(" ")[-1] not in delimiters: - if len(new_ssafile.events[-1].text) + \ - len(temp_ssafile.events[event_count].text) < max_join_size: - new_ssafile.events[-1].end = temp_ssafile.events[event_count].end - if new_ssafile.events[-1].text[-1] != " ": - new_ssafile.events[-1].text = new_ssafile.events[-1].text + " " + \ - temp_ssafile.events[event_count].text - else: - new_ssafile.events[-1].text = \ - new_ssafile.events[-1].text + temp_ssafile.events[event_count].text - merge_count = merge_count + 1 - event_count = event_count + 1 - continue + if not new_ssafile.events[-1].is_comment \ + and not temp_ssafile.events[event_count].is_comment \ + and new_ssafile.events[-1].style == temp_ssafile.events[event_count].style \ + and temp_ssafile.events[event_count].start \ + - new_ssafile.events[-1].end < max_delta_time \ + and new_ssafile.events[-1].text.rstrip(" ")[-1] not in delimiters: + if len(new_ssafile.events[-1].text) + \ + len(temp_ssafile.events[event_count].text) < max_join_size: + new_ssafile.events[-1].end = temp_ssafile.events[event_count].end + if new_ssafile.events[-1].text[-1] != " ": + new_ssafile.events[-1].text = new_ssafile.events[-1].text + " " + \ + temp_ssafile.events[event_count].text + else: + new_ssafile.events[-1].text = \ + new_ssafile.events[-1].text + temp_ssafile.events[event_count].text + merge_count = merge_count + 1 + event_count = event_count + 1 + continue - if not avoid_split: + if not avoid_split: + if len(new_ssafile.events[-1].text) > max_join_size * 0.7: + joint_event = new_ssafile.events[-1] + else: joint_event = join_event(new_ssafile.events[-1], temp_ssafile.events[event_count]) - event_list = [] - while True: - word_dict = get_slice_pos_dict(joint_event.text, delimiters=delimiters) - total_length = len(joint_event.text) - # use punctuations to split the sentence first - if len(word_dict) < 2: - word_dict = get_slice_pos_dict(joint_event.text) - stop_word_set = constants.DEFAULT_ENGLISH_STOP_WORDS_SET & \ + event_list = [] + while True: + word_dict = get_slice_pos_dict(joint_event.text, delimiters=delimiters) + total_length = len(joint_event.text) + # use punctuations to split the sentence first + if len(word_dict) < 2: + word_dict = get_slice_pos_dict(joint_event.text) + stop_word_set = stop_words_set_1 & \ + set(word_dict.keys()) + last_index = find_split_index( + total_length=total_length, + stop_word_set=stop_word_set, + word_dict=word_dict, + min_range_ratio=0.1 + ) + if not last_index: + stop_word_set = stop_words_set_2 & \ set(word_dict.keys()) - else: - stop_word_set = set(word_dict.keys()) + last_index = find_split_index( + total_length=total_length, + stop_word_set=stop_word_set, + word_dict=word_dict, + min_range_ratio=0.1 + ) + else: + stop_word_set = set(word_dict.keys()) last_index = find_split_index( total_length=total_length, stop_word_set=stop_word_set, word_dict=word_dict, - min_range_ratio=0.1, + min_range_ratio=0.1 ) - if 0 < last_index < max_join_size: - if total_length - last_index < max_join_size: - new_ssafile.events.pop() - event_list.extend(split_event(joint_event, last_index)) - new_ssafile.events.extend(event_list) - merge_count = merge_count + 1 - split_count = split_count + len(event_list) + if 0 < last_index < max_join_size: + if total_length - last_index < max_join_size: + event_list.extend(split_event(joint_event, last_index)) + if joint_event.text in new_ssafile.events[-1].text: + last_index = -2 + else: last_index = -1 - break - split_events = split_event(joint_event, last_index) - event_list.append(split_events[0]) - joint_event = split_events[1] - else: + new_ssafile.events.pop() + if len(event_list) > 2: + count = 0 + while count < len(event_list) - 1: + joint_event = join_event(event_list[count], + event_list[count + 1]) + if len(joint_event.text) < max_join_size: + del event_list[count + 1] + event_list[count] = joint_event + merge_count = merge_count + 1 + count = count + 1 + new_ssafile.events.extend(event_list) + split_count = split_count + len(event_list) break + split_events = split_event(joint_event, last_index) + event_list.append(split_events[0]) + joint_event = split_events[1] + else: + break - if last_index == -1: + if last_index < 0: + if last_index > -2: event_count = event_count + 1 - continue + continue new_ssafile.events.append(temp_ssafile.events[event_count]) event_count = event_count + 1 @@ -584,6 +615,7 @@ def find_split_index( if delta < last_delta: last_index = index last_delta = delta + return last_index @@ -610,6 +642,14 @@ def get_slice_pos_dict( j = i + 1 i = i + 1 + if i != j and sentence[j:i].strip(" "): + slice_ = sentence[j:i].lstrip(" ") + index = result_dict.get(slice_) + if not index: + result_dict[slice_] = [j] + else: + result_dict[slice_].append(j) + return result_dict From d0f6061dab1252561aa83624d2a2869e3fb5d150 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sun, 29 Mar 2020 18:01:21 +0800 Subject: [PATCH 14/26] Fix stop words issue in merge_src_assfile method --- autosub/constants.py | 6 ++-- .../zh_CN/LC_MESSAGES/autosub.sub_utils.po | 10 +++---- autosub/sub_utils.py | 29 ++++++++++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/autosub/constants.py b/autosub/constants.py index 2f976268..13afc453 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -445,9 +445,9 @@ def get_cmd(program_name): DEFAULT_CHECK_CMD = FFPROBE_CMD + " {in_} -show_format -pretty -loglevel quiet" DEFAULT_ENGLISH_STOP_WORDS_SET_1 = \ - {'after', 'and', 'as', 'because', 'before', 'between', 'but', 'for', 'how', 'if', 'or', 'so', - 'that', "that'll", 'until', 'what', 'when', 'where', 'which', 'while', 'who', 'whom', 'why', - 'with'} + {'after', 'and', 'as', 'because', 'before', 'between', 'but', 'either', 'except', 'for', 'how', + 'include', 'including', 'includes', 'included', 'if', 'or', 'since', 'so', 'that', "that'll", + 'until', 'what', 'when', 'where', 'which', 'while', 'who', 'whom', 'why', 'with'} DEFAULT_ENGLISH_STOP_WORDS_SET_2 = \ {'a', 'about', 'above', 'after', 'again', 'against', 'ain', 'all', 'am', 'an', 'and', 'any', diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po index f95128da..6434d9c7 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-29 16:29+0800\n" +"POT-Creation-Date: 2020-03-29 18:00+0800\n" "PO-Revision-Date: 2020-03-29 11:48+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,19 +17,19 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/sub_utils.py:585 +#: autosub/sub_utils.py:588 msgid "Merge {count} times." msgstr "合并了{count}次。" -#: autosub/sub_utils.py:586 +#: autosub/sub_utils.py:589 msgid "Split {count} times." msgstr "分割了{count}次。" -#: autosub/sub_utils.py:589 +#: autosub/sub_utils.py:592 msgid "Reduce {count} lines of events." msgstr "减少了{count}行字幕。" -#: autosub/sub_utils.py:591 +#: autosub/sub_utils.py:594 msgid "Add {count} lines of events." msgstr "增加了{count}行字幕。" diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index b74597d2..28d687b8 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -505,7 +505,9 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block continue if not avoid_split: - if len(new_ssafile.events[-1].text) > max_join_size * 0.7: + if len(new_ssafile.events[-1].text) \ + > len(temp_ssafile.events[event_count].text) * 1.4 and \ + len(new_ssafile.events[-1].text) > max_join_size * 0.8: joint_event = new_ssafile.events[-1] else: joint_event = join_event(new_ssafile.events[-1], @@ -515,7 +517,16 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block word_dict = get_slice_pos_dict(joint_event.text, delimiters=delimiters) total_length = len(joint_event.text) # use punctuations to split the sentence first - if len(word_dict) < 2: + stop_word_set = set(word_dict.keys()) + last_index = find_split_index( + total_length=total_length, + stop_word_set=stop_word_set, + word_dict=word_dict, + min_range_ratio=0.1 + ) + + if len(word_dict) < 2 or not last_index: + # then use stop words word_dict = get_slice_pos_dict(joint_event.text) stop_word_set = stop_words_set_1 & \ set(word_dict.keys()) @@ -535,15 +546,6 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block min_range_ratio=0.1 ) - else: - stop_word_set = set(word_dict.keys()) - last_index = find_split_index( - total_length=total_length, - stop_word_set=stop_word_set, - word_dict=word_dict, - min_range_ratio=0.1 - ) - if 0 < last_index < max_join_size: if total_length - last_index < max_join_size: event_list.extend(split_event(joint_event, last_index)) @@ -555,8 +557,9 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block if len(event_list) > 2: count = 0 while count < len(event_list) - 1: - joint_event = join_event(event_list[count], - event_list[count + 1]) + joint_event = join_event( + event_list[count], + event_list[count + 1]) if len(joint_event.text) < max_join_size: del event_list[count + 1] event_list[count] = joint_event From 4edbb750cf2178b5b8ae8016360bc2ccf1cdff91 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Thu, 2 Apr 2020 16:16:08 +0800 Subject: [PATCH 15/26] Fix os.remove() PermissionError in api_xfyun.py --- CHANGELOG.md | 1 + autosub/api_xfyun.py | 4 +- autosub/cmdline_utils.py | 5 +- .../LC_MESSAGES/autosub.cmdline_utils.po | 54 ++--- .../zh_CN/LC_MESSAGES/autosub.options.po | 222 +++++++++--------- .../zh_CN/LC_MESSAGES/autosub.sub_utils.po | 10 +- autosub/options.py | 7 +- autosub/sub_utils.py | 4 +- docs/CHANGELOG.zh-Hans.md | 1 + scripts/pyinstaller_build.bat | 3 + 10 files changed, 160 insertions(+), 151 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a779ea2b..2f917168 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ Click up arrow to go back to TOC. - Fix the size count bug when the last line been split in list_to_googletrans. - Fix delete_chars issue when using `-of full-src`. +- Fix os.remove() PermissionError in api_xfyun.py. #### Removed(Unreleased) diff --git a/autosub/api_xfyun.py b/autosub/api_xfyun.py index f2bc78f4..c489c06d 100644 --- a/autosub/api_xfyun.py +++ b/autosub/api_xfyun.py @@ -142,8 +142,6 @@ def __call__(self, filename): on_close=lambda web_socket: self.on_close(web_socket), on_open=lambda web_socket: self.on_open(web_socket)) self.web_socket_app.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}) - if not self.is_keep: - os.remove(filename) if self.is_full_result: return self.result_list return self.transcript @@ -219,6 +217,8 @@ def run(): # 模拟音频采样间隔 time.sleep(interval) web_socket.close() + if not self.is_keep: + os.remove(self.filename) _thread.start_new_thread(run, ()) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index cafe9949..85a955b6 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -1094,7 +1094,7 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen _("Error: Convert source file to \"{name}\" failed.").format( name=audio_wav)) - print(_("Conversion complete.\nUse Auditok to detect speech regions.")) + print(_("Conversion completed.\nUse Auditok to detect speech regions.")) regions = core.auditok_gen_speech_regions( audio_wav=audio_wav, @@ -1106,7 +1106,8 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen os.remove(audio_wav) gc.collect(0) - print(_("\n\"{name}\" has been deleted.").format(name=audio_wav)) + print(_("Auditok detection completed." + "\n\"{name}\" has been deleted.").format(name=audio_wav)) if not regions: raise exceptions.AutosubException( 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 50c5b314..3b8d882b 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-29 16:29+0800\n" -"PO-Revision-Date: 2020-03-26 14:48+0800\n" +"POT-Creation-Date: 2020-04-02 16:04+0800\n" +"PO-Revision-Date: 2020-04-02 16:04+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -326,16 +326,16 @@ msgstr "" "现在重置为{dmxcs}。" #: autosub/cmdline_utils.py:679 autosub/cmdline_utils.py:912 -#: autosub/cmdline_utils.py:1455 +#: autosub/cmdline_utils.py:1456 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" #: autosub/cmdline_utils.py:683 autosub/cmdline_utils.py:718 #: autosub/cmdline_utils.py:769 autosub/cmdline_utils.py:863 #: autosub/cmdline_utils.py:916 autosub/cmdline_utils.py:969 -#: autosub/cmdline_utils.py:1145 autosub/cmdline_utils.py:1308 -#: autosub/cmdline_utils.py:1350 autosub/cmdline_utils.py:1411 -#: autosub/cmdline_utils.py:1459 autosub/cmdline_utils.py:1507 +#: autosub/cmdline_utils.py:1146 autosub/cmdline_utils.py:1309 +#: autosub/cmdline_utils.py:1351 autosub/cmdline_utils.py:1412 +#: autosub/cmdline_utils.py:1460 autosub/cmdline_utils.py:1508 msgid "" "\n" "All works done." @@ -344,7 +344,7 @@ msgstr "" "做完了。" #: autosub/cmdline_utils.py:714 autosub/cmdline_utils.py:965 -#: autosub/cmdline_utils.py:1503 +#: autosub/cmdline_utils.py:1504 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" @@ -352,15 +352,15 @@ msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" msgid "\"join-events\" subtitles file created at \"{}\"." msgstr "\"join-events\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:814 autosub/cmdline_utils.py:1368 +#: autosub/cmdline_utils.py:814 autosub/cmdline_utils.py:1369 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:859 autosub/cmdline_utils.py:1407 +#: autosub/cmdline_utils.py:859 autosub/cmdline_utils.py:1408 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1009 autosub/cmdline_utils.py:1548 +#: autosub/cmdline_utils.py:1009 autosub/cmdline_utils.py:1549 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" @@ -382,7 +382,7 @@ msgstr "错误:转换源文件至\"{name}\"失败。" #: autosub/cmdline_utils.py:1097 msgid "" -"Conversion complete.\n" +"Conversion completed.\n" "Use Auditok to detect speech regions." msgstr "" "转换完毕。\n" @@ -390,25 +390,25 @@ msgstr "" #: autosub/cmdline_utils.py:1109 msgid "" -"\n" +"Auditok detection completed.\n" "\"{name}\" has been deleted." msgstr "" -"\n" +"Auditok语音区域检测完毕\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:1113 +#: autosub/cmdline_utils.py:1114 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1142 autosub/cmdline_utils.py:1615 +#: autosub/cmdline_utils.py:1143 autosub/cmdline_utils.py:1616 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1166 +#: autosub/cmdline_utils.py:1167 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1170 +#: autosub/cmdline_utils.py:1171 msgid "" "Audio processing complete.\n" "All works done." @@ -416,11 +416,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1222 +#: autosub/cmdline_utils.py:1223 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1237 +#: autosub/cmdline_utils.py:1238 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -430,18 +430,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1242 +#: autosub/cmdline_utils.py:1243 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1256 +#: autosub/cmdline_utils.py:1257 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1268 +#: autosub/cmdline_utils.py:1269 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -449,11 +449,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1304 +#: autosub/cmdline_utils.py:1305 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1312 +#: autosub/cmdline_utils.py:1313 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -461,11 +461,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1346 autosub/cmdline_utils.py:1585 +#: autosub/cmdline_utils.py:1347 autosub/cmdline_utils.py:1586 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1557 +#: autosub/cmdline_utils.py:1558 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -473,7 +473,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1590 +#: autosub/cmdline_utils.py:1591 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.options.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po index 2469cead..dd29e476 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-29 16:29+0800\n" -"PO-Revision-Date: 2020-03-24 11:52+0800\n" +"POT-Creation-Date: 2020-04-02 16:04+0800\n" +"PO-Revision-Date: 2020-03-29 20:30+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -35,6 +35,7 @@ msgid "" "when the option is not given at the command line.\n" "\"(arg_num)\" means if the option is given,\n" "the number of the arguments is required.\n" +"Arguments *ARE* the things given behind the options.\n" "Author: {author}\n" "Email: {email}\n" "Bug report: {homepage}\n" @@ -44,112 +45,113 @@ msgstr "" "如果选项没有在命令行中提供时会使用的参数。\n" "\"参数个数\"指的是如果提供了选项,\n" "该选项所需要的参数个数。\n" +"*参数指的是那些用在选项后面的东西。*\n" "作者: {author}\n" "Email: {email}\n" "问题反馈: {homepage}\n" -#: autosub/options.py:56 +#: autosub/options.py:57 msgid "Input Options" msgstr "输入选项" -#: autosub/options.py:57 +#: autosub/options.py:58 msgid "Options to control input." msgstr "控制输入的选项。" -#: autosub/options.py:59 +#: autosub/options.py:60 msgid "Language Options" msgstr "语言选项" -#: autosub/options.py:60 +#: autosub/options.py:61 msgid "Options to control language." msgstr "控制语言的选项。" -#: autosub/options.py:62 +#: autosub/options.py:63 msgid "Output Options" msgstr "输出选项" -#: autosub/options.py:63 +#: autosub/options.py:64 msgid "Options to control output." msgstr "控制输出的选项。" -#: autosub/options.py:65 +#: autosub/options.py:66 msgid "Speech Options" msgstr "语音选项" -#: autosub/options.py:66 +#: autosub/options.py:67 msgid "" "Options to control speech-to-text. If Speech Options not given, it will only " "generate the times." msgstr "控制语音转文字的选项。" -#: autosub/options.py:69 +#: autosub/options.py:70 msgid "py-googletrans Options" msgstr "py-googletrans选项" -#: autosub/options.py:70 +#: autosub/options.py:71 msgid "" "Options to control translation. Default method to translate. Could be " "blocked at any time." msgstr "控制翻译的选项。同时也是默认的翻译方法。可能随时会被谷歌爸爸封。" -#: autosub/options.py:74 +#: autosub/options.py:75 #, fuzzy msgid "Subtitles Conversion Options" msgstr "音频处理选项" -#: autosub/options.py:75 +#: autosub/options.py:76 #, fuzzy msgid "Options to control subtitles conversions.(Experimental)" msgstr "控制音频处理的选项。" -#: autosub/options.py:77 +#: autosub/options.py:78 msgid "Network Options" msgstr "网络选项" -#: autosub/options.py:78 +#: autosub/options.py:79 msgid "Options to control network." msgstr "控制网络的选项。" -#: autosub/options.py:80 +#: autosub/options.py:81 msgid "Other Options" msgstr "其他选项" -#: autosub/options.py:81 +#: autosub/options.py:82 msgid "Other options to control." msgstr "控制其他东西的选项。" -#: autosub/options.py:83 +#: autosub/options.py:84 msgid "Audio Processing Options" msgstr "音频处理选项" -#: autosub/options.py:84 +#: autosub/options.py:85 msgid "Options to control audio processing." msgstr "控制音频处理的选项。" -#: autosub/options.py:86 +#: autosub/options.py:87 msgid "Auditok Options" msgstr "Auditok的选项" -#: autosub/options.py:87 +#: autosub/options.py:88 msgid "" "Options to control Auditok when not using external speech regions control." msgstr "不使用外部语音区域控制时,用于控制Auditok的选项。" -#: autosub/options.py:90 +#: autosub/options.py:91 msgid "List Options" msgstr "列表选项" -#: autosub/options.py:91 +#: autosub/options.py:92 msgid "List all available arguments." msgstr "列出所有可选参数。" -#: autosub/options.py:95 autosub/options.py:104 autosub/options.py:113 -#: autosub/options.py:195 autosub/options.py:276 autosub/options.py:455 -#: autosub/options.py:651 +#: autosub/options.py:96 autosub/options.py:105 autosub/options.py:114 +#: autosub/options.py:196 autosub/options.py:277 autosub/options.py:456 +#: autosub/options.py:652 msgid "path" msgstr "路径" -#: autosub/options.py:96 +#: autosub/options.py:97 msgid "" "The path to the video/audio/subtitles file that needs to generate subtitles. " "When it is a subtitles file, the program will only translate it. (arg_num = " @@ -158,7 +160,7 @@ msgstr "" "用于生成字幕文件的视频/音频/字幕文件。如果输入文件是字幕文件,程序仅会对其进" "行翻译。(参数个数为1)" -#: autosub/options.py:105 +#: autosub/options.py:106 msgid "" "Path to the subtitles file which provides external speech regions, which is " "one of the formats that pysubs2 supports and overrides the default method to " @@ -167,7 +169,7 @@ msgstr "" "提供外部语音区域(时间轴)的字幕文件。该字幕文件格式需要是pysubs2所支持的。使" "用后会替换掉默认的自动寻找语音区域(时间轴)的功能。(参数个数为1)" -#: autosub/options.py:115 +#: autosub/options.py:116 msgid "" "Valid when your output format is \"ass\"/\"ssa\". Path to the subtitles file " "which provides \"ass\"/\"ssa\" styles for your output. If the arg_num is 0, " @@ -178,11 +180,11 @@ msgstr "" "幕文件。如果不提供参数,它会使用来自\"-esr\"/\"--external-speech-regions\"选" "项提供的样式。更多信息详见\"-sn\"/\"--styles-name\"。(参数个数为0或1)" -#: autosub/options.py:126 +#: autosub/options.py:127 msgid "style_name" msgstr "样式名" -#: autosub/options.py:127 +#: autosub/options.py:128 msgid "" "Valid when your output format is \"ass\"/\"ssa\" and \"-sty\"/\"--styles\" " "is given. Adds \"ass\"/\"ssa\" styles to your events. If not provided, " @@ -197,12 +199,12 @@ msgstr "" "数作为样式名。如果参数个数为2,源语言字幕行会使用第一个参数作为样式名。目标语" "言行使用第二个。(参数个数为1或2)" -#: autosub/options.py:140 autosub/options.py:151 autosub/options.py:161 -#: autosub/options.py:623 autosub/options.py:639 +#: autosub/options.py:141 autosub/options.py:152 autosub/options.py:162 +#: autosub/options.py:624 autosub/options.py:640 msgid "lang_code" msgstr "语言代码" -#: autosub/options.py:141 +#: autosub/options.py:142 #, python-format msgid "" "Lang code/Lang tag for speech-to-text. Recommend using the Google Cloud " @@ -214,7 +216,7 @@ msgstr "" "码。错误的输入不会终止程序。但是后果自负。参考:https://cloud.google.com/" "speech-to-text/docs/languages(参数个数为1)(默认参数: %(default)s)" -#: autosub/options.py:152 +#: autosub/options.py:153 #, python-format msgid "" "Lang code/Lang tag for translation source language. If not given, use " @@ -227,7 +229,7 @@ msgstr "" "googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数为%" "(default)s)" -#: autosub/options.py:162 +#: autosub/options.py:163 #, python-format msgid "" "Lang code/Lang tag for translation destination language. Same attention in " @@ -236,11 +238,11 @@ msgstr "" "用于翻译的目标语言的语言代码/语言标识符。同样的注意参考选项\"-SRC\"/\"--src-" "language\"。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:168 autosub/options.py:466 +#: autosub/options.py:169 autosub/options.py:467 msgid "mode" msgstr "模式" -#: autosub/options.py:170 +#: autosub/options.py:171 msgid "" "Allow langcodes to get a best matching lang code when your input is wrong. " "Only functional for py-googletrans and Google Speech V2. Available modes: s, " @@ -252,7 +254,7 @@ msgstr "" "\"-S\"/\"--speech-language\"。\"src\"指\"-SRC\"/\"--src-language\"。\"d\"指" "\"-D\"/\"--dst-language\"。(参数个数在1到3之间)" -#: autosub/options.py:184 +#: autosub/options.py:185 msgid "" "An integer between 0 and 100 to control the good match group of \"-lsc\"/\"--" "list-speech-codes\" or \"-ltc\"/\"--list-translation-codes\" or the match " @@ -264,7 +266,7 @@ msgstr "" "best-match\"选项中的最佳匹配结果。结果会是一组“好的匹配”,其分数需要超过这个" "参数的值。(参数个数为1)" -#: autosub/options.py:196 +#: autosub/options.py:197 msgid "" "The output path for subtitles file. (default: the \"input\" path combined " "with the proper name tails) (arg_num = 1)" @@ -272,11 +274,11 @@ msgstr "" "输出字幕文件的路径。(默认值是\"input\"路径和适当的文件名后缀的结合)(参数个" "数为1)" -#: autosub/options.py:202 +#: autosub/options.py:203 msgid "format" msgstr "格式" -#: autosub/options.py:203 +#: autosub/options.py:204 msgid "" "Destination subtitles format. If not provided, use the extension in the \"-o" "\"/\"--output\" arg. If \"-o\"/\"--output\" arg doesn't provide the " @@ -289,18 +291,18 @@ msgstr "" "果\"-i\"/\"--input\"的参数是一个字幕文件,那么使用和字幕文件相同的扩展名。" "(参数个数为1)(默认参数为{dft})" -#: autosub/options.py:216 +#: autosub/options.py:217 msgid "" "Prevent pauses and allow files to be overwritten. Stop the program when your " "args are wrong. (arg_num = 0)" msgstr "" "避免任何暂停和覆写文件的行为。如果参数有误,会直接停止程序。(参数个数为0)" -#: autosub/options.py:221 +#: autosub/options.py:222 msgid "type" msgstr "种类" -#: autosub/options.py:224 +#: autosub/options.py:225 #, python-format msgid "" "Output more files. Available types: regions, src, full-src, dst, bilingual, " @@ -318,7 +320,7 @@ msgstr "" "字幕行中,且目标语言先于源语言。src-lf-dst:源语言和目标语言在同一字幕行中," "且源语言先于目标语言。(参数个数在6和1之间)(默认参数为%(default)s)" -#: autosub/options.py:241 +#: autosub/options.py:242 msgid "" "Valid when your output format is \"sub\". If input, it will override the fps " "check on the input file. Ref: https://pysubs2.readthedocs.io/en/latest/api-" @@ -328,11 +330,11 @@ msgstr "" "查。参考:https://pysubs2.readthedocs.io/en/latest/api-reference." "html#supported-input-output-formats(参数个数为1)" -#: autosub/options.py:250 +#: autosub/options.py:251 msgid "API_code" msgstr "API代码" -#: autosub/options.py:253 +#: autosub/options.py:254 #, python-format msgid "" "Choose which Speech-to-Text API to use. Currently support: gsv2: Google " @@ -351,7 +353,7 @@ msgstr "" "ai.baidu.com/ai-doc/SPEECH/Vk38lxily)(参数个数为1)(默认参数为%(default)" "s)" -#: autosub/options.py:267 +#: autosub/options.py:268 msgid "" "The API key for Google Speech-to-Text API. (arg_num = 1) Currently support: " "gsv2: The API key for gsv2. (default: Free API key) gcsv1: The API key for " @@ -362,7 +364,7 @@ msgstr "" "钥。(默认参数为免费API密钥)gcsv1:gcsv1的API密钥。(如果使用了,可以覆盖 " "\"-sa\"/\"--service-account\"提供的服务账号凭据)" -#: autosub/options.py:278 +#: autosub/options.py:279 #, python-format msgid "" "Use Speech-to-Text recognition config file to send request. Override these " @@ -386,7 +388,7 @@ msgstr "" "ai-doc/SPEECH/ek38lxj1u)。如果参数个数是0,使用const路径。(参数个数为0或1)" "(const为%(const)s)" -#: autosub/options.py:303 +#: autosub/options.py:304 #, python-format msgid "" "Google Speech-to-Text API response for text confidence. A float value " @@ -399,11 +401,11 @@ msgstr "" "除。参考:https://github.com/BingLingGroup/google-speech-v2#response(参数个" "数为1)(默认参数为%(default)s)" -#: autosub/options.py:313 +#: autosub/options.py:314 msgid "Drop any regions without speech recognition result. (arg_num = 0)" msgstr "删除所有没有语音识别结果的空轴。(参数个数为0)" -#: autosub/options.py:321 +#: autosub/options.py:322 #, python-format msgid "" "Number of concurrent Speech-to-Text requests to make. (arg_num = 1) " @@ -411,12 +413,12 @@ msgid "" msgstr "" "用于Speech-to-Text请求的并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:326 autosub/options.py:374 autosub/options.py:571 -#: autosub/options.py:580 autosub/options.py:589 +#: autosub/options.py:327 autosub/options.py:375 autosub/options.py:572 +#: autosub/options.py:581 autosub/options.py:590 msgid "second" msgstr "秒" -#: autosub/options.py:329 +#: autosub/options.py:330 #, python-format msgid "" "(Experimental)Seconds to sleep between two translation requests. (arg_num = " @@ -425,7 +427,7 @@ msgstr "" "(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" "(default)s)" -#: autosub/options.py:337 +#: autosub/options.py:338 msgid "" "(Experimental)Customize request urls. Ref: https://py-googletrans." "readthedocs.io/en/latest/ (arg_num >= 1)" @@ -433,20 +435,20 @@ msgstr "" "(实验性)自定义多个请求URL。参考:https://py-googletrans.readthedocs.io/en/" "latest/(参数个数大于等于1)" -#: autosub/options.py:344 +#: autosub/options.py:345 msgid "" "(Experimental)Customize User-Agent headers. Same docs above. (arg_num = 1)" msgstr "" "(实验性)自定义用户代理(User-Agent)头部。同样的参考文档如上。(参数个数为" "1)" -#: autosub/options.py:351 +#: autosub/options.py:352 msgid "" "Drop any .ass override codes in the text before translation. Only affect the " "translation result. (arg_num = 0)" msgstr "在翻译前删除所有文本中的ass特效标签。只影响翻译结果。(参数个数为0)" -#: autosub/options.py:359 +#: autosub/options.py:360 #, python-format msgid "" "Replace the specific chars with a space after translation, and strip the " @@ -456,7 +458,7 @@ msgstr "" "将指定字符替换为空格,并消除每句末尾空格。只会影响翻译结果。(参数个数为0或" "1)(const为%(const)s)" -#: autosub/options.py:369 +#: autosub/options.py:370 #, fuzzy, python-format msgid "" "(Experimental)Max length to join two events. (arg_num = 1) (default: %" @@ -465,7 +467,7 @@ msgstr "" "(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" "(default)s)" -#: autosub/options.py:377 +#: autosub/options.py:378 #, fuzzy, python-format msgid "" "(Experimental)Max delta time to join two events. (arg_num = 1) (default: %" @@ -474,11 +476,11 @@ msgstr "" "(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" "(default)s)" -#: autosub/options.py:382 +#: autosub/options.py:383 msgid "string" msgstr "" -#: autosub/options.py:384 +#: autosub/options.py:385 #, fuzzy, python-format msgid "" "(Experimental)Delimiters not to join two events. (arg_num = 1) (default: %" @@ -487,37 +489,35 @@ msgstr "" "(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" "(default)s)" -#: autosub/options.py:389 autosub/options.py:395 +#: autosub/options.py:390 autosub/options.py:396 msgid "words_delimited_by_space" msgstr "" -#: autosub/options.py:390 -#, fuzzy, python-format +#: autosub/options.py:391 +#, fuzzy msgid "" -"(Experimental)First set of Stop words to split two events. (arg_num = 1) " -"(default: %(default)s)" +"(Experimental)First set of Stop words to split two events. (arg_num = 1)" msgstr "" "(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" "(default)s)" -#: autosub/options.py:396 -#, fuzzy, python-format +#: autosub/options.py:397 +#, fuzzy msgid "" -"(Experimental)Second set of Stop words to split two events. (arg_num = 1) " -"(default: %(default)s)" +"(Experimental)Second set of Stop words to split two events. (arg_num = 1)" msgstr "" "(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" "(default)s)" -#: autosub/options.py:402 +#: autosub/options.py:403 msgid "(Experimental)Don't Split just merge. (arg_num = 0)" msgstr "" -#: autosub/options.py:408 +#: autosub/options.py:409 msgid "Change the Google Speech V2 API URL into the http one. (arg_num = 0)" msgstr "将Google Speech V2 API的URL改为http类型。(参数个数为0)" -#: autosub/options.py:416 +#: autosub/options.py:417 #, python-format msgid "" "Add https proxy by setting environment variables. If arg_num is 0, use const " @@ -526,7 +526,7 @@ msgstr "" "通过设置环境变量的方式添加https代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:424 +#: autosub/options.py:425 #, python-format msgid "" "Add http proxy by setting environment variables. If arg_num is 0, use const " @@ -535,33 +535,33 @@ msgstr "" "通过设置环境变量的方式添加http代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:430 +#: autosub/options.py:431 msgid "username" msgstr "用户名" -#: autosub/options.py:431 +#: autosub/options.py:432 msgid "Set proxy username. (arg_num = 1)" msgstr "设置代理用户名。(参数个数为1)" -#: autosub/options.py:436 +#: autosub/options.py:437 msgid "password" msgstr "密码" -#: autosub/options.py:437 +#: autosub/options.py:438 msgid "Set proxy password. (arg_num = 1)" msgstr "设置代理密码。(参数个数为1)" -#: autosub/options.py:443 +#: autosub/options.py:444 #, python-format msgid "Show %(prog)s help message and exit. (arg_num = 0)" msgstr "显示%(prog)s的帮助信息并退出。(参数个数为0)" -#: autosub/options.py:451 +#: autosub/options.py:452 #, python-format msgid "Show %(prog)s version and exit. (arg_num = 0)" msgstr "显示%(prog)s的版本信息并退出。(参数个数为0)" -#: autosub/options.py:456 +#: autosub/options.py:457 msgid "" "Set service account key environment variable. It should be the file path of " "the JSON file that contains your service account credentials. Can be " @@ -574,7 +574,7 @@ msgstr "" "authentication/getting-started 当前支持:gcsv1" "(GOOGLE_APPLICATION_CREDENTIALS)(参数个数为1)" -#: autosub/options.py:467 +#: autosub/options.py:468 msgid "" "Option to control audio process. If not given the option, do normal " "conversion work. \"y\": pre-process the input first then start normal " @@ -593,15 +593,15 @@ msgstr "" "scripts/subgen.sh https://ffmpeg.org/ffmpeg-filters.html)(参数个数介于1和2" "之间)" -#: autosub/options.py:491 +#: autosub/options.py:492 msgid "Keep audio processing files to the output path. (arg_num = 0)" msgstr "将音频处理中产生的文件放在输出路径中。(参数个数为0)" -#: autosub/options.py:496 autosub/options.py:514 autosub/options.py:526 +#: autosub/options.py:497 autosub/options.py:515 autosub/options.py:527 msgid "command" msgstr "命令" -#: autosub/options.py:497 +#: autosub/options.py:498 msgid "" "This arg will override the default audio pre-process command. Every line of " "the commands need to be in quotes. Input file name is {in_}. Output file " @@ -610,7 +610,7 @@ msgstr "" "这个参数会取代默认的音频预处理命令。每行命令需要放在一个引号内。输入文件名写" "为{in_}。输出文件名写为{out_}。(参数个数大于1)" -#: autosub/options.py:509 +#: autosub/options.py:510 #, python-format msgid "" "Number of concurrent ffmpeg audio split process to make. (arg_num = 1) " @@ -618,11 +618,11 @@ msgid "" msgstr "" "用于ffmpeg音频切割的进程并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:516 -#, python-format +#: autosub/options.py:517 +#, fuzzy, python-format msgid "" "(Experimental)This arg will override the default audio conversion command. " -"\"[\", \"]\" are optional arguments meaning you can remove them. \"{{\", \"}}" +"\"[\", \"]\" are optional arguments meaning you can remove them. \"{\", \"}" "\" are required arguments meaning you can't remove them. (arg_num = 1) " "(default: %(default)s)" msgstr "" @@ -630,7 +630,7 @@ msgstr "" "除。\"{{\", \"}}\"是必选参数,不可移除。(参数个数为1)(默认参数为%(default)" "s)" -#: autosub/options.py:528 +#: autosub/options.py:529 #, python-format msgid "" "(Experimental)This arg will override the default audio split command. Same " @@ -639,11 +639,11 @@ msgstr "" "(实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:535 +#: autosub/options.py:536 msgid "file_suffix" msgstr "文件名后缀" -#: autosub/options.py:537 +#: autosub/options.py:538 #, python-format msgid "" "(Experimental)This arg will override the default API audio suffix. (arg_num " @@ -652,11 +652,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数为%(default)" "s)" -#: autosub/options.py:543 +#: autosub/options.py:544 msgid "sample_rate" msgstr "采样率" -#: autosub/options.py:546 +#: autosub/options.py:547 #, python-format msgid "" "(Experimental)This arg will override the default API audio sample rate(Hz). " @@ -665,11 +665,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频采样率(赫兹)。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:552 +#: autosub/options.py:553 msgid "channel_num" msgstr "声道数" -#: autosub/options.py:555 +#: autosub/options.py:556 #, python-format msgid "" "(Experimental)This arg will override the default API audio channel. (arg_num " @@ -678,11 +678,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频声道数量。(参数个数为1)(默认" "参数为%(default)s)" -#: autosub/options.py:561 +#: autosub/options.py:562 msgid "energy" msgstr "能量(相对值)" -#: autosub/options.py:564 +#: autosub/options.py:565 #, python-format msgid "" "The energy level which determines the region to be detected. Ref: https://" @@ -693,7 +693,7 @@ msgstr "" "latest/apitutorial.html#examples-using-real-audio-data(参数个数为1)(默认参" "数为%(default)s)" -#: autosub/options.py:574 +#: autosub/options.py:575 #, python-format msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" @@ -701,7 +701,7 @@ msgstr "" "最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" "s)" -#: autosub/options.py:583 +#: autosub/options.py:584 #, python-format msgid "" "Maximum region size. Same docs above. (arg_num = 1) (default: %(default)s)" @@ -709,7 +709,7 @@ msgstr "" "最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" "s)" -#: autosub/options.py:592 +#: autosub/options.py:593 #, python-format msgid "" "Maximum length of a tolerated silence within a valid audio activity. Same " @@ -718,7 +718,7 @@ msgstr "" "在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如" "上。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:599 +#: autosub/options.py:600 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." @@ -727,7 +727,7 @@ msgstr "" "如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://" "auditok.readthedocs.io/en/latest/core.html#class-summary(参数个数为0)" -#: autosub/options.py:607 +#: autosub/options.py:608 msgid "" "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)" @@ -735,7 +735,7 @@ msgstr "" "参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" "个数为0)" -#: autosub/options.py:613 +#: autosub/options.py:614 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 " @@ -746,7 +746,7 @@ msgstr "" "SubtitleEdit来对其进行转换。如果输出格式是\"sub\"且输入文件是音频无法获取到视" "频帧率时,你需要提供fps选项指定帧率。(参数个数为0)" -#: autosub/options.py:626 +#: autosub/options.py:627 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 " @@ -764,7 +764,7 @@ msgstr "" "言)-扩展-私有(https://www.zhihu.com/question/21980689/answer/93615123)(参" "数个数为0或1)" -#: autosub/options.py:642 +#: autosub/options.py:643 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 " @@ -774,7 +774,7 @@ msgstr "" "言代码。否则会给出一个“好的匹配”的清单。同样的参考文档如上。(参数个数为0或" "1)" -#: autosub/options.py:652 +#: autosub/options.py:653 #, python-format msgid "" "Use py-googletrans to detect a sub file's first line language. And list a " diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po index 6434d9c7..6f43c32d 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-29 18:00+0800\n" +"POT-Creation-Date: 2020-04-02 16:04+0800\n" "PO-Revision-Date: 2020-03-29 11:48+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,19 +17,19 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/sub_utils.py:588 +#: autosub/sub_utils.py:590 msgid "Merge {count} times." msgstr "合并了{count}次。" -#: autosub/sub_utils.py:589 +#: autosub/sub_utils.py:591 msgid "Split {count} times." msgstr "分割了{count}次。" -#: autosub/sub_utils.py:592 +#: autosub/sub_utils.py:594 msgid "Reduce {count} lines of events." msgstr "减少了{count}行字幕。" -#: autosub/sub_utils.py:594 +#: autosub/sub_utils.py:596 msgid "Add {count} lines of events." msgstr "增加了{count}行字幕。" diff --git a/autosub/options.py b/autosub/options.py index 11a563aa..c6a15f74 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -43,6 +43,7 @@ def get_cmd_parser(): # pylint: disable=too-many-statements "when the option is not given at the command line.\n" "\"(arg_num)\" means if the option is given,\n" "the number of the arguments is required.\n" + "Arguments *ARE* the things given behind the options.\n" "Author: {author}\n" "Email: {email}\n" "Bug report: {homepage}\n").format( @@ -388,13 +389,13 @@ def get_cmd_parser(): # pylint: disable=too-many-statements '-sw1', '--stop-words-1', metavar=_('words_delimited_by_space'), help=_("(Experimental)First set of Stop words to split two events. " - "(arg_num = 1) (default: %(default)s)")) + "(arg_num = 1)")) conversion_group.add_argument( '-sw2', '--stop-words-2', metavar=_('words_delimited_by_space'), help=_("(Experimental)Second set of Stop words to split two events. " - "(arg_num = 1) (default: %(default)s)")) + "(arg_num = 1)")) conversion_group.add_argument( '-ds', '--dont-split', @@ -517,7 +518,7 @@ def get_cmd_parser(): # pylint: disable=too-many-statements "audio conversion command. " "\"[\", \"]\" are optional arguments " "meaning you can remove them. " - "\"{{\", \"}}\" are required arguments " + "\"{\", \"}\" are required arguments " "meaning you can't remove them. " "(arg_num = 1) (default: %(default)s)")) diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index 28d687b8..ae279d49 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -449,6 +449,7 @@ def merge_bilingual_assfile( # pylint: disable=too-many-locals, too-many-branch def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-blocks, # pylint: disable=too-many-statements, too-many-branches, too-many-arguments + # pylint: disable=too-many-boolean-expressions subtitles, stop_words_set_1, stop_words_set_2, @@ -490,7 +491,8 @@ def merge_src_assfile( # pylint: disable=too-many-locals, too-many-nested-block and new_ssafile.events[-1].style == temp_ssafile.events[event_count].style \ and temp_ssafile.events[event_count].start \ - new_ssafile.events[-1].end < max_delta_time \ - and new_ssafile.events[-1].text.rstrip(" ")[-1] not in delimiters: + and new_ssafile.events[-1].text.rstrip(" ")[-1] not in delimiters\ + and temp_ssafile.events[event_count].text.lstrip(" ")[0] not in delimiters: if len(new_ssafile.events[-1].text) + \ len(temp_ssafile.events[event_count].text) < max_join_size: new_ssafile.events[-1].end = temp_ssafile.events[event_count].end diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index ea101cd5..e4dce2ee 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -66,6 +66,7 @@ - 修复list_to_googletrans中当最后一行是需要被分割时的长度计算问题。 - 修复delete_chars问题当使用`-of full-src`时。 +- 修复api_xfyun.py中的os.remove()文件占用问题。 #### 删除(未发布) diff --git a/scripts/pyinstaller_build.bat b/scripts/pyinstaller_build.bat index 7a09b565..97e903bb 100644 --- a/scripts/pyinstaller_build.bat +++ b/scripts/pyinstaller_build.bat @@ -3,5 +3,8 @@ set dist_dir="..\.build_and_dist\pyinstaller.build" @echo on cd %~dp0 +cd ..\ +pip install -r requirements.txt +cd %~dp0 pyinstaller pyinstaller_build.spec --clean --distpath %dist_dir% --workpath %dist_dir% pause \ No newline at end of file From 009e1f06a6a8f06ee552908eefdf2f8cc934145a Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Fri, 3 Apr 2020 12:10:27 +0800 Subject: [PATCH 16/26] Change the default style selection in subtitles translation --- CHANGELOG.md | 1 + autosub/api_xfyun.py | 5 ----- autosub/cmdline_utils.py | 20 +++++++------------ autosub/core.py | 27 +++++++++++++++---------- autosub/sub_utils.py | 42 ++++++++++++++++++++++++--------------- docs/CHANGELOG.zh-Hans.md | 1 + 6 files changed, 51 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f917168..b16659c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ Click up arrow to go back to TOC. - Change the replacement condition of the audio_split_cmd only when the user doesn't modify it. - Change the MAX_REGION_SIZE_LIMIT into 60 seconds. - Change all text file input decoding into "utf-8". +- Change the default style selection in subtitles translation. #### Fixed(Unreleased) diff --git a/autosub/api_xfyun.py b/autosub/api_xfyun.py index c489c06d..b33940b3 100644 --- a/autosub/api_xfyun.py +++ b/autosub/api_xfyun.py @@ -4,7 +4,6 @@ Defines Xun Fei Yun API used by autosub. """ # Import built-in modules -import os import datetime import hashlib import base64 @@ -103,7 +102,6 @@ def __init__(self, api_secret, api_address, business_args, - is_keep=False, is_full_result=False, delete_chars=None): self.common_args = {"app_id": app_id} @@ -111,7 +109,6 @@ def __init__(self, self.api_secret = api_secret self.api_address = api_address self.business_args = business_args - self.is_keep = is_keep self.is_full_result = is_full_result self.delete_chars = delete_chars self.data = {"status": 0, @@ -217,8 +214,6 @@ def run(): # 模拟音频采样间隔 time.sleep(interval) web_socket.close() - if not self.is_keep: - os.remove(self.filename) _thread.start_new_thread(run, ()) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 85a955b6..9d7492cd 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -834,7 +834,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma src_ssafile=bilingual_sub, dst_ssafile=bilingual_sub, text_list=translated_text, - style_name=styles_list[0]) + style_name="") bilingual_string = core.ssafile_to_sub_str( ssafile=bilingual_sub, @@ -886,7 +886,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma src_ssafile=src_sub, dst_ssafile=bilingual_sub, text_list=translated_text, - style_name=styles_list[0], + style_name="", same_event_type=1) bilingual_string = core.ssafile_to_sub_str( @@ -939,7 +939,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma src_ssafile=src_sub, dst_ssafile=bilingual_sub, text_list=translated_text, - style_name=styles_list[0], + style_name="", same_event_type=2) bilingual_string = core.ssafile_to_sub_str( @@ -987,7 +987,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma src_ssafile=src_sub, dst_ssafile=dst_sub, text_list=translated_text, - style_name=styles_list[0]) + style_name="") dst_string = core.ssafile_to_sub_str( ssafile=dst_sub, @@ -1383,13 +1383,11 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen sub_utils.pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=bilingual_sub, - text_list=timed_text, - style_name=None) + text_list=timed_text) sub_utils.pysubs2_ssa_event_add( src_ssafile=bilingual_sub, dst_ssafile=bilingual_sub, text_list=translated_text, - style_name=None, same_event_type=0) bilingual_string = core.ssafile_to_sub_str( ssafile=bilingual_sub, @@ -1431,13 +1429,11 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen sub_utils.pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=src_sub, - text_list=timed_text, - style_name=None) + text_list=timed_text) sub_utils.pysubs2_ssa_event_add( src_ssafile=src_sub, dst_ssafile=bilingual_sub, text_list=translated_text, - style_name=None, same_event_type=1) bilingual_string = core.ssafile_to_sub_str( ssafile=bilingual_sub, @@ -1479,13 +1475,11 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen sub_utils.pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=src_sub, - text_list=timed_text, - style_name=None) + text_list=timed_text) sub_utils.pysubs2_ssa_event_add( src_ssafile=src_sub, dst_ssafile=bilingual_sub, text_list=translated_text, - style_name=None, same_event_type=2) bilingual_string = core.ssafile_to_sub_str( ssafile=bilingual_sub, diff --git a/autosub/core.py b/autosub/core.py index f74d3340..3c611d4d 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -383,7 +383,6 @@ def xfyun_to_text( # pylint: disable=too-many-locals, too-many-arguments, api_secret=config["api_secret"], api_address=api_address, business_args=config["business"], - is_keep=is_keep, is_full_result=result_list is not None, delete_chars=delete_chars) @@ -413,11 +412,19 @@ def xfyun_to_text( # pylint: disable=too-many-locals, too-many-arguments, result_list.append("") text_list.append("") pbar.update(i) + + if not is_keep: + for audio_fragment in audio_fragments: + os.remove(audio_fragment) + pbar.finish() pool.terminate() pool.join() except (KeyboardInterrupt, AttributeError) as error: + if not is_keep: + for audio_fragment in audio_fragments: + os.remove(audio_fragment) pbar.finish() pool.terminate() pool.join() @@ -429,6 +436,9 @@ def xfyun_to_text( # pylint: disable=too-many-locals, too-many-arguments, return None except exceptions.SpeechToTextException as err_msg: + if not is_keep: + for audio_fragment in audio_fragments: + os.remove(audio_fragment) pbar.finish() pool.terminate() pool.join() @@ -707,8 +717,7 @@ def list_to_sub_str( sub_utils.pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=pysubs2_obj, - text_list=timed_text, - style_name=None) + text_list=timed_text) formatted_subtitles = pysubs2_obj.to_string( format_=subtitles_file_format) @@ -725,8 +734,7 @@ def list_to_sub_str( sub_utils.pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=pysubs2_obj, - text_list=timed_text, - style_name=None) + text_list=timed_text) formatted_subtitles = pysubs2_obj.to_string( format_='json') @@ -739,8 +747,7 @@ def list_to_sub_str( sub_utils.pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=pysubs2_obj, - text_list=timed_text, - style_name=None) + text_list=timed_text) formatted_subtitles = pysubs2_obj.to_string( format_='microdvd', fps=fps) @@ -753,8 +760,7 @@ def list_to_sub_str( sub_utils.pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=pysubs2_obj, - text_list=timed_text, - style_name=None) + text_list=timed_text) formatted_subtitles = pysubs2_obj.to_string( format_='mpl2', fps=fps) @@ -769,8 +775,7 @@ def list_to_sub_str( sub_utils.pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=pysubs2_obj, - text_list=timed_text, - style_name=None) + text_list=timed_text) formatted_subtitles = pysubs2_obj.to_string( format_=constants.DEFAULT_SUBTITLES_FORMAT) diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index ae279d49..c6fc3625 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -69,13 +69,11 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem src_ssafile, dst_ssafile, text_list, - style_name, + style_name='Default', same_event_type=0,): """ Serialize a list of subtitles using pysubs2. """ - if not style_name: - style_name = 'Default' if text_list: if not src_ssafile: if isinstance(text_list[0][0], tuple): @@ -105,19 +103,30 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem length = len(text_list) if same_event_type == 0: # append text_list to new events - while i < length: - 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) - i = i + 1 + if style_name: + while i < length: + 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) + i = i + 1 + else: + while i < length: + 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 = src_ssafile.events[i].style + dst_ssafile.events.append(event) + i = i + 1 elif same_event_type == 1: # add text_list to src_ssafile # before the existing text in event - if src_ssafile.events[0].style == style_name: + if not style_name or src_ssafile.events[0].style == style_name: # same style while i < length: event = pysubs2.SSAEvent() @@ -147,7 +156,7 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem elif same_event_type == 2: # add text_list to src_ssafile # after the existing text in event - if src_ssafile.events[0].style == style_name: + if not style_name or src_ssafile.events[0].style == style_name: # same style while i < length: event = pysubs2.SSAEvent() @@ -178,6 +187,8 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem # src_ssafile provides regions only i = 0 length = len(src_ssafile.events) + if not style_name: + style_name = 'Default' while i < length: event = pysubs2.SSAEvent() event.start = src_ssafile.events[i].start @@ -195,8 +206,7 @@ def list_to_vtt_str(subtitles): pysubs2_ssa_event_add( src_ssafile=None, dst_ssafile=pysubs2_obj, - text_list=subtitles, - style_name=None) + text_list=subtitles) formatted_subtitles = pysubs2_obj.to_string( format_='srt') i = 0 diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index e4dce2ee..259bf3e9 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -61,6 +61,7 @@ - 修改音频分割指令的更换条件为仅当用户不修改它时。 - 修改最长语音区域限制为60秒。 - 修改所有文本文件输入编码为"utf-8"。 +- 修改字幕翻译中字幕样式选择的默认方式。 #### 修复(未发布) From 2b44fee1bf0d88e24df8627ef2c0b2cf26f72c0b Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sun, 5 Apr 2020 13:41:32 +0800 Subject: [PATCH 17/26] Fix DEFAULT_AUDIO_PRCS_CMDS and DEFAULT_CHECK_CMD --- CHANGELOG.md | 5 + autosub/__init__.py | 5 +- autosub/cmdline_utils.py | 23 ++- autosub/constants.py | 20 +- autosub/core.py | 5 +- .../LC_MESSAGES/autosub.cmdline_utils.po | 192 +++++++++--------- .../locale/zh_CN/LC_MESSAGES/autosub.core.po | 40 ++-- .../zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po | 49 +++-- .../data/locale/zh_CN/LC_MESSAGES/autosub.po | 20 +- .../zh_CN/LC_MESSAGES/autosub.sub_utils.po | 10 +- autosub/exceptions.py | 2 +- autosub/ffmpeg_utils.py | 99 +++++---- autosub/options.py | 10 +- docs/CHANGELOG.zh-Hans.md | 5 + scripts/create_release.py | 2 +- 15 files changed, 276 insertions(+), 211 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b16659c4..b26d98b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,12 +64,15 @@ Click up arrow to go back to TOC. - Change the MAX_REGION_SIZE_LIMIT into 60 seconds. - Change all text file input decoding into "utf-8". - Change the default style selection in subtitles translation. +- Change check_output into Popen. +- Change the loglevel in ffmpeg commands into `-loglevel error`. #### Fixed(Unreleased) - Fix the size count bug when the last line been split in list_to_googletrans. - Fix delete_chars issue when using `-of full-src`. - Fix os.remove() PermissionError in api_xfyun.py. +- Fix DEFAULT_AUDIO_PRCS_CMDS and DEFAULT_CHECK_CMD. #### Removed(Unreleased) @@ -96,6 +99,8 @@ Click up arrow to go back to TOC. - Deprecate Python 2.7 support. + ↑  + ### [0.5.5-alpha] - 2020-03-04 #### Added(0.5.5-alpha) diff --git a/autosub/__init__.py b/autosub/__init__.py index 9718da1f..00d8346f 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -121,14 +121,13 @@ def main(): # pylint: disable=too-many-branches, too-many-statements, too-many- args.audio_split_cmd.replace( "-vn -ac [channel] -ar [sample_rate] ", "") if not prcs_file: - print(_("Audio pre-processing failed." - "\nUse default method.")) + print(_("Audio pre-processing failed. Try default method.")) else: args.input = prcs_file print(_("Audio pre-processing complete.")) else: - if args.audio_split_cmd == constants.DEFAULT_AUDIO_SPLT: + if args.audio_split_cmd == constants.DEFAULT_AUDIO_SPLT_CMD: # if user doesn't modify the audio_split_cmd if args.api_suffix == ".ogg": # regard ogg as ogg_opus diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 9d7492cd..81bb8ebc 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -7,6 +7,7 @@ # Import built-in modules import gettext import os +import sys import subprocess import tempfile import gc @@ -1057,9 +1058,14 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen sample_rate=16000, out_=audio_wav) print(command) - subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) + prcs = subprocess.Popen(constants.cmd_conversion(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = prcs.communicate() + if out: + print(out.decode(sys.stdout.encoding)) + if err: + print(err.decode(sys.stdout.encoding)) regions = sub_utils.sub_to_speech_regions( audio_wav=audio_wav, sub_file=args.ext_regions) @@ -1085,9 +1091,14 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen "to detect audio regions.").format( name=audio_wav)) print(command) - subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) + prcs = subprocess.Popen(constants.cmd_conversion(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = prcs.communicate() + if out: + print(out.decode(sys.stdout.encoding)) + if err: + print(err.decode(sys.stdout.encoding)) if not ffmpeg_utils.ffprobe_check_file(audio_wav): raise exceptions.AutosubException( diff --git a/autosub/constants.py b/autosub/constants.py index 13afc453..62f5a840 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -78,7 +78,7 @@ DEFAULT_DST_LANGUAGE = 'en-US' DEFAULT_SIZE_PER_TRANS = 4000 -DEFAULT_SLEEP_SECONDS = 5 +DEFAULT_SLEEP_SECONDS = 1 DEFAULT_MAX_SIZE_PER_EVENT = 100 DEFAULT_EVENT_DELIMITERS = r"!()*,.:;?[]^_`~" @@ -422,27 +422,29 @@ def get_cmd(program_name): else: FFMPEG_NORMALIZE_CMD = get_cmd("ffmpeg-normalize") -DEFAULT_AUDIO_PRCS = [ - FFMPEG_CMD + " -hide_banner -i \"{in_}\" -af \"asplit[a],aphasemeter=video=0,\ +DEFAULT_AUDIO_PRCS_CMDS = [ + FFMPEG_CMD + " -hide_banner -i \"{in_}\" -vn -af \"asplit[a],aphasemeter=video=0,\ ametadata=select:key=\ lavfi.aphasemeter.phase:value=-0.005:function=less,\ pan=1c|c0=c0,aresample=async=1:first_pts=0,[a]amix\" \ --ac 1 -f flac \"{out_}\"", - FFMPEG_CMD + " -hide_banner -i \"{in_}\" -af lowpass=3000,highpass=200 \"{out_}\"", +-ac 1 -f flac -loglevel error \"{out_}\"", + FFMPEG_CMD + " -hide_banner -i \"{in_}\" -af \"lowpass=3000,highpass=200\" " + "-loglevel error \"{out_}\"", FFMPEG_NORMALIZE_CMD + " -v \"{in_}\" -ar 44100 -ofmt flac -c:a flac -pr -p -o \"{out_}\"" ] -DEFAULT_AUDIO_CVT = \ - FFMPEG_CMD + " -hide_banner -y -i \"{in_}\" -vn -ac {channel} -ar {sample_rate} \"{out_}\"" +DEFAULT_AUDIO_CVT_CMD = \ + FFMPEG_CMD + " -hide_banner -y -i \"{in_}\" -vn -ac {channel} -ar {sample_rate}" \ + " -loglevel error \"{out_}\"" -DEFAULT_AUDIO_SPLT = \ +DEFAULT_AUDIO_SPLT_CMD = \ FFMPEG_CMD + " -y -ss {start} -i \"{in_}\" -t {dura} " \ "-vn -ac [channel] -ar [sample_rate] -loglevel error \"{out_}\"" DEFAULT_VIDEO_FPS_CMD = FFPROBE_CMD + " -v 0 -of csv=p=0 -select_streams " \ "v:0 -show_entries stream=r_frame_rate \"{in_}\"" -DEFAULT_CHECK_CMD = FFPROBE_CMD + " {in_} -show_format -pretty -loglevel quiet" +DEFAULT_CHECK_CMD = FFPROBE_CMD + " \"{in_}\" -show_format -pretty -loglevel quiet" DEFAULT_ENGLISH_STOP_WORDS_SET_1 = \ {'after', 'and', 'as', 'because', 'before', 'between', 'but', 'either', 'except', 'for', 'how', diff --git a/autosub/core.py b/autosub/core.py index 3c611d4d..8a8713c2 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -104,8 +104,9 @@ def bulk_audio_conversion( # pylint: disable=too-many-arguments pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(regions)).start() try: audio_fragments = [] - for i, flac_region in enumerate(pool.imap(converter, regions)): - audio_fragments.append(flac_region) + for i, audio_fragment in enumerate(pool.imap(converter, regions)): + if audio_fragment: + audio_fragments.append(audio_fragment) pbar.update(i) gc.collect(0) pbar.finish() 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 3b8d882b..02ae9453 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-04-02 16:04+0800\n" -"PO-Revision-Date: 2020-04-02 16:04+0800\n" +"POT-Creation-Date: 2020-04-05 13:23+0800\n" +"PO-Revision-Date: 2020-04-05 13:27+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -17,20 +17,20 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/cmdline_utils.py:44 +#: autosub/cmdline_utils.py:45 msgid "List of output formats:\n" msgstr "列出所有输出格式:\n" -#: autosub/cmdline_utils.py:46 autosub/cmdline_utils.py:54 +#: autosub/cmdline_utils.py:47 autosub/cmdline_utils.py:55 msgid "Format" msgstr "格式" -#: autosub/cmdline_utils.py:47 autosub/cmdline_utils.py:55 -#: autosub/cmdline_utils.py:82 autosub/cmdline_utils.py:100 +#: autosub/cmdline_utils.py:48 autosub/cmdline_utils.py:56 +#: autosub/cmdline_utils.py:83 autosub/cmdline_utils.py:101 msgid "Description" msgstr "描述" -#: autosub/cmdline_utils.py:52 +#: autosub/cmdline_utils.py:53 msgid "" "\n" "List of input formats:\n" @@ -38,36 +38,36 @@ msgstr "" "\n" "列出所有输入格式:\n" -#: autosub/cmdline_utils.py:63 +#: autosub/cmdline_utils.py:64 msgid "Use py-googletrans to detect a sub file's first line language." msgstr "使用py-googletrans来检测字幕文件第一行的语言。" -#: autosub/cmdline_utils.py:70 autosub/cmdline_utils.py:81 -#: autosub/cmdline_utils.py:99 +#: autosub/cmdline_utils.py:71 autosub/cmdline_utils.py:82 +#: autosub/cmdline_utils.py:100 msgid "Lang code" msgstr "语言代码" -#: autosub/cmdline_utils.py:71 +#: autosub/cmdline_utils.py:72 msgid "Confidence" msgstr "可信度" -#: autosub/cmdline_utils.py:79 +#: autosub/cmdline_utils.py:80 msgid "List of all lang codes for speech-to-text:\n" msgstr "列出所有语音转文字的语言代码:\n" -#: autosub/cmdline_utils.py:88 +#: autosub/cmdline_utils.py:89 msgid "Match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:97 +#: autosub/cmdline_utils.py:98 msgid "List of all lang codes for translation:\n" msgstr "列出所有翻译的语言代码:\n" -#: autosub/cmdline_utils.py:106 +#: autosub/cmdline_utils.py:107 msgid "Match py-googletrans lang codes." msgstr "匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:124 +#: autosub/cmdline_utils.py:125 msgid "" "Error: arg of \"-i\"/\"--input\": \"{path}\" isn't valid. You need to give a " "valid path." @@ -75,7 +75,7 @@ msgstr "" "错误:\"-i\"/\"--input\"的参数:\"{path}\"是无效的。你需要提供一个有效的路" "径。" -#: autosub/cmdline_utils.py:130 +#: autosub/cmdline_utils.py:131 msgid "" "Error: arg of \"-sty\"/\"--styles\": \"{path}\" isn't valid. You need to " "give a valid path." @@ -83,15 +83,15 @@ msgstr "" "错误:\"-sty\"/\"--styles\"的参数:\"{path}\"是无效的。你需要提供一个有效的路" "径。" -#: autosub/cmdline_utils.py:136 +#: autosub/cmdline_utils.py:137 msgid "Error: Too many \"-sn\"/\"--styles-name\" arguments." msgstr "错误:\"-sn\"/\"--styles-name\"的参数过多。" -#: autosub/cmdline_utils.py:148 autosub/cmdline_utils.py:155 +#: autosub/cmdline_utils.py:149 autosub/cmdline_utils.py:156 msgid "Error: \"-sn\"/\"--styles-name\" arguments aren't in \"{path}\"." msgstr "错误:\"-sn\"/\"--styles-name\"的参数不在 \"{path}\"文件内。" -#: autosub/cmdline_utils.py:160 +#: autosub/cmdline_utils.py:161 msgid "" "Error: arg of \"-er\"/\"--ext-regions\": \"{path}\" isn't valid. You need to " "give a valid path." @@ -99,16 +99,16 @@ msgstr "" "错误:\"-er\"/\"--ext-regions\"的参数:\"{path}\"是无效的。你需要提供一个有效" "的路径。" -#: autosub/cmdline_utils.py:177 autosub/cmdline_utils.py:195 +#: autosub/cmdline_utils.py:178 autosub/cmdline_utils.py:196 msgid "No output format specified. Use input format \"{fmt}\" for output." msgstr "没有指定输出格式。使用输入的格式\"{fmt}\"作为输出格式。" -#: autosub/cmdline_utils.py:189 +#: autosub/cmdline_utils.py:190 msgid "" "Your output is a directory not a file path. Now file path set to \"{new}\"." msgstr "你的输出路径是一个目录不是一个文件路径。现在输出路径设置为\"{new}\"。" -#: autosub/cmdline_utils.py:212 +#: autosub/cmdline_utils.py:213 msgid "" "Error: Output subtitles format \"{fmt}\" not supported. Run with \"-lf\"/\"--" "list-formats\" to see all supported formats.\n" @@ -118,61 +118,61 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:225 +#: autosub/cmdline_utils.py:226 msgid "Error: No valid \"-of\"/\"--output-files\" arguments." msgstr "错误:\"-of\"/\"--output-files\"参数无效。" -#: autosub/cmdline_utils.py:236 +#: autosub/cmdline_utils.py:237 msgid "Input is a subtitles file." msgstr "输入是一个字幕文件。" -#: autosub/cmdline_utils.py:253 +#: autosub/cmdline_utils.py:254 msgid "Error: Can't decode speech config file \"{filename}\"." msgstr "错误:无法解码语音配置文件\"{filename}\"。" -#: autosub/cmdline_utils.py:257 +#: autosub/cmdline_utils.py:258 msgid "Error: Speech config file \"{filename}\" doesn't exist." msgstr "错误:语音配置文件\"{filename}\"不存在。" -#: autosub/cmdline_utils.py:303 +#: autosub/cmdline_utils.py:304 msgid "Error: No \"app_id\" found in speech config file \"{filename}\"." msgstr "错误:\"app_id\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:314 +#: autosub/cmdline_utils.py:315 msgid "Error: No \"api_key\" found in speech config file \"{filename}\"." msgstr "错误:\"api_key\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:325 +#: autosub/cmdline_utils.py:326 msgid "Error: No \"api_secret\" found in speech config file \"{filename}\"." msgstr "错误:\"api_secret\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:337 +#: autosub/cmdline_utils.py:338 msgid "Error: No \"language\" found in speech config file \"{filename}\"." msgstr "错误:\"language\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:373 +#: autosub/cmdline_utils.py:374 msgid "Error: \"-slp\"/\"--sleep-seconds\" arg is illegal." msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" -#: autosub/cmdline_utils.py:381 +#: autosub/cmdline_utils.py:382 msgid "Let speech lang code to match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:387 +#: autosub/cmdline_utils.py:388 msgid "Use langcodes to standardize the result." msgstr "使用langcodes来标准化结果。" -#: autosub/cmdline_utils.py:389 autosub/cmdline_utils.py:445 -#: autosub/cmdline_utils.py:467 autosub/cmdline_utils.py:540 -#: autosub/cmdline_utils.py:567 +#: autosub/cmdline_utils.py:390 autosub/cmdline_utils.py:446 +#: autosub/cmdline_utils.py:468 autosub/cmdline_utils.py:541 +#: autosub/cmdline_utils.py:568 msgid "Use \"{lang_code}\" instead." msgstr "改用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:392 +#: autosub/cmdline_utils.py:393 msgid "Match failed. Still using \"{lang_code}\"." msgstr "匹配失败。仍在使用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:395 +#: autosub/cmdline_utils.py:396 msgid "" "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" "list-speech-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -182,35 +182,35 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:403 +#: autosub/cmdline_utils.py:404 msgid "Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal." msgstr "错误:\"-mnc\"/\"--min-confidence\"参数的值不合法。" -#: autosub/cmdline_utils.py:408 +#: autosub/cmdline_utils.py:409 msgid "" "Error: You must provide \"-sconf\", \"--speech-config\" option when using " "Xun Fei Yun API." msgstr "错误:使用讯飞云API时,你必须提供\"-sconf\",\"--speech-config\"选项。" -#: autosub/cmdline_utils.py:412 +#: autosub/cmdline_utils.py:413 msgid "" "Translation destination language not provided. Only performing speech " "recognition." msgstr "翻译目的语言未提供。只进行语音识别。" -#: autosub/cmdline_utils.py:417 +#: autosub/cmdline_utils.py:418 msgid "Translation source language not provided. Use speech language instead." msgstr "翻译源语言未提供。改用语音语言。" -#: autosub/cmdline_utils.py:438 +#: autosub/cmdline_utils.py:439 msgid "Let translation source lang code to match py-googletrans lang codes." msgstr "让翻译源语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:449 autosub/cmdline_utils.py:471 +#: autosub/cmdline_utils.py:450 autosub/cmdline_utils.py:472 msgid "Error: Match failed." msgstr "错误:匹配失败。" -#: autosub/cmdline_utils.py:452 +#: autosub/cmdline_utils.py:453 msgid "" "Error: Translation source language \"{src}\" is not supported. Run with \"-" "ltc\"/\"--list-translation-codes\" to see all supported languages. Or use \"-" @@ -220,12 +220,12 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:460 +#: autosub/cmdline_utils.py:461 msgid "" "Let translation destination lang code to match py-googletrans lang codes." msgstr "让翻译目的语言代码匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:474 +#: autosub/cmdline_utils.py:475 msgid "" "Error: Translation destination language \"{dst}\" is not supported. Run with " "\"-ltc\"/\"--list-translation-codes\" to see all supported languages. Or use " @@ -234,29 +234,29 @@ msgstr "" "错误:不支持翻译目的语言\"{dst}\"。用 \"-ltc\"/\"--list-translation-codes\"选" "项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最佳匹配。" -#: autosub/cmdline_utils.py:482 +#: autosub/cmdline_utils.py:483 msgid "" "Speech language is the same as the destination language. Only performing " "speech recognition." msgstr "语音语言和目的语言一致。只进行语音识别。" -#: autosub/cmdline_utils.py:491 +#: autosub/cmdline_utils.py:492 msgid "You've already input times. No works done." msgstr "你已经输入了时间轴。啥都没做。" -#: autosub/cmdline_utils.py:495 +#: autosub/cmdline_utils.py:496 msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:503 autosub/cmdline_utils.py:595 +#: autosub/cmdline_utils.py:504 autosub/cmdline_utils.py:596 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" -#: autosub/cmdline_utils.py:516 +#: autosub/cmdline_utils.py:517 msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" -#: autosub/cmdline_utils.py:532 +#: autosub/cmdline_utils.py:533 msgid "" "Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages." @@ -264,11 +264,11 @@ msgstr "" "警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:544 autosub/cmdline_utils.py:571 +#: autosub/cmdline_utils.py:545 autosub/cmdline_utils.py:572 msgid "Match failed. Still using \"{lang_code}\". Program stopped." msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" -#: autosub/cmdline_utils.py:550 +#: autosub/cmdline_utils.py:551 msgid "" "Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -278,7 +278,7 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:559 +#: autosub/cmdline_utils.py:560 msgid "" "Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages." @@ -286,7 +286,7 @@ msgstr "" "警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" "行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:577 +#: autosub/cmdline_utils.py:578 msgid "" "Error: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages. Or use \"-bm\"/\"--" @@ -296,12 +296,12 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:585 +#: autosub/cmdline_utils.py:586 msgid "" "Error: Translation source language is the same as the destination language." msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:609 +#: autosub/cmdline_utils.py:610 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -309,7 +309,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:616 +#: autosub/cmdline_utils.py:617 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -317,7 +317,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:623 +#: autosub/cmdline_utils.py:624 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -325,17 +325,17 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:679 autosub/cmdline_utils.py:912 -#: autosub/cmdline_utils.py:1456 +#: autosub/cmdline_utils.py:680 autosub/cmdline_utils.py:913 +#: autosub/cmdline_utils.py:1463 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:683 autosub/cmdline_utils.py:718 -#: autosub/cmdline_utils.py:769 autosub/cmdline_utils.py:863 -#: autosub/cmdline_utils.py:916 autosub/cmdline_utils.py:969 -#: autosub/cmdline_utils.py:1146 autosub/cmdline_utils.py:1309 -#: autosub/cmdline_utils.py:1351 autosub/cmdline_utils.py:1412 -#: autosub/cmdline_utils.py:1460 autosub/cmdline_utils.py:1508 +#: autosub/cmdline_utils.py:684 autosub/cmdline_utils.py:719 +#: autosub/cmdline_utils.py:770 autosub/cmdline_utils.py:864 +#: autosub/cmdline_utils.py:917 autosub/cmdline_utils.py:970 +#: autosub/cmdline_utils.py:1157 autosub/cmdline_utils.py:1320 +#: autosub/cmdline_utils.py:1362 autosub/cmdline_utils.py:1421 +#: autosub/cmdline_utils.py:1467 autosub/cmdline_utils.py:1513 msgid "" "\n" "All works done." @@ -343,32 +343,32 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:714 autosub/cmdline_utils.py:965 -#: autosub/cmdline_utils.py:1504 +#: autosub/cmdline_utils.py:715 autosub/cmdline_utils.py:966 +#: autosub/cmdline_utils.py:1509 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:765 +#: autosub/cmdline_utils.py:766 msgid "\"join-events\" subtitles file created at \"{}\"." msgstr "\"join-events\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:814 autosub/cmdline_utils.py:1369 +#: autosub/cmdline_utils.py:815 autosub/cmdline_utils.py:1380 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:859 autosub/cmdline_utils.py:1408 +#: autosub/cmdline_utils.py:860 autosub/cmdline_utils.py:1417 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1009 autosub/cmdline_utils.py:1549 +#: autosub/cmdline_utils.py:1010 autosub/cmdline_utils.py:1554 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1050 +#: autosub/cmdline_utils.py:1051 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:1084 +#: autosub/cmdline_utils.py:1090 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -376,11 +376,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:1094 +#: autosub/cmdline_utils.py:1105 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:1097 +#: autosub/cmdline_utils.py:1108 msgid "" "Conversion completed.\n" "Use Auditok to detect speech regions." @@ -388,27 +388,27 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:1109 +#: autosub/cmdline_utils.py:1120 msgid "" "Auditok detection completed.\n" "\"{name}\" has been deleted." msgstr "" -"Auditok语音区域检测完毕\n" +"Auditok语音区域检测完毕。\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:1114 +#: autosub/cmdline_utils.py:1125 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1143 autosub/cmdline_utils.py:1616 +#: autosub/cmdline_utils.py:1154 autosub/cmdline_utils.py:1621 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1167 +#: autosub/cmdline_utils.py:1178 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1171 +#: autosub/cmdline_utils.py:1182 msgid "" "Audio processing complete.\n" "All works done." @@ -416,11 +416,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1223 +#: autosub/cmdline_utils.py:1234 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1238 +#: autosub/cmdline_utils.py:1249 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -430,18 +430,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1243 +#: autosub/cmdline_utils.py:1254 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1257 +#: autosub/cmdline_utils.py:1268 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1269 +#: autosub/cmdline_utils.py:1280 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -449,11 +449,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1305 +#: autosub/cmdline_utils.py:1316 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1313 +#: autosub/cmdline_utils.py:1324 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -461,11 +461,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1347 autosub/cmdline_utils.py:1586 +#: autosub/cmdline_utils.py:1358 autosub/cmdline_utils.py:1591 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1558 +#: autosub/cmdline_utils.py:1563 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -473,7 +473,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1591 +#: autosub/cmdline_utils.py:1596 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.core.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.po index 85692e20..93bc57b3 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-25 19:51+0800\n" +"POT-Creation-Date: 2020-04-05 12:40+0800\n" "PO-Revision-Date: 2020-03-21 15:41+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -29,7 +29,7 @@ msgstr "" msgid "Converting: " msgstr "转换中: " -#: autosub/core.py:145 +#: autosub/core.py:146 msgid "" "\n" "Sending short-term fragments to Google Speech V2 API and getting result." @@ -37,13 +37,13 @@ msgstr "" "\n" "将短片段语音发送给Google Speech V2 API并得到识别结果。" -#: autosub/core.py:146 autosub/core.py:215 autosub/core.py:373 -#: autosub/core.py:487 +#: autosub/core.py:147 autosub/core.py:216 autosub/core.py:374 +#: autosub/core.py:498 msgid "Speech-to-Text: " msgstr "语音转文字中: " -#: autosub/core.py:187 autosub/core.py:330 autosub/core.py:427 -#: autosub/core.py:535 +#: autosub/core.py:188 autosub/core.py:331 autosub/core.py:435 +#: autosub/core.py:546 msgid "" "Error: Connection error happened too many times.\n" "All works done." @@ -51,7 +51,7 @@ msgstr "" "错误:过多连接错误。\n" "做完了。" -#: autosub/core.py:213 +#: autosub/core.py:214 msgid "" "\n" "Sending short-term fragments to Google Cloud Speech V1P1Beta1 API and " @@ -60,11 +60,11 @@ msgstr "" "\n" "将短片段语音发送给Google Cloud Speech V1P1Beta1 API并得到识别结果。" -#: autosub/core.py:338 autosub/core.py:435 autosub/core.py:543 +#: autosub/core.py:339 autosub/core.py:446 autosub/core.py:554 msgid "Receive something unexpected:" msgstr "收到未预期数据:" -#: autosub/core.py:371 +#: autosub/core.py:372 msgid "" "\n" "Sending short-term fragments to Xun Fei Yun WebSocket API and getting result." @@ -72,7 +72,7 @@ msgstr "" "\n" "将短片段语音发送给讯飞云WebSocket API并得到识别结果。" -#: autosub/core.py:459 +#: autosub/core.py:470 msgid "" "\n" "Sending short-term fragments to Baidu PRO ASR API and getting result." @@ -80,7 +80,7 @@ msgstr "" "\n" "将短片段语音发送给百度短语音识别极速版API并得到识别结果。" -#: autosub/core.py:462 +#: autosub/core.py:473 msgid "" "\n" "Sending short-term fragments to Baidu ASR API and getting result." @@ -88,19 +88,19 @@ msgstr "" "\n" "将短片段语音发送给百度短语音识别API并得到识别结果。" -#: autosub/core.py:473 +#: autosub/core.py:484 msgid "Get the token online." msgstr "在线获取token。" -#: autosub/core.py:478 +#: autosub/core.py:489 msgid "Use the token from the config." msgstr "使用配置文件中的token。" -#: autosub/core.py:481 +#: autosub/core.py:492 msgid "Failed to get the token. Error message:" msgstr "无法获取token。错误信息:" -#: autosub/core.py:567 +#: autosub/core.py:578 msgid "" "\n" "Translating text from \"{0}\" to \"{1}\"." @@ -108,24 +108,24 @@ msgstr "" "\n" "从\"{0}\"翻译为\"{1}\"。" -#: autosub/core.py:622 +#: autosub/core.py:633 msgid "Translation: " msgstr "翻译中: " -#: autosub/core.py:691 +#: autosub/core.py:702 msgid "Cancelling translation." msgstr "取消翻译。" -#: autosub/core.py:764 autosub/core.py:823 +#: autosub/core.py:771 autosub/core.py:829 msgid "Format \"{fmt}\" not supported. Use \"{default_fmt}\" instead." msgstr "不支持格式\"{fmt}\"。改用\"{default_fmt}\"。" -#: autosub/core.py:896 +#: autosub/core.py:902 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/core.py:899 +#: autosub/core.py:905 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.ffmpeg_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po index 50f53f0a..804d8fa0 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,22 +7,22 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-20 20:42+0800\n" -"PO-Revision-Date: 2020-02-03 21:37+0800\n" +"POT-Creation-Date: 2020-04-05 13:27+0800\n" +"PO-Revision-Date: 2020-04-05 13:23+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/ffmpeg_utils.py:93 +#: autosub/ffmpeg_utils.py:99 msgid "" "Error: ffmpeg can't split your file. Check your audio processing options." msgstr "错误:ffmpeg无法分割你的文件。检查一下你的音频处理选项。" -#: autosub/ffmpeg_utils.py:117 +#: autosub/ffmpeg_utils.py:130 msgid "" "ffprobe can't get video fps.\n" "It is necessary when output is \".sub\"." @@ -30,16 +30,16 @@ msgstr "" "ffprobe无法获取到视频的帧率。\n" "当输出格式是\".sub\"时,需要获取帧率。" -#: autosub/ffmpeg_utils.py:120 +#: autosub/ffmpeg_utils.py:133 msgid "" "Input your video fps. Any illegal input will regard as \".srt\" instead.\n" msgstr "输入你视频的帧率。任何非法的值会被当作\".srt\"格式处理。\n" -#: autosub/ffmpeg_utils.py:127 +#: autosub/ffmpeg_utils.py:140 msgid "Use \".srt\" instead." msgstr "改用\".srt\"格式。" -#: autosub/ffmpeg_utils.py:140 +#: autosub/ffmpeg_utils.py:153 msgid "" "\n" "Use ffprobe to check conversion result." @@ -47,22 +47,43 @@ msgstr "" "\n" "使用ffprobe来检查转换结果。" -#: autosub/ffmpeg_utils.py:168 +#: autosub/ffmpeg_utils.py:186 msgid "" "Warning: Dependency ffmpeg-normalize not found on this machine. Try default " "method." msgstr "" "警告:依赖ffmpeg-normalize未在这台电脑上找到。尝试默认的方法去转换格式。" -#: autosub/ffmpeg_utils.py:180 +#: autosub/ffmpeg_utils.py:198 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/ffmpeg_utils.py:183 +#: autosub/ffmpeg_utils.py:201 msgid "Input a new path (including directory and file name) for output file.\n" msgstr "为输出文件输入一个新的路径(包括路径和文件名)。\n" -#: autosub/ffmpeg_utils.py:200 autosub/ffmpeg_utils.py:232 -msgid "Audio pre-processing failed. Try default method." -msgstr "音频预处理失败。尝试默认的方法去转换格式。" +#: autosub/ffmpeg_utils.py:222 autosub/ffmpeg_utils.py:250 +msgid "" +"Error: ffmpeg failed to convert the file.\n" +"Below is the error output.\n" +msgstr "" +"错误:ffmpeg无法转码文件。\n" +"以下是错误输出。\n" + +#~ msgid "" +#~ "Error: ffprobe failed to get fps.\n" +#~ "Below is the error output." +#~ msgstr "" +#~ "错误:ffprobe无法得到fps。\n" +#~ " 以下是错误输出。" + +#~ msgid "" +#~ "Error: ffprobe failed to check the file.\n" +#~ "Below is the error output." +#~ msgstr "" +#~ "错误:ffprobe无法检查文件。\n" +#~ "以下是错误输出。" + +#~ msgid "Audio pre-processing failed. Try default method." +#~ msgstr "音频预处理失败。尝试默认的方法去转换格式。" diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po index 93350765..bfd10be5 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-26 11:26+0800\n" -"PO-Revision-Date: 2020-03-26 14:46+0800\n" +"POT-Creation-Date: 2020-04-05 12:40+0800\n" +"PO-Revision-Date: 2020-04-05 13:21+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -25,7 +25,7 @@ msgstr "" "\n" "输入参数(不包含\"autosub\"): " -#: autosub/__init__.py:64 autosub/__init__.py:182 +#: autosub/__init__.py:64 autosub/__init__.py:181 msgid "" "\n" "All works done." @@ -62,22 +62,20 @@ msgstr "" "做完了。" #: autosub/__init__.py:124 -msgid "" -"Audio pre-processing failed.\n" -"Use default method." +msgid "Audio pre-processing failed. Try default method." msgstr "" "音频预处理失败。\n" "使用默认方法。" -#: autosub/__init__.py:128 +#: autosub/__init__.py:127 msgid "Audio pre-processing complete." msgstr "音频预处理已完成。" -#: autosub/__init__.py:170 +#: autosub/__init__.py:169 msgid "Error: No valid \"-of\"/\"--output-files\" arguments." msgstr "错误:\"-of\"/\"--output-files\"参数无效。" -#: autosub/__init__.py:185 +#: autosub/__init__.py:184 msgid "" "\n" "KeyboardInterrupt. Works stopped." @@ -85,7 +83,7 @@ msgstr "" "\n" "键盘中断。操作终止。" -#: autosub/__init__.py:187 +#: autosub/__init__.py:186 msgid "" "\n" "Error: pysubs2.exceptions. Check your file format." @@ -93,7 +91,7 @@ msgstr "" "\n" "错误:pysubs2异常。检查你的文件格式。" -#: autosub/__init__.py:192 +#: autosub/__init__.py:191 msgid "Press Enter to exit..." msgstr "按回车以退出..." diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po index 6f43c32d..19505a49 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-04-02 16:04+0800\n" +"POT-Creation-Date: 2020-04-05 12:40+0800\n" "PO-Revision-Date: 2020-03-29 11:48+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,19 +17,19 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/sub_utils.py:590 +#: autosub/sub_utils.py:600 msgid "Merge {count} times." msgstr "合并了{count}次。" -#: autosub/sub_utils.py:591 +#: autosub/sub_utils.py:601 msgid "Split {count} times." msgstr "分割了{count}次。" -#: autosub/sub_utils.py:594 +#: autosub/sub_utils.py:604 msgid "Reduce {count} lines of events." msgstr "减少了{count}行字幕。" -#: autosub/sub_utils.py:596 +#: autosub/sub_utils.py:606 msgid "Add {count} lines of events." msgstr "增加了{count}行字幕。" diff --git a/autosub/exceptions.py b/autosub/exceptions.py index 0b3e83b3..8b7b626b 100644 --- a/autosub/exceptions.py +++ b/autosub/exceptions.py @@ -32,7 +32,7 @@ def __str__(self): class ConversionException(AutosubException): """ - Raised when short-term audio fragments conversion failed. + Raised when audio conversion failed. """ diff --git a/autosub/ffmpeg_utils.py b/autosub/ffmpeg_utils.py index 3ec5d8c2..c1dd8f77 100644 --- a/autosub/ffmpeg_utils.py +++ b/autosub/ffmpeg_utils.py @@ -66,9 +66,12 @@ def __call__(self, region): dura=end - start, in_=self.source_path, out_=temp.name) - subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) + prcs = subprocess.Popen(constants.cmd_conversion(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + err = prcs.communicate()[1] + if err: + return None return temp.name filename = self.output \ @@ -80,9 +83,12 @@ def __call__(self, region): dura=end - start, in_=self.source_path, out_=filename) - subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) + prcs = subprocess.Popen(constants.cmd_conversion(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + err = prcs.communicate()[1] + if err: + return None return filename except KeyboardInterrupt: @@ -103,10 +109,17 @@ def ffprobe_get_fps( # pylint: disable=superfluous-parens try: command = constants.DEFAULT_VIDEO_FPS_CMD.format(in_=video_file) print(command) - input_str = subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) - num_list = map(int, re.findall(r'\d+', input_str.decode(sys.stdout.encoding))) + prcs = subprocess.Popen(constants.cmd_conversion(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = prcs.communicate() + if out: + ffprobe_str = out.decode(sys.stdout.encoding) + print(ffprobe_str) + else: + ffprobe_str = err.decode(sys.stdout.encoding) + print(ffprobe_str) + num_list = map(int, re.findall(r'\d+', ffprobe_str.decode(sys.stdout.encoding))) num_list = list(num_list) if len(num_list) == 2: fps = float(num_list[0]) / float(num_list[1]) @@ -140,11 +153,16 @@ def ffprobe_check_file(filename): print(_("\nUse ffprobe to check conversion result.")) command = constants.DEFAULT_CHECK_CMD.format(in_=filename) print(command) - ffprobe_bytes = subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) - ffprobe_str = ffprobe_bytes.decode(sys.stdout.encoding) - print(ffprobe_str) + prcs = subprocess.Popen(constants.cmd_conversion(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = prcs.communicate() + if out: + ffprobe_str = out.decode(sys.stdout.encoding) + print(ffprobe_str) + else: + ffprobe_str = err.decode(sys.stdout.encoding) + print(ffprobe_str) bitrate_idx = ffprobe_str.find('bit_rate') if bitrate_idx < 0 or \ ffprobe_str[bitrate_idx + 9:bitrate_idx + 10].lower() == 'n': @@ -163,7 +181,7 @@ def audio_pre_prcs( # pylint: disable=too-many-arguments, too-many-branches """ output_list = [filename, ] if not cmds: - cmds = constants.DEFAULT_AUDIO_PRCS + cmds = constants.DEFAULT_AUDIO_PRCS_CMDS if not constants.FFMPEG_NORMALIZE_CMD: print(_("Warning: Dependency ffmpeg-normalize " "not found on this machine. " @@ -193,28 +211,24 @@ def audio_pre_prcs( # pylint: disable=too-many-arguments, too-many-branches in_=output_list[i - 1], out_=output_list[i]) print(command) - subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) + prcs = subprocess.Popen(constants.cmd_conversion(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = prcs.communicate() + ffmpeg_str = "" + if out: + ffmpeg_str = out.decode(sys.stdout.encoding) + if err: + print(_("Error: ffmpeg failed to convert the file." + "\nBelow is the error output.\n") + + err.decode(sys.stdout.encoding)) + return None + print(ffmpeg_str) if not ffprobe_check_file(output_list[i]): - print(_("Audio pre-processing failed. Try default method.")) return None else: - temp_file = tempfile.NamedTemporaryFile(suffix='.flac', delete=False) - temp = temp_file.name - temp_file.close() - if os.path.isfile(temp): - os.remove(temp) - output_list.append(temp) - command = cmds[0].format( - in_=output_list[0], - out_=output_list[1]) - print(command) - subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) - for i in range(2, len(cmds) + 1): + for i in range(1, len(cmds) + 1): temp_file = tempfile.NamedTemporaryFile(suffix='.flac', delete=False) temp = temp_file.name temp_file.close() @@ -225,11 +239,20 @@ def audio_pre_prcs( # pylint: disable=too-many-arguments, too-many-branches in_=output_list[i - 1], out_=output_list[i]) print(command) - subprocess.check_output( - constants.cmd_conversion(command), - stdin=open(os.devnull)) + prcs = subprocess.Popen(constants.cmd_conversion(command), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = prcs.communicate() + ffmpeg_str = "" + if out: + ffmpeg_str = out.decode(sys.stdout.encoding) + if err: + print(_("Error: ffmpeg failed to convert the file." + "\nBelow is the error output.\n") + + err.decode(sys.stdout.encoding)) + return None + print(ffmpeg_str) if not ffprobe_check_file(output_list[i]): - print(_("Audio pre-processing failed. Try default method.")) os.remove(output_list[i]) return None os.remove(output_list[i - 1]) diff --git a/autosub/options.py b/autosub/options.py index c6a15f74..26b77488 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -482,9 +482,9 @@ def get_cmd_parser(): # pylint: disable=too-many-statements "https://github.com/stevenj/autosub/blob/master/scripts/subgen.sh " "https://ffmpeg.org/ffmpeg-filters.html) " "(2 >= arg_num >= 1)").format( - dft_1=constants.DEFAULT_AUDIO_PRCS[0], - dft_2=constants.DEFAULT_AUDIO_PRCS[1], - dft_3=constants.DEFAULT_AUDIO_PRCS[2])) + dft_1=constants.DEFAULT_AUDIO_PRCS_CMDS[0], + dft_2=constants.DEFAULT_AUDIO_PRCS_CMDS[1], + dft_3=constants.DEFAULT_AUDIO_PRCS_CMDS[2])) audio_prcs_group.add_argument( '-k', '--keep', @@ -513,7 +513,7 @@ def get_cmd_parser(): # pylint: disable=too-many-statements audio_prcs_group.add_argument( '-acc', '--audio-conversion-cmd', metavar=_('command'), - default=constants.DEFAULT_AUDIO_CVT, + default=constants.DEFAULT_AUDIO_CVT_CMD, help=_("(Experimental)This arg will override the default " "audio conversion command. " "\"[\", \"]\" are optional arguments " @@ -525,7 +525,7 @@ def get_cmd_parser(): # pylint: disable=too-many-statements audio_prcs_group.add_argument( '-asc', '--audio-split-cmd', metavar=_('command'), - default=constants.DEFAULT_AUDIO_SPLT, + default=constants.DEFAULT_AUDIO_SPLT_CMD, help=_("(Experimental)This arg will override the default " "audio split command. " "Same attention above. " diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 259bf3e9..7ffc4b8e 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -62,12 +62,15 @@ - 修改最长语音区域限制为60秒。 - 修改所有文本文件输入编码为"utf-8"。 - 修改字幕翻译中字幕样式选择的默认方式。 +- 修改check_output方法为Popen方法。 +- 修改ffmpeg指令中的loglevel为`-loglevel error`。 #### 修复(未发布) - 修复list_to_googletrans中当最后一行是需要被分割时的长度计算问题。 - 修复delete_chars问题当使用`-of full-src`时。 - 修复api_xfyun.py中的os.remove()文件占用问题。 +- 修复DEFAULT_AUDIO_PRCS_CMDS和DEFAULT_CHECK_CMD。 #### 删除(未发布) @@ -91,6 +94,8 @@ - 修改选项`-sml`为`-nsml`。 - 修改Auditok默认参数。 + ↑  + ### [0.5.5-alpha] - 2020-03-04 #### 添加(0.5.5-alpha) diff --git a/scripts/create_release.py b/scripts/create_release.py index 059446ba..a07de1ba 100644 --- a/scripts/create_release.py +++ b/scripts/create_release.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Defines release creation scripts. From ef8c50f920e533dfb6868d98f7a8c20ec71f3abc Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sun, 5 Apr 2020 14:24:46 +0800 Subject: [PATCH 18/26] Revert some Popen method usage to check_output --- CHANGELOG.md | 1 - .../LC_MESSAGES/autosub.cmdline_utils.po | 2 +- .../zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po | 31 +++++++-------- autosub/ffmpeg_utils.py | 39 +++++-------------- docs/CHANGELOG.zh-Hans.md | 1 - 5 files changed, 25 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b26d98b7..63bcfa05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,6 @@ Click up arrow to go back to TOC. - Change the MAX_REGION_SIZE_LIMIT into 60 seconds. - Change all text file input decoding into "utf-8". - Change the default style selection in subtitles translation. -- Change check_output into Popen. - Change the loglevel in ffmpeg commands into `-loglevel error`. #### Fixed(Unreleased) 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 02ae9453..840a589a 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-04-05 13:23+0800\n" +"POT-Creation-Date: 2020-04-05 14:06+0800\n" "PO-Revision-Date: 2020-04-05 13:27+0800\n" "Last-Translator: \n" "Language-Team: \n" 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 804d8fa0..3b8f84de 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-04-05 13:27+0800\n" +"POT-Creation-Date: 2020-04-05 14:05+0800\n" "PO-Revision-Date: 2020-04-05 13:23+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,12 +17,12 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/ffmpeg_utils.py:99 +#: autosub/ffmpeg_utils.py:97 msgid "" "Error: ffmpeg can't split your file. Check your audio processing options." msgstr "错误:ffmpeg无法分割你的文件。检查一下你的音频处理选项。" -#: autosub/ffmpeg_utils.py:130 +#: autosub/ffmpeg_utils.py:128 msgid "" "ffprobe can't get video fps.\n" "It is necessary when output is \".sub\"." @@ -30,16 +30,16 @@ msgstr "" "ffprobe无法获取到视频的帧率。\n" "当输出格式是\".sub\"时,需要获取帧率。" -#: autosub/ffmpeg_utils.py:133 +#: autosub/ffmpeg_utils.py:131 msgid "" "Input your video fps. Any illegal input will regard as \".srt\" instead.\n" msgstr "输入你视频的帧率。任何非法的值会被当作\".srt\"格式处理。\n" -#: autosub/ffmpeg_utils.py:140 +#: autosub/ffmpeg_utils.py:138 msgid "Use \".srt\" instead." msgstr "改用\".srt\"格式。" -#: autosub/ffmpeg_utils.py:153 +#: autosub/ffmpeg_utils.py:151 msgid "" "\n" "Use ffprobe to check conversion result." @@ -47,29 +47,28 @@ msgstr "" "\n" "使用ffprobe来检查转换结果。" -#: autosub/ffmpeg_utils.py:186 +#: autosub/ffmpeg_utils.py:184 msgid "" "Warning: Dependency ffmpeg-normalize not found on this machine. Try default " "method." msgstr "" "警告:依赖ffmpeg-normalize未在这台电脑上找到。尝试默认的方法去转换格式。" -#: autosub/ffmpeg_utils.py:198 +#: autosub/ffmpeg_utils.py:196 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/ffmpeg_utils.py:201 +#: autosub/ffmpeg_utils.py:199 msgid "Input a new path (including directory and file name) for output file.\n" msgstr "为输出文件输入一个新的路径(包括路径和文件名)。\n" -#: autosub/ffmpeg_utils.py:222 autosub/ffmpeg_utils.py:250 -msgid "" -"Error: ffmpeg failed to convert the file.\n" -"Below is the error output.\n" -msgstr "" -"错误:ffmpeg无法转码文件。\n" -"以下是错误输出。\n" +#~ msgid "" +#~ "Error: ffmpeg failed to convert the file.\n" +#~ "Below is the error output.\n" +#~ msgstr "" +#~ "错误:ffmpeg无法转码文件。\n" +#~ "以下是错误输出。\n" #~ msgid "" #~ "Error: ffprobe failed to get fps.\n" diff --git a/autosub/ffmpeg_utils.py b/autosub/ffmpeg_utils.py index c1dd8f77..3450464b 100644 --- a/autosub/ffmpeg_utils.py +++ b/autosub/ffmpeg_utils.py @@ -69,9 +69,7 @@ def __call__(self, region): prcs = subprocess.Popen(constants.cmd_conversion(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - err = prcs.communicate()[1] - if err: - return None + prcs.communicate() return temp.name filename = self.output \ @@ -211,19 +209,9 @@ def audio_pre_prcs( # pylint: disable=too-many-arguments, too-many-branches in_=output_list[i - 1], out_=output_list[i]) print(command) - prcs = subprocess.Popen(constants.cmd_conversion(command), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - out, err = prcs.communicate() - ffmpeg_str = "" - if out: - ffmpeg_str = out.decode(sys.stdout.encoding) - if err: - print(_("Error: ffmpeg failed to convert the file." - "\nBelow is the error output.\n") - + err.decode(sys.stdout.encoding)) - return None - print(ffmpeg_str) + subprocess.check_output( + constants.cmd_conversion(command), + stdin=open(os.devnull)) if not ffprobe_check_file(output_list[i]): return None @@ -239,22 +227,13 @@ def audio_pre_prcs( # pylint: disable=too-many-arguments, too-many-branches in_=output_list[i - 1], out_=output_list[i]) print(command) - prcs = subprocess.Popen(constants.cmd_conversion(command), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - out, err = prcs.communicate() - ffmpeg_str = "" - if out: - ffmpeg_str = out.decode(sys.stdout.encoding) - if err: - print(_("Error: ffmpeg failed to convert the file." - "\nBelow is the error output.\n") - + err.decode(sys.stdout.encoding)) - return None - print(ffmpeg_str) + subprocess.check_output( + constants.cmd_conversion(command), + stdin=open(os.devnull)) if not ffprobe_check_file(output_list[i]): os.remove(output_list[i]) return None - os.remove(output_list[i - 1]) + if i > 1: + os.remove(output_list[i - 1]) return output_list[-1] diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 7ffc4b8e..01458227 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -62,7 +62,6 @@ - 修改最长语音区域限制为60秒。 - 修改所有文本文件输入编码为"utf-8"。 - 修改字幕翻译中字幕样式选择的默认方式。 -- 修改check_output方法为Popen方法。 - 修改ffmpeg指令中的loglevel为`-loglevel error`。 #### 修复(未发布) From f305bd12951a0cf63a5a2f55cc82120a3a29f997 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Sat, 18 Apr 2020 19:43:32 +0800 Subject: [PATCH 19/26] Change DEFAULT_MIN_REGION_SIZE to 0.5 --- CHANGELOG.md | 1 + autosub/constants.py | 2 +- docs/CHANGELOG.zh-Hans.md | 1 + scripts/create_release.py | 24 +++++++++++++++--------- setup.py | 4 ++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63bcfa05..832b2c7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Click up arrow to go back to TOC. - Change all text file input decoding into "utf-8". - Change the default style selection in subtitles translation. - Change the loglevel in ffmpeg commands into `-loglevel error`. +- Change DEFAULT_MIN_REGION_SIZE to 0.5 #### Fixed(Unreleased) diff --git a/autosub/constants.py b/autosub/constants.py index 62f5a840..810fc41d 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -69,7 +69,7 @@ DEFAULT_SRC_LANGUAGE = 'en-US' DEFAULT_ENERGY_THRESHOLD = 45 DEFAULT_MAX_REGION_SIZE = 6.0 -DEFAULT_MIN_REGION_SIZE = 0.8 +DEFAULT_MIN_REGION_SIZE = 0.5 MIN_REGION_SIZE_LIMIT = 0.6 MAX_REGION_SIZE_LIMIT = 60.0 DEFAULT_CONTINUOUS_SILENCE = 0.2 diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 01458227..762cd06b 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -63,6 +63,7 @@ - 修改所有文本文件输入编码为"utf-8"。 - 修改字幕翻译中字幕样式选择的默认方式。 - 修改ffmpeg指令中的loglevel为`-loglevel error`。 +- 修改DEFAULT_MIN_REGION_SIZE为0.5。 #### 修复(未发布) diff --git a/scripts/create_release.py b/scripts/create_release.py index a07de1ba..0408bb37 100644 --- a/scripts/create_release.py +++ b/scripts/create_release.py @@ -113,14 +113,19 @@ def copytree(src, os.makedirs(target_data) os.makedirs(target_data_pyi) - copytree(src="{}/data".format(package_name), dst=target_data, exts=[".mo"], is_recursive=True) - copytree(src="{}/data".format(package_name), dst=target_data_pyi, exts=[".mo"], is_recursive=True) - copytree(src=".build_and_dist/{}.dist".format(release_name), dst=target_nuitka, is_recursive=True) + copytree(src="{}/data".format(package_name), dst=target_data, exts=[".mo"], + is_recursive=True) + copytree(src="{}/data".format(package_name), dst=target_data_pyi, exts=[".mo"], + is_recursive=True) + copytree(src=".build_and_dist/{}.dist".format(release_name), dst=target_nuitka, + is_recursive=True) exe_dir = "binaries" if os.path.isdir(exe_dir): - ffmpeg_norm_nuitka = os.path.join(exe_dir, "ffmpeg-normalize-Nuitka", "ffmpeg-normalize.exe") - ffmpeg_norm_pyinstaller = os.path.join(exe_dir, "ffmpeg-normalize-pyinstaller", "ffmpeg-normalize.exe") + ffmpeg_norm_nuitka = os.path.join(exe_dir, "ffmpeg-normalize-Nuitka", + "ffmpeg-normalize.exe") + ffmpeg_norm_pyinstaller = os.path.join(exe_dir, "ffmpeg-normalize-pyinstaller", + "ffmpeg-normalize.exe") if os.path.isfile(ffmpeg_norm_nuitka) and os.path.isfile(ffmpeg_norm_pyinstaller): shutil.copy2(ffmpeg_norm_nuitka, target_nuitka) shutil.copy2(ffmpeg_norm_pyinstaller, target_pyi) @@ -146,10 +151,11 @@ def copytree(src, if err: print(err.decode(sys.stdout.encoding)) - command = "7z a -sdel \".release/{release_name}-{version}-win-x64-pyinstaller.7z\" \"{target_pyi}\"".format( - release_name=release_name, - version=metadata['VERSION'], - target_pyi=target_pyi) + command = "7z a -sdel \".release/{release_name}-{version}-win-x64-pyinstaller.7z\"" \ + " \"{target_pyi}\"".format( + release_name=release_name, + version=metadata['VERSION'], + target_pyi=target_pyi) print(command) if sys.platform.startswith('win'): args = command diff --git a/setup.py b/setup.py index 784f06b9..d7203f6e 100644 --- a/setup.py +++ b/setup.py @@ -23,13 +23,13 @@ author=metadata['AUTHOR'], author_email=metadata['AUTHOR_EMAIL'], url=metadata['HOMEPAGE'], - packages=[str('autosub')], + packages=['autosub'], entry_points={ 'console_scripts': [ 'autosub = autosub:main', ] }, - package_data={str('autosub'): [str('data/locale/zh_CN/LC_MESSAGES/*mo')]}, + package_data={'autosub': ['data/locale/zh_CN/LC_MESSAGES/*mo']}, install_requires=[ 'requests>=2.3.0', 'pysubs2>=0.2.4', From a8bd1b1980af938d3b398063d2d3d165b0d84b59 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Tue, 21 Apr 2020 22:23:32 +0800 Subject: [PATCH 20/26] Change Auditok constants --- autosub/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autosub/constants.py b/autosub/constants.py index 810fc41d..3cf6c847 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -68,9 +68,9 @@ DEFAULT_SRC_LANGUAGE = 'en-US' DEFAULT_ENERGY_THRESHOLD = 45 -DEFAULT_MAX_REGION_SIZE = 6.0 +DEFAULT_MAX_REGION_SIZE = 10.0 DEFAULT_MIN_REGION_SIZE = 0.5 -MIN_REGION_SIZE_LIMIT = 0.6 +MIN_REGION_SIZE_LIMIT = 0.3 MAX_REGION_SIZE_LIMIT = 60.0 DEFAULT_CONTINUOUS_SILENCE = 0.2 # Maximum speech to text region length in milliseconds From 00a528bf3d6e89081fef37e52c084870fd8ed0bb Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Wed, 22 Apr 2020 09:08:33 +0800 Subject: [PATCH 21/26] Add *.mo files --- .gitignore | 1 - .../zh_CN/LC_MESSAGES/autosub.api_baidu.mo | Bin 0 -> 491 bytes .../zh_CN/LC_MESSAGES/autosub.cmdline_utils.mo | Bin 0 -> 12780 bytes .../locale/zh_CN/LC_MESSAGES/autosub.core.mo | Bin 0 -> 2569 bytes .../zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.mo | Bin 0 -> 1559 bytes .../LC_MESSAGES/autosub.lang_code_utils.mo | Bin 0 -> 808 bytes .../zh_CN/LC_MESSAGES/autosub.metadata.mo | Bin 0 -> 1007 bytes .../data/locale/zh_CN/LC_MESSAGES/autosub.mo | Bin 0 -> 1654 bytes .../locale/zh_CN/LC_MESSAGES/autosub.options.mo | Bin 0 -> 25506 bytes .../zh_CN/LC_MESSAGES/autosub.sub_utils.mo | Bin 0 -> 634 bytes 10 files changed, 1 deletion(-) create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.mo create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.mo create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.mo create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.mo create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.mo create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.metadata.mo create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.mo create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.mo create mode 100644 autosub/data/locale/zh_CN/LC_MESSAGES/autosub.sub_utils.mo diff --git a/.gitignore b/.gitignore index b6e2a13f..3453adc3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,5 @@ MANIFEST /.build_and_dist_win32 /.release *.po~ -*.mo Pipfile *.lock \ No newline at end of file diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.mo new file mode 100644 index 0000000000000000000000000000000000000000..92507f914e1a1e8be48b44a47297c2f0709b7ff3 GIT binary patch literal 491 zcmZ9GPfrs;7{(VOmpyvs@N&kfyKNfEsxeS2A)#99O1P1s`*u4}W}4Zlv78zpL_C?O ziQ=IUqZa~u-~@rM;ze586JLRM(?kMK=9l@CXP)=@`|!axi!@4%6OV{7;wh1+L`)HH zh=~!)+NJ$DaY$!cca&sU1+A6#AYa4E8njds8d|Ml#ek@SFcHkWEkhN#X=(%!0ZP77 z#~@{uhBh`Iutn67P|^dtj18p?D@LIR*laV5n6K!$^x9{6O(EoBFStPu(oWi8PKKqk z;7)s4chbo@4jEY)--{&ezRv|W>t%97-vW;e^EH=Iotvb-y})JI`qpaDe1jj%<3^ne`2;F8t|K(h-uW+C?$(#YS5dQqtf)Z9(1YBHF#jic zuu)sizp|Iu97@!~9wmi=Fpy4VY-{lKM?a3Q&-Z%2+P%*2%ZvT1z3sul>DABU-uJls j`A={6OZU8edA8G!j|QESe!SEDc-Z~a>2F>9Yj0XNOst<= literal 0 HcmV?d00001 diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.mo new file mode 100644 index 0000000000000000000000000000000000000000..9969e49ef6e964d01d5193d0677fcab5a6e3ffa9 GIT binary patch literal 12780 zcmd5>eQ*@z8DHC~^jiGxceU$P>*pR3wbEEWAO;#62qn?#v>m$KZ7!>KyVu>lK%h*c z0tt{15CRC1Zv;^iR4R}VVq5EU+L?ZgGySJyb*8s_cQbYTr+;)h(@uZS`|j@T-EBTd zvAVLM?C} zklwEbiojQaUjn`ji~-*V9t3_BLGZGQPhZz&UvSHLwQwAK)l(*5!imW#Ie3)4&-J)^~xw z06q$wd8Hsc4om=-0M7v*0bY5PAY1}W0%^Vm#Fm8hzz2X^fepa7fe!(%y;=}%11{+~e7)AiWA2>bz%`1mRCLEziK9|5oV9CQdYfW*%q+~*rVF9-|p z{4|jC@mnD2>tDdH0KfSKzKw*nB>TA(Oc8%K07i1-vJ~$JOO+F_&$*2B!S8MfGRKs zJOUg9{u%fNaP8Lx;ZERuEKc870&9UU0*TKY@HFsq5CX09d*EBZJdnN*LMWu~cY$rd zyJ0*sa1Ss6B;{QKP=MI7kOIOrgpEM*^PRxCz_)<+183aA`B(rXxwiw!4hDcU{tS@h zm8is``XU)zikmKy?;_loA}qx1U9?ZSzKk2{ zV0KA18N6r@-t`^)AfCV?voYEy#K^9h_)Btvc$j^`%~)J&1k!$BM(l!Gm|xHX*&SV% z;eHVJJlx*(3H%_vlFaEM86Y&V7&#w^u)^ecF;K+qU2s?C_n&lMTn4z}1W! z;fm!KsGG%Q0KX!0Qz>z|Zais<30+fSLZnXD+7-hRO+9PG6|q%KDWau|(N&t9R#r#p zcS5n0xFyQjgsO{%l2mog#LPz3v_!pCRJBaj5?gg6En8-7M2IF#OG>p$rV)>dW_FpS zS}Dckl;egXTS`KdEv&FQ8WW;V=&B|u?TTiZQy2}JL>enhK6ozUH)H5=#WYndDaQ45 zCWXDks-!?eE&WM%r`VrAHW7>XqG*#%ahalM7)E3gF=3vX0^zKjnslEKbE}$Aw74R0 ziJKLxJYp)M$3{u!W=2usZ6%>Uq?mC-%~+T$;J2k}GW`})GO>|VCgr2vFm$66fQpilOeL;s31~nzlA>ygYAU593LGRnS; zZ_t&)vj%v##AR7El@Q?yjAlYtOk&&2W->awV}Y(G;TUx(J)00s#b{UID{?%pXE7B< z4b57roHApP#VJLGDzmtCt4%Q~2^rpAVDK!Cg>#a;n zde%ZbmdL5NKXVuLwbR7D2LlC*+;H61^d$Dg7hvY(hWl}h$o(3NxF*!vn$9Rm5ys!_ z=7V|!TrxmJ0+xQ@DqaflIc?@C$&(H^MEL($T72`wVGX&KhZAK5T(Pu2?(&u{S;`7z zP#(vsl9Lmr#VpQcXj)$6nI@Sqk;)3?5G;M1~fM4E{ir-84Ut z%d2!Zssm#j@ z_`tKjTZ~O0q_QeOY_?F&y5<{QMO-c=RZxvO)q&z-Lr)rVS~M*^lc5TR&zwNKC@bW4 zgmifs3daRaO$!?9m(E?hxUr#bZc9VcqNR09>L03K)Y34wu{kDE^$$OknT5OcrR3I^ zZjQxSiwa69q~ zUpoFwDWHl?*s+*V461hMd9s<|y{dffARFolMt8CDSZb^iDp42UR5G7y8Pk2QEQkw?53KNa zjP{x%DQfKw(u`E(+Oq$%Q{GM<%&oCiyDCoz22VW@$^VTGE`rjfGY-&$7BnxaV!6*MST zrB}qw)fCXoG?Ffw5muY5i8ZmvB7Hg8HN{h1T$NzsVnP``9_B#{Zm=qCm^F-03Ms*( zLvL4C(qiviN~*><3#U}Z(qyFEl*ekTgbFoTy3xU6jm(1>s~91l<)ue7H`w;jzf+b| zvPTYo0yCwCg!Cxy^VEuwB?>ioq=jZuO-S>yNmFXk@p^Gni&RI=N`y@5A@nS3#o0Bp zYowaHq?)_MJMOBj`Q~jkb82cZP+Fq2tJF0L8Fy#x?0fjQMj6c$FVs;BF4E|RFw}T* z8qW(G7S@*-yCYUZy;%!REVXoGus&5$voa}J)$SGJZL)#w-SF^Za4wV5jr*jfJ7(#l5fDJ;V0iy?k2t4!djE zS>NdltS_9~YOg))>^p0p?fc;DuJZ1%eSC*~rr++~ZI2Aw14pqeHHC>rSzCC5VS#?| z_@lsG@xT`Q(3#BONJ-XFi z-|OsI1DngQ?{)@W#>Sj&Lr%|AWldgZpx558zi{#eyYH0Ub=>J4#F~-9&?&Apd+qDF zk?lb;PWSdg=h|ZD`r`gG5Pe7T0x4+ocQ+)n_&-BDK=TuCeFA0J{%a4Zqp9Wd|rc($)&Om2w6bX%N zvrOKTnPIPed?#XL$Q*K~?Oo*9o~@VXpFj*Ar?tzCfTBa^SrXjl?(+-Zg|ROC(5^Dp zeDleVjTDBq1Uq0HDsToVWpfBm4dC^4`+pn zPVWU=geOVCt#o$|@%;wNG}=KXXFmU5SY( z_%?N3)9qkE&#HYto>eTyO8nq(m+|sVRgL2Liwlx}WWjf;0^(Be<3VnODpg+Ml=XW_ znCCGze{`cg+?OBec8*g*a;HuzZ0FVeFm{yvNV^cv#626(<&1Lw8@EkK$!YK$Drs(A z#13D_>FKfucLfFLljIf&7Pw&D|KQDy4&W45F+s3*@55V)7p$=5F3t&1S$^o4ePRpF zXNVm3*l520aCq~WPXhxHyYHC0M0p)ZjDL7*c?Cw5^D)s)CSq2~PDNwn%*DO0aX%d| zI+Fy(cB3Zu2CuWbU!v`M&vcjzmc^Km-?rE3-t3porP09+g&q1_nqHMr7^21UBU_z4 z1Jvks4{IR@ZGWxsAu*vk@>K8~zR8MA9Gv59I|I)MN`dyt-&VP+d)g{LQqXw*fvRoR zxTS;7zAn3Ko!zsY@4Gap++%4Z>sth6ntvI`z)mR3k7uRnzS)Ew={%c3%C(2q6`y4% zQ_fp{(~y1O8M|+1v8xY9l&Kk(S1Xrlv%t~6sw%sH)p4na@^i#g%XF#_KNL=aHZoOa zE-Ww8J~L1xJ@smSq>sl?gihbnU|Dwm;o>u+2;k_qaYNh3$5F5z=(G5KF(Jdw-QAJhdp9$8 zDTu_@w6u*|N~M(0G%X?^0orXOma;AFn=fjjiBCTG;?C?YFZ=<%_`NgjA_k+WH<|g& zJ#)_Yo_o&C{cY{4Qv~A~JTKyz$MX`N5AVYZ<0o(<_%m1!uD+j;MsPd02OI>OK^NQw zh8`f~Rq#{rIq)L523!E&2EPYi1J|q~Bm&lf&w>I}x;>y;{|E3%@D}(U_y_nH*tD9E zm%(;$J#v!Z7R*N;BxDEp3)l{>f5>MCxE=E!!FR!R4-@hNsDn>{pMXj?2W|jI!B@cV zz%Y0V^lI~nzt1rEJnTonb>J`<1h0Tf=U0$|Wf19k<0-r$Ltyd-Qt^h;RWaBCLHWG# zDBdbBHBhSRSiAJ~IEYe^03KCWHB_CjZSu651R4ZC$Si5{1hq4a#gf!w2~%*JNDIPZy0xX5>fE3SCcPyrW@l6KKTEW< z?*4x=O+qA6j5ef1)}U?v{`Q1h!u3q*;gx5%B)cqFyK<$ySxy_7Nk0JJXZzbk>;RMh zEElzOZl`pwmXaNkXp2bGnj@j3HLCD6N5V&If}}y`F_ucH7RluR!C|lVIzq`d%Mw3u3M;KkMdMF!uQ_CbuQijUZ|I zt1uNDTf)N4Jd>4Fr<`@rj4qS(b(6#%q1;>eJ4J;hs%=#Nh$=y~e11pOG$wf5Oaw`bB|bt@TC<_; zVV3Rb1zMRZptjRan1)uLP1ssgL};L8cT{UYdTLee9bK{rtqs+Nv{0QE+C;;(k-E@^ z(B@DGj#?`_Xezb4{5EQ}VH(~PsSEplJ9JxW%jv4~64;^hL>7%jUGy~OJDYcIyOUTr z7*bb?#7&_^4`;BxI;L-CQo70CqOqiI*-UO}k2Y$X@A#=R8fTWajmL!QVuWtqZ_4UQ z5&Cg*U&F4zUabiS)6&u22yGF}FeR-GZVZrso9i$2d|l2@Rwk}Fxq>q>;Y=UHcjeqr z`Q}x3;9POG;G7>V&R#A}O!{u6{$6+L+uu7sBLVor>>HLe28Sx0U8T7*r85go;bJwY zoImFDUBRX1+?a6|PCI?mzNIvG(j6aLk(fK)Rq324_4ln*^2i)Pj zo9lAV&O7siOScys-QgRh;Y)wJvXrVbcBxcYyjvAAh4R8lr?=pa^cLr4)OXK?;%q05 zqB}BO8tpD$&pQj%*7a<1DQn{ZD} zy8}}yQ~$`SYK-(clc$TbenF6qJ9*wY-|bxg#vSW-PUIlwt0GF}U%il2_RID5gNrv8 UvB^r$Kkw`$9eQl z;lPZ7?^)Q(Fdgw73Cvf5|{+e z0bjw{FTmHZ{^JQn`4IT(frzgccpB@Ufid9oPb$hwz;}Q_E#1J+fZIUOC~ylu(1jni z6;LWqN6YZ{Df|ZgJQJ+cZkv%zreKL4Mx-F=97}&e(t`Ig%Qgfj7PE_{j4ADwC9DKo z^97bAY06)h#4ebIB>kdjk&I!o7)gfF;RY@0h9KZgGut+JmWYA`pB+;=c%di>C7kt< z0+l&((BNqk?r_o#i>0No`U&NFNJ==(vo}aaSVR1mrUPEVsWD0hSyvzHE zVVW#UO=5(J`mjV7S!(Ho+N33BTe1abwq#U~sY)uxEJh5QP}9N=GDms)43s8wjMyk3 ztO7yUfTt37P9IYkDaaLelXFT2CR8ix?%2U%g z2YP|NL=inh@-Ro9rgH{|rYVS_vkb))NS?`@&|}Kpz@jl^nI!uXs2wushOa(d zMR~SJvrJ1dn#a1cqqBX#u*0#qniO0zj)OG9}2l+}Y#@>ZjUC#+en>(IuFUJKY*PqAIFWdsv^o*%aGb zSn+-=dDm9_+NyVHsa~1#u9hE_zEv92SNyfL-RgYwHoUn-@7|0%Jm`+xb!vs&wCeFqow=ZXyorsT-vRUfJjxEp|wT-#vl?Q)ZM&M9~;7i$$ zna09ZR2%GA&d!2=e>ReB|1o&wTS((SyyA|p*Qf9M1C!3?1#e`> z9bQMYyT0JB%`_^P{hyXYZMOoo$12fOqJo1Yds7Ri;g4;&>s?-p XUWhmMV7EHjD3|=}-!$X*q*ML`O@DmG literal 0 HcmV?d00001 diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.mo new file mode 100644 index 0000000000000000000000000000000000000000..f2db5c1ff4985cc75f2e23a0abd68ce93098d910 GIT binary patch literal 808 zcmZvZOK1~89L86zuc#CSPd*sp!55Qmwk?e-UaVCDO)WKwhk{O%e>W?e*|0mQk5etJ zq+qL13Q~h8A{0a{deJs`)|)49da;|Nr(X5uw_RzAIPl|}Z~m`g=Es4SSq*C!I1C2C z9#940`V4k}FJLeD3J!tq;2`)7_JP(dQTzzB6aEzR7`O>`!;f!`;?vNh@K2#(pGD|? z=r?F9vnHy@G31VrsbveqMubx)<_A7 zzntaW9tnjkenBWQnV}mx*W0Ag5zmq+!e`Q%o{fto6MC%Mm5LV|n z*8DUROuSmH&1u2Ik1G>Xjis6Tv#M5q_o7~%jE;iJLi6pL=KSdL(#yv4`#(p=w8r#8 zP@Rv$|HgvKgZk{kYOS*Nk*l>yEjn3w{bYG@I-K;spKHvG2am>37;Z*u%O9qK$Cdi~ H*>Kt)8mRsB literal 0 HcmV?d00001 diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.metadata.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.metadata.mo new file mode 100644 index 0000000000000000000000000000000000000000..5ebc6d2026cc04d4d5f8ce0b9e81475c911fe292 GIT binary patch literal 1007 zcmY*XO-~a+7+${)_UOrjheCgV2n9Fh>rDxq8nd9Ez(2YtaGcL5wokSI_F$ zL&P>cVp5!?WE8%K)5C+E#*%S0Ho$E`Z73@hL0_6n6fMH+t4J>p$ED)h-Rw==*TG5p zJazD(t#kSCDb$x^qOFudPYVwQZpZH9ThUm_J~EubUqo75i}%Eo#`bQwG_n7AHnCs* zE;oPet-muLys0#5Kf}t3KegPPs|J&=qx|3Uv%`4{-fc9t%Z=@o=;j!9Ytetc1z3N5 zJRIL^?A4od%Ll^~d|Zs6!IyII<7K$92EzXIu3xSG`!&5^UI^=zXjFnvJHgEQQ2^BX zlNJBPX4GpN?|)rrF3rHW_}?ZXe7Ls?&cFpU2e3wM(SJ1+ksqHDsAxM5KCCwDwQyrr Gy8I76#F-cX literal 0 HcmV?d00001 diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.mo new file mode 100644 index 0000000000000000000000000000000000000000..5c644f4926e8bba93752521c5d7ecc74c01289ad GIT binary patch literal 1654 zcma)*U2hvj6o#izz7`4y1UGyQ<|YX3)^SoPGD4zFQm|-Bs0>Biz{Weam)bk4+1V!M zDukp-P)brY32ho^2r(+4e9%$|Nu2%%en2IJcWp~Zh`B-d>`~aCFtuLYL&(Em0&D@_0V((i7y*~Tr@@~=1N;Mwg7l8Y`8U8; z_(NbbxCVBBzk#Y|^PPk|4!#UNi`e7fKKO;bgd6~e!RNpd_zd_9_yoA;E<&2Xr$ANr zFsStTpsM%v*8kVRL-6$6js8KObFkV20dOc>Phap z%reM9-?BM%1=C%@Q_S;hCqq*_@8+0)Eb^=;@Kretv%i^igQv{jEDpv|#(YxIR^TQrJ;`Z0FWR@rtr*AkC4H_ja~J*g*! z>3BI)s!vcmVmcY$%rHI4%sl+AL|5l6Va-NVYv;IvgRp{&`jYj@{cg^*ofl~;YYLCa zm)=Ys*4u8KQ|Z%8=$%fATlmD{w5`XMH!H>I2ibSqk7{r0uP}#+hK_E|EL+l;(V`J8 z_;4mz8Y{1z`n7+6Xtl}n)#c^iH)giRCD<4UR#&kVe%T*hES5`im6^eCdbqs)LpZk) zY>d~Vs+(tnp<*yT5KgT$l~+#(V?)8jx7#PCHn~)}aIU<%7)~#$d}mLWOS6^rk#KQd z<)~e}Qky?hn;#4o1}hV%f*&tKRX8&7KYQEd?@Y4rUG@7SGHB(}waVnB+WNWb(n2`> zQ+Q>np7+LO%bTB7uTD1xB%J*wn7vfJc0L$isZ3t24xTBmejJW&1|uuG#?%Moc7t{w zjz;6cPv^p^k!>~pWi0RnTOqTfcrA6oV5(UAs1#oQ0?(;Z?DWI2(cr@8)zVkx^b>Dw+WII8VDDf+;Q`^5lwMEKYyeP>MR5^wyN~TSb3`x;;Ju0)<{Q+2M zu?y{k6l|*jC6NFnlAtV75?>-I@udd=Dx^p}2y*&Q+oVlrl4+;yB+azR{&pABbd;vk z>7+Bs^mFdHzu*3LvEW0IWDFMvzsJ4z+;h+Qp2xk*Kl{ur`yGCMz~>+HDSg6mei!=A zC;7$CnNK^;SDe1PCxW2bOd^Pi{tRfIRpI( z^j+xF(6)cTct6KD&`&^r|Cb!+A9DZS{j%fS3iY86LjMo+-}1csR~+X~=%;?waWdS$ z@7Els2l^IN`uR)fIj(>4vyMX(X9jvd^xr^#PTGCWadvV23!itK{|DUT&fmUbaL;rnUmKZEXuJ_fBq zzkp01qSNni{TRahC(tv{e+2zQD6cpbC|x?=V#6^?#w#?vuai zIEcjg3iPkws|`9U*SG2V{0Vde*AFq+d(eYWUUAlaRcQ`-7wz^zySV=cUvr!o^lzck z@7Hg4oWFo}L$5-=yu@*yg#H=y5Om#A$2kxEOXxY~ckB+w`3(L2Hl6$gnrwq#=zni_ zoIm2d_d6VirFQ;hr{kbP&L2WQ1^tgux&Np3x(Y>gocE!(K>r3R`tx`8`qMDW5;?yF zm3Fs5rJr^vs^#1bm3BQ)Y4;E`2_I{rOvSmdT<7tp&}X<_bEo6{3+Nv~N1^NPLMNdA z8TuqNb+=ys2~_w>e?#ZL1$vn4&)nlU-=hCX=>5>Yx|e(0Z@W+Rs|WfJ*XyAUaykIr z#Cr$thc9mZuW#z}O~2(h8@Yc3DsuhnZ>e6M>VbEz&qKe+^PhhJ-QoJnD;(#WT>opR z=TJ) z(+k}M?SoE3ze{`f5#=`xQ(xx(d8pX!A6xoAEWKr&-v1KxH+gHn{x|AG4(HYlDf+2}Z%xjq1W0s1%4uS2&#ij1M}3S~b34T|WTTfe7tEmX!C zhyE?}F!T?g2fyz)TcI9+_Y(BKLN7p{#K`^=0{8(@jMBY{)VAH4}I2Nk3vPS zU$ob+LSZBPxr@JKJf`D(n~&)JFZ1~dANl!~`K`ZNAtGxaz}QST^g%xIbB7WKH8DTy z`7QP%KO#@D8Tmn73{IH~`|D09>TB%rllI;k=nDJyr!5tNd6@aOL%+rcb2c~zaUS3! zYx(PZ#CGK8i+oTeqdP2-`MJ$fRN4GsYR+%-`8B;XzyE3EZ&b)xX0Mk+Q5}PAatn2F zFa@(lsD{C2i1StX#m^ExoA`(g$&cvVm-qm0M&D6W=d*me__=wp6y=%e1HC1)8?kM*3!xp*DDlY$lm^3t2ax_Pimt z*DGxGyo_7ensrUjbi;IA%L!c6aqccjdVTR?y3mcR?4L{XjT729kYeJwes^msopzaj zE|*GrF8sQ-joY(sl^ZW6Q&~4L5YJ@1^hZBXK0Y{<_S_tDTJr55E&Uh}dpHtlX0^1Q@=yQ!g zNtKt|pUW19+-#rQ8cXLBX0UXM(Jb3W(5<2nJTF9^N6;u%dr2_FtOE#@2ZvyZhP{KP zUsvID^y&h{=W2DAiD=U~qTl0x*&Xd(M7Q+-2!0NOX-0m@mwJw)Uc=^0& z!di6>=0PF*M0mXdQ0rI3Yg}OieUGkREy4tInU6rco6XdFiH@btih-=~wsjzdYN&?9 z3fb63@2P_6gyvXUo4cZz%VCn}TfR6nl+6Lo{rN3j-3ye2|+g%(xGEDfb7^hIxL^>)nt|Jb@94#|Zh~x^-)tY222`NN4Tw ze6D>4HO2`jME!WC5zqe147)MB95C^5`opN$0_z_QU)>WMv14| zOiMF^cq%3XZCJN*<%(~&Z+c?+J?W=X>0wYTFca~&i=pd-sAejozBOO$Eu;zvUCbCx z41#8|1}(SXC^2+FP*DwJZRjvV zh@u0v{y5oJc)FD#@&&>Q`jfG+fJ8jcD=9JElo{24oEg;E3i=k#B$c+k375FqDDQo_ z?4TLF{{05)iiplIwA6VpmmLCOhTXP!K3|I?6q~I;M4iARB#Fc%G|~XZ0&u*q&r1}{ z*pY`8JL<;A-ooK>UOyrS%CQmz?W*$9s-`E3K8-!p*?OI=^8OHAdIq@-&%k9Li=9be z!98wYIvW?Knl5^c=!$`due!adegWV?kC~cj1u&SGW(6-Nt0$f)fUu(R)&>QWfjDiO zUQfJT3jM2#G$YvX02sHL&%=V@3((=Va8fs90)z>oT+NbH)J>)dUWp54|^Wg0QAWX%dG<%~&0T4DIHxLcHH-LOm?XLP#j*5f~JW zf016TQbnPc$@h6+e!{E8A_QXJTfcVA!|tjz>mJ?cesArX+c&x!Hm+Ugu77mRnpJBa zZgU?%F9cbTH_B$hmh4ty{Z#&m1|7H&{3hejh$DYP%fE;OqGn0B6M|&W`GS}>1i}r? zBbyJ4nLJUQm9Ki zCHh-59J3NLZtYr0v`rx#!+brzv^AiYZ)^56;)0Cx)%?ZSf_h`|Y=ToZmJ)BwQ+#2@ z*iK*H;E>lZ@#+Ta{8j=sHvT2kRcE7J(f1E%n(;idhFP3Z&g~n*m6@=Yn84cN3C~(#+XU<;T!^eQFcpeG{F4C>hFeVK0yJp|vlLR`*o6oKy!s;I=7(6rP+}@kc_O=hk35Rl# zyPG%TdJ3C2w+#)~V3!ch)D^lzrH|zkxztc0rVc7*66H)G7KU=MpIS=t^o* z>^u^Gf&i*0;SA6bD6@%02t?vQ5=#OIK3U9C@M&w=$Xh{GMdJsa(|5APB&X7eRX6U7 zVw>d@2Oy7ZtX>qlX0mE_!k?6nQaLZ#*3uJL zqkBis`jvN>-f;ezeydl6EnHzAA)m~N5Pcw<>vn$}H-9|cvT~55m}^hy(=87a`x!!0 zogWWm2fZNx?dcX|_mqhZ(q5*&Fd&@8vCOn5HJ_xL$F9U>N?3;g;}UMAlGfixT_p-TKUb-e+GQ!V<=8cUhS5W#BOdCWQ z>q42uGn}SfTeOVUs%-Fdlf7#cW?|Np8MIH^TfKLVC=+FqELu;Rm6iep0By1<5ejvZ z;nr^IOdb|#0y@)9@whLQ!%Lx*8G$HJ-S#03iPg870rSN~0&HK#Ly9$6Y-EHWB|)w0 zgFGp0k)~qcFp!0TtW=7cb7AI){99vBnEXouWb!nEgIv*DDwQDHT+4uBL(2Yj8U|1t zSU)S>$bjhqiz7AM-1)To6aA|z{A>Bs?vgs_jQ}gSNsRP(JJy@Uan-@8f@8j&`;^Sv z@&h3gzL44F?&XF*#%?wy! znL{tpV2C96J#-_D zfR4CqQi*G%O`H6(a-q;1?L-Ez8)lJSrBSq3+5lL0FEG_eb*FCUXdSz3q7a7Tx^j{& zd;*tJ6w8}hSQ86gX5WJeYN$apVgqoxMJtDfL7RM65YkJijRfqrlxA8%1Xa`YK8Z@| z!J@$vI_q+RbMzl4-qK!4MX0HSRROF+#@U)n$({@WL4k^vOqE&n=i-BkQYQN#(xVF$ z&u$RPDBE#4t$c}!n|L$c2XuxRDES>G zB(kA6qm!|(X+$X+i*|W&iq?6gqZKZ*9dZ-ZxW#vfHc$&jdhARMQM$n&Q?QK4iYk5W z4VDFs0gjry!J{qIi`{r4ku9=_Pk6&kH@Lu9l0oW#3U(qalc34=aG-79*|2tv-ZlCr zJ|#{yRZA?510{%ykxMErd%P>i`mB<$N6LNKZ<8^k5DiNW`OSj5jKrzpX9-lOXlvn{ zN`!3J#Z2G=@-*8YkgC4Bb)*|=)$n$0WLuY7RjnvJV^R&Qu1 zZ95wVQ0;Jwe85W&ktF2vQcDnh@Sc)FTx2Ow+xjL!^tI^Qx(jB#lC!ZU22(6sw7Ob1 zDiLb437ZX(#vWyxgvQqR0q&d^N`7gu^|7Fl$c|Q~b|cYWfFx$!BCBgNt={3*SUzsz zH>(OUt8=YO%^bxs_mffrCTR<1Ne`1FJC)iZQm{z{Fo~|nvjq7}gKAtC6yigv0s$G@ zwrQ<>+RQZ{GZ7N`YCIh?Ax|tBFT|rOxp>qs!ikhUwWwJK<5Bs_Tw0AAZ8cR=Nk4m; zWm3~yd5mdu%EA?^buprJzEKNhL}Po_X^3;kVgj5ckf1WyS&^zNgEctxWk&KLPMebq5~&9Pl9W*!6pz)Ej;?v|!7$1!Ye|Om<)Y3)OAiM=3)zgeB39 z4zR2*MX}n*lT#xC?>0kZ80$ktRCE)>cV=Uu+ti>4t77cUNt6ZcV_&wJao)@xqXkCE zwS=*-5?(thvj8O3i%ZlMZa%h$?f8phGg~@`I;k$jJKLoMZ+8P%=nxwkJjLQ8Q`utw z6hq6mCA}@2*`bV)Y1iR{13LXYPB31(iDuOjwOyMsuCH$fWAu%M41M5jQ#j944ykRO zT0qLTr{aZ=WS`VC`=pO|7U>JZ*y-v-)XW0EU4YKGx*+YsvN(r16otWu1ruGsGlE%oi zNGI$8MZqn{I%G#fHb>amoHxh(9Bu4~nRA z`_7cl?|=XD!7$yC6T#I>lm3XS7)n}FDeVA=@;f-xllQBymI&${gn?s z<8M0*|ID`h%0(V6Iz!%`pMAADaUz)gOr%`YOafOAFme0x<%9nC%ZOcjV6e*U0pi8d z+*MYD%lV_{=U;!(f8*TzwwDm<{OI`4l8^b(QBijbBImud5rf))?KfZO;72 z!Rpn~>co}G+(c#1r2qP}{`jk`w+!|2w10WLd}-Ey{+QT?nkmdMdik}(f!>MLm0z9g zc>nS))gK9-3-hDGtu|3RgQ;kf($q{xdF*Ae6rPwi+zL-Piw55WZ~2d%In23wS;?k#Z?7 zV3Fm0)AS{FU3qubf9-{)Lt)fnhC9nIys4VFLC?@fPFK^;pL@yQxx2h?vb<{>x+cX! z$bzBKh`_~0_CT+7teVm3Uh9js9#>rZY;|Oq8%ZH`3{xp!i0Z`T{2Qwqa3~ony4CJ98Zw_GS)U>+ts6b>+Ynf96!>=vf`KI=RCi zd%L~iy8PO<`H`cBgHWC~asZo=;IRRME&N{FeF=1p&iH3v@u&BrJmq7T5rM3`@dM@G zI}QYv$M=@59I8&9RNV`mLBo0LV0f{g(0^(_&EK3p8tuQl^G*NV{r=wF^gsX18>Q(n zRZDv^TX+JNuO6tJ-d%^rhSB=N*}{N{8`V%HHZl`b-`>za@DzPo^Tq)`jC`ZQHD|V2 z3u5TZp$i0tES?1N>`7I1|!=;ulY0kRKjq# z0PJf}|K3F98D@CS%*}RCz4-k6+pkKX^Wyo+5l~bRo|^zEuUS_bK}+z~pS)Zhy`T~- z&F#T)D4d2bwMbLO5|J*pq2fv%m=DOP*i=6RZI47eB%4*HQ%xk7#{17TznmJwB zXV@|!vY@EONux8G6!H#SF4B3ROoF&}x$5Jhb|z1dgfZ~A^3Ex`D(^W{-Mv>~z-npK zL8zItz}hklujcn1(5Ou(#3CT<%IsMA?CX^?FZeSe%hKEqzyX*NQHY#ADqOmrQy&jq{LJ(;%#pvXk$SBO9ZT4U?UR}dQ4lOrbqb8i1 zklk(zF3mS#v^=v{nY#fl7q}DgBA9@Qfork!>>hvYmFn>`q!^2Z)8X8-7T55_zXn!h zQO(dgP<^mXOwAlaxswx_ddIFt{Rxz(dUbF0_^uBwJ{4AAUph}yL~)ojURW^zq(vc^ z$0EyDnm+2Edl%)cpG?@y&c}2S)g2MV-c$bA0b>jY7*BzFVGPUI<*Dud?)|38%@t^Z zysvRe%sO-!jn8ztQ77CGhQLs1?pXQR^MupFoC#7e>mV%MMZrZESP#unRf7f>Zki>;8(G&qS6%%`P68&gV z?6mr8bO)EOg)6KGf3G@@;)hrsjw2nnMwyd}f_AOlYTMF`&2eSCFvkE2)ri9Gq^M#7 z$(B2`)37&57G@3sBJifH;@0PnyiU{7)ZyyMt8j8h3t&&`zxZ+b`Bx_9Uw_pf-#ve7 zjJF~O>gg7wEKj^A@%#QUy0u7ff$G^AU1&rh5i(VXiE00;lzb$1J3&Ewta|me%IsOz z%AeRdf8>C^FY5mRO5b!BU8{v2T1Qp>bfjAJ_)(2_ZXEMq$d6;Z%G`^U*~7ZZHg2jf zTWINBv}XDuDk@c&zfXZ%Lo@X%R;pv8{?6ZH06d9AlOM`3ngiGYOuQ{xW?}=;lm)?) zKEh(uot4kN;ZIG8(is&ur;qVqK8gg@}6DTlv(Z2tA)0I_bwHFb&?z))DJmX#C z;J*UzqRHh)ar(ar+?xVxCl!pYXzg{kbwMXyR=>{l)HZFZX~GnpzuxK5v$Rp2bFQtD z_OUKPlXmJbn>(oA2|C||5bXnhv%4x|Q~dMKZQ~t>h_N*Lvi57|thdy&)G?zouk5 zV4wKDuF3W>*^dY^T6&Mp?_l^qxQOKE5)LiWd##D-I@(ItDjFNn&)sz08Jh9+J-sQ) z0=W$~PQ!>2$VQP)Jk&s9tmqwG1Dml(QpwSje3z`Jsrl0$ZY`kf-2;@D4_#&Vvb<+! zXjlr@{^V?V=M`OXg_|a+Va362ffh5Q;x9T=IrOr;-?+dFN_sc)?SaN!FgdG> z(Iz7d92Q(b@&=*)fuB zg&S?JMru7(^CE)oC8|i9G9qfyC>Gruls!V`6t0LiZ^&CP^Xi4^@Etlc|H%?SZs@}H z3m0A!E?sFkoY(y81)62jU!8UuRbx<_LzLebDZlrEXyx8h{EmVcEhS7C9WS4|z^-94 zmAWow+~l_on%g9I8)Vq9<)9%)6x)S&b6l%#2}Uk6Mf(i|eGJIXV=8kmiJ0v9m)*LB z#~r+`zgPA|oAVWvulF4-lRHHA*<^H69c!OAm9zHfLy@B~W#Kx=LSz9V9RQD7ujjl3 zRvsHOPp6 zVr28Z1N)G2Vkk&`Xuf%{kYn<50uKYa>SY^ZCfzHMVxS)$J+lhB*0v&MFOc&Nd*mb7qF{*G78EU?=3I?b$88fL!^xBSG(2dfCG(~(P2bc_ zLfzhg-^C6|sTC0g6Z~ktVkLFmaH5&U%l?-9cSCHVHI{3|@VOgB_Qvf&a9Q9c*q{Jt zBB$a>V-}qLx6EsTpywc7xv0fU0f5;9+FcZC5w$wXNZ0zD72tp-he9*}v~HNamj#DH z^nD4>gMB^4D{7!PEm z;=$!&okr6*X{e`aQP&wV%C``2lO-lDXIKt}Tx%go+QKDbiP`UxsYT3U!TRW28{QH- z(GWRUBAtoIR1X~(j`1Nzn%DaZL{ya+Nrz+%Eo^AOS)DvpJ-w~zwkooJ!~X7z&; z*Nz4lj)s-IEk};noE*6jLtLdd8Fyc|BiorUJ1MpzNDpZ$ z1?{1D6YIf~f_M;GKT4q&UGeBg@U0D5std)*C|g^&g7{?<3 literal 0 HcmV?d00001 From 76d41a79f1ab6b4025050fbd92241a4c445086c2 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Wed, 22 Apr 2020 09:40:45 +0800 Subject: [PATCH 22/26] Fix the issue with path checking in dependency finding --- CHANGELOG.md | 3 ++- autosub/constants.py | 46 ++++++++++++++++++++++----------------- docs/CHANGELOG.zh-Hans.md | 1 + 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 832b2c7f..8ce7b877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,7 +65,7 @@ Click up arrow to go back to TOC. - Change all text file input decoding into "utf-8". - Change the default style selection in subtitles translation. - Change the loglevel in ffmpeg commands into `-loglevel error`. -- Change DEFAULT_MIN_REGION_SIZE to 0.5 +- Change DEFAULT_MIN_REGION_SIZE to 0.5. #### Fixed(Unreleased) @@ -73,6 +73,7 @@ Click up arrow to go back to TOC. - Fix delete_chars issue when using `-of full-src`. - Fix os.remove() PermissionError in api_xfyun.py. - Fix DEFAULT_AUDIO_PRCS_CMDS and DEFAULT_CHECK_CMD. +- Fix the issue with path checking in dependency finding. #### Removed(Unreleased) diff --git a/autosub/constants.py b/autosub/constants.py index 3cf6c847..278f695d 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -394,33 +394,39 @@ def which_exe(program_path): def get_cmd(program_name): """ - Return the executable name. "" returned when no executable exists. + Return the path for a given executable. + "" returned when no executable exists. """ - command = which_exe(program_name) - if command: - return command - - command = which_exe(program_name + ".exe") - if command: - return command + if not sys.platform.startswith('win'): + command = which_exe(program_name) + if command: + return command + else: + command = which_exe(program_name + ".exe") + if command: + return command return "" -if 'FFMPEG_PATH' in os.environ: - FFMPEG_CMD = os.environ['FFMPEG_PATH'] -else: - FFMPEG_CMD = get_cmd("ffmpeg") +def get_cmd_from_env(program_name, env_name): + """ + Return the path or the value of environment variable + for a given executable. + """ + if env_name in os.environ: + if is_exe(os.environ[env_name]): + return os.environ[env_name] + program_name = os.path.join(os.environ[env_name], program_name) + if is_exe(program_name): + return program_name + return program_name + ".exe" + return get_cmd(program_name) -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") +FFMPEG_CMD = get_cmd_from_env("ffmpeg", "FFMPEG_PATH") +FFPROBE_CMD = get_cmd_from_env("ffprobe", "FFPROBE_PATH") +FFMPEG_NORMALIZE_CMD = get_cmd_from_env("ffmpeg-normalize", "FFMPEG_NORMALIZE_PATH") DEFAULT_AUDIO_PRCS_CMDS = [ FFMPEG_CMD + " -hide_banner -i \"{in_}\" -vn -af \"asplit[a],aphasemeter=video=0,\ diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 762cd06b..fab0b5b8 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -71,6 +71,7 @@ - 修复delete_chars问题当使用`-of full-src`时。 - 修复api_xfyun.py中的os.remove()文件占用问题。 - 修复DEFAULT_AUDIO_PRCS_CMDS和DEFAULT_CHECK_CMD。 +- 修复依赖查找中,路径检查的问题。 #### 删除(未发布) From d84ecabd59ec62b01ba595676285d85509ac7568 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Mon, 27 Apr 2020 11:21:07 +0800 Subject: [PATCH 23/26] Fix #114 Baidu's strange error code handling Add limitation in SplitIntoAudioPiece with an audio length of at least 4 bytes --- CHANGELOG.md | 2 ++ autosub/api_baidu.py | 6 ++++-- autosub/ffmpeg_utils.py | 5 +++++ docs/CHANGELOG.zh-Hans.md | 2 ++ requirements.txt | 2 +- setup.py | 2 +- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ce7b877..ccec4013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ Click up arrow to go back to TOC. - Add merge_src_assfile, merge_bilingual_assfile methods. - Add stop words to split events in merge_src_assfile method. - Add punctuations split in merge_src_assfile method. +- Add limitation in SplitIntoAudioPiece with an audio length of at least 4 bytes. #### Changed(Unreleased) @@ -74,6 +75,7 @@ Click up arrow to go back to TOC. - Fix os.remove() PermissionError in api_xfyun.py. - Fix DEFAULT_AUDIO_PRCS_CMDS and DEFAULT_CHECK_CMD. - Fix the issue with path checking in dependency finding. +- Fix Baidu's strange error code handling. [issue #114](https://github.com/BingLingGroup/autosub/issues/114) #### Removed(Unreleased) diff --git a/autosub/api_baidu.py b/autosub/api_baidu.py index 5e9abaec..486a2d2b 100644 --- a/autosub/api_baidu.py +++ b/autosub/api_baidu.py @@ -49,8 +49,10 @@ def get_baidu_transcript( try: err_no = result_dict["err_no"] if err_no != 0: - raise exceptions.SpeechToTextException( - json.dumps(result_dict, indent=4, ensure_ascii=False)) + if err_no not in (3301, 3303, 3307, 3313, 3315): + raise exceptions.SpeechToTextException( + json.dumps(result_dict, indent=4, ensure_ascii=False)) + raise KeyError if delete_chars: result = result_dict["result"][0].translate( str.maketrans(delete_chars, " " * len(delete_chars))) diff --git a/autosub/ffmpeg_utils.py b/autosub/ffmpeg_utils.py index 3450464b..075875ce 100644 --- a/autosub/ffmpeg_utils.py +++ b/autosub/ffmpeg_utils.py @@ -87,6 +87,11 @@ def __call__(self, region): err = prcs.communicate()[1] if err: return None + audio_file = open(filename, mode="rb") + audio_data = audio_file.read() + audio_file.close() + if len(audio_data) <= 4: + return None return filename except KeyboardInterrupt: diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index fab0b5b8..34892b30 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -55,6 +55,7 @@ - 添加方法merge_src_assfile,merge_bilingual_assfile。 - 添加停用词用于merge_src_assfile方法里的断句。 - 添加标点符号分割功能在merge_src_assfile方法里。 +- 添加音频长度至少为4字节的检测,在SplitIntoAudioPiece里。 #### 改动(未发布) @@ -72,6 +73,7 @@ - 修复api_xfyun.py中的os.remove()文件占用问题。 - 修复DEFAULT_AUDIO_PRCS_CMDS和DEFAULT_CHECK_CMD。 - 修复依赖查找中,路径检查的问题。 +- 修复百度奇怪的错误代码处理。[issue #114](https://github.com/BingLingGroup/autosub/issues/114) #### 删除(未发布) diff --git a/requirements.txt b/requirements.txt index 6283f8b9..a6711458 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ requests>=2.3.0 pysubs2>=0.2.4 progressbar2>=3.34.3 -auditok>=0.1.5 +auditok==0.1.5 googletrans>=2.4.0 langcodes>=1.2.0 wcwidth>=0.1.7 diff --git a/setup.py b/setup.py index d7203f6e..1b4b03fe 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ 'requests>=2.3.0', 'pysubs2>=0.2.4', 'progressbar2>=3.34.3', - 'auditok>=0.1.5', + 'auditok==0.1.5', 'googletrans>=2.4.0', 'langcodes>=1.2.0', 'wcwidth>=0.1.7', From f48e445782eab9a7e4ee3440e95fcfc777b7a5e7 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Tue, 5 May 2020 17:37:34 +0800 Subject: [PATCH 24/26] Add support for src language auto-detection when not input `-SRC` language --- CHANGELOG.md | 2 + autosub/cmdline_utils.py | 42 +++++---------- autosub/constants.py | 111 +------------------------------------- autosub/core.py | 22 +++++--- autosub/options.py | 9 ++-- docs/CHANGELOG.zh-Hans.md | 1 + 6 files changed, 36 insertions(+), 151 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccec4013..9a4afc23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Added](#addedunreleased) - [Changed](#changedunreleased) - [Fixed](#fixedunreleased) + - [Removed](#removedunreleased) - [0.5.6-alpha - 2020-03-20](#056-alpha---2020-03-20) - [Added](#added056-alpha) - [Changed](#changed056-alpha) @@ -58,6 +59,7 @@ Click up arrow to go back to TOC. - Add stop words to split events in merge_src_assfile method. - Add punctuations split in merge_src_assfile method. - Add limitation in SplitIntoAudioPiece with an audio length of at least 4 bytes. +- Add support for src language auto-detection when not input `-SRC` language. #### Changed(Unreleased) diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 81bb8ebc..3bc45127 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -99,7 +99,7 @@ def list_args(args): print("{column_1}{column_2}".format( column_1=lang_code_utils.wjust(_("Lang code"), 18), column_2=_("Description"))) - for code, language in sorted(constants.TRANSLATION_LANGUAGE_CODES.items()): + for code, language in sorted(googletrans.constants.LANGUAGES.items()): print("{column_1}{column_2}".format( column_1=lang_code_utils.wjust(code, 18), column_2=language)) @@ -107,7 +107,7 @@ def list_args(args): print(_("Match py-googletrans lang codes.")) lang_code_utils.match_print( dsr_lang=args.list_translation_codes, - match_list=list(constants.TRANSLATION_LANGUAGE_CODES.keys()), + match_list=list(googletrans.constants.LANGUAGES.keys()), min_score=args.min_score) return True @@ -423,18 +423,11 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret elif 'src' not in args.best_match: args.best_match.add('src') - is_src_matched = False - is_dst_matched = False + args.src_language = args.src_language.lower() + args.dst_language = args.dst_language.lower() - for key in googletrans.constants.LANGUAGES: - if args.src_language.lower() == key.lower(): - args.src_language = key - is_src_matched = True - if args.dst_language.lower() == key.lower(): - args.dst_language = key - is_dst_matched = True - - if not is_src_matched: + if args.src_language != 'auto' and \ + args.src_language not in googletrans.constants.LANGUAGES: if args.best_match and 'src' in args.best_match: print(_("Let translation source lang code " "to match py-googletrans lang codes.")) @@ -456,7 +449,7 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret "Or use \"-bm\"/\"--best-match\" to get a best match.").format( src=args.src_language)) - if not is_dst_matched: + if args.dst_language not in googletrans.constants.LANGUAGES: if args.best_match and 'd' in args.best_match: print(_("Let translation destination lang code " "to match py-googletrans lang codes.")) @@ -516,18 +509,11 @@ def validate_sp_args(args): # pylint: disable=too-many-branches,too-many-return raise exceptions.AutosubException( _("Error: Destination language not provided.")) - is_src_matched = False - is_dst_matched = False - - for key in googletrans.constants.LANGUAGES: - if args.src_language.lower() == key.lower(): - args.src_language = key - is_src_matched = True - if args.dst_language.lower() == key.lower(): - args.dst_language = key - is_dst_matched = True + args.src_language = args.src_language.lower() + args.dst_language = args.dst_language.lower() - if not is_src_matched: + if args.src_language != 'auto' and\ + args.src_language not in googletrans.constants.LANGUAGES: if args.best_match and 'src' in args.best_match: print( _("Warning: Source language \"{src}\" not supported. " @@ -554,7 +540,7 @@ def validate_sp_args(args): # pylint: disable=too-many-branches,too-many-return "Or use \"-bm\"/\"--best-match\" to get a best match.").format( src=args.src_language)) - if not is_dst_matched: + if args.dst_language not in googletrans.constants.LANGUAGES: if args.best_match and 'd' in args.best_match: print( _("Warning: Destination language \"{dst}\" not supported. " @@ -800,7 +786,7 @@ def sub_trans( # pylint: disable=too-many-branches, too-many-statements, too-ma # text translation # use googletrans - translated_text = core.list_to_googletrans( + translated_text, args.src_language = core.list_to_googletrans( text_list, src_language=args.src_language, dst_language=args.dst_language, @@ -1365,7 +1351,7 @@ def audio_or_video_prcs( # pylint: disable=too-many-branches, too-many-statemen pass # text translation - translated_text = core.list_to_googletrans( + translated_text, args.src_language = core.list_to_googletrans( text_list, src_language=args.src_language, dst_language=args.dst_language, diff --git a/autosub/constants.py b/autosub/constants.py index 278f695d..87aff84a 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -210,119 +210,10 @@ 'ur-in': 'Urdu (India)', 'ur-pk': 'Urdu (Pakistan)', 'vi-vn': 'Vietnamese (Vietnam)', - 'yue-hant-hk' : 'Chinese, Cantonese (Traditional, Hong Kong)', + 'yue-hant-hk': 'Chinese, Cantonese (Traditional, Hong Kong)', 'zu-za': 'Zulu (South Africa)' } -TRANSLATION_LANGUAGE_CODES = { - 'af': 'Afrikaans', - 'am': 'Amharic', - 'ar': 'Arabic', - 'az': 'Azerbaijani', - 'be': 'Belarusian', - 'bg': 'Bulgarian', - 'bn': 'Bengali', - 'bs': 'Bosnian', - 'ca': 'Catalan', - 'ceb': 'Cebuano', - 'co': 'Corsican', - 'cs': 'Czech', - 'cy': 'Welsh', - 'da': 'Danish', - 'de': 'German', - 'el': 'Greek', - 'en': 'English', - 'eo': 'Esperanto', - 'es': 'Spanish', - 'et': 'Estonian', - 'eu': 'Basque', - 'fa': 'Persian', - 'fi': 'Finnish', - 'fr': 'French', - 'fy': 'Frisian', - 'ga': 'Irish', - 'gd': 'Scots Gaelic', - 'gl': 'Galician', - 'gu': 'Gujarati', - 'ha': 'Hausa', - 'haw': 'Hawaiian', - 'he': 'Hebrew', - 'hi': 'Hindi', - 'hmn': 'Hmong', - 'hr': 'Croatian', - 'ht': 'Haitian Creole', - 'hu': 'Hungarian', - 'hy': 'Armenian', - 'id': 'Indonesian', - 'ig': 'Igbo', - 'is': 'Icelandic', - 'it': 'Italian', - 'iw': 'Hebrew', - 'ja': 'Japanese', - 'jw': 'Javanese', - 'ka': 'Georgian', - 'kk': 'Kazakh', - 'km': 'Khmer', - 'kn': 'Kannada', - 'ko': 'Korean', - 'ku': 'Kurdish', - 'ky': 'Kyrgyz', - 'la': 'Latin', - 'lb': 'Luxembourgish', - 'lo': 'Lao', - 'lt': 'Lithuanian', - 'lv': 'Latvian', - 'mg': 'Malagasy', - 'mi': 'Maori', - 'mk': 'Macedonian', - 'ml': 'Malayalam', - 'mn': 'Mongolian', - 'mr': 'Marathi', - 'ms': 'Malay', - 'mt': 'Maltese', - 'my': 'Myanmar(Burmese)', - 'ne': 'Nepali', - 'nl': 'Dutch', - 'no': 'Norwegian', - 'ny': 'Nyanja(Chichewa)', - 'pa': 'Punjabi', - 'pl': 'Polish', - 'ps': 'Pashto', - 'pt': 'Portuguese(Portugal,Brazil)', - 'ro': 'Romanian', - 'ru': 'Russian', - 'sd': 'Sindhi', - 'si': 'Sinhala(Sinhalese)', - 'sk': 'Slovak', - 'sl': 'Slovenian', - 'sm': 'Samoan', - 'sn': 'Shona', - 'so': 'Somali', - 'sq': 'Albanian', - 'sr': 'Serbian', - 'st': 'Sesotho', - 'su': 'Sundanese', - 'sv': 'Swedish', - 'sw': 'Swahili', - 'ta': 'Tamil', - 'te': 'Telugu', - 'tg': 'Tajik', - 'th': 'Thai', - 'tl': 'Tagalog(Filipino)', - 'tr': 'Turkish', - 'uk': 'Ukrainian', - 'ur': 'Urdu', - 'uz': 'Uzbek', - 'vi': 'Vietnamese', - 'xh': 'Xhosa', - 'yi': 'Yiddish', - 'yo': 'Yoruba', - 'zh': 'Chinese (Simplified)', - 'zh-cn': 'Chinese (Simplified)', - 'zh-tw': 'Chinese (Traditional)', - 'zu': 'Zulu' -} - OUTPUT_FORMAT = { 'srt': 'SubRip', 'ass': 'Advanced SubStation Alpha', diff --git a/autosub/core.py b/autosub/core.py index 8a8713c2..cf518539 100644 --- a/autosub/core.py +++ b/autosub/core.py @@ -575,9 +575,9 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, if not text_list: return None - print(_("\nTranslating text from \"{0}\" to \"{1}\".").format( - src_language, - dst_language)) + translator = googletrans.Translator( + user_agent=user_agent, + service_urls=service_urls) size = 0 i = 0 @@ -630,6 +630,16 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, valid_index.append(i) # valid_index for valid text position end + if src_language == "auto": + content_to_trans = '\n'.join(text_list[i:partial_index[0]]) + result_src = translator.detect(content_to_trans).lang + else: + result_src = src_language + + print(_("\nTranslating text from \"{0}\" to \"{1}\".").format( + result_src, + dst_language)) + widgets = [_("Translation: "), progressbar.Percentage(), ' ', progressbar.Bar(), ' ', @@ -642,9 +652,6 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, # total position j = 0 # valid_index position - translator = googletrans.Translator( - user_agent=user_agent, - service_urls=service_urls) for index in partial_index: content_to_trans = '\n'.join(text_list[i:index]) @@ -654,6 +661,7 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, dest=dst_language, src=src_language) result_text = translation.text.translate(str.maketrans('’', '\'')) + result_src = translation.src result_list = result_text.split('\n') k = 0 len_result_list = len(result_list) @@ -702,7 +710,7 @@ def list_to_googletrans( # pylint: disable=too-many-locals, too-many-arguments, print(_("Cancelling translation.")) return 1 - return translated_text + return translated_text, result_src def list_to_sub_str( diff --git a/autosub/options.py b/autosub/options.py index 26b77488..708e0747 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -150,18 +150,15 @@ def get_cmd_parser(): # pylint: disable=too-many-statements lang_group.add_argument( '-SRC', '--src-language', metavar=_('lang_code'), + default='auto', help=_("Lang code/Lang tag for translation source language. " - "If not given, use langcodes to get a best matching " - "of the \"-S\"/\"--speech-language\". " - "If using py-googletrans as the method to translate, " - "WRONG INPUT STOP RUNNING. " + "If not given, use py-googletrans to auto-detect the src language. " "(arg_num = 1) (default: %(default)s)")) lang_group.add_argument( '-D', '--dst-language', metavar=_('lang_code'), help=_("Lang code/Lang tag for translation destination language. " - "Same attention in the \"-SRC\"/\"--src-language\". " "(arg_num = 1) (default: %(default)s)")) lang_group.add_argument( @@ -170,7 +167,7 @@ def get_cmd_parser(): # pylint: disable=too-many-statements nargs="*", help=_("Allow langcodes to get a best matching lang code " "when your input is wrong. " - "Only functional for py-googletrans and Google Speech V2. " + "Only functional for py-googletrans and Google Speech API. " "Available modes: " "s, src, d, all. " "\"s\" for \"-S\"/\"--speech-language\". " diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index 34892b30..aeaa65e9 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -56,6 +56,7 @@ - 添加停用词用于merge_src_assfile方法里的断句。 - 添加标点符号分割功能在merge_src_assfile方法里。 - 添加音频长度至少为4字节的检测,在SplitIntoAudioPiece里。 +- 添加源语言自动识别功能,当不输入`-SRC`选项时。 #### 改动(未发布) From 2b1f0c7500be5316ca7d41df43427eefe11a4ce4 Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Wed, 6 May 2020 16:31:00 +0800 Subject: [PATCH 25/26] Change (close #108) langcodes into the optional dependency --- CHANGELOG.md | 1 + README.md | 60 +++++++++++++++++++++++++++++++----- autosub/cmdline_utils.py | 15 ++++++--- autosub/constants.py | 5 +++ autosub/lang_code_utils.py | 37 ++++++++++++++-------- autosub/options.py | 3 +- docs/CHANGELOG.zh-Hans.md | 1 + docs/README.zh-Hans.md | 63 ++++++++++++++++++++++++++++++++------ requirements.txt | 3 +- setup.py | 5 +-- 10 files changed, 154 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a4afc23..1f9a78c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ Click up arrow to go back to TOC. - Change the default style selection in subtitles translation. - Change the loglevel in ffmpeg commands into `-loglevel error`. - Change DEFAULT_MIN_REGION_SIZE to 0.5. +- Change langcodes into the optional dependency. #### Fixed(Unreleased) diff --git a/README.md b/README.md index c81d753d..c9938443 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ Color: [Solarized](https://en.wikipedia.org/wiki/Solarized_(color_scheme)#Colors 1. [Description](#description) 2. [License](#license) 3. [Dependencies](#dependencies) + - 3.1 [Optional Dependencies](#optional-dependencies) + - 3.2 [Required Dependencies](#required-dependencies) 4. [Download and Installation](#download-and-installation) - 4.1 [Branches](#branches) - 4.2 [Install on Ubuntu](#install-on-ubuntu) @@ -77,17 +79,31 @@ 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. +#### Optional dependencies + - [ffmpeg](https://ffmpeg.org/) - [ffprobe](https://ffmpeg.org/ffprobe.html) -- [auditok](https://github.com/amsehili/auditok) +- [langcodes](https://github.com/LuminosoInsight/langcodes) +- [ffmpeg-normalize](https://github.com/slhck/ffmpeg-normalize) +- [python-Levenshtein](https://github.com/ztane/python-Levenshtein)(Used by [fuzzywuzzy](https://github.com/seatgeek/fuzzywuzzy)) + +For windows user: + +- [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/downloads/) + - Used by [marisa-trie](https://github.com/pytries/marisa-trie) when installing. + - [marisa-trie](https://github.com/pytries/marisa-trie) is the dependency of the [langcodes](https://github.com/LuminosoInsight/langcodes)) + - Probable components installation: MSVC v14 VS 2019 C++ build tools, windows 10 SDK. + +#### Required dependencies + +- [auditok 0.1.5](https://github.com/amsehili/auditok) - [pysubs2](https://github.com/tkarabela/pysubs2) - [wcwidth](https://github.com/jquast/wcwidth) - [requests](https://github.com/psf/requests) -- [langcodes](https://github.com/LuminosoInsight/langcodes) +- [fuzzywuzzy](https://github.com/seatgeek/fuzzywuzzy) - [progressbar2](https://github.com/WoLpH/python-progressbar) - [websocket-client](https://github.com/websocket-client/websocket-client) - [py-googletrans](https://github.com/ssut/py-googletrans) -- [ffmpeg-normalize](https://github.com/slhck/ffmpeg-normalize) [requirements.txt](requirements.txt). @@ -99,9 +115,17 @@ About how to install these dependencies, see [Download and Installation](#downlo Except the PyPI version, others include non-original codes not from the original repository. -After autosub-0.4.0, all of the codes is compatible with both Python 2.7 and Python 3. It don't matter if you change the Python version in the installation commands below. +0.4.0 > autosub + +- These versions are only compatible with Python 2.7. + +0.5.6a >= autosub >= 0.4.0 -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. +- These versions are compatible with both Python 2.7 and Python 3. It don't matter if you change the Python version in the installation commands below. + +autosub >= 0.5.7a + +- These versions are only compatible with Python 3. 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. @@ -147,6 +171,13 @@ apt install ffmpeg python python-pip git -y pip install git+https://github.com/BingLingGroup/autosub.git@alpha ffmpeg-normalize ``` +Install from `dev` branch.(latest autosub dev version) + +```bash +apt install ffmpeg python python-pip git -y +pip install git+https://github.com/BingLingGroup/autosub.git@dev ffmpeg-normalize langcodes +``` + Install from `origin` branch.(autosub-0.4.0a) ```bash @@ -187,13 +218,24 @@ Choco installation command is for cmd.(not Powershell) @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" ``` +If you don't have visual studio + Install from `alpha` branch.(latest autosub alpha release) ```batch -choco install git python2 curl ffmpeg -y +choco install git python curl ffmpeg -y curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py -pip install git+https://github.com/BingLingGroup/autosub.git@alpha ffmpeg-normalize +pip install git+https://github.com/BingLingGroup/autosub.git@alpha ffmpeg-normalize langcodes +``` + +Install from `dev` branch.(latest autosub dev version) + +```batch +choco install git python curl ffmpeg -y +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py +python get-pip.py +pip install git+https://github.com/BingLingGroup/autosub.git@dev ffmpeg-normalize langcodes ``` Install from `origin` branch.(autosub-0.4.0a) @@ -609,13 +651,15 @@ autosub -sapi baidu -i input_file -sconf baidu_speech_config ...(other options) Translate subtitles to another language. +If not input option `-SRC`, the translation source language will be auto-detected by py-googletrans. + Translate subtitles from an audio/video file. ``` autosub -i input_file -S lang_code (-SRC lang_code) -D lang_code ``` -Translate subtitles from a subtitles file. +Translate subtitles from a subtitles file.(Translation source language auto-detection by py-googletrans) ``` autosub -i input_file -SRC lang_code -D lang_code diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 3bc45127..1fd8ac26 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -16,7 +16,6 @@ # Import third-party modules import auditok import googletrans -import langcodes import pysubs2 # Any changes to the path and your own modules @@ -385,10 +384,18 @@ def validate_aovp_args(args): # pylint: disable=too-many-branches, too-many-ret match_list=list(constants.SPEECH_TO_TEXT_LANGUAGE_CODES.keys()), min_score=args.min_score) if best_result: - print(_("Use langcodes to standardize the result.")) - args.speech_language = langcodes.standardize_tag(best_result[0]) print(_("Use \"{lang_code}\" instead.").format( - lang_code=args.speech_language)) + lang_code=best_result[0])) + args.speech_language = best_result[0] + if constants.langcodes_: + print(_("Use langcodes to standardize the result.")) + args.speech_language = constants.langcodes_.standardize_tag( + best_result[0]) + print(_("Use \"{lang_code}\" instead.").format( + lang_code=args.speech_language)) + else: + print(_("Use the lower case.")) + args.speech_language = best_result[0] else: print(_("Match failed. Still using \"{lang_code}\".").format( lang_code=args.speech_language)) diff --git a/autosub/constants.py b/autosub/constants.py index 87aff84a..d9d0c644 100644 --- a/autosub/constants.py +++ b/autosub/constants.py @@ -18,6 +18,11 @@ except DistributionNotFound: IS_GOOGLECLOUDCLIENT = False +try: + import langcodes as langcodes_ # pylint: disable=unused-import +except ImportError: + langcodes_ = None + # Any changes to the path and your own modules SUPPORTED_LOCALE = { diff --git a/autosub/lang_code_utils.py b/autosub/lang_code_utils.py index 83e1e348..7baae63f 100644 --- a/autosub/lang_code_utils.py +++ b/autosub/lang_code_utils.py @@ -7,12 +7,16 @@ import gettext # Import third-party modules -import langcodes import wcwidth # Any changes to the path and your own modules from autosub import constants +if not constants.langcodes_: + from fuzzywuzzy import process +else: + process = None # pylint: disable=invalid-name + LANG_CODE_TEXT = gettext.translation(domain=__name__, localedir=constants.LOCALE_PATH, languages=[constants.CURRENT_LOCALE], @@ -52,18 +56,22 @@ def better_match(desired_language, match_scores = [] unsupported_languages = [] - for supported in supported_languages: - try: - score = langcodes.tag_match_score(desired_language, supported) - match_scores.append((supported, score)) - except langcodes.tag_parser.LanguageTagError: - unsupported_languages.append(supported) - continue - - match_scores = [ - (supported, score) for (supported, score) in match_scores - if score >= min_score - ] + if constants.langcodes_: + for supported in supported_languages: + try: + score = constants.langcodes_.tag_match_score(desired_language, supported) + if score >= min_score: + match_scores.append((supported, score)) + except constants.langcodes_.tag_parser.LanguageTagError: + unsupported_languages.append(supported) + continue + else: + match_scores = process.extract(query=desired_language, + choices=supported_languages) + match_scores = [ + (supported, score) for (supported, score) in match_scores + if score >= min_score + ] if not match_scores: match_scores.append(('und', 0)) @@ -104,6 +112,9 @@ def match_print( print(_("Now match lang codes.")) + if not constants.langcodes_: + print(_("Langcodes dependency not found. Use fuzzywuzzy instead.")) + if min_score < 0 or min_score > 100: print(_("The value of arg of \"-mns\"/\"--min-score\" isn't legal.")) return None diff --git a/autosub/options.py b/autosub/options.py index 708e0747..e8c08c0e 100644 --- a/autosub/options.py +++ b/autosub/options.py @@ -165,9 +165,10 @@ def get_cmd_parser(): # pylint: disable=too-many-statements '-bm', '--best-match', metavar=_('mode'), nargs="*", - help=_("Allow langcodes to get a best matching lang code " + help=_("Use langcodes to get a best matching lang code " "when your input is wrong. " "Only functional for py-googletrans and Google Speech API. " + "If langcodes not installed, use fuzzywuzzy instead. " "Available modes: " "s, src, d, all. " "\"s\" for \"-S\"/\"--speech-language\". " diff --git a/docs/CHANGELOG.zh-Hans.md b/docs/CHANGELOG.zh-Hans.md index aeaa65e9..0dc1caca 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -66,6 +66,7 @@ - 修改字幕翻译中字幕样式选择的默认方式。 - 修改ffmpeg指令中的loglevel为`-loglevel error`。 - 修改DEFAULT_MIN_REGION_SIZE为0.5。 +- 修改langcodes为可选依赖。 #### 修复(未发布) diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md index 771e1c8e..820483f5 100644 --- a/docs/README.zh-Hans.md +++ b/docs/README.zh-Hans.md @@ -23,6 +23,8 @@ 1. [介绍](#介绍) 2. [证书](#证书) 3. [依赖](#依赖) + - 3.1 [可选依赖](#可选依赖) + - 3.2 [必需依赖](#必需依赖) 4. [下载与安装](#下载与安装) - 4.1 [分支](#分支) - 4.2 [在Ubuntu上安装](#在Ubuntu上安装) @@ -77,16 +79,31 @@ Autosub是一个字幕自动生成工具。它能使用Auditok来自动检测语 Autosub依赖于这些第三方的软件或者Python的site-packages。非常感谢以下这些项目的工作。 +#### 可选依赖 + - [ffmpeg](https://ffmpeg.org/) - [ffprobe](https://ffmpeg.org/ffprobe.html) -- [auditok](https://github.com/amsehili/auditok) +- [ffmpeg-normalize](https://github.com/slhck/ffmpeg-normalize) +- [langcodes](https://github.com/LuminosoInsight/langcodes) +- [python-Levenshtein](https://github.com/ztane/python-Levenshtein)([fuzzywuzzy](https://github.com/seatgeek/fuzzywuzzy)的可选依赖) + +对于windows用户: + +- [Visual Studio 2019 生成工具](https://visualstudio.microsoft.com/downloads/) + - [marisa-trie](https://github.com/pytries/marisa-trie)安装时会用到。 + - [marisa-trie](https://github.com/pytries/marisa-trie)是[langcodes](https://github.com/LuminosoInsight/langcodes))的依赖。 + - 大概需要安装以下两个组件:MSVC v14 VS 2019 C++生成工具, windows 10 SDK。 + +#### 必需依赖 + +- [auditok 0.1.5](https://github.com/amsehili/auditok) - [pysubs2](https://github.com/tkarabela/pysubs2) - [wcwidth](https://github.com/jquast/wcwidth) -- [langcodes](https://github.com/LuminosoInsight/langcodes) +- [requests](https://github.com/psf/requests) +- [fuzzywuzzy](https://github.com/seatgeek/fuzzywuzzy) - [progressbar2](https://github.com/WoLpH/python-progressbar) - [websocket-client](https://github.com/websocket-client/websocket-client) - [py-googletrans](https://github.com/ssut/py-googletrans) -- [ffmpeg-normalize](https://github.com/slhck/ffmpeg-normalize) [requirements.txt](requirements.txt)。 @@ -98,9 +115,17 @@ Autosub依赖于这些第三方的软件或者Python的site-packages。非常感 除去PyPI版本的代码和原仓库的一致,其他的安装方式均包含非原仓库的代码。 -在autosub-0.4.0之后,所有的代码都是Python3和Python2.7兼容的。所以后面的安装指令中的Python版本你可以随便改。 +0.4.0 > autosub + +- 这些版本只与Python 2.7兼容。 + +0.5.6a >= autosub >= 0.4.0 -至于依赖的安装,如果你是通过pip来安装的autosub,那么ffmpeg和ffmpeg-normalize不会被一块儿安装,不像site-packages那样列在`setup.py`或者`requirements.txt`里面自动安装了。你需要分别安装它们。当然安装是可选的,如果你只是翻译字幕,不需要安装这两个软件。 +- 这些版本与Python3和Python2.7兼容。所以后面的安装指令中的Python版本你可以随便改。 + +autosub >= 0.5.7a + +- 这些版本只与Python 3兼容。 ffmpeg, ffprobe, ffmpeg-normalize需要被放在以下位置之一来让autosub检测并使用。以下代码都在[constants.py](autosub/constants.py)里。优先级按照先后顺序确定。 @@ -137,13 +162,20 @@ pip install . #### 在Ubuntu上安装 -第一行包含依赖的安装。 +包含依赖的安装。 从`alpha`分支安装。(最新alpha发布版) ```bash apt install ffmpeg python python-pip git -y -pip install git+https://github.com/BingLingGroup/autosub.git@alpha ffmpeg-normalize +pip install git+https://github.com/BingLingGroup/autosub.git@alpha ffmpeg-normalize langcodes +``` + +从`dev`分支安装。(最新dev版) + +```bash +apt install ffmpeg python python-pip git -y +pip install git+https://github.com/BingLingGroup/autosub.git@dev ffmpeg-normalize langcodes ``` 从`origin`分支安装。(autosub-0.4.0a) @@ -189,12 +221,21 @@ pip install autosub 从`alpha`分支安装。(最新alpha发布版) ```batch -choco install git python2 curl ffmpeg -y +choco install git python curl ffmpeg -y curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py pip install git+https://github.com/BingLingGroup/autosub.git@alpha ffmpeg-normalize ``` +从`dev`分支安装。(最新dev版) + +```batch +choco install git python curl ffmpeg -y +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py +python get-pip.py +pip install git+https://github.com/BingLingGroup/autosub.git@dev ffmpeg-normalize langcodes +``` + 从`origin`分支安装。(autosub-0.4.0a) ```batch @@ -206,7 +247,7 @@ pip install git+https://github.com/BingLingGroup/autosub.git@origin PyPI的版本(autosub-0.3.12)不推荐在windows上使用,因为它无法成功运行。查看[origin分支的更新日志](CHANGELOG.zh-Hans.md#040-alpha---2019-02-17)来了解详情。 -推荐使用`python`而不是`python2`在autosub-0.4.0之后。 +在autosub-0.4.0之后,推荐使用`python`而不是`python2`。  ↑  @@ -610,6 +651,8 @@ autosub -sapi baidu -i 输入文件 -sconf 百度语音配置文件 ...(其他 将字幕翻译为别的语言。 +如果不输入选项`-SRC`,翻译源语言会被py-googletrans自动检测。 + 从音频/视频文件翻译字幕。 ``` @@ -619,7 +662,7 @@ autosub -i 输入文件 -S 语言代码 (-SRC 语言代码) -D 语言代码 从字幕文件翻译字幕。 ``` -autosub -i 输入文件 -SRC 语言代码 -D 语言代码 +autosub -i 输入文件 (-SRC 语言代码) -D 语言代码 ``` 使用"translate.google.cn"翻译字幕,"translate.google.cn"可被某地直连。 diff --git a/requirements.txt b/requirements.txt index a6711458..b6eb6fc7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,8 @@ pysubs2>=0.2.4 progressbar2>=3.34.3 auditok==0.1.5 googletrans>=2.4.0 -langcodes>=1.2.0 wcwidth>=0.1.7 google-cloud-speech>=1.3.1 websocket-client>=0.56.0 +fuzzywuzzy>=0.18.0 +python-Levenshtein>=0.12.0 diff --git a/setup.py b/setup.py index 1b4b03fe..f0dbaef1 100644 --- a/setup.py +++ b/setup.py @@ -36,10 +36,11 @@ 'progressbar2>=3.34.3', 'auditok==0.1.5', 'googletrans>=2.4.0', - 'langcodes>=1.2.0', 'wcwidth>=0.1.7', + 'fuzzywuzzy>=0.18.0', 'google-cloud-speech>=1.3.1', - 'websocket-client>=0.56.0' + 'websocket-client>=0.56.0', + 'python-Levenshtein>=0.12.0' ], license=open(os.path.join(here, "LICENSE")).read() ) From a72eca874609c42ba9c0eb134a72e44334af952b Mon Sep 17 00:00:00 2001 From: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com> Date: Wed, 6 May 2020 18:00:51 +0800 Subject: [PATCH 26/26] Change LICENSE into GPLv2 Docs update changelog, translations --- CHANGELOG.md | 21 +- LICENSE | 906 ++++++------------ README.md | 81 +- .../zh_CN/LC_MESSAGES/autosub.api_baidu.mo | Bin 491 -> 491 bytes .../zh_CN/LC_MESSAGES/autosub.api_baidu.po | 4 +- .../LC_MESSAGES/autosub.cmdline_utils.mo | Bin 12780 -> 12786 bytes .../LC_MESSAGES/autosub.cmdline_utils.po | 185 ++-- .../locale/zh_CN/LC_MESSAGES/autosub.core.mo | Bin 2569 -> 2569 bytes .../locale/zh_CN/LC_MESSAGES/autosub.core.po | 14 +- .../zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.mo | Bin 1559 -> 1559 bytes .../zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.po | 18 +- .../LC_MESSAGES/autosub.lang_code_utils.mo | Bin 808 -> 945 bytes .../LC_MESSAGES/autosub.lang_code_utils.po | 24 +- .../zh_CN/LC_MESSAGES/autosub.options.mo | Bin 25506 -> 25874 bytes .../zh_CN/LC_MESSAGES/autosub.options.po | 291 +++--- autosub/metadata.py | 2 +- docs/CHANGELOG.zh-Hans.md | 29 +- docs/README.zh-Hans.md | 85 +- 18 files changed, 703 insertions(+), 957 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f9a78c2..127f26b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Changed](#changedunreleased) - [Fixed](#fixedunreleased) - [Removed](#removedunreleased) +- [0.5.7-alpha - 2020-05-06](#057-alpha---2020-05-06) + - [Added](#added057-alpha) + - [Changed](#changed057-alpha) + - [Fixed](#fixed057-alpha) + - [Removed](#removed057-alpha) - [0.5.6-alpha - 2020-03-20](#056-alpha---2020-03-20) - [Added](#added056-alpha) - [Changed](#changed056-alpha) @@ -49,7 +54,9 @@ Click up arrow to go back to TOC. ### [Unreleased] -#### Added(Unreleased) +### [0.5.7-alpha] - 2020-05-06 + +#### Added(0.5.7-alpha) - Add support for Xun Fei Yun Speech-to-Text WebSocket API. - Add support for Baidu Automatic Speech Recognition API. [issue #68](https://github.com/BingLingGroup/autosub/issues/68) @@ -61,7 +68,7 @@ Click up arrow to go back to TOC. - Add limitation in SplitIntoAudioPiece with an audio length of at least 4 bytes. - Add support for src language auto-detection when not input `-SRC` language. -#### Changed(Unreleased) +#### Changed(0.5.7-alpha) - Change the replacement condition of the audio_split_cmd only when the user doesn't modify it. - Change the MAX_REGION_SIZE_LIMIT into 60 seconds. @@ -70,8 +77,9 @@ Click up arrow to go back to TOC. - Change the loglevel in ffmpeg commands into `-loglevel error`. - Change DEFAULT_MIN_REGION_SIZE to 0.5. - Change langcodes into the optional dependency. +- Change LICENSE into GPLv2. -#### Fixed(Unreleased) +#### Fixed(0.5.7-alpha) - Fix the size count bug when the last line been split in list_to_googletrans. - Fix delete_chars issue when using `-of full-src`. @@ -80,10 +88,12 @@ Click up arrow to go back to TOC. - Fix the issue with path checking in dependency finding. - Fix Baidu's strange error code handling. [issue #114](https://github.com/BingLingGroup/autosub/issues/114) -#### Removed(Unreleased) +#### Removed(0.5.7-alpha) - Remove Python 2.7 support. + ↑  + ### [0.5.6-alpha] - 2020-03-20 #### Added(0.5.6-alpha) @@ -274,7 +284,8 @@ Click up arrow to go back to TOC.  ↑  -[Unreleased]: https://github.com/BingLingGroup/autosub/compare/0.5.6-alpha...HEAD +[Unreleased]: https://github.com/BingLingGroup/autosub/compare/0.5.7-alpha...HEAD +[0.5.7-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.6-alpha...0.5.7-alpha [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 diff --git a/LICENSE b/LICENSE index 94a9ed02..b679b665 100644 --- a/LICENSE +++ b/LICENSE @@ -1,626 +1,286 @@ + GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 + Version 2, June 1991 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to this License. - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs + + Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it @@ -628,15 +288,15 @@ free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least +convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - Copyright (C) + Copyright (C) 19yy - This program is free software: you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -645,30 +305,36 @@ the "copyright" line and a pointer to where the full notice is found. GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA Also add information on how to contact you by electronic and paper mail. - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. \ No newline at end of file diff --git a/README.md b/README.md index c9938443..76053633 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ The new features mentioned above are only available in the latest alpha branch. This repo has a different license from [the original repo](https://github.com/agermanidis/autosub). -[GPLv3](LICENSE) +[GPLv2](LICENSE) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FBingLingGroup%2Fautosub.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FBingLingGroup%2Fautosub) @@ -723,18 +723,16 @@ Language Options: text/docs/languages(arg_num = 1) (default: None) -SRC lang_code, --src-language lang_code Lang code/Lang tag for translation source language. If - not given, use langcodes to get a best matching of the - "-S"/"--speech-language". If using py-googletrans as - the method to translate, WRONG INPUT STOP RUNNING. - (arg_num = 1) (default: None) + not given, use py-googletrans to auto-detect the src + language. (arg_num = 1) (default: auto) -D lang_code, --dst-language lang_code Lang code/Lang tag for translation destination - language. Same attention in the "-SRC"/"--src- - language". (arg_num = 1) (default: None) + language. (arg_num = 1) (default: None) -bm [mode [mode ...]], --best-match [mode [mode ...]] - Allow langcodes to get a best matching lang code when + Use langcodes to get a best matching lang code when your input is wrong. Only functional for py- - googletrans and Google Speech V2. Available modes: s, + googletrans and Google Speech API. If langcodes not + installed, use fuzzywuzzy instead. Available modes: s, src, d, all. "s" for "-S"/"--speech-language". "src" for "-SRC"/"--src-language". "d" for "-D"/"--dst- language". (3 >= arg_num >= 1) @@ -834,7 +832,7 @@ py-googletrans Options: -slp second, --sleep-seconds second (Experimental)Seconds to sleep between two translation - requests. (arg_num = 1) (default: 5) + requests. (arg_num = 1) (default: 1) -surl [URL [URL ...]], --service-urls [URL [URL ...]] (Experimental)Customize request urls. Ref: https://py- googletrans.readthedocs.io/en/latest/ (arg_num >= 1) @@ -845,6 +843,31 @@ py-googletrans Options: Drop any .ass override codes in the text before translation. Only affect the translation result. (arg_num = 0) + -gt-dc [chars], --gt-delete-chars [chars] + Replace the specific chars with a space after + translation, and strip the space at the end of each + sentence. Only affect the translation result. (arg_num + = 0 or 1) (const: ,。!) + +Subtitles Conversion Options: + Options to control subtitles conversions.(Experimental) + + -mjs integer, --max-join-size integer + (Experimental)Max length to join two events. (arg_num + = 1) (default: 100) + -mdt second, --max-delta-time second + (Experimental)Max delta time to join two events. + (arg_num = 1) (default: 0.2) + -dms string, --delimiters string + (Experimental)Delimiters not to join two events. + (arg_num = 1) (default: !()*,.:;?[]^_`~) + -sw1 words_delimited_by_space, --stop-words-1 words_delimited_by_space + (Experimental)First set of Stop words to split two + events. (arg_num = 1) + -sw2 words_delimited_by_space, --stop-words-2 words_delimited_by_space + (Experimental)Second set of Stop words to split two + events. (arg_num = 1) + -ds, --dont-split (Experimental)Don't Split just merge. (arg_num = 0) Network Options: Options to control network. @@ -890,14 +913,15 @@ Audio Processing Options: procedure. "o": only pre-process the input audio. ("-k"/"--keep" is true) "s": only split the input audio. ("-k"/"--keep" is true) Default command to pre- - process the audio: - c:\programdata\chocolatey\bin\ffmpeg.exe -hide_banner - -i "{in_}" -af "asplit[a],aphasemeter=video=0,ametadat - a=select:key=lavfi.aphasemeter.phase:value=-0.005:func - tion=less,pan=1c|c0=c0,aresample=async=1:first_pts=0,[ - a]amix" -ac 1 -f flac "{out_}" | - c:\programdata\chocolatey\bin\ffmpeg.exe -hide_banner - -i "{in_}" -af lowpass=3000,highpass=200 "{out_}" | + process the audio: C:\Program + Files\ImageMagick-7.0.10-Q16\ffmpeg.exe -hide_banner + -i "{in_}" -vn -af "asplit[a],aphasemeter=video=0,amet + adata=select:key=lavfi.aphasemeter.phase:value=-0.005: + function=less,pan=1c|c0=c0,aresample=async=1:first_pts + =0,[a]amix" -ac 1 -f flac -loglevel error "{out_}" | + C:\Program Files\ImageMagick-7.0.10-Q16\ffmpeg.exe + -hide_banner -i "{in_}" -af + "lowpass=3000,highpass=200" -loglevel error "{out_}" | C:\Python37\Scripts\ffmpeg-normalize.exe -v "{in_}" -ar 44100 -ofmt flac -c:a flac -pr -p -o "{out_}" (Ref: https://github.com/stevenj/autosub/blob/master/s @@ -916,16 +940,18 @@ Audio Processing Options: -acc command, --audio-conversion-cmd command (Experimental)This arg will override the default audio conversion command. "[", "]" are optional arguments - meaning you can remove them. "{{", "}}" are required + meaning you can remove them. "{", "}" are required arguments meaning you can't remove them. (arg_num = 1) - (default: c:\programdata\chocolatey\bin\ffmpeg.exe - -hide_banner -y -i "{in_}" -vn -ac {channel} -ar - {sample_rate} "{out_}") + (default: C:\Program + Files\ImageMagick-7.0.10-Q16\ffmpeg.exe -hide_banner + -y -i "{in_}" -vn -ac {channel} -ar {sample_rate} + -loglevel error "{out_}") -asc command, --audio-split-cmd command (Experimental)This arg will override the default audio split command. Same attention above. (arg_num = 1) - (default: c:\programdata\chocolatey\bin\ffmpeg.exe -y - -ss {start} -i "{in_}" -t {dura} -vn -ac [channel] -ar + (default: C:\Program + Files\ImageMagick-7.0.10-Q16\ffmpeg.exe -y -ss {start} + -i "{in_}" -t {dura} -vn -ac [channel] -ar [sample_rate] -loglevel error "{out_}") -asf file_suffix, --api-suffix file_suffix (Experimental)This arg will override the default API @@ -944,13 +970,13 @@ Auditok Options: The energy level which determines the region to be detected. Ref: https://auditok.readthedocs.io/en/lates t/apitutorial.html#examples-using-real-audio-data - (arg_num = 1) (default: 50) + (arg_num = 1) (default: 45) -mnrs second, --min-region-size second Minimum region size. Same docs above. (arg_num = 1) - (default: 0.8) + (default: 0.5) -mxrs second, --max-region-size second Maximum region size. Same docs above. (arg_num = 1) - (default: 6.0) + (default: 10.0) -mxcs second, --max-continuous-silence second Maximum length of a tolerated silence within a valid audio activity. Same docs above. (arg_num = 1) @@ -1000,6 +1026,7 @@ The default value is used when the option is not given at the command line. "(arg_num)" means if the option is given, the number of the arguments is required. +Arguments *ARE* the things given behind the options. Author: Bing Ling Email: binglinggroup@outlook.com Bug report: https://github.com/BingLingGroup/autosub diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.mo index 92507f914e1a1e8be48b44a47297c2f0709b7ff3..dbb5afb8f6e59a7c9b45ed435403dd3dd51398f1 100644 GIT binary patch delta 21 ccmaFO{F-^fIWALO15*ViD0aN$})c^nh delta 21 ccmaFO{F-^fIWA*eBU1%KODj{ujW>iD0aNq_(*OVf diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po index a927f4c7..50879a84 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.api_baidu.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-25 19:51+0800\n" +"POT-Creation-Date: 2020-05-05 17:19+0800\n" "PO-Revision-Date: 2020-03-21 15:38+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,6 +17,6 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/api_baidu.py:83 +#: autosub/api_baidu.py:85 msgid "Error: Check you project if its ASR feature is enabled." msgstr "错误:检查你的项目是否打开了语音识别功能。" diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.cmdline_utils.mo index 9969e49ef6e964d01d5193d0677fcab5a6e3ffa9..fede191b997468147e3a394a6a282dc6ce5422df 100644 GIT binary patch delta 1587 zcmYk+Sx8i26u|K_>6mF&jxAb_-6<`5uq_lEqd8n)eeTX(H+OP$)f()#u9uoSWoQE!R@9+EW_MPvX?@oWkuL}2ji~n(9 zD`t;mzdcN(7E8?>*o@&KW6*}PF$Kf12IH{~6R_Ra|A=w)Ljpz8F#}_969(Z)oP*~v zSi~)#Xw2fo4@|@5cPZm8u$Psuovw(h|L(!Tifs{#-f|ICSwbZ#dkOt2XG$R zM~YxlBVJ_>L`T4H>c<9rSBQ4bAWZX3&3$NjPe>$Q^XzL>$Ch7*4vD;4@r> z)=-hvxD^ZWF_xgsA`-y(vYm#$U>7neX+$SBV;=V6B1{MqnTeY*2Afbz(Ty|kqwjnm z)7DZYqk$Vx1F6S(*o$QtJ&tUZ(%4HwBl>{acZ?TVj7L#R@)osbK@&tKVGb7J8qC4# zs1x{ux`rkYl?FHqv#|{I`O~Nqd5y#>)(G;i8AztEJMbD_!g$`Mi|92jM?Xf@OcY^0 zp7Hg+q0PjiWK^mp#a59tT!Z|ik;62+iPN#i*Y}TNozahrV)RTJOF1za51^LdBBo$F z24Ej*>ibb^AI{ASFb{RWdW^wk1Ut}%nH+S2rEVJfz<$iav*^Sg zoP$=voQtc`jwi4UyYL=vn<|ouX^gJdt5GM^h#Ke%yoF}cpyS-dE_{W0-Q7f9wDwQ1 z3a7D>%JC4c#Q_Y!5(>)Xr4;#4WGCu(e*ov>4a~;hsDY%%4yAq_>YAuWy}t!Dldq6K z-Qq_c7+bQj5?xq;k8lG{0X{OSwqP;2bP419wITDYjCNkyG$HL{N7 z6lx~gFc1!pxm!R%UAmes#y zp>Y;?J_Uq@7SrOh`}bE#fKuc&4-d3hO18L+tyM0gX5)6(W}~8fi_04vk?R-aNJvUE zk{y|j6i-=X)PG%XU1W^Er_;XPn{TTOv3$PM@%7lnzN?4(_BHmkp7?U5!P{zg`uznp CH_CMY delta 1524 zcmXZcYe4`CYRzgU1N7LimufMM8*h1iDk zL_9J~kVnNBW?@9Ahy#mJ>o1@UUt$c7U?xuEBaEfhPVB{0JVC2Dco(Da6K=o>+=%h> zMT)Q%o%Ap51p2}#cA(YjvkUVnA6(#@;cZ+;`8{UiKYW8(3q_XUGO?7 zk-b=tRrnTnVR(dynf|4bKpQxYOiEhNg$8cL5!`}tks_<{5T@XD)TQXcRXF6Y|AV?z z2~6LH`%njR9yj6$?#HNT@?S%6iaKSfms$p)Scs)HR#M<+yfuAP4)RYgR zuK8~)#$;a74i94zK0qcV1DK9ucmu<1zRh_L6DV)vq7yuZ`uuGVK@q`obm25=sxlbn z20Vh9_yjxgEB4~$M3FUELhpLtjSlQU9q142#%R)@9eu_RIEi|{leFlPd&UV46Xdgl z4&r^RM_oWOG$50fW5@xKE2!uF4sOB^=tN7ZZy=?psXv3d7ur#u??KJvBF+7TCJbe;xq3#6>dDTqqL2a-NwWEGqhdyn<7?y{anougK1Dqxvwn+nd>L#-6ZP8pPNN|> zF|>k+N+~yP2D?m^#&B?!smw5$N8)s1WI_K4=d!}KnOlAxj~FxN$na_cj@8^>Ap?>s zZ*+(y!kZIQ5*U`3k)3bL$#Z0{H7>@+`-^KFxdq;i*pwjSn|(<@{b^&y-t2WGG+Mn~ InT3J>0Sv3QW&i*H 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 840a589a..dbac86fb 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-04-05 14:06+0800\n" -"PO-Revision-Date: 2020-04-05 13:27+0800\n" +"POT-Creation-Date: 2020-05-06 15:52+0800\n" +"PO-Revision-Date: 2020-05-06 15:52+0800\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -17,20 +17,20 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/cmdline_utils.py:45 +#: autosub/cmdline_utils.py:44 msgid "List of output formats:\n" msgstr "列出所有输出格式:\n" -#: autosub/cmdline_utils.py:47 autosub/cmdline_utils.py:55 +#: autosub/cmdline_utils.py:46 autosub/cmdline_utils.py:54 msgid "Format" msgstr "格式" -#: autosub/cmdline_utils.py:48 autosub/cmdline_utils.py:56 -#: autosub/cmdline_utils.py:83 autosub/cmdline_utils.py:101 +#: autosub/cmdline_utils.py:47 autosub/cmdline_utils.py:55 +#: autosub/cmdline_utils.py:82 autosub/cmdline_utils.py:100 msgid "Description" msgstr "描述" -#: autosub/cmdline_utils.py:53 +#: autosub/cmdline_utils.py:52 msgid "" "\n" "List of input formats:\n" @@ -38,36 +38,36 @@ msgstr "" "\n" "列出所有输入格式:\n" -#: autosub/cmdline_utils.py:64 +#: autosub/cmdline_utils.py:63 msgid "Use py-googletrans to detect a sub file's first line language." msgstr "使用py-googletrans来检测字幕文件第一行的语言。" -#: autosub/cmdline_utils.py:71 autosub/cmdline_utils.py:82 -#: autosub/cmdline_utils.py:100 +#: autosub/cmdline_utils.py:70 autosub/cmdline_utils.py:81 +#: autosub/cmdline_utils.py:99 msgid "Lang code" msgstr "语言代码" -#: autosub/cmdline_utils.py:72 +#: autosub/cmdline_utils.py:71 msgid "Confidence" msgstr "可信度" -#: autosub/cmdline_utils.py:80 +#: autosub/cmdline_utils.py:79 msgid "List of all lang codes for speech-to-text:\n" msgstr "列出所有语音转文字的语言代码:\n" -#: autosub/cmdline_utils.py:89 +#: autosub/cmdline_utils.py:88 msgid "Match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:98 +#: autosub/cmdline_utils.py:97 msgid "List of all lang codes for translation:\n" msgstr "列出所有翻译的语言代码:\n" -#: autosub/cmdline_utils.py:107 +#: autosub/cmdline_utils.py:106 msgid "Match py-googletrans lang codes." msgstr "匹配py-googletrans的语言代码。" -#: autosub/cmdline_utils.py:125 +#: autosub/cmdline_utils.py:124 msgid "" "Error: arg of \"-i\"/\"--input\": \"{path}\" isn't valid. You need to give a " "valid path." @@ -75,7 +75,7 @@ msgstr "" "错误:\"-i\"/\"--input\"的参数:\"{path}\"是无效的。你需要提供一个有效的路" "径。" -#: autosub/cmdline_utils.py:131 +#: autosub/cmdline_utils.py:130 msgid "" "Error: arg of \"-sty\"/\"--styles\": \"{path}\" isn't valid. You need to " "give a valid path." @@ -83,15 +83,15 @@ msgstr "" "错误:\"-sty\"/\"--styles\"的参数:\"{path}\"是无效的。你需要提供一个有效的路" "径。" -#: autosub/cmdline_utils.py:137 +#: autosub/cmdline_utils.py:136 msgid "Error: Too many \"-sn\"/\"--styles-name\" arguments." msgstr "错误:\"-sn\"/\"--styles-name\"的参数过多。" -#: autosub/cmdline_utils.py:149 autosub/cmdline_utils.py:156 +#: autosub/cmdline_utils.py:148 autosub/cmdline_utils.py:155 msgid "Error: \"-sn\"/\"--styles-name\" arguments aren't in \"{path}\"." msgstr "错误:\"-sn\"/\"--styles-name\"的参数不在 \"{path}\"文件内。" -#: autosub/cmdline_utils.py:161 +#: autosub/cmdline_utils.py:160 msgid "" "Error: arg of \"-er\"/\"--ext-regions\": \"{path}\" isn't valid. You need to " "give a valid path." @@ -99,16 +99,16 @@ msgstr "" "错误:\"-er\"/\"--ext-regions\"的参数:\"{path}\"是无效的。你需要提供一个有效" "的路径。" -#: autosub/cmdline_utils.py:178 autosub/cmdline_utils.py:196 +#: autosub/cmdline_utils.py:177 autosub/cmdline_utils.py:195 msgid "No output format specified. Use input format \"{fmt}\" for output." msgstr "没有指定输出格式。使用输入的格式\"{fmt}\"作为输出格式。" -#: autosub/cmdline_utils.py:190 +#: autosub/cmdline_utils.py:189 msgid "" "Your output is a directory not a file path. Now file path set to \"{new}\"." msgstr "你的输出路径是一个目录不是一个文件路径。现在输出路径设置为\"{new}\"。" -#: autosub/cmdline_utils.py:213 +#: autosub/cmdline_utils.py:212 msgid "" "Error: Output subtitles format \"{fmt}\" not supported. Run with \"-lf\"/\"--" "list-formats\" to see all supported formats.\n" @@ -118,61 +118,65 @@ msgstr "" "看所有支持的格式。\n" "或者使用ffmpeg或者SubtitleEdit来转换格式。" -#: autosub/cmdline_utils.py:226 +#: autosub/cmdline_utils.py:225 msgid "Error: No valid \"-of\"/\"--output-files\" arguments." msgstr "错误:\"-of\"/\"--output-files\"参数无效。" -#: autosub/cmdline_utils.py:237 +#: autosub/cmdline_utils.py:236 msgid "Input is a subtitles file." msgstr "输入是一个字幕文件。" -#: autosub/cmdline_utils.py:254 +#: autosub/cmdline_utils.py:253 msgid "Error: Can't decode speech config file \"{filename}\"." msgstr "错误:无法解码语音配置文件\"{filename}\"。" -#: autosub/cmdline_utils.py:258 +#: autosub/cmdline_utils.py:257 msgid "Error: Speech config file \"{filename}\" doesn't exist." msgstr "错误:语音配置文件\"{filename}\"不存在。" -#: autosub/cmdline_utils.py:304 +#: autosub/cmdline_utils.py:303 msgid "Error: No \"app_id\" found in speech config file \"{filename}\"." msgstr "错误:\"app_id\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:315 +#: autosub/cmdline_utils.py:314 msgid "Error: No \"api_key\" found in speech config file \"{filename}\"." msgstr "错误:\"api_key\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:326 +#: autosub/cmdline_utils.py:325 msgid "Error: No \"api_secret\" found in speech config file \"{filename}\"." msgstr "错误:\"api_secret\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:338 +#: autosub/cmdline_utils.py:337 msgid "Error: No \"language\" found in speech config file \"{filename}\"." msgstr "错误:\"language\"不在语音配置文件\"{filename}\"中。" -#: autosub/cmdline_utils.py:374 +#: autosub/cmdline_utils.py:373 msgid "Error: \"-slp\"/\"--sleep-seconds\" arg is illegal." msgstr "错误:\"-slp\"/\"--sleep-seconds\"参数非法。" -#: autosub/cmdline_utils.py:382 +#: autosub/cmdline_utils.py:381 msgid "Let speech lang code to match Google Speech-to-Text lang codes." msgstr "匹配Google Speech-to-Text的语言代码。" -#: autosub/cmdline_utils.py:388 +#: autosub/cmdline_utils.py:387 autosub/cmdline_utils.py:394 +#: autosub/cmdline_utils.py:446 autosub/cmdline_utils.py:468 +#: autosub/cmdline_utils.py:534 autosub/cmdline_utils.py:561 +msgid "Use \"{lang_code}\" instead." +msgstr "改用\"{lang_code}\"。" + +#: autosub/cmdline_utils.py:391 msgid "Use langcodes to standardize the result." msgstr "使用langcodes来标准化结果。" -#: autosub/cmdline_utils.py:390 autosub/cmdline_utils.py:446 -#: autosub/cmdline_utils.py:468 autosub/cmdline_utils.py:541 -#: autosub/cmdline_utils.py:568 -msgid "Use \"{lang_code}\" instead." -msgstr "改用\"{lang_code}\"。" +#: autosub/cmdline_utils.py:397 +msgid "Use the lower case." +msgstr "使用小写字母。" -#: autosub/cmdline_utils.py:393 +#: autosub/cmdline_utils.py:400 msgid "Match failed. Still using \"{lang_code}\"." msgstr "匹配失败。仍在使用\"{lang_code}\"。" -#: autosub/cmdline_utils.py:396 +#: autosub/cmdline_utils.py:403 msgid "" "Warning: Speech language \"{src}\" is not recommended. Run with \"-lsc\"/\"--" "list-speech-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -182,23 +186,23 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:404 +#: autosub/cmdline_utils.py:411 msgid "Error: The arg of \"-mnc\"/\"--min-confidence\" isn't legal." msgstr "错误:\"-mnc\"/\"--min-confidence\"参数的值不合法。" -#: autosub/cmdline_utils.py:409 +#: autosub/cmdline_utils.py:416 msgid "" "Error: You must provide \"-sconf\", \"--speech-config\" option when using " "Xun Fei Yun API." msgstr "错误:使用讯飞云API时,你必须提供\"-sconf\",\"--speech-config\"选项。" -#: autosub/cmdline_utils.py:413 +#: autosub/cmdline_utils.py:420 msgid "" "Translation destination language not provided. Only performing speech " "recognition." msgstr "翻译目的语言未提供。只进行语音识别。" -#: autosub/cmdline_utils.py:418 +#: autosub/cmdline_utils.py:425 msgid "Translation source language not provided. Use speech language instead." msgstr "翻译源语言未提供。改用语音语言。" @@ -248,7 +252,7 @@ msgstr "你已经输入了时间轴。啥都没做。" msgid "Speech language not provided. Only performing speech regions detection." msgstr "语音语言未提供。只生成时间轴。" -#: autosub/cmdline_utils.py:504 autosub/cmdline_utils.py:596 +#: autosub/cmdline_utils.py:504 autosub/cmdline_utils.py:589 msgid "Error: External speech regions file not provided." msgstr "错误:外部时间轴文件未提供。" @@ -256,7 +260,7 @@ msgstr "错误:外部时间轴文件未提供。" msgid "Error: Destination language not provided." msgstr "错误:目的语言未提供。" -#: autosub/cmdline_utils.py:533 +#: autosub/cmdline_utils.py:526 msgid "" "Warning: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages." @@ -264,11 +268,11 @@ msgstr "" "警告:源语言\"{src}\"不在推荐的清单里面。用 \"-lsc\"/\"--list-translation-" "codes\"选项运行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:545 autosub/cmdline_utils.py:572 +#: autosub/cmdline_utils.py:538 autosub/cmdline_utils.py:565 msgid "Match failed. Still using \"{lang_code}\". Program stopped." msgstr "匹配失败。仍在使用\"{lang_code}\"。程序终止。" -#: autosub/cmdline_utils.py:551 +#: autosub/cmdline_utils.py:544 msgid "" "Error: Source language \"{src}\" not supported. Run with \"-lsc\"/\"--list-" "translation-codes\" to see all supported languages. Or use \"-bm\"/\"--best-" @@ -278,7 +282,7 @@ msgstr "" "codes\"选项运行来查看所有支持的语言。或者使用\"-bm\"/\"--best-match\"来获得最" "佳匹配。" -#: autosub/cmdline_utils.py:560 +#: autosub/cmdline_utils.py:553 msgid "" "Warning: Destination language \"{dst}\" not supported. Run with \"-lsc\"/\"--" "list-translation-codes\" to see all supported languages." @@ -286,22 +290,21 @@ msgstr "" "警告:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" "行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:578 +#: autosub/cmdline_utils.py:571 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来转换格式。" +"错误:不支持目的语言\"{dst}\"。用 \"-lsc\"/\"--list-translation-codes\"选项运" +"行来查看所有支持的语言。" -#: autosub/cmdline_utils.py:586 +#: autosub/cmdline_utils.py:579 msgid "" "Error: Translation source language is the same as the destination language." msgstr "错误:翻译源语言和目的语言一致。" -#: autosub/cmdline_utils.py:610 +#: autosub/cmdline_utils.py:603 msgid "" "Your minimum region size {mrs0} is smaller than {mrs}.\n" "Now reset to {mrs}." @@ -309,7 +312,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还小。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:617 +#: autosub/cmdline_utils.py:610 msgid "" "Your maximum region size {mrs0} is larger than {mrs}.\n" "Now reset to {mrs}." @@ -317,7 +320,7 @@ msgstr "" "你输入的语音区域{mrs0}比{mrs}还大。\n" "现在重置为{mrs}。" -#: autosub/cmdline_utils.py:624 +#: autosub/cmdline_utils.py:617 msgid "" "Your maximum continuous silence {mxcs} is smaller than 0.\n" "Now reset to {dmxcs}." @@ -325,17 +328,17 @@ msgstr "" "你输入的最大连续安静区域{mxcs}比0还小。\n" "现在重置为{dmxcs}。" -#: autosub/cmdline_utils.py:680 autosub/cmdline_utils.py:913 -#: autosub/cmdline_utils.py:1463 +#: autosub/cmdline_utils.py:673 autosub/cmdline_utils.py:906 +#: autosub/cmdline_utils.py:1456 msgid "\"dst-lf-src\" subtitles file created at \"{}\"." msgstr "\"dst-lf-src\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:684 autosub/cmdline_utils.py:719 -#: autosub/cmdline_utils.py:770 autosub/cmdline_utils.py:864 -#: autosub/cmdline_utils.py:917 autosub/cmdline_utils.py:970 -#: autosub/cmdline_utils.py:1157 autosub/cmdline_utils.py:1320 -#: autosub/cmdline_utils.py:1362 autosub/cmdline_utils.py:1421 -#: autosub/cmdline_utils.py:1467 autosub/cmdline_utils.py:1513 +#: autosub/cmdline_utils.py:677 autosub/cmdline_utils.py:712 +#: autosub/cmdline_utils.py:763 autosub/cmdline_utils.py:857 +#: autosub/cmdline_utils.py:910 autosub/cmdline_utils.py:963 +#: autosub/cmdline_utils.py:1150 autosub/cmdline_utils.py:1313 +#: autosub/cmdline_utils.py:1355 autosub/cmdline_utils.py:1414 +#: autosub/cmdline_utils.py:1460 autosub/cmdline_utils.py:1506 msgid "" "\n" "All works done." @@ -343,32 +346,32 @@ msgstr "" "\n" "做完了。" -#: autosub/cmdline_utils.py:715 autosub/cmdline_utils.py:966 -#: autosub/cmdline_utils.py:1509 +#: autosub/cmdline_utils.py:708 autosub/cmdline_utils.py:959 +#: autosub/cmdline_utils.py:1502 msgid "\"src-lf-dst\" subtitles file created at \"{}\"." msgstr "\"src-lf-dst\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:766 +#: autosub/cmdline_utils.py:759 msgid "\"join-events\" subtitles file created at \"{}\"." msgstr "\"join-events\"字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:815 autosub/cmdline_utils.py:1380 +#: autosub/cmdline_utils.py:808 autosub/cmdline_utils.py:1373 msgid "Error: Translation failed." msgstr "错误:翻译失败。" -#: autosub/cmdline_utils.py:860 autosub/cmdline_utils.py:1417 +#: autosub/cmdline_utils.py:853 autosub/cmdline_utils.py:1410 msgid "Bilingual subtitles file created at \"{}\"." msgstr "双语字幕创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1010 autosub/cmdline_utils.py:1554 +#: autosub/cmdline_utils.py:1003 autosub/cmdline_utils.py:1547 msgid "Destination language subtitles file created at \"{}\"." msgstr "目的语言字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1051 +#: autosub/cmdline_utils.py:1044 msgid "Use external speech regions." msgstr "使用外部时间轴。" -#: autosub/cmdline_utils.py:1090 +#: autosub/cmdline_utils.py:1083 msgid "" "\n" "Convert source file to \"{name}\" to detect audio regions." @@ -376,11 +379,11 @@ msgstr "" "\n" "将源文件转换为\"{name}\"来检测语音区域。" -#: autosub/cmdline_utils.py:1105 +#: autosub/cmdline_utils.py:1098 msgid "Error: Convert source file to \"{name}\" failed." msgstr "错误:转换源文件至\"{name}\"失败。" -#: autosub/cmdline_utils.py:1108 +#: autosub/cmdline_utils.py:1101 msgid "" "Conversion completed.\n" "Use Auditok to detect speech regions." @@ -388,7 +391,7 @@ msgstr "" "转换完毕。\n" "使用Auditok检测语音区域。" -#: autosub/cmdline_utils.py:1120 +#: autosub/cmdline_utils.py:1113 msgid "" "Auditok detection completed.\n" "\"{name}\" has been deleted." @@ -396,19 +399,19 @@ msgstr "" "Auditok语音区域检测完毕。\n" "\"{name}\"已被删除。" -#: autosub/cmdline_utils.py:1125 +#: autosub/cmdline_utils.py:1118 msgid "Error: Can't get speech regions." msgstr "错误:无法得到语音区域。" -#: autosub/cmdline_utils.py:1154 autosub/cmdline_utils.py:1621 +#: autosub/cmdline_utils.py:1147 autosub/cmdline_utils.py:1614 msgid "Times file created at \"{}\"." msgstr "时间轴文件创建在了\"{}\"." -#: autosub/cmdline_utils.py:1178 +#: autosub/cmdline_utils.py:1171 msgid "Error: Conversion failed." msgstr "错误:转换失败。" -#: autosub/cmdline_utils.py:1182 +#: autosub/cmdline_utils.py:1175 msgid "" "Audio processing complete.\n" "All works done." @@ -416,11 +419,11 @@ msgstr "" "音频处理完毕。\n" "做完了。" -#: autosub/cmdline_utils.py:1234 +#: autosub/cmdline_utils.py:1227 msgid "Use the API key given in the option \"-skey\"/\"--speech-key\"." msgstr "使用选项\"-skey\"/\"--speech-key\"提供的API密钥。" -#: autosub/cmdline_utils.py:1249 +#: autosub/cmdline_utils.py:1242 msgid "" "Error: Current build version doesn't support Google Cloud service account " "credentials.\n" @@ -430,18 +433,18 @@ msgstr "" "错误:当前构建版本不支持Google Cloud 服务账号凭据。\n" "请使用其他构建版本或者选项\"-skey\"/\"--speech-key\"来替代。" -#: autosub/cmdline_utils.py:1254 +#: autosub/cmdline_utils.py:1247 msgid "" "Set the GOOGLE_APPLICATION_CREDENTIALS given in the option \"-sa\"/\"--" "service-account\"." msgstr "" "设置选项\"-sa\"/\"--service-account\"提供的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1268 +#: autosub/cmdline_utils.py:1261 msgid "Use the GOOGLE_APPLICATION_CREDENTIALS in the environment variables." msgstr "使用环境变量中的GOOGLE_APPLICATION_CREDENTIALS。" -#: autosub/cmdline_utils.py:1280 +#: autosub/cmdline_utils.py:1273 msgid "" "No available GOOGLE_APPLICATION_CREDENTIALS. Use \"-sa\"/\"--service-account" "\" to set one." @@ -449,11 +452,11 @@ msgstr "" "没有可用的GOOGLE_APPLICATION_CREDENTIALS。使用选项\"-sa\"/\"--service-account" "\"来设置一个。" -#: autosub/cmdline_utils.py:1316 +#: autosub/cmdline_utils.py:1309 msgid "Speech-to-Text recogntion result json file created at \"{}\"." msgstr "语音转文字识别结果json文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1324 +#: autosub/cmdline_utils.py:1317 msgid "" "Error: Speech-to-text failed.\n" "All works done." @@ -461,11 +464,11 @@ msgstr "" "错误:语音转文字失败。\n" "做完了。" -#: autosub/cmdline_utils.py:1358 autosub/cmdline_utils.py:1591 +#: autosub/cmdline_utils.py:1351 autosub/cmdline_utils.py:1584 msgid "Speech language subtitles file created at \"{}\"." msgstr "语音字幕文件创建在了\"{}\"。" -#: autosub/cmdline_utils.py:1563 +#: autosub/cmdline_utils.py:1556 msgid "" "Override \"-of\"/\"--output-files\" due to your args too few.\n" "Output source subtitles file only." @@ -473,7 +476,7 @@ msgstr "" "因为你其他参数输入得太少了,忽略\"-of\"/\"--output-files\"参数。\n" "只输出源语言字幕文件。" -#: autosub/cmdline_utils.py:1596 +#: autosub/cmdline_utils.py:1589 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.core.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.core.mo index d9e7da86fb2a2bd13fc2f6fb878190aba04c42e4..10daee5f9533e553d6b5d7ad779c8eab90946d4d 100644 GIT binary patch delta 23 ecmeAa=@i+plaXX;@&;c3 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 93bc57b3..9c1d4273 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-04-05 12:40+0800\n" +"POT-Creation-Date: 2020-05-06 15:48+0800\n" "PO-Revision-Date: 2020-03-21 15:41+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -100,7 +100,7 @@ msgstr "使用配置文件中的token。" msgid "Failed to get the token. Error message:" msgstr "无法获取token。错误信息:" -#: autosub/core.py:578 +#: autosub/core.py:639 msgid "" "\n" "Translating text from \"{0}\" to \"{1}\"." @@ -108,24 +108,24 @@ msgstr "" "\n" "从\"{0}\"翻译为\"{1}\"。" -#: autosub/core.py:633 +#: autosub/core.py:643 msgid "Translation: " msgstr "翻译中: " -#: autosub/core.py:702 +#: autosub/core.py:710 msgid "Cancelling translation." msgstr "取消翻译。" -#: autosub/core.py:771 autosub/core.py:829 +#: autosub/core.py:779 autosub/core.py:837 msgid "Format \"{fmt}\" not supported. Use \"{default_fmt}\" instead." msgstr "不支持格式\"{fmt}\"。改用\"{default_fmt}\"。" -#: autosub/core.py:902 +#: autosub/core.py:910 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/core.py:905 +#: autosub/core.py:913 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.ffmpeg_utils.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.ffmpeg_utils.mo index 833f1581136935ee61d777fab070222ebc7c68dc..1290c2ab880b7de0bff26cd78003dceadb216e5e 100644 GIT binary patch delta 23 ecmbQvGo5FH0yCGXu7Rn7p}Ccz1HkFw@d&=90lC~ 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 3b8f84de..daa8d2da 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-04-05 14:05+0800\n" +"POT-Creation-Date: 2020-05-05 17:19+0800\n" "PO-Revision-Date: 2020-04-05 13:23+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,12 +17,12 @@ msgstr "" "Language: zh_CN\n" "X-Generator: Poedit 2.3\n" -#: autosub/ffmpeg_utils.py:97 +#: autosub/ffmpeg_utils.py:102 msgid "" "Error: ffmpeg can't split your file. Check your audio processing options." msgstr "错误:ffmpeg无法分割你的文件。检查一下你的音频处理选项。" -#: autosub/ffmpeg_utils.py:128 +#: autosub/ffmpeg_utils.py:133 msgid "" "ffprobe can't get video fps.\n" "It is necessary when output is \".sub\"." @@ -30,16 +30,16 @@ msgstr "" "ffprobe无法获取到视频的帧率。\n" "当输出格式是\".sub\"时,需要获取帧率。" -#: autosub/ffmpeg_utils.py:131 +#: autosub/ffmpeg_utils.py:136 msgid "" "Input your video fps. Any illegal input will regard as \".srt\" instead.\n" msgstr "输入你视频的帧率。任何非法的值会被当作\".srt\"格式处理。\n" -#: autosub/ffmpeg_utils.py:138 +#: autosub/ffmpeg_utils.py:143 msgid "Use \".srt\" instead." msgstr "改用\".srt\"格式。" -#: autosub/ffmpeg_utils.py:151 +#: autosub/ffmpeg_utils.py:156 msgid "" "\n" "Use ffprobe to check conversion result." @@ -47,19 +47,19 @@ msgstr "" "\n" "使用ffprobe来检查转换结果。" -#: autosub/ffmpeg_utils.py:184 +#: autosub/ffmpeg_utils.py:189 msgid "" "Warning: Dependency ffmpeg-normalize not found on this machine. Try default " "method." msgstr "" "警告:依赖ffmpeg-normalize未在这台电脑上找到。尝试默认的方法去转换格式。" -#: autosub/ffmpeg_utils.py:196 +#: autosub/ffmpeg_utils.py:201 msgid "" "There is already a file with the same name in this location: \"{dest_name}\"." msgstr "在此处已有同名文件:\"{dest_name}\"。" -#: autosub/ffmpeg_utils.py:199 +#: autosub/ffmpeg_utils.py:204 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.lang_code_utils.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.mo index f2db5c1ff4985cc75f2e23a0abd68ce93098d910..9db79840c3ee8bf1f55bc550220f64b9a9519cfa 100644 GIT binary patch delta 406 zcmZ3%wvoO5o)F7a1|Z-BVi_P#0b*VtUIWA+@BoO}fcPO0n*;F+Am#yL1x5x2X&|i& zq(yWW5J>9-=|&(8Gy@D+fF#H;ki$R#D8;}I#H=6=5CF|)-~h9LglAqs zX^9nsPhwtra(+r`u|i5}L26z~YF=`sLY`uNi9%X_X(~b>~8=9W%-T!>b3WO~$_RoH?u;{MQQ delta 269 zcmYk$yAA40p=d+N|I3@~-WLdLhWA8xc0u-)56x148%|wG%qScD1=~Ua%NpxBo z@h*)&dGgISlbOuczwwQ)NzYti0?49^FjjEp2p>*};EW6|Na2Mj;_B}_M>gpdvV=!caUVZ?Zog`fV diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.po b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.po index d78f21a6..55a7f2f3 100644 --- a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.po +++ b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.lang_code_utils.po @@ -7,40 +7,44 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-03-20 20:42+0800\n" -"PO-Revision-Date: 2019-07-27 15:24+0800\n" +"POT-Creation-Date: 2020-05-06 16:32+0800\n" +"PO-Revision-Date: 2020-05-06 15:53+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.3\n" +"X-Generator: Poedit 2.3\n" -#: autosub/lang_code_utils.py:105 +#: autosub/lang_code_utils.py:113 msgid "Now match lang codes." msgstr "现在匹配语言代码。" -#: autosub/lang_code_utils.py:108 +#: autosub/lang_code_utils.py:116 +msgid "Langcodes dependency not found. Use fuzzywuzzy instead." +msgstr "Langcodes依赖未找到。使用fuzzywuzzy进行替代。" + +#: autosub/lang_code_utils.py:119 msgid "The value of arg of \"-mns\"/\"--min-score\" isn't legal." msgstr "\"-mns\"/\"--min-score\"的参数的值不合法。" -#: autosub/lang_code_utils.py:112 +#: autosub/lang_code_utils.py:123 msgid "Input:" msgstr "输入:" -#: autosub/lang_code_utils.py:116 +#: autosub/lang_code_utils.py:127 msgid "Score above:" msgstr "分数高于:" -#: autosub/lang_code_utils.py:124 +#: autosub/lang_code_utils.py:135 msgid "No lang codes been matched." msgstr "没有匹配到语言代码。" -#: autosub/lang_code_utils.py:128 +#: autosub/lang_code_utils.py:139 msgid "Match result" msgstr "匹配结果" -#: autosub/lang_code_utils.py:129 +#: autosub/lang_code_utils.py:140 msgid "Score (0-100)" msgstr "分数(0-100)" diff --git a/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.mo b/autosub/data/locale/zh_CN/LC_MESSAGES/autosub.options.mo index aa89ad77c403e0a8a1d745eea7e7039ea71d23fa..8a2007b98ec3651666fd9c5f65be4e0dd79c5f0a 100644 GIT binary patch delta 2676 zcmZ|Pdr%cs9Ki7(#zT>OA^1#J6wwmQ2O%WBz|_b>G4Y)@Sc!sr?cR%qrk8Zg>@kv? z(*w(tEYl40_A)j8X?%`0W|KAJG*iMAE6cL9W^(HL+g(Zj=**n`>^W!8p0nrt&Tc&v zwc%(~=-V#Q8-+BF+?)J&8<7y6iQz)}I!>f7euH=8U-&TQw-qt50UyGob|Q;$C6?hY z_#+m_i_~CVdl4R$&+u_Pjw^JiyAwp(M2Q^6?lc^`S)?O2VLtwj$7s*)ATknTI*E9x z&*>~O9^b~^)c=UPDYs1&p^NOrTs(wP+OMm~e9Cc2BCnu{o$OCd7GZ4Zj1AZaZ^0AT zgg@a4UU0IT$es9l50PcmpXuqWNO3R6t*8^ffOGIF>VUIY)?`-oL(~;K-bZ8rc4t|8 z=u+o$qf1|m^pPO)ZmGqExD&H5!Ej!jkNSn1k-5k&WO3vWUSxt_;XW;=I9s*4zeo|~ zpYa2n!07$(PYmfz&s332I*!KSl>Gxm(s3K=i%+3W@OwOq|6n7YO%r((>j#O{VbWlc zFusSo`C{`{k^6XWGB4|bi!#`ItRBh-;N{y{|C4lxW>n%qzCz+lzQ)#QCA#I_$ZknL)c1`-eNR3Thf;vrZzgKLxg$a%rOc$13O+`TjC8)}S6oH8 zB$J572(Cr*4z>j^pnmyE_T?B}M6KUH%9-HQY-dG^aTE2IFqd&^b65$=C+^hX6ZtO0 z&0XC5hQg9%k7jl}m@|e+QT6;-r~NX{pgwn;v&0+5J3)Kb1eTcRim)f`^%$W1X`aYO zI6U8Z?g!T^_yzUR6P;KKo#sY6UcxC%pu;4Q$&_bJA@F!`3nA;nsRfP)P)|$xJt7Zc z4lcr1v4H;3Q=JJHGAjaIUPL|CAG&_-+Ts|Js6rOlM5`Xg?+McWzZ z5B!q$nMKZz=e8Ll4^ZBO&*0y98$NZv2yrLxt9;m5WHF^nu^JMY&W#SV0d;RS<5k>) zM{)Nok)^nNwupt7@O@m%AwSJTM$Z+Q&5OG(5E+ABW^ovIE#!ZIOIW50JpW{g6B|MH zRfBRRCNaLO;iev+stLTsmfRQh3GvZnD4_BDm8Zp#3&PDcxhoASx=Ovd&q>v z4Jnh-SdoGDd5v+KrXg`?r#M$7+bWOk70TyMcd{E>iTuADjH zyh>-ctmIyIKa+cc#ZDu+vhVh9Pb=7a`=@=gt^yk__i8OE)j|062>~G^tbTFb<`avO z=(Z3V!f6)b)c&jLR%Ma-Mc7GyNS(-I$hv*{LrNlZ@WdcbAon73Q0(o@3vY}&(k4{m z^DZ&{fpVYMDDhQRdc36>M#|ijAx6sl6vN{;4d3D*jh+e$WmT1?HyAJ~O^>(STV_=I zs*Dnk*YKN_z9ps+e8{Y%^K$LH!s+ZcAFV3)o2CETxuZ8Nczu8CiTE_DvE4AMO_oyzr?8Uc+09hWmZl6pm1$+-}nK6st1GR!3s0Lw_f|~K*penk1aO+<@#-&ioxMJ zV{>fRqShz#TAvILOB)bt?P#ODev?8f=0PFzzZtO(ji7wz%&+B zEn8N-R4;am=_$1`66(U!((_{CGt+Os!x)yCGjf#m+VDQD#mubm!QsWxg{>P9d8wg! zeZ%>hboIx$ItPs^PtsfQj#@p zcB)mFnQpD06C3W3wIwQiG5e8rR^p^Cc1xeUF;+OY^H7FpI?#CTh3z*kapcu)Eo*l) zKfOItUlaM@naC%#Ee*R`w%53C9vF_BSlm9LdDn~0dpEWmcqj7Q)^I`Lw7A6UYna{n zEqldU-#t0Jr+9j-b!t@gh&NY7UfZM_Wv^po(~jnM*R|BIX`RM@tH=~0b&XB?>aEGy LZ-@VxUmx=?G!PIi delta 2485 zcmZ|Pdr%cs9Ki7($irs{3JR#K_)NWUxgaW}h>{2zARt%`=uNJGgItxXrfJuFq>kik zwGydO8yhMUb#?O1^hf#1W^`(*(VUvNa4j3nrfFwE5Q&h$rT=Im#GXLrvzd-ivB z*Oj1y7lXXFqeAuw<$3A=YJ0GV7Y~PWptOXGB;W^_kC$;F_U$U-LNC^!4;N!WH<4;= z!?ie~y9k%01y|!ST!TqH7%zyS4s#M5M8`cv`g7rnULq0b!yNnruW~)(DUmb`>n&1G zduF6aHhze7BzN&BakoAqJR)asB3{BE^;}<(M&ho~B7fl??5$pPM~nz#%K>b~BRCK% z`>`6h8o#6iC$q~$dz{EB+Uw%Y73s8euzYIbYw!hp11r#vF|6t|I?X4pU^$0k3&t|O zT;qg$q!Z~&LNpP^5Dn*HCaMmbQN7up7>l8UMOYL`!23)r3D2r{i1~?bVhQmyMmvd3 z$SqPd%ycPw$MWEAP8?jgGF-%lk5F|ydW6VNn1O9LXr#yzyp8*?=xGrH@8VJ3aQ`Tg zDEga4C#$h4i3#J6$s*Ue@19+RuPvXZh>%8dErs$nMv z#*!EKEiS>@bTht*YGQTc%oSLU&BRgTMJ6*qD^A4w6KJD7DN`jG6TxX%jKWIo#WL<| z@=j!CwEZ^8yrC>hq?8Nqpjz4olg;FOKbzST8yLs+E>lP#;z3hICJ|pmmBeAsn)bmP z#2Uuq@2H-OU>12yU{tQibYib3Pvj$RI8SQ2v37>(cc?ndnRY;k@4=WH@hcqOI1KTpxYAe90)_J(4f=v>5 z;ba#6y|75{6k_!W`%%@dQ6-K_3I%e84-+UuEY(g@g-s^2sF5nL$}|6-Aekd$tT+|P zn81HcHIXI49#CIqkdP9AUo*%sb)bx-mQmyNS>gRENJi;Hbx?z;Y9F%$o)rEIGR}(B zH|$MiYX`og`U9!NP(`D%vjSx%NA+E^jnBd_2OFz;6b6OV)wx&bv9?!&%N+Vu+dkt` z&zHOQEpaY#X-<#FRqv^F*K4))nx{rjj)~P%28`Gh6QcKsPS7_;57FangBQ6MaM7hD z+Da0W6K%GJ#V*(U8e5&SzIvIn+Lf53W3pCd`J+3iYd2wMuu9jC&G`mzQDJ?A0if0!TaM zhsTE*3zM=!9cebZLrY1|u&0f-kGI>q7ZuuyUCV15n7u8B9y2tD-C?)cQ*Dk3oMxoj zjhm_EA;#nJyMl)Lnp^xAbl=899nD+(t*xC+8#>l+^u2zv{nXZb=Nf$*U-KV1rN>pS z)UQ+?GInMx>=y6a(b%#76Lq7}(y?K?Z~Hp`+VywVZn<;dw4M^vPtTtlrMt6Yb@#Xk z{le6UE*)of=(#zQ2A*qbKi}55yG5= arg_num >= 1)" +"Use langcodes to get a best matching lang code when your input is wrong. " +"Only functional for py-googletrans and Google Speech API. If langcodes not " +"installed, use fuzzywuzzy instead. Available modes: s, src, d, all. \"s\" " +"for \"-S\"/\"--speech-language\". \"src\" for \"-SRC\"/\"--src-language\". " +"\"d\" for \"-D\"/\"--dst-language\". (3 >= arg_num >= 1)" msgstr "" -"在输入有误的情况下,允许langcodes为输入获取一个最佳匹配的语言代码。仅在使用" -"py-googletrans和Google Speech V2时起作用。可选的模式:s, src, d, all。\"s\"指" -"\"-S\"/\"--speech-language\"。\"src\"指\"-SRC\"/\"--src-language\"。\"d\"指" -"\"-D\"/\"--dst-language\"。(参数个数在1到3之间)" +"使用langcodes为输入获取一个最佳匹配的语言代码。仅在使用py-googletrans和" +"Google Speech V2时起作用。如果langcodes未安装,使用fuzzywuzzy来替代。可选的模" +"式:s, src, d, all。\"s\"指\"-S\"/\"--speech-language\"。\"src\"指\"-SRC\"/" +"\"--src-language\"。\"d\"指\"-D\"/\"--dst-language\"。(参数个数在1到3之间)" -#: autosub/options.py:185 +#: autosub/options.py:183 msgid "" "An integer between 0 and 100 to control the good match group of \"-lsc\"/\"--" "list-speech-codes\" or \"-ltc\"/\"--list-translation-codes\" or the match " @@ -266,7 +262,7 @@ msgstr "" "best-match\"选项中的最佳匹配结果。结果会是一组“好的匹配”,其分数需要超过这个" "参数的值。(参数个数为1)" -#: autosub/options.py:197 +#: autosub/options.py:195 msgid "" "The output path for subtitles file. (default: the \"input\" path combined " "with the proper name tails) (arg_num = 1)" @@ -274,11 +270,11 @@ msgstr "" "输出字幕文件的路径。(默认值是\"input\"路径和适当的文件名后缀的结合)(参数个" "数为1)" -#: autosub/options.py:203 +#: autosub/options.py:201 msgid "format" msgstr "格式" -#: autosub/options.py:204 +#: autosub/options.py:202 msgid "" "Destination subtitles format. If not provided, use the extension in the \"-o" "\"/\"--output\" arg. If \"-o\"/\"--output\" arg doesn't provide the " @@ -291,18 +287,18 @@ msgstr "" "果\"-i\"/\"--input\"的参数是一个字幕文件,那么使用和字幕文件相同的扩展名。" "(参数个数为1)(默认参数为{dft})" -#: autosub/options.py:217 +#: autosub/options.py:215 msgid "" "Prevent pauses and allow files to be overwritten. Stop the program when your " "args are wrong. (arg_num = 0)" msgstr "" "避免任何暂停和覆写文件的行为。如果参数有误,会直接停止程序。(参数个数为0)" -#: autosub/options.py:222 +#: autosub/options.py:220 msgid "type" msgstr "种类" -#: autosub/options.py:225 +#: autosub/options.py:223 #, python-format msgid "" "Output more files. Available types: regions, src, full-src, dst, bilingual, " @@ -320,7 +316,7 @@ msgstr "" "字幕行中,且目标语言先于源语言。src-lf-dst:源语言和目标语言在同一字幕行中," "且源语言先于目标语言。(参数个数在6和1之间)(默认参数为%(default)s)" -#: autosub/options.py:242 +#: autosub/options.py:240 msgid "" "Valid when your output format is \"sub\". If input, it will override the fps " "check on the input file. Ref: https://pysubs2.readthedocs.io/en/latest/api-" @@ -330,11 +326,11 @@ msgstr "" "查。参考:https://pysubs2.readthedocs.io/en/latest/api-reference." "html#supported-input-output-formats(参数个数为1)" -#: autosub/options.py:251 +#: autosub/options.py:249 msgid "API_code" msgstr "API代码" -#: autosub/options.py:254 +#: autosub/options.py:252 #, python-format msgid "" "Choose which Speech-to-Text API to use. Currently support: gsv2: Google " @@ -342,18 +338,18 @@ msgid "" "Cloud Speech-to-Text V1P1Beta1 (https://cloud.google.com/speech-to-text/" "docs). xfyun: Xun Fei Yun Speech-to-Text WebSocket API (https://www.xfyun.cn/" "doc/asr/voicedictation/API.html). baidu: Baidu Automatic Speech Recognition " -"API (https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) (arg_num = 1) (default: %" -"(default)s)" +"API (https://ai.baidu.com/ai-doc/SPEECH/Vk38lxily) (arg_num = 1) (default: " +"%(default)s)" msgstr "" "选择使用Speech-to-Text API。当前支持:gsv2:Google Speech V2 (https://" "github.com/gillesdemey/google-speech-v2)。 gcsv1:Google Cloud Speech-to-" "Text V1P1Beta1 (https://cloud.google.com/speech-to-text/docs)。xfyun:讯飞" "开放平台语音听写(流式版)WebSocket API(https://www.xfyun.cn/doc/asr/" "voicedictation/API.html)。baidu: 百度短语音识别/短语音识别极速版(https://" -"ai.baidu.com/ai-doc/SPEECH/Vk38lxily)(参数个数为1)(默认参数为%(default)" -"s)" +"ai.baidu.com/ai-doc/SPEECH/Vk38lxily)(参数个数为1)(默认参数" +"为%(default)s)" -#: autosub/options.py:268 +#: autosub/options.py:266 msgid "" "The API key for Google Speech-to-Text API. (arg_num = 1) Currently support: " "gsv2: The API key for gsv2. (default: Free API key) gcsv1: The API key for " @@ -364,7 +360,7 @@ msgstr "" "钥。(默认参数为免费API密钥)gcsv1:gcsv1的API密钥。(如果使用了,可以覆盖 " "\"-sa\"/\"--service-account\"提供的服务账号凭据)" -#: autosub/options.py:279 +#: autosub/options.py:277 #, python-format msgid "" "Use Speech-to-Text recognition config file to send request. Override these " @@ -388,7 +384,7 @@ msgstr "" "ai-doc/SPEECH/ek38lxj1u)。如果参数个数是0,使用const路径。(参数个数为0或1)" "(const为%(const)s)" -#: autosub/options.py:304 +#: autosub/options.py:302 #, python-format msgid "" "Google Speech-to-Text API response for text confidence. A float value " @@ -401,11 +397,11 @@ msgstr "" "除。参考:https://github.com/BingLingGroup/google-speech-v2#response(参数个" "数为1)(默认参数为%(default)s)" -#: autosub/options.py:314 +#: autosub/options.py:312 msgid "Drop any regions without speech recognition result. (arg_num = 0)" msgstr "删除所有没有语音识别结果的空轴。(参数个数为0)" -#: autosub/options.py:322 +#: autosub/options.py:320 #, python-format msgid "" "Number of concurrent Speech-to-Text requests to make. (arg_num = 1) " @@ -413,21 +409,21 @@ msgid "" msgstr "" "用于Speech-to-Text请求的并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:327 autosub/options.py:375 autosub/options.py:572 -#: autosub/options.py:581 autosub/options.py:590 +#: autosub/options.py:325 autosub/options.py:373 autosub/options.py:570 +#: autosub/options.py:579 autosub/options.py:588 msgid "second" msgstr "秒" -#: autosub/options.py:330 +#: autosub/options.py:328 #, python-format 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:338 +#: autosub/options.py:336 msgid "" "(Experimental)Customize request urls. Ref: https://py-googletrans." "readthedocs.io/en/latest/ (arg_num >= 1)" @@ -435,20 +431,20 @@ msgstr "" "(实验性)自定义多个请求URL。参考:https://py-googletrans.readthedocs.io/en/" "latest/(参数个数大于等于1)" -#: autosub/options.py:345 +#: autosub/options.py:343 msgid "" "(Experimental)Customize User-Agent headers. Same docs above. (arg_num = 1)" msgstr "" "(实验性)自定义用户代理(User-Agent)头部。同样的参考文档如上。(参数个数为" "1)" -#: autosub/options.py:352 +#: autosub/options.py:350 msgid "" "Drop any .ass override codes in the text before translation. Only affect the " "translation result. (arg_num = 0)" msgstr "在翻译前删除所有文本中的ass特效标签。只影响翻译结果。(参数个数为0)" -#: autosub/options.py:360 +#: autosub/options.py:358 #, python-format msgid "" "Replace the specific chars with a space after translation, and strip the " @@ -458,66 +454,54 @@ msgstr "" "将指定字符替换为空格,并消除每句末尾空格。只会影响翻译结果。(参数个数为0或" "1)(const为%(const)s)" -#: autosub/options.py:370 -#, fuzzy, python-format +#: autosub/options.py:368 +#, python-format msgid "" -"(Experimental)Max length to join two events. (arg_num = 1) (default: %" -"(default)s)" +"(Experimental)Max length to join two events. (arg_num = 1) (default: " +"%(default)s)" msgstr "" -"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" -"(default)s)" -#: autosub/options.py:378 -#, fuzzy, python-format +#: autosub/options.py:376 +#, python-format msgid "" -"(Experimental)Max delta time to join two events. (arg_num = 1) (default: %" -"(default)s)" +"(Experimental)Max delta time to join two events. (arg_num = 1) (default: " +"%(default)s)" msgstr "" -"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" -"(default)s)" -#: autosub/options.py:383 +#: autosub/options.py:381 msgid "string" msgstr "" -#: autosub/options.py:385 -#, fuzzy, python-format +#: autosub/options.py:383 +#, python-format msgid "" -"(Experimental)Delimiters not to join two events. (arg_num = 1) (default: %" -"(default)s)" +"(Experimental)Delimiters not to join two events. (arg_num = 1) (default: " +"%(default)s)" msgstr "" -"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" -"(default)s)" -#: autosub/options.py:390 autosub/options.py:396 +#: autosub/options.py:388 autosub/options.py:394 msgid "words_delimited_by_space" msgstr "" -#: autosub/options.py:391 -#, fuzzy +#: autosub/options.py:389 msgid "" "(Experimental)First set of Stop words to split two events. (arg_num = 1)" msgstr "" -"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" -"(default)s)" -#: autosub/options.py:397 -#, fuzzy +#: autosub/options.py:395 msgid "" "(Experimental)Second set of Stop words to split two events. (arg_num = 1)" msgstr "" -"(实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为%" -"(default)s)" -#: autosub/options.py:403 +#: autosub/options.py:401 msgid "(Experimental)Don't Split just merge. (arg_num = 0)" msgstr "" -#: autosub/options.py:409 +#: autosub/options.py:407 msgid "Change the Google Speech V2 API URL into the http one. (arg_num = 0)" msgstr "将Google Speech V2 API的URL改为http类型。(参数个数为0)" -#: autosub/options.py:417 +#: autosub/options.py:415 #, python-format msgid "" "Add https proxy by setting environment variables. If arg_num is 0, use const " @@ -526,7 +510,7 @@ msgstr "" "通过设置环境变量的方式添加https代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:425 +#: autosub/options.py:423 #, python-format msgid "" "Add http proxy by setting environment variables. If arg_num is 0, use const " @@ -535,33 +519,33 @@ msgstr "" "通过设置环境变量的方式添加http代理。如果参数个数是0,使用const里的代理URL。" "(参数个数为0或1)(const为%(const)s)" -#: autosub/options.py:431 +#: autosub/options.py:429 msgid "username" msgstr "用户名" -#: autosub/options.py:432 +#: autosub/options.py:430 msgid "Set proxy username. (arg_num = 1)" msgstr "设置代理用户名。(参数个数为1)" -#: autosub/options.py:437 +#: autosub/options.py:435 msgid "password" msgstr "密码" -#: autosub/options.py:438 +#: autosub/options.py:436 msgid "Set proxy password. (arg_num = 1)" msgstr "设置代理密码。(参数个数为1)" -#: autosub/options.py:444 +#: autosub/options.py:442 #, python-format msgid "Show %(prog)s help message and exit. (arg_num = 0)" msgstr "显示%(prog)s的帮助信息并退出。(参数个数为0)" -#: autosub/options.py:452 +#: autosub/options.py:450 #, python-format msgid "Show %(prog)s version and exit. (arg_num = 0)" msgstr "显示%(prog)s的版本信息并退出。(参数个数为0)" -#: autosub/options.py:457 +#: autosub/options.py:455 msgid "" "Set service account key environment variable. It should be the file path of " "the JSON file that contains your service account credentials. Can be " @@ -571,10 +555,10 @@ 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:468 +#: autosub/options.py:466 msgid "" "Option to control audio process. If not given the option, do normal " "conversion work. \"y\": pre-process the input first then start normal " @@ -593,15 +577,15 @@ msgstr "" "scripts/subgen.sh https://ffmpeg.org/ffmpeg-filters.html)(参数个数介于1和2" "之间)" -#: autosub/options.py:492 +#: autosub/options.py:490 msgid "Keep audio processing files to the output path. (arg_num = 0)" msgstr "将音频处理中产生的文件放在输出路径中。(参数个数为0)" -#: autosub/options.py:497 autosub/options.py:515 autosub/options.py:527 +#: autosub/options.py:495 autosub/options.py:513 autosub/options.py:525 msgid "command" msgstr "命令" -#: autosub/options.py:498 +#: autosub/options.py:496 msgid "" "This arg will override the default audio pre-process command. Every line of " "the commands need to be in quotes. Input file name is {in_}. Output file " @@ -610,7 +594,7 @@ msgstr "" "这个参数会取代默认的音频预处理命令。每行命令需要放在一个引号内。输入文件名写" "为{in_}。输出文件名写为{out_}。(参数个数大于1)" -#: autosub/options.py:510 +#: autosub/options.py:508 #, python-format msgid "" "Number of concurrent ffmpeg audio split process to make. (arg_num = 1) " @@ -618,19 +602,19 @@ msgid "" msgstr "" "用于ffmpeg音频切割的进程并行数量。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:517 -#, fuzzy, python-format +#: autosub/options.py:515 +#, 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:529 +#: autosub/options.py:527 #, python-format msgid "" "(Experimental)This arg will override the default audio split command. Same " @@ -639,24 +623,24 @@ msgstr "" "(实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:536 +#: autosub/options.py:534 msgid "file_suffix" msgstr "文件名后缀" -#: autosub/options.py:538 +#: autosub/options.py:536 #, python-format 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:544 +#: autosub/options.py:542 msgid "sample_rate" msgstr "采样率" -#: autosub/options.py:547 +#: autosub/options.py:545 #, python-format msgid "" "(Experimental)This arg will override the default API audio sample rate(Hz). " @@ -665,11 +649,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频采样率(赫兹)。(参数个数为1)" "(默认参数为%(default)s)" -#: autosub/options.py:553 +#: autosub/options.py:551 msgid "channel_num" msgstr "声道数" -#: autosub/options.py:556 +#: autosub/options.py:554 #, python-format msgid "" "(Experimental)This arg will override the default API audio channel. (arg_num " @@ -678,11 +662,11 @@ msgstr "" "(实验性)这个参数会取代默认的给API使用的音频声道数量。(参数个数为1)(默认" "参数为%(default)s)" -#: autosub/options.py:562 +#: autosub/options.py:560 msgid "energy" msgstr "能量(相对值)" -#: autosub/options.py:565 +#: autosub/options.py:563 #, python-format msgid "" "The energy level which determines the region to be detected. Ref: https://" @@ -693,23 +677,23 @@ msgstr "" "latest/apitutorial.html#examples-using-real-audio-data(参数个数为1)(默认参" "数为%(default)s)" -#: autosub/options.py:575 +#: autosub/options.py:573 #, python-format msgid "" "Minimum region size. Same docs above. (arg_num = 1) (default: %(default)s)" msgstr "" -"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为%(default)" -"s)" +"最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数" +"为%(default)s)" -#: autosub/options.py:584 +#: autosub/options.py:582 #, 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:593 +#: autosub/options.py:591 #, python-format msgid "" "Maximum length of a tolerated silence within a valid audio activity. Same " @@ -718,7 +702,7 @@ msgstr "" "在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如" "上。(参数个数为1)(默认参数为%(default)s)" -#: autosub/options.py:600 +#: autosub/options.py:598 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." @@ -727,7 +711,7 @@ msgstr "" "如果不输入这个选项,它会严格控制所有语音区域的最小大小。参考:https://" "auditok.readthedocs.io/en/latest/core.html#class-summary(参数个数为0)" -#: autosub/options.py:608 +#: autosub/options.py:606 msgid "" "Ref: https://auditok.readthedocs.io/en/latest/core.html#class-summary " "(arg_num = 0)" @@ -735,7 +719,7 @@ msgstr "" "参考:https://auditok.readthedocs.io/en/latest/core.html#class-summary(参数" "个数为0)" -#: autosub/options.py:614 +#: autosub/options.py:612 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 " @@ -746,7 +730,7 @@ msgstr "" "SubtitleEdit来对其进行转换。如果输出格式是\"sub\"且输入文件是音频无法获取到视" "频帧率时,你需要提供fps选项指定帧率。(参数个数为0)" -#: autosub/options.py:627 +#: autosub/options.py:625 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 " @@ -764,7 +748,7 @@ msgstr "" "言)-扩展-私有(https://www.zhihu.com/question/21980689/answer/93615123)(参" "数个数为0或1)" -#: autosub/options.py:643 +#: autosub/options.py:641 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 " @@ -774,7 +758,7 @@ msgstr "" "言代码。否则会给出一个“好的匹配”的清单。同样的参考文档如上。(参数个数为0或" "1)" -#: autosub/options.py:653 +#: autosub/options.py:651 #, python-format msgid "" "Use py-googletrans to detect a sub file's first line language. And list a " @@ -787,6 +771,17 @@ msgstr "" "的)。参考:https://cloud.google.com/speech-to-text/docs/languages(参数个数" "为1)(默认参数 %(default)s)" +#~ msgid "" +#~ "Lang code/Lang tag for translation source language. If not given, use " +#~ "langcodes to get a best matching of the \"-S\"/\"--speech-language\". If " +#~ "using py-googletrans as the method to translate, WRONG INPUT STOP " +#~ "RUNNING. (arg_num = 1) (default: %(default)s)" +#~ msgstr "" +#~ "用于翻译的源语言的语言代码/语言标识符。如果没有提供,会使用langcodes从列表" +#~ "里获取一个最佳匹配选项\"-S\"/\"--speech-language\"的语言代码。如果使用py-" +#~ "googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数" +#~ "为%(default)s)" + #~ msgid "Google Translate V2 Options" #~ msgstr "Google Translate V2选项" @@ -805,26 +800,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/metadata.py b/autosub/metadata.py index 0f5b69ef..23b8be99 100644 --- a/autosub/metadata.py +++ b/autosub/metadata.py @@ -8,7 +8,7 @@ # For gettext po files NAME = 'autosub' -VERSION = '0.5.6-alpha' +VERSION = '0.5.7-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 0dc1caca..925de1b9 100644 --- a/docs/CHANGELOG.zh-Hans.md +++ b/docs/CHANGELOG.zh-Hans.md @@ -13,8 +13,14 @@ - [改动](#改动未发布) - [修复](#修复未发布) - [删除](#删除未发布) +- [0.5.7-alpha - 2020-05-06](#057-alpha---2020-05-06) + - [添加](#添加057-alpha) + - [改动](#改动057-alpha) + - [修复](#修复057-alpha) + - [删除](#删除057-alpha) - [0.5.6-alpha - 2020-03-20](#056-alpha---2020-03-20) - [添加](#添加056-alpha) + - [改动](#改动056-alpha) - [即将删除](#即将删除056-alpha) - [修复](#修复056-alpha) - [0.5.5-alpha - 2020-03-04](#055-alpha---2020-03-04) @@ -46,7 +52,9 @@ ### [未发布](未发布) -#### 添加(未发布) +### [0.5.7-alpha] - 2020-05-06 + +#### 添加(0.5.7-alpha) - 添加讯飞开放平台语音听写(流式版)WebSocket API支持。 - 添加百度智能云语音识别/极速语音识别API支持。[issue #68](https://github.com/BingLingGroup/autosub/issues/68) @@ -58,7 +66,7 @@ - 添加音频长度至少为4字节的检测,在SplitIntoAudioPiece里。 - 添加源语言自动识别功能,当不输入`-SRC`选项时。 -#### 改动(未发布) +#### 改动(0.5.7-alpha) - 修改音频分割指令的更换条件为仅当用户不修改它时。 - 修改最长语音区域限制为60秒。 @@ -67,8 +75,9 @@ - 修改ffmpeg指令中的loglevel为`-loglevel error`。 - 修改DEFAULT_MIN_REGION_SIZE为0.5。 - 修改langcodes为可选依赖。 +- 修改证书为GPLv2。 -#### 修复(未发布) +#### 修复(0.5.7-alpha) - 修复list_to_googletrans中当最后一行是需要被分割时的长度计算问题。 - 修复delete_chars问题当使用`-of full-src`时。 @@ -77,10 +86,12 @@ - 修复依赖查找中,路径检查的问题。 - 修复百度奇怪的错误代码处理。[issue #114](https://github.com/BingLingGroup/autosub/issues/114) -#### 删除(未发布) +#### 删除(0.5.7-alpha) - 删除Python 2.7支持。 + ↑  + ### [0.5.6-alpha] - 2020-03-20 #### 添加(0.5.6-alpha) @@ -89,6 +100,11 @@ - 添加无参数启动时的请求输入参数解析功能。[issue #92](https://github.com/BingLingGroup/autosub/issues/92) - 添加字幕处理功能,当不输入`-SRC`选项时。 +#### 修改(0.5.6-alpha) + +- 修改选项`-sml`为`-nsml`。 +- 修改Auditok默认参数。 + #### 即将删除(0.5.6-alpha) - 即将删除Python 2.7支持。 @@ -96,8 +112,6 @@ #### 修复(0.5.6-alpha) - 修复Google Speech-to-Text API空结果返回bug。[issue #89](https://github.com/BingLingGroup/autosub/issues/89) -- 修改选项`-sml`为`-nsml`。 -- 修改Auditok默认参数。  ↑  @@ -262,7 +276,8 @@  ↑  -[未发布]: https://github.com/BingLingGroup/autosub/compare/0.5.6-alpha...HEAD +[未发布]: https://github.com/BingLingGroup/autosub/compare/0.5.7-alpha...HEAD +[0.5.7-alpha]: https://github.com/BingLingGroup/autosub/compare/0.5.6-alpha...0.5.7-alpha [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 diff --git a/docs/README.zh-Hans.md b/docs/README.zh-Hans.md index 820483f5..aeefa806 100644 --- a/docs/README.zh-Hans.md +++ b/docs/README.zh-Hans.md @@ -71,7 +71,7 @@ Autosub是一个字幕自动生成工具。它能使用Auditok来自动检测语 这个仓库和[原仓库](https://github.com/agermanidis/autosub)的证书不一样。 -[GPLv3](../LICENSE) +[GPLv2](../LICENSE) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FBingLingGroup%2Fautosub.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FBingLingGroup%2Fautosub) @@ -709,17 +709,16 @@ usage: 不会终止程序。但是后果自负。参考:https://cloud.google.com/speech-to- text/docs/languages(参数个数为1)(默认参数: None) -SRC 语言代码, --src-language 语言代码 - 用于翻译的源语言的语言代码/语言标识符。如果没有提供,会使用langcodes从列表里获取一个最佳匹配选项" - -S"/"--speech-language"的语言代码。如果使用py- - googletrans作为翻译的方法,错误的输入会终止运行。(参数个数为1)(默认参数为None) + 用于翻译的目标语言的语言代码/语言标识符。如果没有提供,使用py- + googletrans来自动检测源语言。(参数个数为1)(默认参数为auto) -D 语言代码, --dst-language 语言代码 - 用于翻译的目标语言的语言代码/语言标识符。同样的注意参考选项"-SRC"/"--src- - language"。(参数个数为1)(默认参数为None) + 用于翻译的目标语言的语言代码/语言标识符。(参数个数为1)(默认参数为None) -bm [模式 [模式 ...]], --best-match [模式 [模式 ...]] - 在输入有误的情况下,允许langcodes为输入获取一个最佳匹配的语言代码。仅在使用py- - googletrans和Google Speech V2时起作用。可选的模式:s, src, d, - all。"s"指"-S"/"--speech-language"。"src"指"-SRC"/"--src- - language"。"d"指"-D"/"--dst-language"。(参数个数在1到3之间) + 使用langcodes为输入获取一个最佳匹配的语言代码。仅在使用py-googletrans和Google + Speech V2时起作用。如果langcodes未安装,使用fuzzywuzzy来替代。可选的模式:s, + src, d, all。"s"指"-S"/"--speech- + language"。"src"指"-SRC"/"--src-language"。"d"指"-D"/"-- + dst-language"。(参数个数在1到3之间) -mns integer, --min-score integer 一个介于0和100之间的整数用于控制以下两个选项的匹配结果组,"-lsc"/"--list-speech- codes"以及"-ltc"/"--list-translation-codes"或者在"-bm"/"-- @@ -790,7 +789,7 @@ py-googletrans选项: 控制翻译的选项。同时也是默认的翻译方法。可能随时会被谷歌爸爸封。 -slp 秒, --sleep-seconds 秒 - (实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为5) + (实验性)在两次翻译请求之间睡眠(暂停)的时间。(参数个数为1)(默认参数为1) -surl [URL [URL ...]], --service-urls [URL [URL ...]] (实验性)自定义多个请求URL。参考:https://py- googletrans.readthedocs.io/en/latest/(参数个数大于等于1) @@ -798,6 +797,28 @@ py-googletrans选项: (实验性)自定义用户代理(User-Agent)头部。同样的参考文档如上。(参数个数为1) -doc, --drop-override-codes 在翻译前删除所有文本中的ass特效标签。只影响翻译结果。(参数个数为0) + -gt-dc [chars], --gt-delete-chars [chars] + 将指定字符替换为空格,并消除每句末尾空格。只会影响翻译结果。(参数个数为0或1)(const为,。!) + +字幕转换选项: + 控制字幕转换的选项。 + + -mjs integer, --max-join-size integer + (Experimental)Max length to join two events. (arg_num + = 1) (default: 100) + -mdt 秒, --max-delta-time 秒 + (Experimental)Max delta time to join two events. + (arg_num = 1) (default: 0.2) + -dms string, --delimiters string + (Experimental)Delimiters not to join two events. + (arg_num = 1) (default: !()*,.:;?[]^_`~) + -sw1 words_delimited_by_space, --stop-words-1 words_delimited_by_space + (Experimental)First set of Stop words to split two + events. (arg_num = 1) + -sw2 words_delimited_by_space, --stop-words-2 words_delimited_by_space + (Experimental)Second set of Stop words to split two + events. (arg_num = 1) + -ds, --dont-split (Experimental)Don't Split just merge. (arg_num = 0) 网络选项: 控制网络的选项。 @@ -832,14 +853,16 @@ py-googletrans选项: -ap [模式 [模式 ...]], --audio-process [模式 [模式 ...]] 控制音频处理的选项。如果没有提供选项,进行正常的格式转换工作。"y":它会先预处理输入文件,如果成功了,在语 音转文字之前不会对音频进行额外的处理。"o":只会预处理输入音频。("-k"/"-- - keep"选项自动置为真)"s":只会分割输入音频。("-k"/"--keep"选项自动置为真)以下是用于处 - 理音频的默认命令:c:\programdata\chocolatey\bin\ffmpeg.exe - -hide_banner -i "{in_}" -af "asplit[a],aphasemeter=vid - eo=0,ametadata=select:key=lavfi.aphasemeter.phase:valu - e=-0.005:function=less,pan=1c|c0=c0,aresample=async=1: - first_pts=0,[a]amix" -ac 1 -f flac "{out_}" | - c:\programdata\chocolatey\bin\ffmpeg.exe -hide_banner - -i "{in_}" -af lowpass=3000,highpass=200 "{out_}" | + keep"选项自动置为真)"s":只会分割输入音频。("-k"/"-- + keep"选项自动置为真)以下是用于处理音频的默认命令:C:\Program + Files\ImageMagick-7.0.10-Q16\ffmpeg.exe -hide_banner + -i "{in_}" -vn -af "asplit[a],aphasemeter=video=0,amet + adata=select:key=lavfi.aphasemeter.phase:value=-0.005: + function=less,pan=1c|c0=c0,aresample=async=1:first_pts + =0,[a]amix" -ac 1 -f flac -loglevel error "{out_}" | + C:\Program Files\ImageMagick-7.0.10-Q16\ffmpeg.exe + -hide_banner -i "{in_}" -af + "lowpass=3000,highpass=200" -loglevel error "{out_}" | C:\Python37\Scripts\ffmpeg-normalize.exe -v "{in_}" -ar 44100 -ofmt flac -c:a flac -pr -p -o "{out_}"(参考:h ttps://github.com/stevenj/autosub/blob/master/scripts/ @@ -852,15 +875,16 @@ py-googletrans选项: -ac integer, --audio-concurrency integer 用于ffmpeg音频切割的进程并行数量。(参数个数为1)(默认参数为4) -acc 命令, --audio-conversion-cmd 命令 - (实验性)这个参数会取代默认的音频转换命令。"[", "]" 是可选参数,可以移除。"{{", "}}"是必 - 选参数,不可移除。(参数个数为1)(默认参数为c:\programdata\chocolatey\bin\f - fmpeg.exe -hide_banner -y -i "{in_}" -vn -ac {channel} - -ar {sample_rate} "{out_}") - -asc 命令, --audio-split-cmd 命令 - (实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)(默认参数为c:\program - data\chocolatey\bin\ffmpeg.exe -y -ss {start} -i - "{in_}" -t {dura} -vn -ac [channel] -ar [sample_rate] + (实验性)这个参数会取代默认的音频转换命令。"[", "]" 是可选参数,可以移除。"{", + "}"是必选参数,不可移除。(参数个数为1)(默认参数为C:\Program + Files\ImageMagick-7.0.10-Q16\ffmpeg.exe -hide_banner + -y -i "{in_}" -vn -ac {channel} -ar {sample_rate} -loglevel error "{out_}") + -asc 命令, --audio-split-cmd 命令 + (实验性)这个参数会取代默认的音频转换命令。相同的注意如上。(参数个数为1)(默认参数为C:\Program + Files\ImageMagick-7.0.10-Q16\ffmpeg.exe -y -ss {start} + -i "{in_}" -t {dura} -vn -ac [channel] -ar + [sample_rate] -loglevel error "{out_}") -asf 文件名后缀, --api-suffix 文件名后缀 (实验性)这个参数会取代默认的给API使用的音频文件后缀。(默认参数为.flac) -asr 采样率, --api-sample-rate 采样率 @@ -874,11 +898,11 @@ Auditok的选项: -et 能量(相对值), --energy-threshold 能量(相对值) 用于检测是否是语音区域的能量水平。参考:https://auditok.readthedocs.io/en/ latest/apitutorial.html#examples-using-real-audio- - data(参数个数为1)(默认参数为50) + data(参数个数为1)(默认参数为45) -mnrs 秒, --min-region-size 秒 - 最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为0.8) + 最小语音区域大小。同样的参考文档如上。(参数个数为1)(默认参数为0.5) -mxrs 秒, --max-region-size 秒 - 最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数为6.0) + 最大音频区域大小。同样的参考文档如上。(参数个数为1)(默认参数为10.0) -mxcs 秒, --max-continuous-silence 秒 在一段有效的音频活动区域中可以容忍的最大(连续)安静区域。同样的参考文档如上。(参数个数为1)(默认参数为0 .2) @@ -917,6 +941,7 @@ Auditok的选项: 如果选项没有在命令行中提供时会使用的参数。 "参数个数"指的是如果提供了选项, 该选项所需要的参数个数。 +*参数指的是那些用在选项后面的东西。* 作者: Bing Ling Email: binglinggroup@outlook.com 问题反馈: https://github.com/BingLingGroup/autosub