CS 3733 Operating Systems, Spring 2000 Assignment 4


Due Friday, March 31, 2000

In this assignment you will design an audio object that can speak a sentence in your own voice. It will have a limited vocabulary of about 20 words.

For each word it can speak, you will record an audiofile for that word. You can use the audiotool to do this, but remember that you must remove the headers from these files.

Part 1
Make a directory for this assignment. Make subdirectories called withheaders and withoutheaders which will contain the audio files. Create audio files in withheaders which correspond to your speaking each of the following:

The files for the digits should be called 0.au through 9.au. The files for the words should have the word as the filename and .au as the extension. For example, "written" would be in the file written.au. Your name files should follow the same format as the ones for the other words. For example, if I were doing this project I would make two files called Steven.au and Robbins.au. The files should be edited so that there is little silence before and after each spoken word.

When you get done you should have at least 25 audio files. Try playing each with audioplay. Copy all of these into withoutheaders and remove the headers. You can remove headers with audioconvert. For example, in the directory you could execute:

   audioconvert -f raw -o ../withoutheaders/program.au program.au

Part 2
Get the audio object called Program 3.4 in PUP from /usr/local/courses/cs3733/pup/ch03/raw/prog03.04.c. Change the name of this file to audiolib.c. Make a file audiolib.h that contains prototypes for the functions in audiolib.c.

Add the function:

   int initialize_audio_files(char *dir);
which takes a directory name and reads all of the files from that directory into an array of file_data structures. It returns 0 on success and -1 on failure. You can just use get_directory_files from your previous assignment. If you got less than 25 out of 30 on assignment 3, you may use my implementation without penalty. If you got over 25 on assignment 3 and you use my directory_utilities implementation, your score on assignment 3 will be reduced to 25. My implmentation can be found in /usr/local/courses/cs3733/spring2000/assign3.

Also write a function:

     int play_word(char *str);
which plays the audiofile corresponding to the word str. This just appends .au to str and looks up the corresponding entry in the the array created by get_directory_files, and sends the corresponding data to the audio device. The function returns the size of the audio file, or -1 if it is not in the list. In checking the name of the file, use strcasecmp instead of strcmp so that the difference between upper and lower case letters is ignored.

Write a main program which tests this by playing a few words in sequence.

Part 3
Add the function:
int play_sentence(char *str, int delay)
to the audio object. It parses the string into words and plays the words one at a time. It pauses delay milliseconds between words. It returns 0 on success and -1 if any of the words could not be found or another error occurred. Use usleep for the delay, but note that usleep sleeps for a given number of microseconds. You may assume that the delay argument is less than 1000.

Add the function:

   int play_integer(unsigned int n)
which plays the integer one digit at a time. It returns 0 on success and -1 on failure. For example, if n = 1352, you would hear the words "one three five two." Do not include any delay between the individual digits.

Write a main program to test these. The main program should take a single string command line parameter. For example, if your main program is called testpart3 you might test this with something like:

   testpart3 "this program was written by yourname"

Part 4
Modify play_word so that if the word passed contains only a string of digits, it will use play_integer to play this word. In this case it should return 0.

Write a main program which takes no command line arguments and uses your audio object to say two sentences. The first sentence will be:
This program was written by ...
where it says your name at the end.
The second sentence will be of the form:
This process has ID x and the parent process has ID y.
where x and y are replaced by the appropriate process IDs.

It should also print each sentence to standard output before syaing it. Use a delay of 100 milliseconds between words.


Print out all of your source code and hand it in. Be prepared to demonstrate your programs.

Notes: