“教导” Python 其他语言(TTS 语言...)如何?
所以我找到了这段代码:
#!/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)
Wich是使用Python在谷歌翻译中使用谷歌“文本到语音”功能的一个很好的例子,问题是,它只能用英语“说话”!传递西班牙语文本(例如)会使 TTS 功能说“西班牙英语”,而在浏览器中,TTS 功能(与本示例中生成的 URL 格式相同)实际上可以用西班牙语或您选择的任何其他语言说话想要...我尝试更改网址,使用以下网址为程序提供语言代码:(
http://translate.google.com/translate_tts?tl=es_MX&q=
用于西班牙语识别)
但结果是相同的,西班牙语...关于为什么会发生这种情况以及如何使其“说话”的任何想法“ 在多种语言中网络工具? (或者至少是其他一加英语),呵呵
So I found this code:
#!/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)
Wich is a great example of usage of the Google's "Text to Speech" Feature available in Google Translate using Python, the problem is, it only can "speak" in English! passing a text in spanish (for example) makes the TTS feature to speak "spanglish" while in the browser the TTS Feature (with an identical URL format compared to the one generated in this example) can ACTUALLY speak in spanish or any other language you want... I tried to change the url giving the program a language code using this url:
http://translate.google.com/translate_tts?tl=es_MX&q=
(For spanish recognition)
But the result was the same, Spanglish... Any ideas of Why this is happening and How to make it "speak" in as many languages as the web tool? (or at least in other one plus english), hehe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用
tl=es_MX
,只需使用tl=es
。例如:http://translate.google.com/translate_tts?tl=es&q =que+hora+es
Don't use
tl=es_MX
, just usetl=es
.Por ejemplo: http://translate.google.com/translate_tts?tl=es&q=que+hora+es