2

如何将文本转换为可以通过 python/django 视图在浏览器中播放的音频文件?如何在 python 中进行文本到语音的转换?我想将字符串转换为 .wav 文件,该文件将通过 python/django 视图在浏览器中播放。

例如:

text = "how are you?"
convert text to audio file (text.wav)
open text.wav file & play in browser via django view. 
4

2 回答 2

0

正如Tichodroma所说,在再次提问之前,您应该始终查看是否有人已经问过您的问题。谷歌搜索python text to speech返回http://code.google.com/p/pyspeech/How to make Python speak等。

于 2012-09-28T16:47:31.753 回答
0

我试图按照以下方式做,它对我有用。谢谢。

#Write text to file
text_file_path = '/user/share/project/test.txt'
audio_file_path = '/user/share/project/test.wav'
text_file = open(text_file_path, "w")
text_file.write('How are you?')
text_file.close()

#Convert file
conv = 'flite -f "%s" -o "%s"' % (text_file_path, audio_file_path)
response = commands.getoutput(conv)

if os.path.isfile(audio_file_path):
    response = HttpResponse()
    f = open(audio_file_path, 'rb')
    response['Content-Type'] = 'audio/x-wav'
    response.write(f.read())
    f.close()
    return response
于 2012-10-09T07:21:03.980 回答