Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > e8ef26e5419f97f63237d371a51b4251 > files > 29

flite-1.3-14.fc12.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on July 25, 2009 by texi2html 1.82
texi2html was written by: 
            Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>Flite: a small, fast speech synthesis engine: 7. APIs</title>

<meta name="description" content="Flite: a small, fast speech synthesis engine: 7. APIs">
<meta name="keywords" content="Flite: a small, fast speech synthesis engine: 7. APIs">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="APIs"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="flite_6.html#cst_005fval" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#flite-binary" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flite_6.html#Structure" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="flite.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="flite_8.html#Converting-FestVox-Voices" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flite.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="flite_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="flite_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="APIs-1"></a>
<h1 class="chapter">7. APIs</h1>

<p>Flite is a library that we expected will be embedded into other
applications.  Included with the distribution is a small example
executable that allows synthesis of strings of text and text files
from the command line.
</p>
<hr size="6">
<a name="flite-binary"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#APIs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C-example" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#APIs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#APIs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="flite_8.html#Converting-FestVox-Voices" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flite.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="flite_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="flite_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">7.1 flite binary</h2>

<p>The example flite binary may be suitable for very simple applications.
Unlike Festival its start up time is very short (less that 25ms on a PIII
500MHz) making it practical (on larger machines) to call it each
time you need to synthesize something.
</p><table><tr><td>&nbsp;</td><td><pre class="example">flite TEXT OUTPUTTYPE
</pre></td></tr></table>
<p>If <code>TEXT</code> contains a space it is treated as a string of text and
converted to speech, if it does not contain a space <code>TEXT</code> is
treated as a file name and the contents of that file are converted to
speech.  The option <code>-t</code> specifies <code>TEXT</code> is to be treat
as text (not a filename) and <code>-f</code> forces treatment as a file.
Thus
</p><table><tr><td>&nbsp;</td><td><pre class="example">flite -t hello 
</pre></td></tr></table>

<p>will say the word &quot;hello&quot; while
</p><table><tr><td>&nbsp;</td><td><pre class="example">flite hello 
</pre></td></tr></table>

<p>will say the content of the file &lsquo;<tt>hello</tt>&rsquo;.  Likewise
</p><table><tr><td>&nbsp;</td><td><pre class="example">flite &quot;hello world.&quot;
</pre></td></tr></table>

<p>will say the words &quot;hello world&quot; while
</p><table><tr><td>&nbsp;</td><td><pre class="example">flite -f &quot;hello world&quot;
</pre></td></tr></table>

<p>will say the contents of a file &lsquo;<tt>hello world</tt>&rsquo;.  If no argument is
specified text is read from standard input.
</p>
<p>The second argument <code>OUTPUTTYPE</code> is the name of a file the output
is written to, or if it is <code>play</code> then it is played to the audio
device directly.  If it is <code>none</code> then the audio is created but
discarded, this is used for benchmarking.  If <code>OUTPUTTYPE</code> is
omitted, <code>play</code> is assumed.  You can also explicitly set the
outputtype with the <code>-o</code> flag.
</p><table><tr><td>&nbsp;</td><td><pre class="example">flite -f doc/alice -o alice.wav
</pre></td></tr></table>

<hr size="6">
<a name="C-example"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#flite-binary" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Public-Functions" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#APIs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#APIs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="flite_8.html#Converting-FestVox-Voices" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flite.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="flite_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="flite_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">7.2 C example</h2>

<p>Each voice in Flite is held in a structure, a pointer to which is
returned by the voice registration function.  In the standard
distribution, the example diphone voice is <code>cmu_us_kal</code>.
</p>
<p>Here is a simple C program that uses the flite library
</p><table><tr><td>&nbsp;</td><td><pre class="example">#include &quot;flite.h&quot;

cst_voice *register_cmu_us_kal();

int main(int argc, char **argv)
{
    cst_voice *v;

    if (argc != 2)
    {
        fprintf(stderr,&quot;usage: flite_test FILE\n&quot;);
        exit(-1);
    }

    flite_init();

    v = register_cmu_us_kal();

    flite_file_to_speech(argv[1],v,&quot;play&quot;);

}
</pre></td></tr></table>
<p>Assuming the shell variable FLITEDIR is set to the flite directory
the following will compile the system (with appropriate changes for
your platform if necessary).
</p><table><tr><td>&nbsp;</td><td><pre class="example">gcc -Wall -g -o flite_test flite_test.c -I$FLITEDIR/include -L$FLITEDIR/lib 
    -lflite_cmu_us_kal -lflite_usenglish -lflite_cmulex -lflite -lm
</pre></td></tr></table>

<hr size="6">
<a name="Public-Functions"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C-example" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="flite_8.html#Converting-FestVox-Voices" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#APIs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#APIs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="flite_8.html#Converting-FestVox-Voices" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flite.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="flite_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="flite_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">7.3 Public Functions</h2>

<p>Although, of course you are welcome to call lower level functions,
there a few key functions that will satisfy most users
of flite.
</p><dl compact="compact">
<dt> <code>void flite_init(void);</code></dt>
<dd><p>This must be called before any other flite function can be called.  As
of Flite 1.1, it actually does nothing at all, but there is no guarantee
that this will remain true.
</p></dd>
<dt> <code>cst_wave *flite_text_to_wave(const char *text,cst_voice *voice);</code></dt>
<dd><p>Returns a waveform (as defined in &lsquo;<tt>include/cst_wave.h</tt>&rsquo;) synthesized
from the given text string by the given voice.
</p></dd>
<dt> <code>float flite_file_to_speech(const char *filename, cst_voice *voice, const char *outtype);</code></dt>
<dd><p>synthesizes all the sentences in the file &lsquo;<tt>filename</tt>&rsquo; with 
given voice.  Output (at present) can only reasonably be, <code>play</code>
or <code>none</code>.
</p></dd>
<dt> <code>float flite_text_to_speech(const char *text, cst_voice *voice, const char *outtype);</code></dt>
<dd><p>synthesizes the text in string point to by <code>text</code>, with the given
voice.  <code>outtype</code> may be a filename where the generated waveform is
written to, or &quot;play&quot; and it will be sent to the audio device, or
&quot;none&quot; and it will be discarded.  The return value is the
number of seconds of speech generated.
</p></dd>
<dt> <code>cst_utterance *flite_synth_text(const char *text,cst_voice *voice);</code></dt>
<dd><p>synthesize the given text with the given voice and returns an utterance
from it for further processing and access.
</p></dd>
<dt> <code>cst_utterance *flite_synth_phones(const char *phones,cst_voice *voice);</code></dt>
<dd><p>synthesize the given phones with the given voice and returns an utterance
from it for further processing and access.
</p></dd>
</dl>

<hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#APIs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="flite_8.html#Converting-FestVox-Voices" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flite.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="flite_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="flite_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated on <i>July 25, 2009</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
 </font>
 <br>

</p>
</body>
</html>