The eSpeakPackage provides a useful capability in which a program may speak text to the user. The eSpeakPackage.h outlines library functions available for output as spoken text just as C provides the stdio.h library for input and output for a terminal window. In the next few labs, we shall learn how users might test programs for a Scribbler robot using eSpeak by referencing the MyroC and eSpeak libraries.
Details of the various eSpeak functions are given in the header file, eSpeakPackage.h
To utilize speech synthesis within a program, the eSpeakPackage provides these commands.
Command | Brief Description |
---|---|
eSpeakConnect | establish a connection with the eSpeak library. |
eSpeakTalk | given a string as parameter, utilize the speech synthesizer to create audio through the computer speakers. |
eSpeakSetGender | specify a parameter "male" or "female" to set voice characteristics to reflect a simulated male or female. |
eSpeakDisconnect | disconnect from the the eSpeak library. |
An example using these commands follows shortly in this reading.
The following simple example, eSpeakExample1.c, illustrates the use of the eSpeakPackage. Steps for compiling and running the code follow the program listing.
/** This test demonstrate the basic * text-to-speech capability of eSpeak * * Author: Jordan Yuan * Date created: 10-2-2013 * Date revised: 10-9-2013 */ #include "eSpeakPackage.h" int main () {
This program is slighted edited and reformatted from the original version by Jordan Yuan.
#include specifies the eSpeakPackage; the program does not use other input or output.
The main procedure follows the same framework that we saw in earlier programs.
eSpeakConnect ();
Set up and connect to the eSpeak speech synthesizer. As part of the process, the voice is set randomly to female or male tone qualities.
eSpeakTalk( "setting up testing environment"); eSpeakTalk( "setting voice to male");
The parameter to eSpeakTalk presents text for processing by the eSpeak speech synthesizer.
eSpeakSetGender ("male"); eSpeakTalk("Once upon a time in a kingdom far far away"); eSpeakSetGender("female"); // set gender female eSpeakTalk("there was a little princess"); eSpeakTalk("who loves to stare into the stars"); eSpeakSetGender("male"); eSpeakTalk("one day a big dragon swooped down and they became the best of friends"); eSpeakSetGender("female"); eSpeakTalk("The end");
eSpeakDisconnect ();//disconnect from eSpeak } //end of main
The program should disconnect from the eSpeak synthesizer before the program finishes.
As with earlier programs in the course, we can compile and run software involving eSpeak using the gcc compiler.
As suggested in the diagram at the right, compiling and running a program requires several steps.
When using standard libraries, such as stdio, the gcc compiler knows where the relevant header and implementation files may be found. Thus, a programmer need not supply this information to gcc, and the entire compiling process for quarts.c can be reasonably short and simple:
gcc -o quarts quarts.c ./quarts
When using the eSpeakPackage, the process might be similar if all pieces of this package were located in the same directories as stdio and other standard libraries. In practice, however, user packages often are stored in different locations, and we must specify the directories for the eSpeakPackage as part of our gcc command. Details will vary, depending upon how the package was installed. Here is a typical example:
gcc -Wall -Wno-deprecated-declarations -std=gnu99 -leSpeakPackage eSpeakExample1.c -o eSpeakExample1
In this line to compile,
In the jargon of Linux, The -l and -o parts of this line indicate options or flags for compiling. More generally, many Linux commands provide many options to users. Typically, a flag begins with a dash (-) and a letter. As an example,
typing the ls command in a terminal window yields a brief listing of names of files in a directory, and
typing ls -l (e.g., using ls with its -l or "long" flag or option) yields a listing of files, including the file name, its permissions, its size, when it was accessed, etc.
As you might expect, typing this long line for the gcc compiler is long, tedious, and error prone. Thus, Linux and Mac OS X provide a capability to place such compiling details in a separate file, called a Makefile. Through the course, we will discover that Makefiles provide a very powerful mechanism for program development. For now, we begin with just enough discussion to handle programs involving eSpeak.
The following Makefile illustrates information that might be part of the compiling process.
# Generic Makefile for compiling a single C program # and linking with relevant MyroC, bluetooth, jpeg, # etc. libraries # # Patterned on Makefile by Jerod Weinman for CSC 161, Spring 2015 # # This program and all MyroC software is licensed # under the Creative Commons # Attribution-Noncommercial-Share Alike 4.0 # International License. Details may be found at # http://creativecommons.org/licenses/by-nc-sa/4.0/ # Type "make foo". # We rely on the implicit rules foo.c -> foo.o for compiling and # foo.o --> foo for linking # Use the gcc compiler CC = gcc # Set preprocessor flags #CPPFLAGS= # Set appropriate compiling flags CFLAGS=-Wall -Wno-deprecated-declarations -std=gnu99 -pthread -lMyroC -leSpeakPackage # Set dynamic library path #DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/lib # Set linker flags to include the relevant libraries LDFLAGS= -lMyroC -leSpeakPackage -framework OpenGL -framework GLUT -lm #---------------------------------------------------------------------------- # cleanup rules: To invoke this command, type "make clean". # Use this target to clean up your directory, deleting (without warning) # object files, old emacs source versions, and core dumps. clean: rm -f *.o *~ core*\
As with C programs, a Makefile file may contain comments for the user. These comments begin with the number sign (#) character, just as comments on a single line in C may begin with // .
In compiling, the C compiler (abbreviated CC in Makefiles) will be the gcc compiler.
When compiling/translating (later in Step 2), report all warnings (all code that has high potential to be wrong), specified with the -Wall flag.
Also when compiling (again Step 2), use the 1999 version of Standard C, specified with the -std=gnu99 flag.
When looking for details of the eSpeakPackage (Step 2), look in the locations for the standard C libraries, and if needed in /usr/local/lib
When running the program (Step 3), use the "linker flags" to locate various run-time libraries (e.g. files MyroC, and eSpeakPackage, and collections OpenGL and GLUT. The -lm flag indicates C's mathematics library — useful for a range of common mathematical functions.
Once a Makefile has been placed in the directory of a program, compiling and running the program is straightforward. For program eSpeakExample1.c, these steps suffice:
make eSpeakExample1 ./eSpeakExample1
The simplest application of a Makefile uses a make command to apply the Makefile rules to whatever program is listed.
make myProgram
uses the program name as a base, adds the output file option (-o myProgram, assumes the C program has the name ending with .c, and utilizes the given "CC" compiler (in this case, gcc).
Finally, when compiling with emacs, backup copies of files are created. (When you save a file (e.g., myProgram.c), the old version is save under a new name (e.g., myProgram.c~). Other, temporary files also may be created in some circumstances (e.g., files ending in .o or starting with core). These can be deleted with the command
rm -f *.o *~ core*
However, removing files quickly may be considered dangerous — mistyping a file name could delete something you wanted. To reduce the risk, it is convenient to include a "clean" option within the Makefile. In the example, the command
make cleanremoves the backup files, files ending in .o and files starting with core.
As this example suggests, make can invoke a range of capabilities. The basic format of a Makefile requires that the name of a command starts at the beginning of a line, followed by a colon (:)
clean:
The next line(s) give the details for the command. For historical reasons, the details must be on lines that begin with a tab character. (Several spaces is not adequate!)
created 2 October 2013 by Jordan Yuan revised 9-15 October by Jordan Yuan (with minor editing by Henry M. Walker) reformatted 10 May 2016 by Henry M. Walker Adjusted for Mac OS X at SSU 29 January 2022 by Henry M. Walker |
![]() ![]() |
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |