element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Blog Upcycled Clock - Reading out tweets on a Bluetooth speakers
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: carmelito
  • Date Created: 6 May 2017 4:47 AM Date Created
  • Views 613 views
  • Likes 2 likes
  • Comments 2 comments
  • upcycledclock
  • intel
  • upcycle_it
  • bluetoooth
  • Espeak
  • upcycle it
  • tweepy
  • twitter
  • Gstreamer
  • iot
  • intel edison
Related
Recommended

Upcycled Clock - Reading out tweets on a Bluetooth speakers

carmelito
carmelito
6 May 2017

In my previous blog post, titled Reading out the weather using eSpeak , we installed eSpeak on the Intel Edison to read out the weather via a speaker connected to the USB sound card. Continuing on the same theme, and since I bought a new bluetooth speaker this weeks from my local electronic store for a 50% discount, we are going to enable bluetooth on Intel Edison and pair the new speaker. In addition, we are going to use tweepy, which is a python wrapper library for the twitter API to read tweets , and then use eSpeak to create a wav file, which is then read out by gstreamer.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

While putting the python code together and testing it out, I found out that Workshopshed (Andy Clark) is working on an interesting 3D part for his project - Interactive Racing Car Driver , hmm I wonder  if that is going to be a part of his next blog post.. Sorry Workshopshed , but the cat is out of the bag ! image ...Here are the list of tweets read out as part of the video above-

image

 

Here are commands to follow, to enable bluetooth on the Intel Edison and then pair and connect to the bluetooth speaker , the speaker I bought is the Vivitar portable bluetooth speaker.

SSH into the Intel Edsion and run the following command as shown in the pictures below

rfkill unblock bluetooth

bluetoothctl

 

This puts the bluetooth on the Intel Edison in discoverable mode and then you can scan for bluetooth device using the command

scan on

Make a note of the mac address of your speaker( in my case it is [NEW] Device 00:25:DB:14:53:30 Vivitar Speaker) and pair it with the Edison, using

pair 00:25:DB:14:53:30

And to connect to the speaker, use the command

connect 00:25:DB:14:53:30

Then quit the bluetoothctl prompt using

quit

 

Now run the following command to verify that the speaker is recognized in pulse audio

pactl list sinks

Configure the default sink to use pulse audio server with the following command, replacing with the details of your device.

pactl set-default-sink bluez_sink.00_25_DB_14_53_30

 

It is now finally! image time to play some sound on the bluetooth speaker using gStreamer

gst-launch-1.0 filesrc location= /usr/share/sounds/alsa/Front_Center.wav ! wavparse ! pulsesink

 

Note: we are able use the Front_Center.wav, because we installed ALSA-utils in previous blog post, but we don’t really need to install ALSA as we are using gStreamer to play the audio wav file.

 

 

{gallery} Connecting to Bluetooth Speaker

image

Intel Edison and Vivitar portable bluetooth speaker

image

Pairing and connecting to the bluetooth speaker.

image

output of the command - pactl list sinks

image

Playing wav file using gStreamer

 

 

Now if you are following this blog independently, and not in conjunction with previous blog here are the steps to install eSpeak and create a wav file that you can play on the bluetooth speaker using gStreamer. To install eSpeak run the following command

opkg install espeak

 

Run the following command to create a wav file

espeak -w speech.wav "hello from the Intel Edison bluetooth test successful"

 

Now run the gStreamer to play the sound via the bluetooth speaker using the wav file created

gst-launch-1.0 filesrc location= speech.wav ! wavparse ! pulsesink

 

 

To read tweets, we will install tweepy which is python wrapper library for the twitter API, use the following command to install tweepy

pip install tweepy

Note: If you run into errors while installing tweepy this could be because  you have an older version  PIP installed, you need pip version 9/higher.To upgrade pip run the following command -

pip install --upgrade pip

image

 

Now you will have to go to - https://dev.twitter.com/  and create an App, and generate access tokens. And make a note of the following, which you will have to replace in the python program below

  • consumer key
  • consumer secret
  • access_token key
  • access_token secret

In addition, modify the hashTag variable if you want to scrape twitter for a different hash tag.

 

#!/usr/bin/python
#create by Carmelito to use espeak to read out the tweets based on a hashTag on a speaker connected to the Intel Edison
#Based on the tweepy libary http://www.tweepy.org/
#Follow the blog on element14 to install espeak and tweepy
import tweepy
import re,string
import os,subprocess


consumer_key = "XXXXXXXXXXXXXXXXXX"
consumer_secret = "XXXXXXXXXXXXXXXXXXXXXXXXX"
access_token_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
access_token_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
hashTag = "inteledison"


