最近发现WINDOWS自带的一个辅助发音功能有点意思,于是想到用它来朗读英文文章岂不是很爽,虽然发音不是很清晰也不是太标准,可是有这么个免费的外教口语老师真是很不错,而且错误的单词都能读的哦(它好像是根据构词法来发音的)!
结合刚刚学到的几个方法:用VBS创建IE窗口、获取剪贴板内容等,写了这么个小脚本,最核心的还是 sapi.spvoice 。可以直接把一个包含英文的文本文件拖到本程序上,也可以双机运行在对话矿输入一句英文让他阅读,如果不在对话矿中输入内容的话我设定为提取剪贴板的内容来读,方便浏览网页的时候。
附件中有成品,这里是原代码:
set shl=createobject("wscript.shell")
set spv=createobject("sapi.spvoice")
Set ie= createobject("InternetExplorer.Application")
set fso=createobject("scripting.filesystemobject")
function readfile(txtfile)
set f=fso.opentextfile(txtfile,1)
ie.Navigate "about:blank"
ie.ToolBar= 0
ie.StatusBar= 0
ie.Left= 100
ie.Top= 100
ie.Width= 800
ie.Height= 300
ie.Visible= 1
ie.Document.Title="Reading---"&txtfile
wscript.sleep 421
shl.appactivate "Reading---"
do until f.AtEndOfStream
toread=f.readline
line2="<font color=#0044aa size=16>"&toread&"</font>"
ie.Document.Body.InnerHTML=line1&line2
spv.speak(toread)
loop
f.close
end function
line1="<center><B>现在<a href=http://182484135.qzone.qq.com>据说是李先生</a>正在为你朗读</B><center><BR><BR>"
if wscript.arguments.count<1 then
toread=inputbox("使用方法"&chr(13)&chr(13)&"1 直接把一个文本文件拖动到本程序上"&chr(13)&"2 在此处输入一个英文句子"&chr(13)&"3 不输入任何字符则会读取剪贴板内容","Input")
if not toread="" then
spv.speak(toread)
else
ie.navigate "about:blank"
ie.visible=False
tmpfile=fso.getspecialfolder(2)&"\clipbrd.txt"
set f=fso.opentextfile(tmpfile,2,true)
str=ie.document.parentwindow.clipboarddata.getdata("text")
f.Write str
f.close
wscript.sleep 1000
readfile(tmpfile)
Set f=fso.getfile(tmpfile)
f.delete
end if
else
readfile(wscript.arguments(0))
end if