pi 9000

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

pi 9000

Post by tldr »

couldn't figure out why phil would want to use an arduino for his hal 9000 project, (i tried to provide a link to the project, but the file name contains a banned spam word), when he could have used a pi. piece of cake to get a pi to play .wav files off of an sd card, but, really, that's kind of lame.

install festival.

Code: Select all

apt-get update
apt-get install festival
echo "no 9000 computer has ever made a mistake" | festivall --tts
echo "I'm sorry, Dave. I'm afraid I can't do that." | festival --tts
create a file called daisybell.xml with the following contents.

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE SINGING PUBLIC "-//SINGING//DTD SINGING mark up//EN"
      "Singing.v0_1.dtd"
[]>
<SINGING BPM="30">

<PITCH NOTE="D4"><DURATION BEATS="0.3">day</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.3">zee</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.3">day</DURATION></PITCH>
<PITCH NOTE="D3"><DURATION BEATS="0.3">ZEE</DURATION></PITCH>
<PITCH NOTE="E3"><DURATION BEATS="0.1">GIVE</DURATION></PITCH>
<PITCH NOTE="F#3"><DURATION BEATS="0.1">ME</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.1">YOUR</DURATION></PITCH>
<PITCH NOTE="E3"><DURATION BEATS="0.2">AN</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.1">sir</DURATION></PITCH>
<PITCH NOTE="D3"><DURATION BEATS="0.3">DO</DURATION></PITCH>
<REST BEATS="0.3"></REST>
<PITCH NOTE="A3"><DURATION BEATS="0.3">I'm</DURATION></PITCH>
<PITCH NOTE="D4"><DURATION BEATS="0.3">half</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.3">cray</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.3">zee</DURATION></PITCH>
<PITCH NOTE="E3"><DURATION BEATS="0.1">all</DURATION></PITCH>
<PITCH NOTE="F#3"><DURATION BEATS="0.1">for</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.1">the</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.2">love</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.1">of</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.3">you</DURATION></PITCH>
<REST BEATS="0.2"></REST>
<PITCH NOTE="B3"><DURATION BEATS="0.1">it</DURATION></PITCH>
<PITCH NOTE="C4"><DURATION BEATS="0.1">won't</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.1">be</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.1">a</DURATION></PITCH>
<PITCH NOTE="D4"><DURATION BEATS="0.2">sty</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.1">lish</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.1">mare</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.2">edge</DURATION></PITCH>
<REST BEATS="0.2"></REST>
<PITCH NOTE="A3"><DURATION BEATS="0.1">i</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.2">can't</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.1">uh</DURATION></PITCH>
<PITCH NOTE="E3"><DURATION BEATS="0.2">ford</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.1">a</DURATION></PITCH>
<PITCH NOTE="E3"><DURATION BEATS="0.1">care</DURATION></PITCH>
<PITCH NOTE="D3"><DURATION BEATS="0.2">edge</DURATION></PITCH>
<REST BEATS="0.2"></REST>
<PITCH NOTE="D3"><DURATION BEATS="0.1">but</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.2">you'll</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.1">look</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.2">sweet</DURATION></PITCH>
<PITCH NOTE="D3"><DURATION BEATS="0.1">uh</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.2">pon</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.1">the</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.2">seat</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.05">of</DURATION></PITCH>
<PITCH NOTE="C4"><DURATION BEATS="0.05">a</DURATION></PITCH>
<PITCH NOTE="D4"><DURATION BEATS="0.1">by</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.1">sick</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.1">ul</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.2">built</DURATION></PITCH>
<PITCH NOTE="C3"><DURATION BEATS="0.1">for</DURATION></PITCH>
<PITCH NOTE="G3"><DURATION BEATS="0.4">two</DURATION></PITCH>

</SINGING>
sometimes it's easier to get what you want if you use phonetic spellings with festival.

type

Code: Select all

festival "(tts_file \"daisybell.xml\" 'singing)" "(exit)"
now you've got a hal 9000.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: pi 9000

Post by adafruit_support_rick »

