Go to the first, previous, next, last section, table of contents.


Utility Functions

The utils part of the library provides utility functions for commonly used operations. The rest of the speech tools library makes use of these functions, and you are encouraged to use them too to save time in writing programs.

There are three main classes in the utilities, section Tlist C++ Class section KVL C++ Class and section Option C++ Class.

Most of the utility functions are concerned with command line options and library options

parse_command_line2()

parse_command_line2() is the main part in a sophisticated command line parsing system. This function takes the standard C command line variables argv and argc and makes an object of class section Option C++ Class containing all the command line options. This system aloows for the definition and documentation of command line arguments together. The arguments are automatically checked and parsed into the section Option C++ Class class and also allows for the options and help to keep in sync.

int parse_command_line2(int argc,        // number of c.l. args (from main())
		   char *argv[],	 // definition of c.l. args
		   const EST_String &usage,
		   EST_StrList &files,
		   EST_Option &al, int make_stdio=1)

The system operates by using the usage string to define the possible command line arguments, the type of their arguments and their defaults. The usage string should also be of a form suitable as help for the command. Options are defined only lines that start with a - sign. Each option definition consists of its name, followed by an optional type, and an optional default value. Types for options may be one of

Default values are denoted within braces.

A number of options are automatically defined when using these functions.

Any items on the command line that are not associated with options are treated as filenames (though may be arbitrary tokens) and returned in an EST_StrList in the order they are specified in.

Options and filename may appears on the command line in any order.

A typical call might be

parse_command_line2(argc, argv, 
      EST_String("Usage:\n")+
      "parse <options> <input files>\n"+
      "-g <ifile>   grammar file (required)\n"+
      "-w <ifile>   lexicon file\n"+
      "-n_parses <int> {5}\n"+
      "             max number of parses to look for\n"+
      "-g_weight <float>\n"+
      "             grammar weighting factor\n"+
      "-o <ofile>   output file for parses\n"+
      "-quiet       don't output debug information",
                   files, al);

The use of the function parse_command_line() provides similar function but separates the descriptions of the options from the definitoins of them is still used in some parts of the system. However becuase it allows options and help descriptions to be different its use is deprecated and the function is likely to be removed in later versions of the library.

init_lib_ops(): initialise library options

init_lib_ops() may be used after parse_command_line2(). Its purpose is to set up an object of type EST_Option, referred to as the library options. In the speech tools library, this object is used to provide complex sets of options to functions. For instance, sampling frequency is specified by "sampling_rate" in the library EST_Option object. It would be unweildy to have -sampling_rate as a command line variable; something like -f would be more suitable. init_lib_ops() is used to set up the library options and convert command line options into library options.

init_lib_ops() takes two arguments, the command line Option object and the library EST_Option object. i.e.

init_lib_ops(EST_Option &al, EST_Option &options);

It is possible to keep library options in a file. This file can be specified on the command line using (usually with the -c option), or it can be specified by the Unix environment variable EST_OP_FILE. If EST_OP_FILE is specified this file is read in and the library EST_Option object is created. If the -c option is then used, that file is read in, and overwrites any definitions in the library EST_Option object which are the same. Finally, the command line options overwrite the library EST_Option object. Commonly, a flag -N is used which prevents the reading of the EST_OP_FILE file.

The function override_lib_ops() is then called by init_lib_ops().

override_lib_ops(): Convert command line arguments to library options

int override_lib_ops(EST_Option &al, EST_Option &options);

If init_lib_ops() is used in a program, the programmer may provide their own override_lib_ops() function, which specifies the mapping between the command line options and the library options.

For example:

void override_lib_ops(Option &a_list, Option &al)
{
    a_list.override_val("frame_shift", al.val("-S", 0));
    a_list.override_val("color", al.val("-color", 0));
    a_list.override_val("in_lab_file_type", al.val("-itype", 0));
    a_list.override_val("out_lab_file_type", al.val("-otype", 0));
    a_list.override_val("label_offset", al.val("-off", 0));
    a_list.override_val("label_range", al.val("-range", 0));

    if (al.val("-style", 0) == "track")
        a_list.override_val("track_file_type", al.val("-otype", 0));
}

Audio input and output

There are a bewildering number of audio devices out there with many obscure options. The intention of this section of the library to hide that from you as much as possible. Actually accessing your audio device still unfortunately seems to be a major reason people do not consider speech in their applications.

Ideally we see a future where audio devices are controlled by audio servers and simple clients merely pass and received audio data from them using standard protocols. Much in the same way that graphics hardware is hidden by servers like X. But unfortunately this is not the case yet although some software offering this facility does exists.

The following forms out audio output are supported

Currently, support exists for audio output only, audio input hopefully will be added at some point in the future.


Go to the first, previous, next, last section, table of contents.