If your a fan of Stephen Hawking's then this blog post is for you !! As part of this blog post, we am going to setup eSpeak on the Intel Edison and have it read out today's weather condition via a speaker connected to the USB port of Edison Arduino breakout.
eSpeak is a compact open source software speech synthesizer for English and other languages, for Linux and Windows and it runs perfectly on Yacto linux. To read more about eSpeak check out the documentation at sourceforge.net
For the getting the weather we are going to use pyOWM which is a python wrapper library for the OpenWeatherMap.
Connect the USB sound card to the Intel Edison and connect power to the Edison using the DC power jack as shown in the picture below.
Now SSH into your Edison and install ALSA using the following the commands
opkg install alsa-utils
To check if you USB sound card is detected run following command
lsusb
you should now see the name of sound card, in my case in the screenshot below it is the second entry.
Create a file under the /etc directory and add the following line in the file
vi /etc/asound.conf
pcm.!default sysdefault:Device
No to select your sound card and increase/decrease the volume, run the command
alsamixer
- select the USB sound card by hitting F6 on the screen and selecting the option "USB PnP sound device"
- Increase and decrease the speaker volume using up and down arrow keys.
Finally to check if you are able to hear sound from the speakers run the following command which will play a test file which was created as part of the alsa-utils intall
aplay /usr/share/sounds/alsa/Front_Center.wav
Now if you have heard sound from the speaker , it is now time to install eSpeak by running the following commands
opkg install espeak
And also run the following to test if you can hear the text phrase on your speaker.
espeak "Hello from the Intel Edison"
Now to get weather data from openweathermap.org you will have to create an new account at , and run the following command to install pyOWM
Install PIP using the follow command
opkg install python-pip
in my case, as you see the screenshot below , I had installed python-pip a couple of days back. Once done install pyOWM using the command
pip install pyowm
Now you are ready to run the python program below, and hear the weather read out on your speakers as shown in the video above. As part of the python program, you will have to replace the API key and placeName and you can find the API key at - https://home.openweathermap.org/api_keys
#!/usr/bin/python #create by Carmelito to use espeak to read out the weather on a speaker connected to the Intel Edison #For more detials on pyowm https://github.com/csparpa/pyowm/blob/master/pyowm/docs/usage-examples.md #Follow the blog on element14 to install espeak import subprocess import pyowm APIKey = 'XXXXXXXXXXXXXXXXXXXXXXX' placeName = 'Los Angeles,US' owm = pyowm.OWM(APIKey) observation = owm.weather_at_place(placeName) w = observation.get_weather() temp = w.get_temperature(unit='celsius')['temp'] status = w.get_status() detailedStatus = w.get_detailed_status() windSpeed = w.get_wind()['speed'] humidity = w.get_humidity() pressure = w.get_pressure()['press'] print ('Temperature : '+ str(temp) + ' C') print ('Weather Condition : ' + status) print ('Wind Speed : '+ str(windSpeed) + ' m/s') print ('Humidity : ' + str(humidity) + ' %') print ('Pressure : ' + str(pressure) + ' hpa') print ('Details Weather :' + detailedStatus) #for the future, read out for the future weather condition fc = owm.daily_forecast('Los Angeles,US', limit=3) f = fc.get_forecast() lst = f.get_weathers() for weather in f: print (weather.get_reference_time('iso'),weather.get_status()) #text that will be spoken out using espeak text = 'Rise and shine, Todays weather is ' + detailedStatus + ' and the Temperature is '+ str(temp) + ' degree celsius with humidity ' + str(humidity) + ' percent' try: subprocess.check_output(['espeak', text]) except subprocess.CalledProcessError: print ("Errr something is not working..")
Top Comments