Skip to content

Commit

Permalink
Fix #114 Baidu's strange error code handling
Browse files Browse the repository at this point in the history
Add limitation in SplitIntoAudioPiece with an audio length of at least 4 bytes
  • Loading branch information
BingLingGroup committed Apr 27, 2020
1 parent 76d41a7 commit d84ecab
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions autosub/api_baidu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
5 changes: 5 additions & 0 deletions autosub/ffmpeg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- 添加方法merge_src_assfile,merge_bilingual_assfile。
- 添加停用词用于merge_src_assfile方法里的断句。
- 添加标点符号分割功能在merge_src_assfile方法里。
- 添加音频长度至少为4字节的检测,在SplitIntoAudioPiece里。

#### 改动(未发布)

Expand All @@ -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)

#### 删除(未发布)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d84ecab

Please sign in to comment.