【问题标题】:How to convert text into audio file and play in browser via python/django?如何将文本转换为音频文件并通过 python/django 在浏览器中播放?
【发布时间】:2012-09-20 02:09:02
【问题描述】:

如何将文本转换为可以通过 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. 

【问题讨论】:

标签: python django django-views text-to-speech


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我尝试按照以下方式进行操作,它对我有用。谢谢。

    #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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-25
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多