Install AutoSub Step to Step in Windows with Translate subtitle

Hướng dẫn tạo phụ đề tự động cho Video bằng phần mềm Autosub

Trong bài viết này mình sẽ hướng dẫn các bạn tự tạo subtitle cho video một cách hoàn toàn tự động bằng cách nhận diện giọng nói của Google Speech API. Trong bài viết mình sẽ làm mẫu ví dụ 02 đoạn video tiếng Anh và tiếng Tây Ban Nha để có thể tự động dịch và hiện subtitle. Sau đó có thể tự động chuyển sang ngôn ngữ khác nếu muốn.

Cách hoạt động của nó dựa trên nguyên lý lấy một file âm thanh audio ( hoặc video) làm đầu vào để dò tìm các vùng hội thoại và gửi cho Google Speech API để xử lý và chuyển thành văn bản, sau đó xuất ra định dạng .srt

Hướng dẫn tạo phụ đề tự động cho Video bằng phần mềm Autosub
Hướng dẫn tạo phụ đề tự động cho Video bằng phần mềm Autosub

Install AutoSub Step to Step in Windows with Translate subtitle

Yêu cầu cần có để có thể làm việc:
Windows 32 or 64 bits.
Yêu cầu có kết nối Internet.
Links Downloads các công cụ cần thiết
Python
FFMPEG
AutoInstall autosub_app 0.3.12.zip
SampleVideos Spanish – English.zip
Subtitle Editor Aegisub
Đối với phiên bản Version autosub 0.3.9 bạn phải gỡ bỏ Python 3.x và cài đặt Python 2.x

Xem Video hướng dẫn chi tiế tại Youtube

Bước 1: Cài đặt Python 2.7 (32 bits) (nếu máy tính của bạn là 64 bit thì tải bản 64bit nha)
https://www.python.org

## Lưu ý: Nhớ chọn Add Python.exe to Path

Bước 2: Chạy cmd (Win+R)
C:\Python27\Scripts\pip.exe install autosub

Hoặc
C:\Python27\Scripts\pip.exe install https://pypi.python.org/packages/35/7b/9d5361c0f7abfcc6d826a5279b1c4501f7616505629f6c54857587ec6e37/autosub-0.3.9.tar.gz

