12.12.2012 Views

Festival Speech Synthesis System: - Speech Resource Pages

Festival Speech Synthesis System: - Speech Resource Pages

Festival Speech Synthesis System: - Speech Resource Pages

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[ < ] [ > ] [ > ] [Top] [Contents] [Index] [ ? ]<br />

8.4 Scheme I/O<br />

Different Scheme's may have quite different implementations of file i/o functions so in this section we will describe<br />

the basic functions in <strong>Festival</strong> SIOD regarding i/o.<br />

Simple printing to the screen may be achieved with the function print which prints the given s-expression to the<br />

screen. The printed form is preceded by a new line. This is often useful for debugging but isn't really powerful<br />

enough for much else.<br />

Files may be opened and closed and referred to file descriptors in a direct analogy to C's stdio library. The SIOD<br />

functions fopen and fclose work in the exactly the same way as their equivalently named partners in C.<br />

The format command follows the command of the same name in Emacs and a number of other Lisps. C<br />

programmers can think of it as fprintf. format takes a file descriptor, format string and arguments to print. The<br />

file description may be a file descriptor as returned by the Scheme function fopen, it may also be t which means<br />

the output will be directed as standard out (cf. printf). A third possibility is nil which will cause the output to<br />

printed to a string which is returned (cf. sprintf).<br />

The format string closely follows the format strings in ANSI C, but it is not the same. Specifically the directives<br />

currently supported are, %%, %d, %x, %s, %f, %g and %c. All modifiers for these are also supported. In addition %l is<br />

provided for printing of Scheme objects as objects.<br />

For example<br />

(format t "%03d %3.4f %s %l %l %l\n" 23 23 "abc" "abc" '(a b d) utt1)<br />

will produce<br />

023 23.0000 abc "abc" (a b d) #<br />

on standard output.<br />

When large lisp expressions are printed they are difficult to read because of the parentheses. The function pprintf<br />

prints an expression to a file description (or t for standard out). It prints so the s-expression is nicely lined up and<br />

indented. This is often called pretty printing in Lisps.<br />

For reading input from terminal or file, there is currently no equivalent to scanf. Items may only be read as Scheme<br />

expressions. The command<br />

(load FILENAME t)<br />

will load all s-expressions in FILENAME and return them, unevaluated as a list. Without the third argument the<br />

load function will load and evaluate each s-expression in the file.<br />

To read individual s-expressions use readfp. For example<br />

(let ((fd (fopen trainfile "r"))<br />

(entry)<br />

(count 0))<br />

(while (not (equal? (set! entry (readfp fd)) (eof-val)))<br />

(if (string-equal (car entry) "home")<br />

(set! count (+ 1 count))))<br />

(fclose fd))

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!