好的。我找到了一個辦法,似乎很好。感謝所有幫助過的人!下面是我使用的代碼:
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