Practice with Elementary C, eSpeak, and Makefiles
Work Started in Class
Time saving Linux Capabilities
In the introduction to C lab, you edited, compiled, and ran a C program quarts.c. This part of the lab provides experience with several Linux capabilities that can simplify some parts of program development.
Autocompletion
-
Try using "autocompletion" with quarts and quarts.c by typing
gcc -o q followed by the TAB key
You should find that when you press TAB the system completes the file name for you. In this case, both quarts and quarts.c are files in your directory, so the TAB completes q with the common prefix quarts, giving
gcc -o quarts
Type q and the TAB key again:
gcc -o quarts q followed by the TAB key
Again, autocompletion gives
gcc -o quarts quarts
Type a period and the TAB, and autocompletion gives
gcc -o quarts quarts.c
-
This time, start the same as in the previous step, but hit the TAB key twice typing
gcc -o q TAB TAB
Describe what you see.
The Manual
-
Use the man command to consult the online Linux manual (Note the q key is used to quit or exit man pages):
-
What do the following command options mean? Note the ability to combine flags (or smash them together).
cp -i ls -ltr mkdir -p
-
Why does the cat command have the name "cat", which stands for "concatenate"?
-
Use the man page for the C function sqrt to identify the parameters and return type for a collection of functions related to sqrt. Also, what "include" statement is needed for sqrt?
-
-
The command man -k keyword lists commands that seem related to the given keyword. For example, to print a list of man pages that include the word "square" in the name or description fields, you could use "man -k square". Try this command to locate sqrt and to determine various commands related to the keyword "print".
eSpeak
In many applications, it is helpful to include speech synthesis within a C program. Although not perfect (actually far from perfect), the eSpeak package provides a simple way to instruct the workstation to talk, given specific text.
In order to limit interference with the work of others in the lab, use the volume controls on your workstation to set the volume at a moderate level.
The Linux/Mac OS directory with documentation for the eSpeak package contains a commentary, a header file, and two C programs as examples.
-
As an example, program quarts-espeak.c provides some audible commentary to a program that converts quarts to liters.
- Load quarts-espeak.c into your browser, paste it into aquamacs, and save the file to your Desktop.
-
To compile quarts-espeak.c, you must tell the gcc compiler where to find the eSpeakPackage. This is done by adding several pieces to the usual compile line:
gcc -Wall -Wno-deprecated-declarations -std=gnu99 -leSpeakPackage quarts-espeak.c -o quarts-espeak
-
Run the program with the expected name of the compiled program:
./quarts-espeak
-
As an alternative approach to compiling this program,
- Copy Makefile (if you have not copied this file to your Desktop previously).
- Save the program to your account.
Compile and run quarts-espeak.c using the make command:
make quarts-espeak ./quarts-espeak
-
The make command checks whether the current version of the file has already been compiled. If so, no compilation is needed. If not, the gcc command compiles the program as it normally does.
-
Open quarts-espeak.c with the aquamacs editor.
-
Change the program in some way (e.g., add a comment).
-
Use make to compile the program:
make quarts-espeak
-
Use the same command to compile again the program (without changing it), and observe how make responds.
-
Run quarts-espeak to check that it runs properly.
-
-
Open quarts-espeak.c in an editor, and find the various eSpeak commands. Review the program with the following notes:
- eSpeakConnect () sets up the eSpeak environment. As part of this activity, the synthesized voice is set randomly to a male or female voice.
- eSpeakSetGender (parm) allows the parameter to be "female" or "male", and sets the corresponding voice characteristics.
- eSpeakTalk ("text goes here") instructs eSpeak to create audio related to the text specified.
- eSpeakDisconnect () cleans up the eSpeak environment. If this command is omitted, the workstation's speaker may hum for awhile after the program finishes.
-
Modify quarts-espeak.c in several ways to explore the capabilities of this package.
-
Now copy program eSpeakExample1.c to your account.
- Compile the program with make, and run it.
- Edit the program to reflect a short dialog between two people. Use the eSpeakSetGender function, so that one speaker speaks in a generally "male" sounding tone and the other speaker speaks in a generally "female" sounding tone. Once written, compile and run the program.
created 15 January 2014 by Henry M. Walker, based on earlier
labs by
readings added 1 September 2014 by Henry M. Walker Makefile added and lab reformatted and generalized 11 May 2016 by Henry M. Walker revised for Sonoma State University 28 January 2022 by Henry M. Walker |
![]() ![]() |
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |