我正在尝试编写我的pi来说出我的Twitter主题标签和电子邮件。如何以及如何将TTS合并到我的python脚本中。
import tweepy
import time
import imaplib
import email
consumer_key = 'xxxxxx'
consumer_secret = 'xxxxx'
access_token = 'xxxxxx'
access_token_secret = 'xxxxxx'
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('xxxxx', 'xxxxx')
mail.select('inbox')
obj, data = mail.search(None, 'ALL')
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
class Listener(tweepy.StreamListener):
def on_status(self, status):
print('----------------')
print(status.text)
for hashtag in status.entities['hashtags']:
print("")
return True
#error code
def on_error(self, status_code):
print('Error with code: ' + str(status_code))
return True
def on_timeout(self):
print('timeout')
return true
listener = Listener()
stream = tweepy.Stream(auth, listener)
stream.filter(track=['#123Emergency'])
for num in data [0].split():
type, data = mail.fetch(num, "(UID BODY[1])")
msg = email.message_from_string(data[0][1])
print 'Message %s\n%s\n' % (num, data[0] [1])
所以到目前为止,我有这个,我需要将TTS合并到这个脚本中。我该如何开始?
答案 0 :(得分:1)
你可以使用pyttsx Python库让python说话。
import pyttsx
engine = pyttsx.init()
engine.setProperty('rate', 70)
voices = engine.getProperty('voices')
for voice in voices:
print "Using voice:", repr(voice)
engine.setProperty('voice', voice.id)
engine.say("Hi there, how's you ?")
engine.say("A B C D E F G H I J K L M")
engine.say("N O P Q R S T U V W X Y Z")
engine.say("0 1 2 3 4 5 6 7 8 9")
engine.say("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")
engine.say("Violet Indigo Blue Green Yellow Orange Red")
engine.say("Apple Banana Cherry Date Guava")
engine.runAndWait()