Google TTS- 有没有人最近运气好?

Google TTS- Has anyone had any luck with it recently?

我一直在尝试在我的 Raspberry Pi 2 上使用类似 "JARVIS" 的系统。我尝试过 eSpeak、Festival 和 pico,但我发现 pico 是其中最好的。

但是pico听起来很无聊,完全单调。一些站点有 2013-14 年的帖子,其中用户可以使用 Google 翻译的 TTS。但是,最近 Google 更改了他们的一些政策,因此这些非官方应用程序将无法运行,因此现在它要求验证码和 HTTP 503 错误。

这是我在一个网站上找到的代码示例,该代码曾经可以工作,但自从 Google 的政策更改后就停止了。

#!/usr/bin/python

import urllib, pycurl, os

def downloadFile(url, fileName):
    fp = open(fileName, "wb")
    curl = pycurl.Curl()
    curl.setopt(pycurl.URL, url)
    curl.setopt(pycurl.WRITEDATA, fp)
    curl.perform()
    curl.close()
    fp.close()

def getGoogleSpeechURL(phrase):
    googleTranslateURL = "http://translate.google.com/translate_tts?    tl=en&"
    parameters = {'q': phrase}
    data = urllib.urlencode(parameters)
    googleTranslateURL = "%s%s" % (googleTranslateURL,data)
    return googleTranslateURL

def speakSpeechFromText(phrase):
    googleSpeechURL = getGoogleSpeechURL(phrase)
    downloadFile(googleSpeechURL,"tts.mp3")
    os.system("mplayer tts.mp3 -af extrastereo=0 &")

speakSpeechFromText("testing, testing, 1 2 3.")

有没有人用过 Google TTS?

您可以安装 python 可用的 gtts 包。然后通过使用它,您可以将文本保存在 mp3 文件中然后播放。我使用 gtts 来打招呼的一个简单示例是

tts = gTTS(text=, lang="en")
tts.save("hello.mp3")
os.system("mpg321 hello.mp3")