好的。我找到了一个办法,似乎很好。感谢所有帮助过的人!下面是我使用的代码:
from urllib import quote_plus
def speak(text):
import pydshow
words = text.split()
temp = []
stuff = []
while words:
temp.append(words.pop(0))
if len(temp) == 24:
stuff.append(' '.join(temp))
temp = []
stuff.append(' '.join(temp))
for i in stuff:
pydshow.PlayFileWait('http://api.ispeech.org/api/rest?apikey=8d1e2e5d3909929860aede288d6b974e&format=mp3&action=convert&voice=ukenglishmale&text='+quote_plus(i))
if __name__ == '__main__':
speak('Hello. This is a text-to speech test.')
我觉得这是理想的,因为它使用的API,但它使用的是用于演示程序的API密钥。因此,它永远不会耗尽。关键是8d1e2e5d3909929860aede288d6b974e
。
实际上,你可以在工作中测试这种没有计划,通过键入以下到您的地址栏:
http://api.ispeech.org/api/rest?apikey=8d1e2e5d3909929860aede288d6b974e&format=mp3&action=convert&voice=ukenglishmale&text=
其次是你想说的文字。您还可以调整语言,在此情况下,将ukenglishmale
更改为iSpeech提供的其他内容。例如,ukenglishfemale
。这会说同样的文字,但以一种女性化的声音。
注意:Pydshow是我的DirectShow封装。你可以使用你的。
您的问题是关于如何使用python生成文本到语音 - >文件,或者是关于如何通过Web应用程序传递内容的问题?我不确定要回答的方法。 – jdi 2012-03-30 22:21:53
有两种方法可以实现这一点: 1.如何使用Python生成清晰的语音 或 2.使用Python来流式处理已完成此操作的Web应用程序的输出。 – Xyene 2012-03-30 22:23:11