couldn't figure out why phil would want to use an arduino for his hal 9000 project
Phil was simply being cautious. Since the Pi is a more powerful machine, there was a much higher risk of it attaining sentience, turning evil, and locking them out of the building.

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: pi 9000

Post by tldr »

chong 9000.

Code: Select all

echo "Dave's not here." | festival --tts

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: pi 9000

Post by tldr »

rude pi. the raspberry alarm clock.

install at.

Code: Select all

apt-get update
apt-get install at
at allows you to schedule jobs to run at particular times in the future.

place the following code in a file called wakeup.sh

Code: Select all

#!/bin/bash
date +"It is %A %B %d, %_I:%M %p, now get the fuh cout of bed" | \
sed -e "s/AM/ay em/" | festival --tts
to be rudely awakened the next time 5:00 a.m. rolls around type this

Code: Select all

at 5:00 -f wakeup.sh
so, what's going on here?

the command at 5:00 -f wakeup.sh causes the file wakeup.sh to be executed the next time 5:00 a.m. rolls around. at expects the time in 24 hour format so, it you want something done at 5:00 p.m., use 17:00. the -f flag tells at that the commands to be executed will be found in the file wakeup.sh. without -f at expects you to enter the commands directly at the console.

... and what's going on in wakeup.sh?

the first line, #!/bin/bash tells the system that we want the contents of the file interpreted by the bash shell. the bash shell is the program that interprets your input in lxterminal or any time you are interacting with your pi in the absence of a gui.

the second line. date +"It is %A %B %d, %_I:%M %p, now get the fuh cout of bed"| \, runs the program date to access the system date and time. the quoted string following the plus sign formats the output of the program. characters preceded by % are formattign codes that will be replaced by specific fields of the system time. type man date at the console for an explanation of the formatting codes. the plus sign, itself, announces the presence of the formatting string. without it the date and time are displayed in a default format. the vertical bar following the formatting string is the pipe operator and causes the output of the date command to be passed along to the next command on the line as its input. the backslash at the end of this line is a continuation character which tells bash to treat the following line as a continuation of the current one.

the third line of this script invokes two more programs with the output of the first, sed, being piped to the input of the second, festival. the input to sed is the output of date in the previous line, which at five o'clock in the morning is liable to look like this:

Code: Select all

pi@SimpleSimon ~ $ date +"It is %A %B %d, %_I:%M %p, now get the fuh cout of bed"
It is Friday May 03,  5:00 AM, now get the fuh cout of bed
pi@SimpleSimon ~ $ 
which is swell, but festival will pronounce "AM" as if it were the first person singular form of the verb "to be." which is a problem. so we pass it to sed, a stream editor. sed is able to process a file or the output of some other command and perform editing operations on each line of its input. in our case that happens to be the single line above. the sed command we use is sed -e "s/AM/ay em/". -e tells sed that the string following it is an editing command, in this case "s/AM/AY em /", which substitutes an occurrence of "AM" with "ay em", so the output to our command so far will be

Code: Select all

pi@SimpleSimon ~ $ date +"It is %A %B %d, %_I:%M %p, now get the fuh cout of bed" | \
> sed -e "s/AM/ay em/"
It is Friday May 03,  5:00 ay em, now get the fuh cout of bed
pi@SimpleSimon ~ $
which will be piped to festival, | festival --tts, to be spoken aloud.

note that if it happens to be past noon when the script is run, festival will read PM correctly, once it decides that it is not an english word.

sed is a wonderful tool to which i could not begin to do justice. here is the documentation from gnu.org.

and festival just makes me happy.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: pi 9000

Post by adafruit_support_rick »

I'm going to have to try festival - it looks like fun. An alarm clock ordering me to get the fuh cout of bed at 5 am would have a very short life expectancy. Could get expensive...

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: pi 9000

Post by tldr »

adafruit_support_rick wrote:I'm going to have to try festival - it looks like fun. An alarm clock ordering me to get the fuh cout of bed at 5 am would have a very short life expectancy. Could get expensive...
use a model a.

but, when you've got to get the fuh cout of bed at 5:00 a.m., it helps to have a gentle reminder.

what i usually run is a python script that scrapes the local weather off of a website, but everytime they make a change to the site it breaks the script. then i fall back to the bash script 'til i get around to fixing the python.

Code: Select all

#!/usr/bin/python
import urllib, re, time

timestr = re.sub ('AM','ay em',time.strftime('It is %A %B %d %Y %I:%M %p'))

try:
  content = urllib.urlopen ("http://www.weather.com/weather/right-now/94606").read()

except IOError:
  print 'Error accessing weather data, {0}'.format (timestr)
  exit ()

try:
  pat = re.compile (
     '"temperature-fahrenheit".(?P<temp>-?\d+).+?'
     '"wx-phrase *">(?P<phrase>[A-Za-z ]+).+?'
     '"wx-wind-label">(?P<wind>[A-Za-z0-9 ]+).+?'
     'Humidity:.+\n.+>(?P<humidity>\d+%).+?'
     'incheshg">\n(?P<barometer>[0-9.]+).+?'
     'wx-pressure-(?P<trend>[A-Za-z]+)'
     , re.DOTALL)

  m = pat.search (content)

  trend = m.group ("trend")
  trend = trend.replace ('up', 'rising')
  trend = trend.replace ('down', 'falling')

  wind = m.group ("wind")
  wind = wind.replace ('N', 'North ')
  wind = wind.replace ('S', 'South ')
  wind = wind.replace ('E', 'East ')
  wind = wind.replace ('W', 'West ')
  wind = wind.replace ('mph', 'miles per hour')

  foo = '''{0}, current conditions are {2} and {1} degrees, humidity\
  is {4}, wind is out of the {3},the barometer is\
  {5} and {6}, now get the fuh cout of bed'''

  print foo.format (timestr, m.group ("temp"), 
        m.group ("phrase"), wind, m.group ("humidity"), 
        m.group ("barometer"), trend) 

except (NameError, AttributeError) :
  print 'Error parsing weather data, (see weather.err), {0}'.format (timestr)
  f = open ('weather.err','w')
  f.write (content)

exit ()
i've got a very short bash script that runs the python and pipes the output to festival.

Code: Select all

./weather.py | festival --tts
which i run like so

Code: Select all

at 5:00 -f weather

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: pi 9000

Post by skr0d »

Cool post! I just spent the last hour listening to my pi talk to me. Also note that there are other voices available. I haven't played with them yet, but maybe after I get the fuh cout of bed in the morning, I'll download some more. http://ubuntuforums.org/showthread.php?t=751169

I'm going to clean up your weather script and use it in a programming class for kids in a couple of weeks. We are teaching them Python on the Pi, and adding a voice to it will show them an entirely new dimension to programming.

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: pi 9000

Post by tldr »

i may be wrong, but i'm pretty sure this will make installing festival worthwhile.

copy the contents of the code window to your pi console. WARNING! if you have a file named iwalu.xml, this will destroy it.

Code: Select all

cat <<foo >iwalu.xml
<?xml version="1.0"?>
<!DOCTYPE SINGING PUBLIC "-//SINGING//DTD SINGING mark up//EN" 
      "Singing.v0_1.dtd"
