BingLingGroup / autosub

Command-line utility to transcribe/translate from video/audio/subtitles to subtitles
GNU General Public License v2.0
1.97k stars 243 forks source link

翻译报错TypeError: 'NoneType' object is not subscriptable #158

Closed Andrea-lyz closed 3 years ago

Andrea-lyz commented 3 years ago

确保你已经看过 readme,也搜索并阅读过和你遇到的情况相关的问题。否则会被认为是重复的并被立刻关闭。

描述问题 根据#155的方法更新googletrans==4.0.0rc1后出现以下错误

复现问题 复现问题的步骤:

从视频转中文字幕

从识别的英文字幕转中文字幕

安装代码

usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install ffmpeg git
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Sudo python3 get-pip.py
pip3 install git+https://github.com/BingLingGroup/autosub.git@dev ffmpeg-normalize langcodes
没有指定输出格式。使用输入的格式"srt"作为输出格式。
输入是一个字幕文件。
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/bin/autosub", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/__init__.py", line 170, in main
    cmdline_utils.sub_trans(args,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/cmdline_utils.py", line 796, in sub_trans
    translated_text, args.src_language = core.list_to_googletrans(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/core.py", line 578, in list_to_googletrans
    translator = googletrans.Translator(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/googletrans/client.py", line 88, in __init__
    client=self.client, host=self.service_urls[0])
TypeError: 'NoneType' object is not subscriptable
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

期待的行为 希望得到帮助,能在Mac上正常运行

操作环境(请提供以下完整数据):

额外信息 单独运行translate,能够正常输出

translate "veritas lux mea" -s la -d zh-cn  
[la] veritas lux mea
    ->
[zh-cn] 事实是我的光
[pron.] Shìshí shì wǒ de guāng
BingLingGroup commented 3 years ago

我需要的是你运行时的命令行参数,不是你安装时的命令行参数

Andrea-lyz commented 3 years ago

我需要的是你运行时的命令行参数,不是你安装时的命令行参数

额,真小白第一次发没经验,抱歉 但运行代码就很简单

#!/bin/bash
export filename="*.srt"
autosub -i $filename -D zh-cn

同样直接输入

autosub -i *.srt -S it-it -D zh-cn

或者

autosub -i *.srt -D zh-cn

这样输入后都会报一下错误

没有指定输出格式。使用输入的格式"srt"作为输出格式。
输入是一个字幕文件。
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/bin/autosub", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/__init__.py", line 170, in main
    cmdline_utils.sub_trans(args,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/cmdline_utils.py", line 796, in sub_trans
    translated_text, args.src_language = core.list_to_googletrans(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/core.py", line 578, in list_to_googletrans
    translator = googletrans.Translator(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/googletrans/client.py", line 88, in __init__
    client=self.client, host=self.service_urls[0])
TypeError: 'NoneType' object is not subscriptable
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed...
BingLingGroup commented 3 years ago

有一点可以确定的是,你运行的不是github上dev分支最新版本的代码 https://github.com/BingLingGroup/autosub/blob/dev/autosub/cmdline_utils.py#L796cmdline_utils.py文件中的第796行,是空行,不是你报错信息里显示的那行 你可以尝试其他方式安装,先用pip3 uninstall autosub卸载,然后在项目主页右上角Code选择Download Zip,下载完整代码文件,然后解压,切换到刚解压出来的文件的根目录,使用pip3 install .(注意这里有个点)进行安装,之后再运行一次,看有没有问题

BingLingGroup commented 3 years ago

刚才查了下,可以确定你安装的还是0.5.7-alpha而不是最新版dev

Andrea-lyz commented 3 years ago

刚才查了下,可以确定你安装的还是0.5.7-alpha而不是最新版dev

我已经按照您说的方法切换到了dev版

zhengdan@zhengdandeMacBook-Air ~ % cd /Users/zhengdan/Downloads/autosub-dev 
zhengdan@zhengdandeMacBook-Air autosub-dev % pip3 install .
Processing /Users/zhengdan/Downloads/autosub-dev
Requirement already satisfied: requests>=2.3.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (2.25.1)
Requirement already satisfied: pysubs2>=0.2.4 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (1.0.0)
Requirement already satisfied: progressbar2>=3.34.3 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (3.53.1)
Requirement already satisfied: auditok<=0.1.8,>=0.1.5 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from autosub==0.5.7a0) (0.1.5)
Requirement already satisfied: googletrans>=2.4.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from autosub==0.5.7a0) (4.0.0rc1)
Requirement already satisfied: wcwidth>=0.1.7 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (0.2.5)
Requirement already satisfied: fuzzywuzzy>=0.18.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (0.18.0)
Requirement already satisfied: google-cloud-speech<2.0.0,>=1.3.1 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (1.3.2)
Requirement already satisfied: websocket-client>=0.56.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (0.57.0)
Requirement already satisfied: python-docx>=0.8.10 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (0.8.10)
Requirement already satisfied: send2trash>=1.5.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from autosub==0.5.7a0) (1.5.0)
Requirement already satisfied: google-api-core[grpc]<2.0.0dev,>=1.14.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (1.24.1)
Requirement already satisfied: six>=1.13.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (1.15.0)
Requirement already satisfied: setuptools>=34.0.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (51.0.0)
Requirement already satisfied: protobuf>=3.12.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (3.14.0)
Requirement already satisfied: google-auth<2.0dev,>=1.21.1 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (1.24.0)
Requirement already satisfied: googleapis-common-protos<2.0dev,>=1.6.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (1.52.0)
Requirement already satisfied: pytz in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (2020.4)
Requirement already satisfied: grpcio<2.0dev,>=1.29.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (1.34.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-auth<2.0dev,>=1.21.1->google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (0.2.8)
Requirement already satisfied: rsa<5,>=3.1.4 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-auth<2.0dev,>=1.21.1->google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (4.6)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from google-auth<2.0dev,>=1.21.1->google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (4.2.0)
Requirement already satisfied: httpx==0.13.3 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from googletrans>=2.4.0->autosub==0.5.7a0) (0.13.3)
Requirement already satisfied: hstspreload in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (2020.11.21)
Requirement already satisfied: idna==2.* in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (2.10)
Requirement already satisfied: sniffio in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (1.2.0)
Requirement already satisfied: httpcore==0.9.* in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (0.9.1)
Requirement already satisfied: certifi in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (2020.12.5)
Requirement already satisfied: chardet==3.* in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (3.0.4)
Requirement already satisfied: rfc3986<2,>=1.3 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (1.4.0)
Requirement already satisfied: h2==3.* in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpcore==0.9.*->httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (3.2.0)
Requirement already satisfied: h11<0.10,>=0.8 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from httpcore==0.9.*->httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (0.9.0)
Requirement already satisfied: hyperframe<6,>=5.2.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from h2==3.*->httpcore==0.9.*->httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (5.2.0)
Requirement already satisfied: hpack<4,>=3.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from h2==3.*->httpcore==0.9.*->httpx==0.13.3->googletrans>=2.4.0->autosub==0.5.7a0) (3.0.0)
Requirement already satisfied: python-utils>=2.3.0 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from progressbar2>=3.34.3->autosub==0.5.7a0) (2.4.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from pyasn1-modules>=0.2.1->google-auth<2.0dev,>=1.21.1->google-api-core[grpc]<2.0.0dev,>=1.14.0->google-cloud-speech<2.0.0,>=1.3.1->autosub==0.5.7a0) (0.4.8)
Requirement already satisfied: lxml>=2.3.2 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from python-docx>=0.8.10->autosub==0.5.7a0) (4.6.2)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/zhengdan/Library/Python/3.8/lib/python/site-packages (from requests>=2.3.0->autosub==0.5.7a0) (1.26.2)
Building wheels for collected packages: autosub
  Building wheel for autosub (setup.py) ... done
  Created wheel for autosub: filename=autosub-0.5.7a0-py3-none-any.whl size=92112 sha256=d76e5cf59dd3f5b399bacf12a120a4adce7bed4a5345a8e4d71e599dfd2420ac
  Stored in directory: /Users/zhengdan/Library/Caches/pip/wheels/59/c5/64/f685f97a5e0f8a29853d81dbbc4546ac4da94d42e7b5072cd1
Successfully built autosub
Installing collected packages: autosub
Successfully installed autosub-0.5.7a0

但似乎又出现新的问题 无论使用手动输入还是command命令,都报以下错

autosub -i /Users/zhengdan/Desktop/1/Lezione6.srt -D zh-cn
没有指定输出格式。使用输入的格式"srt"作为输出格式。
输入是一个字幕文件。
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/bin/autosub", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/__init__.py", line 173, in main
    cmdline_utils.sub_trans(args,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/cmdline_utils.py", line 1093, in sub_trans
    translated_text, args.src_language = core.list_to_googletrans(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/autosub/core.py", line 772, in list_to_googletrans
    result_src = translator.detect(content_to_trans).lang
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/googletrans/client.py", line 369, in detect
    translated = self.translate(text, src='auto', dest='en')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/googletrans/client.py", line 219, in translate
    parsed = json.loads(data[0][2])
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 341, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType

请问如何解决,麻烦了,感谢回复

BingLingGroup commented 3 years ago

请指定源语言,我刚才试了下,当前版本的py-googletrans似乎没法自动识别源语言

Andrea-lyz commented 3 years ago

请指定源语言,我刚才试了下,当前版本的py-googletrans似乎没法自动识别源语言

非常感谢,已成功运行