Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Google speech in Vbscript

Status
Not open for further replies.

crackoo

Programmer
Feb 17, 2011
132
TN
Hi
I want to perform a Google speech in vbscript but i have some issues with this code :
Code:
input = InputBox("Enter a text to Speak","Enter a text to Speak")

HTTPDownload "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q="[/URL] &input,"c:\Gspeak.mp3"
 
Sub HTTPDownload(strFileURL,strHDLocation)
'MsgBox "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q="[/URL] &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 : 800C0005
msxml3.dll
 
The HTTPDownload line is syntactally wrong and you'll likely need to encode input to make it. To a simple degree, change spaces to &.

Code:
input = replace(input, " ", "&")
HTTPDownload "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q="[/URL] & input [red]&[/red] "c:\Gspeak.mp3"

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
oops, just the encoding part need to be done. HTTPDownload line is fine.

-Geates



"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I have a little progress in the script but I do not know why sometimes it works and sometimes does not work especially for Text2speech-ar.mp3
Tested on a Windows XP Pro SP3.
Code:
Title = "Text2Speech Powered by © Google"
inputLang = InputBox("Choose the Language :"&vbcr& "- 1 pour Français "&vbcr& "- 2 For English "&vbcr& "- 3 العربية",Title,"1")
Set ws = CreateObject("wscript.shell")
set fso = CreateObject("scripting.FileSystemObject")
select case inputLang
case 1
input = InputBox("Indiquez un texte à lire",Title,"Salut tout le Monde!") ' French
MsgBox "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q="[/URL] &Escape(input)
URL"[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q="[/URL] &Escape(input)
Download2MP3 "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q="[/URL] &Escape(input),"c:\Text2speech-fr.mp3"
If fso.FileExists("c:\Text2speech-fr.mp3") Then
ws.run "wmplayer.exe c:\Text2speech-fr.mp3",0,True
TerminateProcess "iexplore.exe"
TerminateProcess "wmplayer.exe"
end if
case 2
input = InputBox("Enter text to speech",Title,"Hello World") 'English
MsgBox "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q="[/URL] &Escape(input)
URL"[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q="[/URL] &Escape(input)
Download2MP3 "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q="[/URL] &Escape(input),"c:\Text2speech-en.mp3"
If fso.FileExists("c:\Text2speech-en.mp3") Then
ws.run "wmplayer.exe c:\Text2speech-en.mp3",0,True
TerminateProcess "iexplore.exe"
TerminateProcess "wmplayer.exe"
end if
Case 3
input = InputBox("أدخل النص للخطاب",Title,"199") ' Arabic
MsgBox "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q="[/URL] &Escape(input)
URL"[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=ar&q="[/URL] &Escape(input)
Download2MP3 "[URL unfurl="true"]http://translate.google.com/translate_tts?ie=UTF-8&tl=ar&q="[/URL] &Escape(input),"c:\Text2speech-ar.mp3"
If fso.FileExists("c:\Text2speech-ar.mp3") Then
ws.run "wmplayer.exe c:\Text2speech-ar.mp3",0,True
TerminateProcess "iexplore.exe"
TerminateProcess "wmplayer.exe"
end if
end select


Function Download2MP3(URL,strHDLocation)
Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", URL, False
objXMLHTTP.Send
Set objStream = createobject("Adodb.Stream")
objStream.type = 1
objStream.open
objStream.write objXMLHTTP.responseBody
objStream.savetofile strHDLocation, 2
objStream.close
set objStream = nothing
Set objXMLHTTP = Nothing
End Function

Function URL(adress)
Set ie = CreateObject("InternetExplorer.Application") 
ie.Navigate(adress) 
ie.Visible=False
DO While ie.busy
WScript.Sleep 20
Loop
end Function

Sub TerminateProcess(App)
Ws.Run "cmd /C taskkill /f /im "&App&"",0,TRUE
End Sub

Function Escape(str)
Dim strNocode,out,Car,i
strNocode = "*+-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
out = ""
If Len(str) > 0 Then
 str = Replace(str, " ", "+")
 For i = 1 To Len(str)
  Car = Mid(str, i, 1)
  If InStr(strNocode, Car) Then
    out = out & Car
  Else
    out = out & "%" & Hex(Asc(Car))
  End If
 Next 
End If
Escape = out
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top