This will allow you to produce a basic program which makes a Raspberry Pi (or any computer with Python) speak the latest tweet from a particular person or search.
Espeak is a text to speech engine.
To install it you need to type sudo apt-get install espeak into the terminal on the Raspberry Pi
Whilst espeak provides the text to speech engine, it doesn’t come with a python interface. For this we need to install pyTTSx
Type the following into the terminal:
- sudo apt-get install python-pip
This allows you to install python libraries
- sudo pip install pyttsx
Installs pyttsx using pip
Twitter API wrapper
This is required to allow python to access Twitter’s API. Type the following into the terminal:
sudo pip install python-twitter
Get access to Twitter API
These instructions assume you already have a twitter account, if not you need to create one before proceeding
- Navigate to https://dev.twitter.com/apps and click Create a new application
- Complete the form provided including the Capcha and click Create your Twitter application
- You will now be provided with consumer key and consumer secret which will look something like this:
Consumer key 05d0FO30g50rIwM3zVfKQ Consumer secret SCEOp3iYPs0s2YjqKHbw6ggEr6kgpgMzgrtXHrMgHAM
- Click on Create my access token then click on Details at the top of the screen to reload the page. You will then get your access token and access secret similar to shown below:
Access token 281981832-h0dYhnapEWZAVAyodSlX4u80r7vwDy8H6AlDA7Ee Access token secret bTsHKqR2EvR1UQNjbqPyYFea2Q2SRmsKShYmpw2sT2Aog
NOTE THE TOKENS AND SECRETS PROVIDED ARE NOT REAL AND WILL NOT WORK FOR YOUR PROGRAM
Type the following into your preferred IDE (e.g. IDLE):
consumerKey = ''
engine = pyttsx.init()
api = twitter.Api(consumer_key=consumerKey,consumer_secret=consumerSecret,access_token_key=accessTokenKey, access_token_secret=accessTokenSecret)
t = tweets
Modify lines 3-6 to use the information you provided when setting up a Twitter application earlier. You can also modify the search and text on lines 11, 13 and 15.
Save this as twitter-speaker.py and run using python twitter-speaker.py