Hoặc
(Tải phiên bản mới nhất tại https://pypi.python.org/pypi/autosub)

C:\Python27\Scripts\pip.exe install “c:\youdownloaded\autosub-0.3.9.tar.gz”

Hiện thông báo như bên dưới là OK nhé

Installing collected packages: autosub
Successfully installed autosub-0.3.9

Bước 3: Đổi tên File “autosub” thành “autosub_app.py” bằng lệnh cmd

Rename C:\Python27\Scripts\autosub autosub_app.py

Bước 4: Mở file autosub_app.py bằng notepad.exe hoặc Notepad++(Edit Text) hoặc bất cứ trình soạn thảo đơn giản nào mà bạn có.

4.1 Tại dòng 48 thêm vào “, delete=False”
temp = tempfile.NamedTemporaryFile(suffix=’.flac’)
Thay bằng
temp = tempfile.NamedTemporaryFile(suffix=’.flac’, delete=False)

4.2 Tại dòng 53 os.system(‘stty sane’). (Optional)

Thông tin Cập nhật cho phiên bản mới Version Autosub (23 May 2017)
Áp dụng cho Windows xp,7,8,10
Tìm đến các dòng code bên dưới và đổi chúng cho chuẩn:

Dòng 127

exe_file = os.path.join(path, program)
Đổi thành
exe_file = os.path.join(path, program + “.exe”)

Dòng 47
temp = tempfile.NamedTemporaryFile(suffix=’.flac’)

đổi thành

temp = tempfile.NamedTemporaryFile(suffix=’.flac’, delete=False)

Bước 5: Download FFMPEG phiên bản mới nhất, lựa chọn 32bit hoặc 64bit cho phù hợp(https://ffmpeg.zeranoe.com/builds/) sau đó Copy file ffmpeg.exe vào thư mục C:\Python27\

Bước 6: Khởi động lại máy tính để các thay đổi cài đặt có hiệu lực

Bước 7: Kiểm tra xem có hoạt động hay không bạn gỏ lênh bên dưới vào cmd (copy và dán vào rồi enter thôi)
C:\Python27\python.exe C:\Python27\scripts\autosub_app.py –list-languages

Link tải video mẫu và file autosub_app chuẩn
SampleVideos Spanish – English.zip
autosub_app 0.3.12.zip

Tự động tạo Subtitle cho bất kỳ video file nào bạn muốn.

Tiếng Tây Ban Nha – Spanish
C:\Python27\python.exe C:\Python27\scripts\autosub_app.py -S es -D es TuVideo.mp4

Tiếng Anh – English ( đây là ngôn ngữ mặt định nếu không có thông số)
C:\Python27\python.exe C:\Python27\scripts\autosub_app.py -S en -D en YouVideo.mp4

Tiếng Nhật – Japanese
C:\Python27\python.exe C:\Python27\scripts\autosub_app.py -S ja -D ja YouAnimeVideo.mp4

Tùy chọn thêm cho bạn nào muốn gọn hơn

Biên dịch script Python(Tạo File thực thi Exe)
C:\Python27\python.exe -m compileall C:\Python27\scripts\autosub_app.py
Ví dụ chạy lệnh
C:\Python27\scripts\autosub_app.pyc YouVideo.mp4 (English là ngôn ngữ mặt định)

Upgrade Pip thì chạy lệnh bên dưới
python -m pip install –upgrade pip

Tự động tạo phụ đề chỉ với 1 cú click chuột

Tài file autosub_app.zip về máy tính của bạn

Chạy file Install_AutoSub.bat để sao chép code thực thi vào thư mục SenTo.
Bạn có thể mở thư mục này bằng cách gõ dòng bên dưới vào khung RUN ( Start –> Run hoặc bấn phím Windows + R)
“%APPDATA%\Microsoft\Windows\SendTo”

Hoặc gõ shell:sendto để mở Folder SENDTO

sendto shell

Các file code mẫu sẽ được sao chép đến thư mục đó và để các bạn tiện dụng khi nhấp chuột phải chọn SenTo

Code mẫu trong file AutoSub_Jap.bat có dạng

C:\Python27\python.exe C:\Python27\Scripts\autosub_app.py -C 2 -S ja -D ja %1

Bạn hoàn toàn có thể tạo thêm nhiều file .bat của các ngôn ngữ khác, chỉ cần đổi ký hiệu ngôn ngữ quốc gia là được. Ví dụ tiếng Anh thì là en, còn tiếng Nhật là ja, trong tiếng Việt thì là vi. Muốn biết phần mềm hỗ trợ các ngôn ngữ và mã quốc gia nào thì bạn chạy lệnh hiện ngôn ngữ nha.

C:\Python27\python.exe C:\Python27\scripts\autosub_app.py –list-languages

7.- Dịch tự động Subtitles sang các ngôn ngữ khác

Download Subtitle Edit tại về máy tính https://github.com/SubtitleEdit/subtitleedit/releases

Chạy file SubtitleEdit.exe để cài đặt
Mở Subtitle bất kỳ file nào có định dạng .srt(TuVideo.srt,YouAnimeVideo.srt,YouVideo)
Click vào Menu-Auto-Translate-(PowerbyGoogle)
Lựa chọn ngôn ngữ, ví dụ ở đây là dịch từ tiếng Nhật sang tiếng Anh – From(Japanese) To:English
Click Translate để bắt đầu dịch tự động

Hoặc bạn có thể sử dụng phần mề SRT -Tran tải tại địa chỉ https://sourceforge.net/projects/srt-tran/


(hình ảnh dịch SRTTRANSLATOR)

Kết quả đạt được xem tại Link Video Youtube

Một số lỗi thương gặp trong quá trình cài đặt – Errors Commons in Windows

Lỗi cài đặt pip
“python setup.py egg_info”
Giải pháp
Cài đặt Python 2.7 gỡ bỏ phiên bản Python 3.x

Lỗi hiển thị “WindowsError [Error 2]”

C:\Python27>python.exe C:\Python27\scripts\autosub_app.py -S en -D en test.mp4
Traceback (most recent call last):
File “C:\Python27\scripts\autosub_app.py”, line 284, in <module>
sys.exit(main())
File “C:\Python27\scripts\autosub_app.py”, line 210, in main
audio_filename, audio_rate = extract_audio(args.source_path)
File “C:\Python27\scripts\autosub_app.py”, line 120, in extract_audio
subprocess.check_output(command)
File “C:\Python27\lib\subprocess.py”, line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File “C:\Python27\lib\subprocess.py”, line 710, in __init__
errread, errwrite)
File “C:\Python27\lib\subprocess.py”, line 958, in _execute_child
startupinfo)
WindowsError: [Error 2]