OAUTH_KEYS = {'consumer_key':consumer_key, 'consumer_secret':consumer_secret,
              'access_token_key':access_token_key, 'access_token_secret':access_token_secret}
auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)
getTweet = tweepy.Cursor(api.search, q=hashTag).items(30)


#Filtering the un-readable things in the tweet.text
def strip_links(text):
    link_regex = re.compile('((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)', re.DOTALL)
    links = re.findall(link_regex, text)
    for link in links:
        text = text.replace(link[0], ', ')
    return text


def strip_all_entities(text):
    entity_prefixes = ['@','#']
    for separator in  string.punctuation:
        if separator not in entity_prefixes :
            text = text.replace(separator,' ')
    words = []
    for word in text.split():
        word = word.strip()
        if word:
            if word[0] not in entity_prefixes:
                words.append(word)
    return ' '.join(words)


file = open("tweetsFile.txt","w")
for tweet in getTweet:
    #filtering tweets in english(en), and also filtering retweets (RT @) based on tweepy docs
    if tweet.lang == 'en' and 'RT @' not in tweet.text:
        fileText = 'From '+ tweet.author.name.encode('utf8') + ' the tweets reads ' + strip_all_entities(strip_links(tweet.text.encode('utf8'))) + "     "
        # added encode('utf8') to resolve the encoding error on some tweets
        file.write(fileText)
        print fileText
        print "Name:", tweet.author.name.encode('utf8') #this is what we need
        print "Screen-name:", tweet.author.screen_name.encode('utf8')
        print "Tweet created:", tweet.created_at
        print "Tweet:", tweet.text.encode('utf8') #this is what we need to apply a filter
        #print "Retweeted:", tweet.retweeted
        #print "Favourited:", tweet.favorited
        #print "Location:", tweet.user.location.encode('utf8')
        #print "Time-zone:", tweet.user.time_zone
        #print "Geo:", tweet.geo
        print "-------------------------------"
file.close()


#creating a wav file using espeak and the txt file create above
os.system("espeak -ven+f3 -s 150 -f tweetsFile.txt -w readTweets.wav")
#using gstream to play the wav file above on the bluetooth speakser
os.system ("gst-launch-1.0 filesrc location= readTweets.wav ! wavparse ! volume volume=0.1 ! pulsesink")

 

 

Now, it’s pretty obvious that if you restart your Intel Edison you will lose connection with the bluetooth speaker, to solve this minor inconvinence if you don’t have access to a Terminal, we are going to setup service to execute when the intel Edison starts to connect to the bluetooth speaker.

Create a shell script - startBluetooth.sh to pair the device

vi bluetoothConnect.sh

 

#!/bin/sh  
rfkill unblock bluetooth  
sleep 1  
bluetoothctl << EOF  
connect 00:25:DB:14:53:30
EOF  
sleep 1 

 

And then make the file executable using

chmod +x startbluetooth.sh

 

Now go to the following folder and create startBluetooth.service

Cd /lib/systemd/system/

Vi startBluetooth.service

 

#!/bin/sh  
[Unit]  
Description=Sets up the Edison's Bluetooth interface and connects it to a paired device.  
[Service]  
ExecStart=/home/root/bluetoothConnect.sh
Type=idle  
[Install]  
WantedBy=basic.target 

 

To enable the service run

systemctl enable startBluetooth.service

 

Now when you reboot the Edison reboot it will automatically connect to the bluetooth speaker.

 

 

Reference -

Play Audio from Your Intel Edison via Bluetooth -https://software.intel.com/en-us/articles/play-audio-from-your-intel-edison-via-bluetooth-using-advanced-audio-distribution-profile

Tweepy Documentation -http://www.tweepy.org/

eSpeak Documentation - http://espeak.sourceforge.net/commands.html

Automatically connect to a device through Bluetooth - https://communities.intel.com/docs/DOC-102152

  • Sign in to reply

Top Comments

  • DAB
    DAB over 8 years ago +2
    Nice update. I have been advocating a speak option for test equipment so that engineers can probe systems without needing to take their eyes off the connection. So you implementation could be repurposed…
  • DAB
    DAB over 8 years ago

    Nice update.

     

    I have been advocating a speak option for test equipment so that engineers can probe systems without needing to take their eyes off the connection.

     

    So you implementation could be repurposed for that type of project.

     

    Very useful.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 8 years ago

    Great results, and useful notes on Bluetooth.

     

    Hope to have more details on the mystery 3D models on Monday.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube