Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > media > contrib-updates > by-pkgid > c7095aefea7b97fbd2a596dcbfb9d481 > files > 411

asterisk-docs-1.4.26.1-1mdv2008.1.i586.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Festival</title><link rel="stylesheet" href="styles.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.69.1" /><link rel="start" href="index.html" title="Asterisk™: The Future of Telephony" /><link rel="up" href="asterisk-CHP-14.html" title="Chapter 14. Potpourri" /><link rel="prev" href="asterisk-CHP-14.html" title="Chapter 14. Potpourri" /><link rel="next" href="asterisk-CHP-14-SECT-5.html" title="Call Files" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Festival</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="asterisk-CHP-14.html">Prev</a> </td><th width="60%" align="center">Chapter 14. Potpourri</th><td width="20%" align="right"> <a accesskey="n" href="asterisk-CHP-14-SECT-5.html">Next</a></td></tr></table><hr /></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="asterisk-CHP-14-SECT-1"></a>Festival</h2></div></div></div><p>Festival is a popular open <a id="ch14_festival" class="indexterm"></a>source text-to-speech engine.<a id="I_indexterm14_tt1677" class="indexterm"></a> The basic premise of using Festival with Asterisk is that
    your dialplan can pass a body of text to Festival, which will then “speak”
    the text to the caller. Probably the most obvious use for Festival would
    be to have it read your email to you when you are on the road.<sup>[<a id="id4159692" href="#ftn.id4159692">147</a>]</sup></p><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="asterisk-CHP-14-SECT-1.1"></a>Getting Festival Set Up and Ready for Asterisk</h3></div></div></div><p>There are currently two ways to use Festival with Asterisk. The
      first (and easiest) method—without having to patch and recompile
      Festival—is to add the following text to Festival’s configuration
      file<a id="I_indexterm14_tt1678" class="indexterm"></a> (<span class="emphasis"><em>festival.scm</em></span>, usually located in
      <span class="emphasis"><em>/etc/</em></span> or
      <span class="emphasis"><em>/usr/share/festival/</em></span>):</p><a id="I_programlisting14_tt1679"></a><pre class="programlisting">(define (tts_textasterisk string mode)
"(tts_textasterisk STRING MODE)

Apply tts to STRING. This function is specifically designed for use in 
server mode so a single function call may synthesize the string. This 
function name may be added to the server safe functions."
(let ((wholeutt (utt.synth (eval (list 'Utterance 'Text string)))))
(utt.wave.resample wholeutt 8000)
(utt.wave.rescale wholeutt 5)
(utt.send.wave.client wholeutt)))</pre><p>You may place this text anywhere in the file, as long as it is not
      between any other parentheses.</p><p>The second (and more traditional) way is to compile Festival with
      an Asterisk-specific patch (located in the <span class="emphasis"><em>contrib/</em></span>
      directory of the Asterisk source).</p><p>Information on both of these methods is contained in the<a id="I_indexterm14_tt1680" class="indexterm"></a> <span class="emphasis"><em>README.festival</em></span> file, located in the
      <span class="emphasis"><em>contrib/</em></span> directory of <a id="I_indexterm14_tt1681" class="indexterm"></a>the Asterisk source.</p><p>For either method, you’ll need to modify the Festival access list
      in the <span class="emphasis"><em>festival.scm</em></span> file. Simply search for the
      word “localhost” and replace it with the fully qualified domain name of
      your server.</p><p>Both of these methods set up Festival to be able to correctly
      communicate with Asterisk. After setting up Festival, you should start
      the Festival server. You can then call the <code class="literal">Festival()</code> application<a id="I_indexterm14_tt1682" class="indexterm"></a> from within your dialplan.</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="asterisk-CHP-14-SECT-1.2"></a>Configuring Asterisk for Festival</h3></div></div></div><p>The Asterisk configuration file that deals with Festival is aptly
      called <span class="emphasis"><em>festival.conf</em></span>. Inside this file, you specify
      the hostname and port of your Festival server, as well some settings for
      the caching of Festival speech. For most installations (if you’re going
      to run Festival on your Asterisk server), the defaults will work just
      fine.</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="asterisk-CHP-14-SECT-1.3"></a>Starting the Festival Server</h3></div></div></div><p>To start the Festival <a id="I_indexterm14_tt1683" class="indexterm"></a>server for debugging purposes, simply run <code class="literal">festival</code> with the <code class="literal">--server</code> argument, like this:</p><a id="I_programlisting14_tt1684"></a><pre class="programlisting">[root@asterisk ~]# <strong class="userinput"><code>festival --server</code></strong></pre><p>Once you’re sure that the Festival server is running and not
      rejecting your connections, you can start Festival by typing:</p><a id="I_programlisting14_tt1685"></a><pre class="programlisting">[root@asterisk ~]# <strong class="userinput"><code>festival_server 2&gt;&amp;1 &gt;/dev/null &amp;</code></strong></pre></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="asterisk-CHP-14-SECT-1.4"></a>Calling Festival from the Dialplan</h3></div></div></div><p>Now that Festival is configured and the Festival server <a id="I_indexterm14_tt1686" class="indexterm"></a>is started, let’s call it from within a simple
      dialplan:</p><a id="I_programlisting14_tt1687"></a><pre class="programlisting">exten =&gt; 123,1,Answer()
