Skip to content

Commit

Permalink
Fourth Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tianclll committed Sep 15, 2023
1 parent 88abf05 commit c84cc0d
Show file tree
Hide file tree
Showing 25 changed files with 26 additions and 19 deletions.
Binary file added DocImgTranslation/.DS_Store
Binary file not shown.
Binary file added DocImgTranslation/FastSAM/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion DocImgTranslation/structure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import cv2
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils
import numpy as np
from bs4 import BeautifulSoup
Expand Down
Binary file added FileTranslation/.DS_Store
Binary file not shown.
Binary file added FileTranslation/Excel/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion FileTranslation/Excel/excel_translation_en2ch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import pandas as pd
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils
from bs4 import BeautifulSoup
import transformers
Expand Down
Binary file added FileTranslation/Image/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion FileTranslation/Image/image_translation_en2ch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import cv2
import numpy as np
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils
from bs4 import BeautifulSoup
from PIL import Image,ImageFont,ImageDraw
Expand Down
2 changes: 1 addition & 1 deletion FileTranslation/PDF/pdf_translation_en2ch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import cv2
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils
import numpy as np
import fitz # fitz就是pip install PyMuPDF
Expand Down
Binary file added FileTranslation/PPT/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion FileTranslation/PPT/ppt_translation_en2ch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils


Expand Down
Binary file added FileTranslation/TXT/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion FileTranslation/TXT/txt_translation_en2ch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils
import transformers
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
Expand Down
2 changes: 1 addition & 1 deletion FileTranslation/Word/word_translation_en2ch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from docx import Document
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils
import transformers
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
Expand Down
2 changes: 1 addition & 1 deletion HyperTranslation/hyper_translation_en2ch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import tkinter as tk
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils
import pyperclip
import transformers
Expand Down
Binary file added ScreenshotTranslation/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file added SubtitleTranslation/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 5 additions & 6 deletions SubtitleTranslation/subtitle_translation_ch2en.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from moviepy.editor import VideoFileClip
from moviepy.editor import TextClip
from moviepy.editor import CompositeVideoClip
import glob
running = True
def cvsecs(time):
print(time)
Expand All @@ -25,7 +24,7 @@ def cvsecs(time):

return float(hours) * 3600 + float(minutes) * 60 + float(seconds) + float(milliseconds) / 1000

def gen_video(video_path, output_file):
def gen_video(video_path, output_file,fps):
# 读取原始视频
video = VideoFileClip(video_path)

Expand Down Expand Up @@ -63,14 +62,14 @@ def gen_video(video_path, output_file):
# 叠加字幕剪辑到视频上
subtitled_video = CompositeVideoClip([subtitled_video.set_audio(None), subtitle_clip])


# 设置视频的持续时间
subtitled_video = subtitled_video.set_duration(video.duration)

print(subtitled_video)
# 添加原始视频的音频
subtitled_video = subtitled_video.set_audio(video.audio)

# 生成输出视频文件
subtitled_video.write_videofile(output_file, codec='libx264',audio_codec="aac")
subtitled_video.write_videofile(output_file, codec='libx264',audio_codec="aac", fps=fps)

def translate(video_path, output_path, type):
src_video = cv2.VideoCapture(video_path)
Expand Down Expand Up @@ -131,7 +130,7 @@ def translate(video_path, output_path, type):

if type == "输出视频":
output_path = os.path.join(output_path, os.path.basename(video_path))
gen_video(video_path, output_path)
gen_video(video_path, output_path,fps)

text = "已处理完成!"
return text
Expand Down
8 changes: 4 additions & 4 deletions SubtitleTranslation/subtitle_translation_en2ch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from moviepy.editor import TextClip
from moviepy.editor import CompositeVideoClip
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils

running = True
Expand All @@ -28,7 +28,7 @@ def cvsecs(time):

return float(hours) * 3600 + float(minutes) * 60 + float(seconds) + float(milliseconds) / 1000

def gen_video(video_path, output_file):
def gen_video(video_path, output_file,fps):
# 读取原始视频
video = VideoFileClip(video_path)

Expand Down Expand Up @@ -73,7 +73,7 @@ def gen_video(video_path, output_file):
subtitled_video = subtitled_video.set_audio(video.audio)

# 生成输出视频文件
subtitled_video.write_videofile(output_file, codec='libx264',audio_codec="aac")
subtitled_video.write_videofile(output_file, fps=fps, codec='libx264',audio_codec="aac")

def translate(video_path, output_path, type):
src_video = cv2.VideoCapture(video_path)
Expand Down Expand Up @@ -135,7 +135,7 @@ def translate(video_path, output_path, type):

if type == "输出视频":
output_path = os.path.join(output_path, os.path.basename(video_path))
gen_video(video_path, output_path)
gen_video(video_path, output_path,fps)

text = "已处理完成!"
return text
Expand Down
8 changes: 8 additions & 0 deletions SubtitleTranslation/tmp.srt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1
0:00:01,000 --> 0:00:01,1500
Let's travel from time to time.

2
0:00:03,000 --> 0:00:03,1500
The story of opening a plant paradise.

Binary file modified Translation/__pycache__/translation_en2ch.cpython-38.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Translation/translation_en2ch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.getcwd())
import my_utils
def translate(text):
model_path = 'models/translate/en-zh'
Expand Down

0 comments on commit c84cc0d

Please sign in to comment.