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] 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',