有可以翻译视频字幕的软件么??

2022-03-13 科技 61阅读
有时从网上下载到新的电影,却没有中文字幕,好不容易找到个字幕却是英文版的,本程序原理是调用谷哥的翻译功能,仅调用了英翻汉功能,如果需要其他语言可回贴说明一下,改起来应该不难。为便于修改,使用了VBS来写,随时随地可修改.....

1、生成程序:把下列语句存于一个纯文本文件(比如用你系统的“记事本”粘贴进去再存成“字幕翻译.vbs”即可使用。
2、使用方法:把英文字幕的“.srt”文件用鼠标拖到这个程序上松手即可开始自动翻译,翻译完成后自动生成一个同名文件的汉字字幕文件。

'程序调用谷哥的翻译功能,仅调用了英翻汉功能,如果需要其他语言请回贴说明一下,改起来应该不难。
'为便于修改,使用了VBS来写,随时随地可修改……
'使用方法是把“英文字幕。srt”用鼠标拖到这个程序上松手即可开始自动翻译。
'[程序开始]
DimWshShell,file_name,str,val(5000,3),reg,wmi
SetWshShell=WScript.CreateObject("WScript.Shell")
SetobjFSO=CreateObject("Scripting.FileSystemObject")
SetobjShell=CreateObject("Shell.Application")'建立Shell.Applciation对象
SetShell=CreateObject("Shell.Application")
SetobjArgs=WScript.Arguments'取得拖入的文件名
onerrorresumenext
SetwmiService=GetObject("winmgmts:\\.\root\cimv2")'关闭内存中未完全退出占用小于8M的IE
SetwmiObjects=wmiService.ExecQuery("SELECT*FROMWin32_processwherecaption='iexplore.exe'")
ifwmiObjects.count>0then
ForEachwmiObjectInwmiObjects
if(wmiObject.workingsetsize/1048576)next
Endif
file_name=""
ifobjArgs(0)=Emptythenfile_name="No"
WshShell.RegWrite"HKEY_CURRENT_USER\Software\Microsoft\InternetExplorer\Main\WindowTitle","","REG_SZ"'去除标题栏后IE说明
onerrorgoto0
start_time=now()
iffile_name="No"thenmsgbox"未找到匹配文件,请拖动字幕文件到本程序。":Wscript.Quit
setie=wscript.createobject("internetexplorer.application","event_")'创建ie对象'
Setgoogle=WScript.CreateObject("InternetExplorer.Application")
google.visible=false
WshShell.RegDelete"HKEY_CURRENT_USER\Software\Microsoft\InternetExplorer\Main\WindowTitle"'恢复IE标题栏说明为InternetExporer
'ie.fullscreen=0:ie.menubar=0:ie.addressbar=0:ie.toolbar=0:ie.statusbar=0:ie.resizable=1
'不使用全屏'取消菜单栏'取消地址栏'取消工具栏'取消状态栏'允许用户改变窗口大小
ie.width=500:ie.height=500:ie.top=2:ie.navigate"about:blank"'宽高打开空白页面
ie.document.write" -字幕英翻汉程序"
ie.document.write""
ie.document.write"http://bbs.dp168.com/thread-108654-1-1.htmlstyle=font-size:12px;>论坛
"
setwnd=ie.document.parentwindow'设置wnd为窗口对象'
setid=ie.document.all'设置id为document中全部对象的集合'
tmp1=InstrRev(objArgs(0),".")-1'计算中间应使用的中文字幕文件名
iftmp1>0then
ifinstr(objArgs(0),"eng")then
file_name=replace(objArgs(0),"eng","chs")
else
file_name=left(objArgs(0),tmp1)&".chs"&right(objArgs(0),len(objArgs(0))-tmp1)
endif
else
file_name=objArgs(0)&"chs.txt"
endif
onerrorresumenext
objFSO.deletefilefile_name,true
onerrorgoto0
'msgboxfile_name
txt=""
Settmp1=objFSO.OpenTextFile(objArgs(0),1)'打开英文字幕原始文件准备读取
txt=trim(tmp1.ReadAll)'读所有进内存
settmp1=nothing
fori=1to3'修正头部出错
line=mid(txt,i,1)
ifasc(line)=31thenexitfor
next
txt="1"&vbCrLf&right(txt,len(txt)-i)
reg=split(txt,vbCrLf)'在内存中提取已读入的注册表关键字并放入val
count=1
ie.document.write""
ie.visible=1'窗口可见
fori=0toUBound(reg)'翻译开始:读一行处理一行
forj=1toUBound(reg)
ifIsNumeric(reg(i))thenifcint(reg(i))=countthenexitfor
i=i+1
next'出循环时已找到第count句
i=i+1:ifi>UBound(reg)thenexitfor
onerrorresumenext
whileinstr(reg(i),"-->")=0andii=i+1
wend'如果行号是第i,并且下行有表示时间轴的"-->"则后面是文字
iferr.number0then
msgboxerr.number
err.clear
endif
onerrorgoto0
val(count,0)=reg(i)'出循环时已找到有"-->"的时间轴
i=i+1:str=""
ifi>UBound(reg)andcountifcountie.document.write"这个字幕格式不能被识别:
"&file_name&"。
"
Wscript.Quit
endif
exitfor
endif
forj=1toUBound(reg)
iftrim(reg(i))>""thenstr=str®(i)&vbCrLf
if(i+1)>UBound(reg)thenexitfor
ifIsNumeric(reg(i+1))thenifint(reg(i+1))=count+1thenexitfor
i=i+1:ifi>UBound(reg)thenexitfor
next
ifj=UBound(reg)thenstr="Notfindthenstring."
ifright(str,1)=chr(10)orright(str,1)=chr(13)thenstr=left(str,len(str)-1)
ifright(str,1)=chr(10)orright(str,1)=chr(13)thenstr=left(str,len(str)-1)
val(count,1)=str
val(count,2)=trans(str)
ie.document.getElementById("txt")。value=count&vbCrLf&val(count,1)&vbCrLf&val(count,2)&vbCrLf
count=count+1
next
txt=""
fori=1tocount-1
txt=txt&i&vbCrLf&val(i,0)&vbCrLf&val(i,1)
txt=txt&vbCrLf&val(i,2)&vbCrLf&vbCrLf
next
Settmp1=objFSO.OpenTextFile(file_name,8,True,0)'打开TXT准备写入
txt=txt&vbCrLf&vbCrLf
tmp1.write(txt)
tmp1.close
i=datediff("s",start_time,now()):ifi>60thenj=(imod60)&"分"&int(i/60)&"秒"elsej=i&"秒"
k=int(i/(count-1)*100)/100:ifkj=j&"平均每句"&k&"秒"
ie.document.write"

翻译"&count-1&"句用去"&j&",请直接"
ie.document.write"关闭本窗口。
已生成"&file_name&"。


"
ie.document.parentwindow.scrollby0,150
Wscript.Quit
'程序是否在运行
FunctiOnis_Process(ProcessName)'程序是否在运行
dimProcess_n,prog
Setprog=getobject("winmgmts:\\.")。instancesof("win32_process")
ForEachProcess_nInprog
IfLCase(Process_n.name)=LCase(ProcessName)Then
is_Process=1
Else
is_Process=0
EndIf
Next
setprog=nothing
EndFunction
'使用谷歌翻译对应的句子,请注意之前使用了以下两句
'Setgoogle=WScript.CreateObject("InternetExplorer.Application")
'google.visible=false
FunctiOntrans(str_in)
dimi,j,str_out,strURL,ping_time,tmpval
iftrim(str_in)=""thentrans="翻译字符串不能为空":ExitFunction
str_in=trim(replace(str_in,vbCrLf,""))
strURL=trim(replace(str_in,"","%20"))
strURL="http://translate.google.cn/?sl=auto&tl=zh-CN#en/zh-CN/"&strURL&""
google.navigatestrURL
SetobjWMI=GetObject("winmgmts:\\.")
SetcolPings=objWMI.ExecQuery("Select*FromWin32_PingStatuswhereAddress='"&"translate.google.cn"&"'")
ping_time=9999
Onerrorresumenext
ForEachobjPingincolPings
ping_time=objPing.ResponseTime+0
Next
Onerrorgoto0
ifping_time>2000thentrans="翻译服务器太慢,请改时段翻译":ExitFunction
fori=1to5
trans="":str_out="":tmpval=0
wscript.sleepping_time*3
onerrorresumenext
trans=google.document.body.innerText
onerrorgoto0
tmpval=instr(trans,"地址,或者上传文档")+32'之前定义39结果少取了3个,36也少取4个?
iftmpval>0then
trans=right(trans,len(trans)-tmpval)
tmpval=instr(trans,"正式用语")-3
iftmpval>0then
trans=left(trans,tmpval)
tmpval=instr(trans,"仍然翻译")+4
trans=right(trans,len(trans)-tmpval)
tmpval=instr(trans,str_in)
iftmpval>0thentrans=right(trans,len(trans)-tmpval-len(str_in))
whileright(trans,1)=chr(10)orright(trans,1)=chr(13)
trans=left(trans,len(trans)-1)
wend
tmpval=instr(trans,vbCrLf&vbCrLf)
iftmpval>0thentrans=right(trans,len(trans)-tmpval)
whilelen(trans)>len(replace(trans,vbCrLf&vbCrLf,vbCrLf))
trans=replace(trans,vbCrLf&vbCrLf,vbCrLf)
trans=trim(trans)
wend
trans=replace(trans,"","")
trans=replace(trans,"
","
")
ifleft(trans,1)=chr(10)orleft(trans,1)=chr(13)thentrans=right(trans,len(trans)-1)
ifleft(trans,1)=chr(10)orleft(trans,1)=chr(13)thentrans=right(trans,len(trans)-1)
ifleft(trans,1)=chr(10)orleft(trans,1)=chr(13)thentrans=right(trans,len(trans)-1)
ifleft(trans,1)=chr(10)orleft(trans,1)=chr(13)thentrans=right(trans,len(trans)-1)
ifright(trans,1)=chr(10)orright(trans,1)=chr(13)thentrans=left(trans,len(trans)-1)
ifright(trans,1)=chr(10)orright(trans,1)=chr(13)thentrans=left(trans,len(trans)-1)
iftrans>""thenexitfor
endif
endif
next
iftrans=""thentrans="不知道为什么,反复试了5次都取不出翻译结果"
EndFunction
'[程序结束]
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com