python - "Teach"Python 其他语言(TTS 说话...)如何?

标签 python text-to-speech

所以我找到了这段代码:

#!/usr/bin/python

import sys      #for cmd line argv
import time     #for delay
import pygst        #for playing mp3 stream
import gst      # " "

#take command line args as the input string
input_string = sys.argv
#remove the program name from the argv list
input_string.pop(0)

#convert to google friendly url (with + replacing spaces)
tts_string = '+'.join(input_string)

print tts_string

#use string in combination with the translate url as the stream to be played
music_stream_uri = 'http://translate.google.com/translate_tts?q=' + tts_string
player = gst.element_factory_make("playbin", "player")
player.set_property('uri', music_stream_uri)
player.set_state(gst.STATE_PLAYING)

#requires a delay, if the py process closes before the mp3 has finished it will be cut off.
time.sleep(12)

这是使用 Python 在谷歌翻译中使用谷歌“文本到语音”功能的一个很好的例子,问题是,它只能用英语“说话”!传递西类牙语文本(例如)使 TTS 功能说“西类牙语”,而在浏览器中,TTS 功能(与本例中生成的 URL 格式相同)实际上可以说西类牙语或任何其他语言想要...我尝试更改 url,使用此 url 为程序提供语言代码:

http://translate.google.com/translate_tts?tl=es_MX&q=

(用于识别西类牙语)

但结果是一样的,西类牙式英语...关于为什么会发生这种情况以及如何使其以与网络工具一样多的语言“说话”的任何想法? (或者至少是其他的加英文),呵呵

最佳答案

不要使用tl=es_MX,只使用tl=es

例如:http://translate.google.com/translate_tts?tl=es&q=que+hora+es

关于python - "Teach"Python 其他语言(TTS 说话...)如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9051715/

相关文章:

python - 在不创建菜单项的情况下为功能分配快捷方式

python - 无法导入 `fiona`(OGR 包装器)和 `geopandas`

javascript - JS/JQuery 文本转语音 : How to chain audios?

android - 在android中以编程方式覆盖Text-To-Speech设置中的 "Always use my settings"选项

python - GAE 开发服务器上的 SMTP 电子邮件 - 如何? Python 2.5.4、GAE SDK 1.7.4

python - 将 CNN 的输出传递给 BILSTM

python - 如何使用Scrapy同时运行一个蜘蛛的多个版本?

android - TTS 类 : How to TTS chinese Pinyin?

ios - 在iOS应用程序中使用音频文件或文本进行语音转换

python - Azure TTS 超时 python