|
GOOGLE的在线翻译中有个很强大的功能,就是能将翻译后的内容生成音频文件进行朗读,
某天突发奇想,我能不能在线调用他来为我们朗读自已想要的内容呢?
调试了一下,是可以成功的.朗读的语音有点象外国人说中文,呵呵...
觉得挺有趣的,发上来共享一下,写成了函数,如下:
代码: | '************************************************
'*函数功能:调用GOOGLE进行中文语言朗读
'*函数无返回要朗读的中文以字符串传入参数sWord
'*by:hyy514_2011.09
'************************************************
Private Declare Function mciExecute Lib "winmm.dll" ( ByVal lpstrcommand As String ) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( ByVal pCaller As Long , ByVal szURL As String , ByVal szFileName As String , ByVal dwReserved As Long , ByVal lpfnCB As Long ) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" ( ByVal nBufferLength As Long , ByVal lpBuffer As String ) As Long
Private mciID As Integer
Function GoogleSay( ByVal sWord As String )
Dim objJs As Object
Dim sFile As String
Dim sTmpPath As String
sTmpPath = Space(255)
GetTempPath 255, sTmpPath
sTmpPath = Left(sTmpPath, InStr(sTmpPath, Chr(0)) - 1)
sFile = sTmpPath & mciID Mod 2 & ".mp3"
mciID = mciID + 1
Set objJs = CreateObject("MSScriptControl.ScriptControl")
objJs.Language = "JavaScript"
sWord = objJs.Eval("encodeURI('" & Replace(sWord, "'", "\'") & "');")
URLDownloadToFile 0, "http://translate.google.cn/translate_tts?ie=UTF-8&q=" & sWord & "&tl=zh-CN&prev=input", sFile, 0, 0
mciExecute "play " & sFile
End Function | 可以这样调用:
代码: | Sub t()
GoogleSay "来自Excelhome中文网 HYY5_1_4 "
End Sub | 示例文件:
googleSay.rar
(8.31 KB, 下载次数: 525)
|
评分
-
2
查看全部评分
-
|