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

JSON object must be str, bytes or bytearray, not 'NoneType' #163

Open orophix opened 3 years ago

orophix commented 3 years ago

Make sure you have read the readme, searched and read the issues related to yours. Otherwise it will be considered as a duplicate which will be closed immediately.

Describe the bug Errors when trying to run. To Reproduce Steps to reproduce the behavior:

file = 'file.mp4'
src_language = 'ja' 
dst_language = 'en'
output_format = 'ass'

autosub -i {file} -S {src_language} -D {dst_language} -F {output_format} -o {file}.{output_format}
Sending short-term fragments to Google Speech V2 API and getting result.
Speech-to-Text: 100% |##########################################| Time:  0:02:27
Traceback (most recent call last):
  File "/usr/local/bin/autosub", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/autosub/__init__.py", line 162, in main
    styles_list=styles_list)
  File "/usr/local/lib/python3.6/dist-packages/autosub/cmdline_utils.py", line 1628, in audio_or_video_prcs
    delete_chars=args.trans_delete_chars)
  File "/usr/local/lib/python3.6/dist-packages/autosub/core.py", line 772, in list_to_googletrans
    result_src = translator.detect(content_to_trans).lang
  File "/usr/local/lib/python3.6/dist-packages/googletrans/client.py", line 369, in detect
    translated = self.translate(text, src='auto', dest='en')
  File "/usr/local/lib/python3.6/dist-packages/googletrans/client.py", line 219, in translate
    parsed = json.loads(data[0][2])
  File "/usr/lib/python3.6/json/__init__.py", line 348, in loads
    'not {!r}'.format(s.__class__.__name__))
TypeError: the JSON object must be str, bytes or bytearray, not 'NoneType'
Use this to display your config.

Expected behavior A clear and concise description of what you expected to happen.

To complete without error.

Screenshots If applicable, add screenshots to help explain your problem. But it is not recommended using screenshots to demonstrate the commandline output unless you think it really matters.

Environment (please complete the following information):

Additional context (Optional) Add any other context about the problem here.

BingLingGroup commented 3 years ago

It seems to be this https://github.com/ssut/py-googletrans/issues/234 caused by py-googletrans. Perhaps replacing the dependency to https://github.com/Saravananslb/py-googletranslation may solve this issue.

Currently if you don't have too many subtitles files to do a bulk translation, you can use the following command to do a manual-copy-and-paste translation. (Not listed in the readme)

autosub -i {file} -tapi man -of dst -doc -mts 9820 -tf txt -F ass

This will generate a txt file which contain a certain amount of words to be translated. Then you copy them to any of the translation website such as https://www.deepl.com/translator. After that you copy all the translation results from the website and then overwrite all the content in the previous txt. Then input enter in autosub and do these again until all the content being translated and the translated subtitles will be generated.

orophix commented 3 years ago

Is there an easy way to make it use py-google translation instead?

BingLingGroup commented 3 years ago

I tried these arguments and it works.

autosub -SRC en -D zh -surl translate.google.com -slp 0.1
zhenghan3 commented 3 years ago

It seems to be this ssut/py-googletrans#234 caused by py-googletrans. Perhaps replacing the dependency to https://github.com/Saravananslb/py-googletranslation may solve this issue.

Currently if you don't have too many subtitles files to do a bulk translation, you can use the following command to do a manual-copy-and-paste translation. (Not listed in the readme)

autosub -i {file} -tapi man -of dst -doc -mts 9820 -tf txt -F ass

This will generate a txt file which contain a certain amount of words to be translated. Then you copy them to any of the translation website such as https://www.deepl.com/translator. After that you copy all the translation results from the website and then overwrite all the content in the previous txt. Then input enter in autosub and do these again until all the content being translated and the translated subtitles will be generated.

tried with the command and got the error "autosub: error: unrecognized arguments: -tapi man -mts 9820 -tf txt"

BingLingGroup commented 3 years ago

@zhenghan3 You need to use the latest dev version in the github repo dev branch.

abrichr commented 3 years ago

Not working for me on MacOS:

$ git status
On branch dev
Your branch is up to date with 'origin/dev'.

nothing to commit, working tree clean
$
$ git log -n 1
commit 0d6687831e69195d31d66d503b50113a3939501f (HEAD -> dev, origin/dev, origin/HEAD)
Author: BingLingGroup <42505588+BingLingGroup@users.noreply.github.com>
Date:   Tue Mar 23 15:14:13 2021 +0800

    Fix unable to type into the terminal after running
$ 
$ autosub -i out.mkv -S de-DE -D en -surl translate.google.com -slp 0.1
...
Sending short-term fragments to Google Speech V2 API and getting result.                                                                                                             
Speech-to-Text: 100% |##############################################################################################################################################| Time:  0:07:15 
Traceback (most recent call last):                                                                                                                                                   
...
TypeError: the JSON object must be str, bytes or bytearray, not NoneType  

Edit: after including the SRC option it works:

$ autosub -i out.mkv -S de-DE -SRC de -D en              

Convert source file to "/var/folders/35/pqjnmmwx24d2mtf4frt5dhcc0000gn/T/tmpd8rnw4uf.wav" to detect audio regions.
/usr/local/bin/ffmpeg -hide_banner -y -i "out.mkv" -vn -ac 1 -ar 48000 -loglevel error "/var/folders/35/pqjnmmwx24d2mtf4frt5dhcc0000gn/T/tmpd8rnw4uf.wav"

Use ffprobe to check conversion result.
/usr/local/bin/ffprobe "/var/folders/35/pqjnmmwx24d2mtf4frt5dhcc0000gn/T/tmpd8rnw4uf.wav" -show_format -pretty -loglevel quiet
[FORMAT]                                                                                                                                                                             
filename=/var/folders/35/pqjnmmwx24d2mtf4frt5dhcc0000gn/T/tmpd8rnw4uf.wav              
nb_streams=1
nb_programs=0 
format_name=wav                                                                           
format_long_name=WAV / WAVE (Waveform Audio)
start_time=N/A                                                                            
duration=0:00:25.493333                                                                                                                                                              
size=2.334059 Mibyte
bit_rate=768.024000 Kbit/s                                                                                                                                                           
probe_score=99                                                                                                                                                                       
TAG:encoder=Lavf58.45.100
[/FORMAT]                              

Conversion completed.
Use Auditok to detect speech regions.                                                     
Auditok detection completed.
"/var/folders/35/pqjnmmwx24d2mtf4frt5dhcc0000gn/T/tmpd8rnw4uf.wav" has been deleted.

Converting speech regions to short-term fragments.
Converting: 100% |##################################################################################################################################################| Time:  0:00:00

Sending short-term fragments to Google Speech V2 API and getting result.
Speech-to-Text: 100% |##############################################################################################################################################| Time:  0:00:04

Translating text from "de" to "en".
Translation: 100% |#################################################################################################################################################| Time:  0:00:00
Destination language subtitles file created at "/tmp/autosub/out.en.srt".

All work done.
tangjiahaodw commented 2 years ago

20220510,[0.5.7-alpha]windows发布版使用翻译功能报错'NoneType' object has no attribute 'group',请问如何解决?

BingLingGroup commented 2 years ago

20220510,[0.5.7-alpha]windows发布版使用翻译功能报错'NoneType' object has no attribute 'group',请问如何解决?

https://github.com/BingLingGroup/autosub/issues/163#issuecomment-782791740