Working with the eSpeak Speech Synthesizer
and using Makefiles

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

eSpeak Commands

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.


A Simple eSpeak Example

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 ()
{

Program notes


  eSpeakConnect ();

  eSpeakTalk( "setting up testing environment");
  eSpeakTalk( "setting voice to male");

  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


Compiling Programs involving eSpeak

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.

  1. Start with a C program (e.g., eSpeakExample1.c)
  2. Include and consult any header files (e.g., stdio.h, eSpeakPackage.h), so the compiler will know how to use library functions, such as printf or eSpeakTalk
  3. Translate the C program, plus header information, into a machine-language version.
    • Include coding details about external libraries or files.
    • Create an output file (e.g., eSpeakExample1 if the -o option is used with gcc is used; a.out if no -o option is specified).
    • Run the machine-language version of the program. In addition to previous work, this may include dynamic, run-time libraries that are needed for a specific workstation.
Compiling process

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,

Command Flags in Linux

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,


Makefiles

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*\

Basic Elements of a Makefile


Using a Makefile

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

Default Makefile Uses

The simplest application of a Makefile uses a make command to apply the Makefile rules to whatever program is listed.


Cleaning up a bit

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 clean
removes the backup files, files ending in .o and files starting with core.

A Typing Detail!

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
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.