Google speech in Vbscript

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
hackoo
Posts: 103
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Sat Jan 22, 2011 12:27 am

Google speech in Vbscript

Post by hackoo »

Hi !I want to perform a Google speech in vbscript but i have some issues with this code :

Code: Select all

input = InputBox("Enter a text to Speak","Enter a text to Speak")

HTTPDownload "http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q=" &input,"c:Gspeak.mp3" 
 
Sub HTTPDownload(strFileURL,strHDLocation)
'MsgBox "http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q=" &input
    Set Ws = CreateObject("WScript.Shell")
    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
    objXMLHTTP.open "GET", strFileURL, false
    objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0    'Set the stream position to the start
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End If
Set objXMLHTTP = Nothing 
Ws.Run strHDLocation
Set WS = Nothing
End Sub
So i get this

Error Line 10 Caract :5
The system cannot locate the resource specified
Code : 800C0005msxml3.dll

User avatar
jhicks
Posts: 1789
Joined: Sun Jan 21, 2007 11:31 pm

Google speech in Vbscript

Post by jhicks »

Also, if input has spaces you need to encode them in HTML.

User avatar
jhicks
Posts: 1789
Joined: Sun Jan 21, 2007 11:31 pm

Google speech in Vbscript

Post by jhicks »

If you have spaces you need to use %20. Look at the URL in the browser. I would try testing with a hard coded input string first.

User avatar
hackoo
Posts: 103
Joined: Sat Jan 22, 2011 12:27 am

Google speech in Vbscript

Post by hackoo »

Well I did with another method but it's not exactly what I want to do ; because I want to retrieve the file.mp3 by saving it on my hard drive.
So with this code I just read the text without Saving the file.mp3 on my hard disk

Code: Select all

Function URL(adress)
Set ie = CreateObject("InternetExplorer.Application") 
ie.Navigate(adress) 
ie.Visible=false
DO While ie.busy
WScript.Sleep 20
Loop
URL = ie.document.documentElement.innertext 
end Function
input = InputBox("Indiquez un texte à lire","Indiquez un texte à lire")
URL"http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q=" &input
Is there a method or trick to retrieve and save the file.mp3
Thank You !


User avatar
jhicks
Posts: 1789
Joined: Sun Jan 21, 2007 11:31 pm

Google speech in Vbscript

Post by jhicks »

Can you use PowerShell instead? This might be easier with the .NET Webclient class.

jvierra
Posts: 14444
Joined: Tue May 22, 2007 9:57 am
Contact:

Google speech in Vbscript

Post by jvierra »

I already posted this answer for you.

Here it is again:

Code: Select all

HTTPDownload "http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q=hello you idiot","e:test2Gspeak.mp3"
Sub HTTPDownload(strFileURL,strHDLocation)
    Set objXMLHTTP = CreateObject("Msxml2.XMLHTTP.4.0")
    objXMLHTTP.open "GET", strFileURL, False
    objXMLHTTP.send()
    If objXMLHTTP.Status = 200 Then
        Set objADOStream = CreateObject("ADODB.Stream")
        objADOStream.Open
        objADOStream.Type = 1 'adTypeBinary
        objADOStream.Write objXMLHTTP.ResponseBody
        objADOStream.Position = 0    'Set the stream position to the start
        objADOStream.SaveToFile strHDLocation, 2
        objADOStream.Close
        Set Ws = CreateObject("WScript.Shell")
        Ws.Run strHDLocation
    Else
        WScript.Echo "Status not good:" & objXMLHTTP.Status 
    End If
    
End Sub

I removed some mistakes in logic and unnecessary lines of code. I also switched to using teh newer MSXML v4 which should exists on all systems post XP.

If that fails use MSXML2.XMLHTTP which should load the latest version available.

Your XML may be damaged

Objects will be set to nothing by system when subroutine exits. Setting them to nothing is not normally necessary in scripting.

jvierra
2012-04-09 10:59:59

Locked