User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Pi speaks my twitter feed!

Sun Oct 28, 2012 8:29 am

I was reading an article on the raspberry pi wiki about methods of implementing text to speech and that got me thinking about potential solutions which could make use of it. I had this idea about a talking twitter client, a program which would automatically read tweets out as and when they arrived, so one evening while the wife was watching Holby City, this is what I created.

Hear it in action ... http://youtu.be/IWpjcgtv8zs

It uses oauth to authenticate with twitter before opening a twitter user stream, the program then waits for data to appear, when it does, it uses google translate to create an mp3 file which is then stream by mplayer and hey presto, the Pi talks the tweet!

Its not really a finished program, more, a proof of concept, but I thought it might be useful for other people who want to use twitter in their projects and needed a starting point.

I've put the details of how it works, how to install it, the code and how to run it on my blog http://www.stuffaboutcode.com/2012/10/r ... itter.html.

LHIS
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Pi speaks my twitter feed!

Sun Oct 28, 2012 9:05 am

That's pretty cool. I am about to start working on something similar, but it will display the tweet on a 40x2 display.

I don't see a loop in there that's looking for the new tweet. Does the curl stuff fire an event when a new tweet comes in? Can you explain how that works a little bit, please? Pretty please?

Thanks!
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Pi speaks my twitter feed!

Sun Oct 28, 2012 9:41 am

rickseiden wrote:That's pretty cool. I am about to start working on something similar, but it will display the tweet on a 40x2 display.

I don't see a loop in there that's looking for the new tweet. Does the curl stuff fire an event when a new tweet comes in? Can you explain how that works a little bit, please? Pretty please?

Thanks!
The first thing to note, is that this program uses the twitter streaming api https://dev.twitter.com/docs/streaming-apis so new tweets are delivered to you, rather than the more traditional rest api's where you would have had to periodically poll to get new data.

Its managed by:

Code: Select all

class TalkingTwitterStreamClient:
I'm paraphrasing but the line:

Code: Select all

self.conn.setopt(pycurl.WRITEFUNCTION, self.on_receive)
creates a call back which calls the on_receive method when data arrives which needs to be written, there is then some code in on_receive method which checks to make sure a full 'line' of data has been received before outputting

Code: Select all

if data.endswith("\n") and self.buffer.strip():
I reference a good tutorial on my blog which gives some background to how this all works, that would be a good start.
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

nemo096
Posts: 26
Joined: Wed Dec 26, 2012 10:54 am

Re: Pi speaks my twitter feed!

Wed Jul 31, 2013 8:42 pm

Hi LHIS

Could you post just the code you used to grab the status?

I used the tweepy and have this to update the status

Code: Select all

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(sys.argv[1])
Any help is greatly appreciated

Thanks,
Ethan

User avatar
DougieLawson
Posts: 36316
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Pi speaks my twitter feed!

Wed Jul 31, 2013 10:14 pm

My favourite command line Twitter client written in Perl is TTYTTER. http://www.floodgap.com/software/ttytter/

It has a userexit where you can do your own stuff with the tweets it's streaming. You need a little bit of Perl programming skill for that.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

txt3rob
Posts: 365
Joined: Sat Aug 11, 2012 3:45 pm
Contact: Website

Re: Pi speaks my twitter feed!

Tue Aug 06, 2013 10:41 am

rickseiden - one of my to do projects will be displaying it on a 16x2 LCD myself.

will have to post your code when you have yours working see if i can mod it to adafruits LCD.
The Raspberry Pi Hell Guy - Random Ramblings to assist me and others.
http://raspberrypihell.blogspot.com
My Github - http:/www.github.com/random-robbie/
http://www.smspi.co.uk - send free uk sms via your raspberry pi from here

Return to “Graphics, sound and multimedia”