get Google Translate TTs Speech

Dossfm0q

Well-known Member
Joined
Mar 9, 2009
Messages
507
Office Version
  1. 2019
Platform
  1. Windows
how to get URL below from Google TTS speech after click Liston Button from inspect Element >> F11 window >> then Network?
can I filter what I need as Medea then copy it through VBA ?
I have problem with ( "Ctrl+4 " SendKeys String:="^4") Some time works and some not, also Keyboard " Num Lock" deactivate how to reactivate

"https://translate.google.com.sa/tra...n=3&tk=656820.834353&client=webapp&prev=input"
VBA Code:
Public Sub Google_TTS()

''''''''''''''
ClosingIE ' Close open IE
'''''''''''''''
    Dim IE As InternetExplorer
    Set IE = Nothing
    Set IE = CreateObject("InternetExplorer.application")
    IELang = "hl=" & "en"
    TrnsFrom = "sl=" & "en"
    TrnsTo = "tl=" & "ar"
    TXT = "My Car" ' orActiveCell
    StrUrl = "https://translate.google.com/?" & IELang & "&tab=wT1&authuser=0#view=home&op=translate&" & TrnsFrom & "&" & TrnsTo & "&text=" & TXT
    With IE
    .Navigate StrUrl
    .Visible = True
  
        SendKeys String:="{F12}" ' call  Inspect Elements
      
        While .Busy Or .ReadyState < 4: DoEvents: Wend
        '.Document.queryselector(".ttsbutton").Click ' or
         Application.Wait Now + TimeValue("00:00:01")
        .Visible = True ' reactive IE for "Ctrl+4 "  SendKeys String:="^4"
        
        ' Some time work smoe not work
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
         SendKeys String:="^4" ' call  Inspect Elements Network
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
         While .Busy Or .ReadyState < 4: DoEvents: Wend

        .Document.queryselector(".src-tts").Click ' all of them work will
      
       '.Quit
       Set IE = Nothing
    End With
End Sub
Private Sub ClosingIE()

On Error Resume Next
    Dim objWMI As Object, objProcess As Object, objProcesses As Object
    Set objWMI = GetObject("winmgmts://.")
    Set objProcesses = objWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'iexplore.exe'")
    For Each objProcess In objProcesses
        Call objProcess.Terminate
    Next
    Set objProcesses = Nothing: Set objWMI = Nothing
    On Error GoTo 0
End Sub
 

Attachments

  • network.gif
    network.gif
    232 KB · Views: 4

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Dan_W

Active Member
Joined
Jul 11, 2018
Messages
258
Office Version
  1. 365
Platform
  1. Windows
Hi - this is a good attempt. There are a few suggestions I would make about changing your code because a fair bit of it is unnecessary.

I know that this has been accomplished by someone in Python (and not VBA), and it does it really well - called gTTS. You could always run that through a shell in VBA and create mp3s that way. It'd be easier. The point is, reading how they had to do it in python suggests that it's going to be a bit tricky.

If you really want to do it only in VBA, I suppose you could always record a WAV file through your microphone as you play the sound. There is VBA code that can do that. It wouldn't sound great though.
 

Watch MrExcel Video

Forum statistics

Threads
1,119,087
Messages
5,576,035
Members
412,694
Latest member
Deaf1Too
Top