Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Google Text to Speech TTS


  • Please log in to reply
22 replies to this topic
johfor77
  • Members
  • 39 posts
  • Last active: Jan 13 2015 02:04 PM
  • Joined: 18 Mar 2011
I did a wireshark to see what I'm sending to google translate and this is what i got.

sending åäö I get this,
Request URI: /translate_tts?tl=sv&q=\xe5\xe4\xf6

Edit: in wireshark it displays /translate_tts?tl=sv&q=\345\344\366
weird copy paste thing
**********************************

sending abc I get this on the same spot
Request URI: /translate_tts?tl=sv&q=abc
**********************************

using web browser to adress
<!-- m -->http://translate.goo...te_tts?tl=sv&q=<!-- m -->åäö
witch change when pressing enter to
<!-- m -->http://translate.goo...<!-- m -->

Request URI: /translate_tts?tl=sv&q=%E5%E4%F6

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
It should return the same thing if you send /translate_tts?tl=sv&q=%E5%E4%F6 in the URL, %E5, %E4 and %F6 are the three URL codes for å, ä and ö.
I'm partway into a subroutine convertor using StringReplace, I'll finish it tomorrow :) still trying to figure out how to get the original name on the mp3. I think I'm confused though lol

johfor77
  • Members
  • 39 posts
  • Last active: Jan 13 2015 02:04 PM
  • Joined: 18 Mar 2011
does not do any difference if I change the åäö to %E5%E4%F6
even if I change the line below I still get the same result
UrlDownloadToFile, http://translate.google.com/translate_tts?tl=%Lang%&q=%Input%, c:\GoogleSpeech\%Input%.mp3
to
UrlDownloadToFile, http://translate.google.com/translate_tts?tl=sv&q=%E5%E4%F6, c:\GoogleSpeech\%Input%.mp3
Actualy, even if I change the line to below gets the same thing
UrlDownloadToFile, http://tinyurl.com/6cljyjo, c:\GoogleSpeech\%Input%.mp3
<!-- m -->http://translate.goo...ts?tl=sv&q=<!-- m -->åäö.
So replacing characters might not be the solution...

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
There does seem to be a a small need to replace some characters, like quotation marks and question marks... number signs are ignored, and plus signs, semicolons mess it up, etc... they block stuff in the URL and nothing is returned. I put together a little something below. Remember I'm still learning as well so... :) This one copies the User's input to the clipboard and then replaces characters in the URL. When the Mp3 is finished playing, it is renamed to what was given to the clipboard... so the Mp3's name is what the User typed. Most of the time.
FileCreateDir, c:\GoogleSpeech ; makes folder in temp folder
Gui, Color, 222222 ; Dark grey background
Gui, Add, DropDownList, w40 x5 y5 vLang Choose1, sv|en|fr|es|de|fi|el|ja|pl|ru|uk
Gui, Add, Edit, w120 x50 y5 vName, type here ; makes search edit box
Gui, add, button, w80 x5 y30 Default, Speech ; ENTER presses this button
Gui, add, button, w80 x90 y30, Open Folder
Gui, Show, w175 h60, Speech
Send, {TAB} ; pressed TAB once to highlight default search-box text
return

ButtonSpeech:
Gui, Submit, NoHide ; sends input to variable
GoSub URLconvert ; Converts characters for URL string in Google Translate
FileDelete, c:\GoogleSpeech\*.mp3 ; gets rid of existing speech file
UrlDownloadToFile, http://translate.google.com/translate_tts?tl=%Lang%&q=%Name%, c:\GoogleSpeech\%Name%.mp3
Soundplay, c:\GoogleSpeech\%Name%.mp3, Wait ; plays the downloaded speech file and waits for it to finish
GoSub RenameSavedMp3 ; Replaces any URL substitutions for original characters
return

ButtonOpenFolder:
Run, explore c:\GoogleSpeech
return

GuiClose:
ExitApp

URLconvert:
If Name = ; If User does not type anything, message is shown
  {
    MsgBox Please type something.
    return
  }
; msgbox before conversion: %Name% ; uncomment this line to see message box with original input
StringReplace, Name, Name, `",, All ; quotation marks seem to cause problems generally, all are first removed
Clipboard = %Name% ; original Name variable is sent to clipboard
StringReplace, Name, Name, %A_Space%, `%20, All ; spaces are replaced for URL
StringReplace, Name, Name, `?,, All ; question marks seem to cause problems in sending URL, all are removed
StringReplace, Name, Name, `#, `%20, All ; number signs
StringReplace, Name, Name, `', `%27, All ; apostrophes
StringReplace, Name, Name, `&, `%26, All ; ampersands
StringReplace, Name, Name, `$, dollars, All ; dollar signs (substitute your own language here)
StringReplace, Name, Name, `+, plus, All ; plus signs (substitute your own language here)
StringReplace, Name, Name, `,, `%2C, All ; comma
StringReplace, Name, Name, `-, `%2D, All ; dashes
StringReplace, Name, Name, `., `%2E, All ; periods
StringReplace, Name, Name, `:, `%20, All ; semicolons seem to cause problems, replaced with spaces
StringReplace, Name, Name, `;, `%20, All ; these characters seem to cause problems, replaced with spaces
StringReplace, Name, Name, `/, `%20, All ; forward slashes seem to cause problems, all are removed
; msgbox after conversion: %Name% ; uncomment this line to see message box with URL converted input
return

RenameSavedMp3:
Name = %Clipboard%
FileMove, c:\GoogleSpeech\*.mp3, c:\GoogleSpeech\%Name%.mp3, 1 ; Mp3 file name is restored from clipboard
return



thesoupmeat
  • Members
  • 188 posts
  • Last active: Mar 10 2013 04:30 AM
  • Joined: 03 Jun 2010
anyway we can do the reverse as well? as in use chrome's very nice voice recognition engine to get a string input

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
aaronbewza: that's Percent_Encoding :wink:
I wrote you functions for it :D

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Hey!! :D that's a 2+2 I never realized. yes since May you've built the percent-encoder which would be perfect for this... with it, anything in the URL will be automatically swapped for it's equivalent in percentage. Cool!!

  • Guests
  • Last active:
  • Joined: --

does not do any difference if I change the åäö to %E5%E4%F6
even if I change the line below I still get the same result

UrlDownloadToFile, http://translate.google.com/translate_tts?tl=%Lang%&q=%Input%, c:\GoogleSpeech\%Input%.mp3
to
UrlDownloadToFile, http://translate.google.com/translate_tts?tl=sv&q=%E5%E4%F6, c:\GoogleSpeech\%Input%.mp3
Actualy, even if I change the line to below gets the same thing
UrlDownloadToFile, http://tinyurl.com/6cljyjo, c:\GoogleSpeech\%Input%.mp3
<!-- m -->http://translate.goo...ts?tl=sv&q=<!-- m -->åäö.
So replacing characters might not be the solution...


Google translate TTS will return 404 if Referer in the header. It will also return 403 if there is no User-Agent. Make use you both have this when accessing the web service. Here is blog about a working implementation IT IS A java servlet.

<!-- m -->http://kahimyang.inf...ogs.xhtml?b=757<!-- m -->