2016-04-14 16 views
0

私のpiをコードして、自分のtwitterハッシュタグと電子メールを話そうとしています。どのように私はPythonスクリプトにTTSを組み込むために使用するでしょう。PythonスクリプトにText to Speechを組み込む方法

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

python 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() 
+0

初心者の質問には申し訳ありませんが、どのようにこれを統合しますか? – JimmyJ

+0

次のようなテキストではなく、値の代わりに値を使用することができます。engine.say(code value) –

+0

コードが構文的に正しくありません。適切なインデントはありません。 –

関連する問題