exten =&gt; 123,2,Festival(Asterisk and Festival are working together)</pre><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><a id="asterisk-CHP-14-NOTE-49"></a>Tip</h3><p>You should always call the<a id="I_indexterm14_tt1688" class="indexterm"></a> <code class="literal">Answer()</code> application
        before calling <code class="literal">Festival()</code>, to ensure that a channel is
        established.</p></div><p>As Asterisk connects to Festival, you should see output like this
      in the terminal where you started the Festival server:</p><a id="I_programlisting14_tt1689"></a><pre class="programlisting">[root@asterisk ~]# <strong class="userinput"><code>festival --server</code></strong>
server    Sun May  1 18:38:51 2005 : Festival server started on port 1314
client(1) Sun May  1 18:39:20 2005 : accepted from asterisk.localdomain
client(1) Sun May  1 18:39:21 2005 : disconnected</pre><p>If you see output like the following, it means you didn’t add the
      host to the access list in<a id="I_indexterm14_tt1690" class="indexterm"></a>
      <span class="emphasis"><em>festival.scm</em></span>:</p><a id="I_programlisting14_tt1691"></a><pre class="programlisting">[root@asterisk ~]# <strong class="userinput"><code>festival --server</code></strong>
server    Sun May  1 18:30:52 2005 : Festival server started on port 1314
client(1) Sun May  1 18:32:32 2005 : rejected from asterisk.localdomain not 
in access list</pre><div class="sidebar"><a id="asterisk-CHP-14-SIDEBAR-1.1"></a><p class="title"><b>Yet Another Way to Use Festival with Asterisk</b></p><p>Some people in the Asterisk community have reported success with
        passing text to <a id="I_indexterm14_tt1692" class="indexterm"></a>Festival’s <span class="emphasis"><em>text2wave</em></span> utility and
        then having Asterisk play back the resulting <span class="emphasis"><em>.wav</em></span>
        file. For example, you might do something like this:</p><a id="I_programlisting14_tt1693"></a><pre class="programlisting">exten =&gt; 124,1,Answer()
exten =&gt; 124,2,System(echo "This is a test of Festival" | /usr/bin/text2wave
-scale 1.5 -F 8000 -o /tmp/festival.wav)
exten =&gt; 124,3,Playback(/tmp/festival)
exten =&gt; 124,4,System(rm /tmp/festival.wav)
exten =&gt; 124,5,Hangup()</pre><p>This method also allows you to call other text-to-speech
        engines, such as the popular speech engine from Cepstral <a href="http://www.cepstral.com" target="_top">http://www.cepstral.com</a>, which
        is an inexpensive commercial derivative of Festival with very
        good-sounding voices. For this example, we’ll assume that Cepstral is
        installed in <span class="emphasis"><em>/usr/local/cepstral/</em></span>:</p><a id="I_programlisting14_tt1694"></a><pre class="programlisting">exten =&gt; 125,1,Answer()
exten =&gt; 125,2,System(/usr/local/cepstral/bin/swift -o /tmp/swift.wav
"This is a test of Cepstral")
exten =&gt; 125,3,Playback(/tmp/swift)
exten =&gt; 125,4,System(rm /tmp/swift.wav)
exten =&gt; 125,5,Hangup()</pre></div></div><div class="footnotes"><br /><hr width="100" align="left" /><div class="footnote"><p><sup>[<a id="ftn.id4159692" href="#id4159692">147</a>] </sup>Probably the coolest use of Festival is in Simon Ditner’s ZoIP,
        a port of the famous Zork game to a fully speech-enabled engine
        running on Asterisk (ZoIP also uses Sphinx, which we will not be
        covering in this book). We’re going to have to come up with a new kind
        of name for this sort of thing. It’s not a video game, since there is
        no screen, so do we need to call these audio games? Regardless, check
        it out at <a href="http://www.zoip.org" target="_top">http://www.zoip.org</a>.</p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="asterisk-CHP-14.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="asterisk-CHP-14.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="asterisk-CHP-14-SECT-5.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 14. Potpourri </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Call Files</td></tr></table></div><div xmlns="" id="svn-footer"><hr /><p>You are reading <em>Asterisk: The Future of Telephony</em> (2nd Edition for Asterisk 1.4), by Jim van Meggelen, Jared Smith, and Leif Madsen.<br />
       This work is licensed under the <a href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative Commons Attribution-Noncommercial-No Derivative Works License v3.0</a>.<br />
       To submit comments, corrections, or other contributions to the text, please visit <a href="http://oreilly.com/catalog/9780596510480/">http://www.oreilly.com/</a>.</p></div></body></html>