Sign in to follow this  
Followers 0
Exit

[solved] Trouble with accentuated chars in Google text-to-speech

2 posts in this topic

#1 ·  Posted (edited)

Here is my text-to-speech script.

It runs fine when only normal characters are used.

When using accentuated characters, the words are pronounced wrong.

#include <string.au3>
#include <Inet.au3>

_Language("This is an English text")
_Language("Dies ist ein deutscher Text")
_Language("Se trata de un texto español")
_Language("Questo è un testo italiano")
_Language("Ceci est un texte en français")

Func _Language($text)
    Local $sTemp = _INetGetSource("http://translate.google.com/translate_a/t?client=t&sl=auto&text=" & $text)
    Local $aTemp = _StringBetween($sTemp, ',[["', '"]],')
    $sLang = $aTemp[UBound($aTemp) - 1]
    ConsoleWrite($sLang & @LF)
    $sTemp = _INetGetSource("http://translate.google.com/translate_tts?tl=" & $sLang & "&q=" & $text)
    FileWrite(@ScriptFullPath & ".mp3", $sTemp)
    SoundPlay(@ScriptFullPath & ".mp3", 1)
    FileDelete(@ScriptFullPath & ".mp3")
    Return $sLang
EndFunc   ;==>_Language
How to fix it?

 

See fix in next post.

Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Found it.
Added:

$text = __WinHttpURLEncode($text)
and 
_INetGetSource(...."&ie=UTF-8")
#include <string.au3>
#include <Inet.au3>
#include <winhttp.au3>
_Language("This is an English text")
_Language("Dies ist ein deutscher Text")
_Language("Se trata de un texto español")
_Language("Questo è un testo italiano")
_Language("Ceci est un texte en français")

Func _Language($text)
    $text = __WinHttpURLEncode($text)
    Local $sTemp = _INetGetSource("http://translate.google.com/translate_a/t?client=t&sl=auto&text=" & $text & "&ie=UTF-8")
    Local $aTemp = _StringBetween($sTemp, ',[["', '"]],')
    $sLang = $aTemp[UBound($aTemp) - 1]
    ConsoleWrite($sLang & @LF)
    $sTemp = _INetGetSource("http://translate.google.com/translate_tts?tl=" & $sLang & "&q=" & $text & "&ie=UTF-8")
    FileWrite(@ScriptFullPath & ".mp3", $sTemp)
    SoundPlay(@ScriptFullPath & ".mp3", 1)
    FileDelete(@ScriptFullPath & ".mp3")
    Return $sLang
EndFunc   ;==>_Language
Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0