Giải pháp khắc phục

Copy ffmpeg.exe vào thư mục C:\Python27\
Hoặc
Or ADD Path (Directory) File ffmpeg.
Examples: c:\ffmpeg\ , c:\Program Files\ffmpeg, c:\Mydownloads
Link Help Add Path(Directory)
http://www.computerhope.com/issues/ch000549.htm
python

Lỗi Error infinite loop

“File “C:\Python27\lib\multiprocessing\forking.py”, line 380″
“File “C:\Python27\lib\multiprocessing\forking.py”, line 503″
ImportError : prepare(preparation_data)

Giải pháp

Đổi tên file từ autosub thành autosub_app.py
C:\Python27\Scripts\autosub autosub_app.py

Lỗi Error Permission denied Files Flac
c:…local\temp\tmpksjd.flac Permission denied
Giải pháp:
Thay đổi file autosub_app.py theo hướng dẫn tại 4.1

———————-Before – Original————————-

class FLACConverter(object):
def __init__(self, source_path, include_before=0.25, include_after=0.25):
self.source_path = source_path
self.include_before = include_before
self.include_after = include_after

def __call__(self, region):
try:
start, end = region
start = max(0, start – self.include_before)
end += self.include_after
temp = tempfile.NamedTemporaryFile(suffix=’.flac’)
command = [“ffmpeg”, “-y”, “-i”, self.source_path,
“-ss”, str(start), “-t”, str(end – start),
“-loglevel”, “error”, temp.name] subprocess.check_output(command)
os.system(‘stty sane’)
return temp.read()
———————-After – Modified Option 1 ————————

class FLACConverter(object):
def __init__(self, source_path, include_before=0.25, include_after=0.25):
self.source_path = source_path
self.include_before = include_before
self.include_after = include_after

def __call__(self, region):
try:
start, end = region
start = max(0, start – self.include_before)
end += self.include_after
temp = tempfile.NamedTemporaryFile(suffix=’.flac’)
temp.close()
command = [“ffmpeg”, “-y”, “-i”, self.source_path,
“-ss”, str(start), “-t”, str(end – start),
“-loglevel”, “error”, temp.name] subprocess.check_output(command)
return open(temp.name, “rb”).read()
———————-after – Modified Option 2 ————————

class FLACConverter(object):
def __init__(self, source_path, include_before=0.25, include_after=0.25):
self.source_path = source_path
self.include_before = include_before
self.include_after = include_after

def __call__(self, region):
try:
start, end = region
start = max(0, start – self.include_before)
end += self.include_after
temp = tempfile.NamedTemporaryFile(suffix=’.flac’, delete=False)
command = [“ffmpeg”, “-y”, “-i”, self.source_path,
“-ss”, str(start), “-t”, str(end – start),
“-loglevel”, “error”, temp.name] subprocess.check_output(command)
return temp.read()

