C with eSpeak
Timesaving 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.
Background Processes
-
Move to your
labssubdirectory, compilequarts.c, and run the program. Your work in a terminal window might involve the following:cd csc161/labs clang -o quarts quarts.c ./quarts
Now editquarts.cand try to compile and run the program.-
First, type
emacs quarts.c
This will open emacs just fine, but now switch back to your terminal window. You will notice that it is unavailable for further use (i.e., you won't get another command prompt until emacs is closed). For example, you will not be able to compile and runquarts.cuntil the emacs editor is closed. -
Now close emacs, and then re-open it from the terminal
window, but this time add an ampersand character to the end of
the command:
emacs quarts.c &
Now when you return to your terminal window, a prompt is waiting for you, making it easy to do multiple tasks at once—you can compile and runquarts.cwithout interruption. Adding the ampersand character to a command causes the command to be launched as a background process, allowing you to continue working with your terminal window.
-
First, type
Autocompletion
-
Try using "autocompletion" with
quartsandquarts.cby typingclang -o qtab
You should find that when you press tab ,the system completes the file name for you. In this case, bothquartsandquarts.care files in your directory, so the tab completesqwith the common prefixquarts, givingclang -o quarts
Typeqand the tab key again:clang -o quarts qtab
Again, autocompletion givesclang -o quarts quarts
Type a period and the tab, and autocompletion givesclang -o quarts quarts.c
-
This time, start the same as in the previous step, but hit
the tab key twice typing
clang -o qtab tab
Describe what you see.
The Manual
-
Use the
mancommand to consult the online Linux manual (Note the q key is used to exitmanpages): -
What do the following command options mean? Note the ability to
combine flags.
cp -p ls -ltrF mkdir -p
-
Why does the
catcommand have the name "cat," which is short for "concatenate"? -
Use the
manpage for the C functionsqrtto identify the parameters and return type for a collection of functions related tosqrt. Also, what#includedirective is needed forsqrt? -
The command
man -k keywordlists 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 locatesqrtand to determine various commands related to the keyword "print".
eSpeak
Many applications can benefit from speech synthesis. 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, you please use earphones to listen to audio from your workstation. See the appendix for instructions on adjusting the volume.
Documentation for the eSpeak package includes a commentary, a header file, and two C programs as examples.
-
As an example, compile and run
quarts-espeak.c.-
In the Linux basics lab, you
copied
quarts-espeak.cto yourlabssubdirectory. If this did not work properly, copy the file now:cp /home/weinman/courses/CSC161/2024F/modules/getting-started/src/quarts-espeak.c ./
-
To compile
quarts-espeak.c, you must tell the linker to link theeSpeakPackage(and where to find it). This is done by adding a piece to the usual compile line:clang -I/home/walker/MyroC/include/MyroC -L/home/walker/MyroC/lib -leSpeakPackage -o quarts-espeak quarts-espeak.c
-
Run the program with the expected name of the compiled program:
./quarts-espeak
-
In the Linux basics lab, you
copied
-
Open
quarts-espeak.cin 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.cin several ways to explore the capabilities of this package.
Displaying Text Files
-
One at a time, try the following commands that display all or part of this
laboratory exercise:
cat /home/weinman/courses/CSC161/2024F/modules/getting-started/labs/c-espeak.shtml more /home/weinman/courses/CSC161/2024F/modules/getting-started/labs/c-espeak.shtml less /home/weinman/courses/CSC161/2024F/modules/getting-started/labs/c-espeak.shtml head /home/weinman/courses/CSC161/2024F/modules/getting-started/labs/c-espeak.shtml tail /home/weinman/courses/CSC161/2024F/modules/getting-started/labs/c-espeak.shtml tail -n 20 /home/weinman/courses/CSC161/2024F/modules/getting-started/labs/c-espeak.shtml
(Note that this is a wonderful time to use the arrow keys to edit previous commands rather than to retype the full lines each time. You can also use the tab autocomplete utility.)
For the
lesscommand, try the arrow keys to move up and down in the file.
Directory and File Permissions
The following steps ask you to review the permissions for your account directories and adjust them for this course.
-
Move to your home directory and obtain a "long" listing of the
files present using the commands:
cd ls -l
(The
cdcommand without parameters takes you to your home directory.)Interpret the meaning of each part of the directory and file listings.
Appendix: Volume Adjustment
The headphone volume on your Debian Linux workstation may be muted or
too soft to hear. To adjust the volume, type the
command alsamixer in a terminal. Type F3 to
adjust the playback volume (rather than another audio channel, such
as the microphone), then use the arrow keys ↑
and ↓ to adjust the volume to a suitable
level. Type Esc to quit and return to the terminal prompt.