[]>
<SINGING BPM="60">
<PITCH NOTE="E4"><DURATION BEATS="0.5">and</DURATION></PITCH>
<PITCH NOTE="A4"><DURATION BEATS="3.5">i</DURATION></PITCH>
<PITCH NOTE="B4"><DURATION BEATS="0.25">i</DURATION></PITCH>
<PITCH NOTE="A4"><DURATION BEATS="1.75">i</DURATION></PITCH>
<PITCH NOTE="A4"><DURATION BEATS="0.25">wih</DURATION></PITCH>
<PITCH NOTE="G#4"><DURATION BEATS="0.25">ill</DURATION></PITCH>
<PITCH NOTE="G#4"><DURATION BEATS="0.5">all</DURATION></PITCH>
<PITCH NOTE="A4"><DURATION BEATS="0.5">ways</DURATION></PITCH>
<REST BEATS="1.25"/>
<PITCH NOTE="B4"><DURATION BEATS="0.5">love</DURATION></PITCH>
<PITCH NOTE="A4"><DURATION BEATS="0.25">you</DURATION></PITCH>
<PITCH NOTE="A4"><DURATION BEATS="0.25">oo</DURATION></PITCH>
<PITCH NOTE="B4"><DURATION BEATS="0.25">oo</DURATION></PITCH>
<PITCH NOTE="C5"><DURATION BEATS="0.25">oo</DURATION></PITCH>
<PITCH NOTE="B4"><DURATION BEATS="0.25">oo</DURATION></PITCH>
<PITCH NOTE="C5"><DURATION BEATS="0.25">oo</DURATION></PITCH>
<PITCH NOTE="B4"><DURATION BEATS="0.25">oo</DURATION></PITCH>
<PITCH NOTE="A4"><DURATION BEATS="0.75">oo</DURATION></PITCH>
</SINGING>
foo
festival "(tts_file \"iwalu.xml\" 'singing)" "(exit)"


to hear it again type this ...

Code: Select all

festival "(tts_file \"iwalu.xml\" 'singing)" "(exit)"

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: pi 9000

Post by tldr »

sKr0d wrote:Also note that there are other voices available
i think i've got most of them. the higher quality voices all seem to have some kind of ringing in them, so i prefer kal.

User avatar
mtbfzero
 
Posts: 16
Joined: Sun Mar 29, 2015 11:28 am

Re: pi 9000

Post by mtbfzero »

well, thought i'd update this post.

it's been a long time since the above script has worked, so here's a new version that uses the weather underground api to download weather data as a json file. before you can use it, you'll have to go to the weather underground site and get an api key which can be had for free for as many as 500 lookups a day. that's one every 2.88 minutes. once you have secured your api key stick it in the script in place of ***yourwundergroundapikeyhere***

Code: Select all

#!/usr/bin/python
import re
import urllib2
import json
directions = {'North' : 'North',
              'NNE'   : 'North North East',
              'NE'    : 'North East',
              'ENE'   : 'East North East',
              'East'  : 'East',
              'ESE'   : 'East South East',
              'SE'    : 'South East',
              'SSE'   : 'South South East',
              'South' : 'South',
              'SSW'   : 'South South West',
              'SW'    : 'South West',
              'WSW'   : 'West South West',
              'West'  : 'West',
              'WNW'   : 'West North West',
              'NW'    : 'North West',
              'NNW'   : 'North North West'}
trends = {'+' : 'Rising',
          '-' : 'Falling',
          u'0' : 'Steady'}
from time import strftime,localtime
print re.sub('AM','ay em',strftime ("It is %A %B %d, %Y %I:%M %p.", localtime()))
f = urllib2.urlopen('http://api.wunderground.com/api/***yourwundergroundapikeyhere***/geolookup/conditions/q/94606.json')
json_string = f.read()
parsed_json = json.loads(json_string)
location = parsed_json['location']['city']
temp_f = parsed_json['current_observation']['temp_f']
print "Current conditions are %s." % (parsed_json['current_observation']['weather'])
print "temperature is %s degrees Fahrenheit" % (temp_f)
if parsed_json['current_observation']['wind_string'] == 'Calm' :
  print 'Winds are calm.'
else :
  wind_dir = directions[parsed_json['current_observation']['wind_dir']]
  wind_mph = parsed_json['current_observation']['wind_mph']
  print "Winds are at %s miles per hour out of the %s." % (wind_mph, wind_dir)
humidity = parsed_json['current_observation']['relative_humidity']
print "Relative humidity is %s." % (humidity)
baro_pressure = parsed_json['current_observation']['pressure_in']
baro_trend = trends [parsed_json['current_observation']['pressure_trend']]
print "Barometric pressure is %s inches and %s." % (baro_pressure, baro_trend)
print "Now, get out of bed."
f.close()

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”