Programming Assignment 08b


Creating a clock for the blind
 

Due: Friday, May 5th,  10:00 A.M.

 

An introduction

Suppose that you were blind and had a hard time seeing a clock.  How would you know what time it was?

In this activity I want you to write a basic program that will read the system clock on your computer (see additional information below) and use this to produce a sound file that, when played, will announced the time that the file was created.  For example, at this exact moment if I were to run the program and play the returned sound I would expect to hear "The time is three oh two PM."

 

To begin

Inside this unzipped directory are Twenty Seven (27) sound files representing the numbers "oh" (technically it's a zero, but everyone say "oh" rather than zero), 1-20, 30, 40, and 50.  These are in files which use the English word for the number in the file (eg. 1 is in the file one.wav, 2 is in the file two.wav, 20 is in the file twenty.wav, etc.)  There also are two files representing AM and PM as well as a file called "time.wav"  which is the phrase "the time is"

Feel free to open these and play with them to get a feel for the sounds.

 

Reading from the system clock

Python has a package called time which allows you to run several methods involving clocks, including timers to find out how long things take (something you will use in Data Structures) and to read from the system clock on your computer.  To use this, you first need to import the time package and any methods you will use. 

Type the following at the interactions pane:

from time import localtime
time = localtime()
print time
(2009,4,21,15,02,11,1,111,1)

You will notice that the result is a data structure that we haven't talked about called a tuple (it looks an awful lot like a list, but it is slightly different.  The tuple for time represents (year,month,date,hour,minute,second,weekday,yearday,isDaylightSavings).  To get access to a particular piece of information you can reference it by it's index number.  For example:

hour = time[3]

By the way, notice that the hour is given in a 24 hour clock.  Thus, right now, on my computer the hour would be 15 which is 3 PM (if the number is greater than 12 you simply subtract 12 to find the "American" time)

Creating a Sound from this information

generateTimeSound()

In other words, this method should return one, new Sound object which is the "concatenation" of the individual sound files represented by the current time.   Thus,

output = generateTimeSound()
play(output)

would return and play the current time.

 

Things to think about:

 

Optional Bonus

The microphone that I used to record these sound clips had a slight negative bias.  That is, if I recorded "nothing' I wouldn't get a sound where every sample is zero, I would instead see some negative number.  This causes a SLIGHT clicking when you first start and stop playing my sounds.  For a bonus, look at these sound files and figure out what that negative bias is.  As you copy the files over to the output sound add a number to each sound sample to eliminate this bias (in effect, shifting the resting point from the negative value to the zero value.