CSC 161 Schedule Readings Labs & Projects Homework Deadlines Resources

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

  1. Move to your labs subdirectory, compile quarts.c, and run the program. Your work in a terminal window might involve the following:

    cd csc161/labs
    gcc -o quarts quarts.c
    ./quarts

    Now edit quarts.c and try to compile and run the program.

    1. 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 run quarts.c until the emacs editor is closed.

    2. 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 run quarts.c without 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.

Autocompletion

  1. Try using "autocompletion" with quarts and quarts.c by typing

    gcc -o qtab

    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 qtab

    Again, autocompletion gives

    gcc -o quarts quarts

    Type a period and the tab, and autocompletion gives

    gcc -o quarts quarts.c
  2. This time, start the same as in the previous step, but hit the tab key twice typing

    gcc -o qtab tab

    Describe what you see.

The Manual

  1. Use the man command to consult the online Linux manual (Note the q key is used to exit man pages):
    1. What do the following command options mean? Note the ability to combine flags.

      cp -p
      ls -ltrF
      mkdir -p
    2. Why does the cat command have the name "cat" which stands for "concatenate"?
    3. 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
  2. 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, you may need earphones to listen to audio from your workstation.

Documentation for the eSpeak package includes a commentary, a header file, and two C programs as examples.

  1. As an example, compile and run quarts-espeak.c.

    1. In the Linux basics lab, you copied quarts-espeak.c to your labs subdirectory. If this did not work properly, copy the file now:

      cp /home/weinman/public_html/courses/CSC161/2015S/modules/getting-started/src/quarts-espeak.c ./
    2. To compile quarts-espeak.c, you must tell the gcc compiler where to find the eSpeakPackage. This is done by adding a piece to the usual compile line:

      gcc -I/home/walker/Myro/include/MyroC -L/home/walker/Myro/lib -leSpeakPackage -o quarts-espeak quarts-espeak.c
    3. Run the program with the expected name of the compiled program:

      ./quarts-espeak
  2. 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.
  3. Modify quarts-espeak.c in several ways to explore the capabilities of this package.

Displaying Text Files

  1. Try the following commands that display all or part of this laboratory exercise:

    cat  /home/weinman/public_html/courses/CSC161/2015S/modules/getting-started/labs/c-espeak.shtml
    more /home/weinman/public_html/courses/CSC161/2015S/modules/getting-started/labs/c-espeak.shtml
    less /home/weinman/public_html/courses/CSC161/2015S/modules/getting-started/labs/c-espeak.shtml
    head /home/weinman/public_html/courses/CSC161/2015S/modules/getting-started/labs/c-espeak.shtml
    tail /home/weinman/public_html/courses/CSC161/2015S/modules/getting-started/labs/c-espeak.shtml
    tail -n 20 /home/weinman/public_html/courses/CSC161/2015S/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 less command, 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.

  1. Move to your home directory and obtain a "long" listing of the files present using the commands:

    cd
    ls -l

    (The cd command without parameters takes you to your home directory.)

    Interpret the meaning of each part of the directory and file listings.