except KeyboardInterrupt:
return
Message Normal Output Pip install autosub

Collecting autosub
Downloading autosub-0.3.9.tar.gz
Collecting google-api-python-client>=1.4.2 (from autosub)
Downloading google_api_python_client-1.5.1-py2.py3-none-any.whl (50kB)
Collecting requests>=2.3.0 (from autosub)
Downloading requests-2.11.0-py2.py3-none-any.whl (514kB)
Collecting pysrt>=1.0.1 (from autosub)
Downloading pysrt-1.1.1.tar.gz (104kB)
Collecting progressbar>=2.3 (from autosub)
Downloading progressbar-2.3.tar.gz
Collecting six<2,>=1.6.1 (from google-api-python-client>=1.4.2->autosub)
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting uritemplate<1,>=0.6 (from google-api-python-client>=1.4.2->autosub)
Downloading uritemplate-0.6.tar.gz
Collecting httplib2<1,>=0.8 (from google-api-python-client>=1.4.2->autosub)
Downloading httplib2-0.9.2.zip (210kB)
Collecting oauth2client (from google-api-python-client>=1.4.2->autosub)
Downloading oauth2client-3.0.0.tar.gz (77kB)
Collecting chardet (from pysrt>=1.0.1->autosub)
Downloading chardet-2.3.0.tar.gz (164kB)
Collecting simplejson>=2.5.0 (from uritemplate<1,>=0.6->google-api-python-client>=1.4.2->autosub)
Downloading simplejson-3.8.2-cp27-cp27m-win32.whl (65kB)
Collecting pyasn1>=0.1.7 (from oauth2client->google-api-python-client>=1.4.2->autosub)
Downloading pyasn1-0.1.9-py2.py3-none-any.whl
Collecting pyasn1-modules>=0.0.5 (from oauth2client->google-api-python-client>=1.4.2->autosub)
Downloading pyasn1_modules-0.0.8-py2.py3-none-any.whl
Collecting rsa>=3.1.4 (from oauth2client->google-api-python-client>=1.4.2->autosub)
Downloading rsa-3.4.2-py2.py3-none-any.whl (46kB)
Installing collected packages: six, simplejson, uritemplate, httplib2, pyasn1, pyasn1-modules, rsa, oauth2client, google-api-python-client, requests, chardet, pysrt, progressbar, autosub
Running setup.py install for uritemplate: started
Running setup.py install for uritemplate: finished with status ‘done’
Running setup.py install for httplib2: started
Running setup.py install for httplib2: finished with status ‘done’
Running setup.py install for oauth2client: started
Running setup.py install for oauth2client: finished with status ‘done’
Running setup.py install for chardet: started
Running setup.py install for chardet: finished with status ‘done’
Running setup.py install for pysrt: started
Running setup.py install for pysrt: finished with status ‘done’
Running setup.py install for progressbar: started
Running setup.py install for progressbar: finished with status ‘done’
Running setup.py install for autosub: started
Running setup.py install for autosub: finished with status ‘done’
Successfully installed autosub-0.3.9 chardet-2.3.0 google-api-python-client-1.5.1 httplib2-0.9.2 oauth2client-3.0.0 progressbar-2.3 pyasn1-0.1.9 pyasn1-modules-0.0.8 pysrt-1.1.1 requests-2.11.0 rsa-3.4.2 simplejson-3.8.2 six-1.10.0 uritemplate-0.6

Đối với phiên bản Version autosub 0.3.9 bạn tải file bên dưới về rồi đổi tên autosub_app.py.txt thành autosub_app.py, sau đó sao chép vào thư mục C:\Python27\Scripts

autosub_app.py.txt
SampleVideos Spanish – English.zip
autosub_app 0.3.12.zip

Lỗi Exception: Dependency not found: ffmpeg

C:\Users”NAME”>C:\Python27\python.exe C:\Python27\scripts\autosub_app.p
y -S en -D en c:\1.ZBrush_Introduction.mkv
ffmpeg: Executable not found on machine.
Traceback (most recent call last):
File “C:\Python27\scripts\autosub_app.py”, line 304, in
sys.exit(main())
File “C:\Python27\scripts\autosub_app.py”, line 230, in main
audio_filename, audio_rate = extract_audio(args.source_path)
File “C:\Python27\scripts\autosub_app.py”, line 140, in extract_audio
raise Exception(“Dependency not found: ffmpeg”)
Exception: Dependency not found: ffmpeg

Giải pháp: Lỗi này phát sinh là do không tìm thấy file ffmpeg để thực thi code, bạn có thể khắc phục nhanh bằng cách sao chép file ffmpeg nằm cùng thư mục file video mà bạn đang thực thi.

Chúc các bạn thành công, nhớ đăng ký kênh Youtube của mình để nhận thêm nhiều video hay nữa nhé.

Subscribe
Notify of
guest
18 Bình luận
Cũ nhất
Mới nhất Most Voted
Inline Feedbacks
View all comments
Hyen

Chào bạn, mình đã cài autosub theo cách của bạn thì ban đầu chạy rất ok, nhưng hôm nay quét sub ra sự cố. Mình install lại thì ở phần cmd: C:\Python27\Scripts\pip.exe install autosub Mình lại gặp lỗi như thế này C:\Users\Tham>C:\Python27\Scripts\pip.exe install autosub Collecting autosub Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAI LED] certificate verify failed (_ssl.c:590)’),)’: /simple/autosub/ Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAI LED] certificate verify failed (_ssl.c:590)’),)’: /simple/autosub/ Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAI LED] certificate verify… Đọc thêm »

pham locthanh

chao ban minh cai xong xai rat ok cho minh hoi la co code tieng trung khong ak\

khoa

chào bạn mình muốn chỉnh màu cho chữ thì làm sao bạn

Hung

chào bạn!
Cho mình hỏi là mình làm theo như đúng hướng dẫn.
Nhưng sau khi chọn Video rồi Sendto để Sub thì nó chỉ hiện lê bảng đen sau đó tắt đi.
Lỗi đó là sao vậy bạn?

thang

không được :< giá như có thể gửi ảnh cho bạn nó k tự dịch :<

fumetsuno2003

Có tiếng việt, tiếng trung không ạ?

Hoa Yen

Anh ơi trên video em tải về theo link của a ,ko hiện nút để nhấn vào thêm phụ đề thì phải làm sao ạ?

Phan Văn Khoa

Bạn ơi, Mình đã làm theo hướng dẫn nhưng khi SendTo Video thì hiện lên bảng đen rồi tắt luôn (mặc dù mình đã copy file ffmpeg.exe vào thu mục có video). Có cách nào để khắc phục không ạ? Mình cảm ơn.

Thanh Huong

Bạn cho Hỏi chút, Sau khi chạy phần mềm dịch tự động file Subtitle được khoảng hơn 10 lần thì giờ toàn báo lỗi connection Translation service bắt check Internet connection. Cho dù vẫn mở được google translate bình thường và dịch từng câu đc, như vậy phỉ đăng ký khóa cho API trong Seting/ Tools và gắn khoá API của google translate à bạn ơi??

Nguyễn An

Bạn có thể hướng dẫn rõ hôn cách dùng API khác để dịch và những phần mềm nào tương tự Autosub không ạ?
Thanks bạn!!

Nguyễn An

Khi mình load video bằng autosub thì trong Khung cmd Autosub
Dòng đầu tiên Converter…. chạy rất nhanh
Đến dòng 2 Performing ….. chạy rất chậm là lỗi sao vậy ạ??
Xin Bạn giải đáp giúp mình. Thanks bạn nhiều..!!

18
0
Would love your thoughts, please comment.x