Skip to content

Instantly share code, notes, and snippets.

@skorotkiewicz
Created December 8, 2016 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skorotkiewicz/f88bcd73159bde75ebc1ed7b66abeb70 to your computer and use it in GitHub Desktop.
Save skorotkiewicz/f88bcd73159bde75ebc1ed7b66abeb70 to your computer and use it in GitHub Desktop.
My Raspberry Pi speech Tweets!
import os, re, time
from twython import TwythonStreamer
# Search terms
TERMS = '#yes'
# Twitter application authentication
APP_KEY = ''
APP_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
# Setup callbacks from Twython Streamer
class BlinkyStreamer(TwythonStreamer):
def on_success(self, data):
if 'text' in data:
print data['text'].encode('utf-8')
tweet = data['text'].encode('utf-8')
tweetToSpeech = re.sub(r'\w+:\/{2}[\d\w-]+(\.[\d\w-]+)*(?:(?:\/[^\s/]*))*', '', tweet) # remove url
os.system('espeak -ven+f2 "{0}" --stdout | aplay 2>/dev/null >/dev/null'.format(tweetToSpeech)) #speech this!
stream = BlinkyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
stream.statuses.filter(track=TERMS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment