python Google文本到Python演讲(TTS),更多信息,请访问http://alexsleat.co.uk/2011/11/14/python-making-use-of-googles

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Google文本到Python演讲(TTS),更多信息,请访问http://alexsleat.co.uk/2011/11/14/python-making-use-of-googles相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python

import sys		#for cmd line argv

#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
#!/usr/bin/python

import time		#for delay
import pygst		#for playing mp3 stream
import gst		# " "

#Play an .mp3 file from the internet
music_stream_uri = 'http://www.sample-url.com/file.mp3'
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)
#!/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 Google文本到Python演讲(TTS),更多信息,请访问http://alexsleat.co.uk/2011/11/14/python-making-use-of-googles的主要内容,如果未能解决你的问题,请参考以下文章

GCS - 从 Google Cloud Storage 直接读取文本文件到 python

正则表达式以python分割文本文件

python 将文本文件添加为Google Keep Notes

Google GAN之父Ian Goodfellow ICLR演讲:GAN的进展与挑战

从 google book api 获取缩略图到 python 变量

Python NTL - 识别文本兴趣/主题