# TTS Engine

**URL:** <https://community.asterisk.org/t/tts-engine/2732>\
**Category:** Asterisk Support\
**Created:** [November 26, 2005, 6:44am UTC](https://community.asterisk.org/t/tts-engine/2732 "2005-11-26T06:44:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdulzu](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@abdulzu](https://community.asterisk.org/u/abdulzu)\
**Post date:** [November 26, 2005, 6:44am UTC](https://community.asterisk.org/t/tts-engine/2732/1 "2005-11-26T06:44:11Z")

</div>

Hi all,

Is there another TTS Engine for Asterisk instead of Festival? I am facing bad voice quality problem in Festival.

I will be thankfull if anyone can tell me supported TTS engines.

---

<div class="post-metadata">

**Author:** ![smither](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@smither](https://community.asterisk.org/u/smither)\
**Post date:** [November 27, 2005, 2:03pm UTC](https://community.asterisk.org/t/tts-engine/2732/2 "2005-11-27T14:03:29Z")

</div>

Cepstral ([cepstral.com](http://www.cepstral.com)) is mentioned in the Asterisk book - page 177. I have not tried it.

---

<div class="post-metadata">

**Author:** ![greyhound](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@greyhound](https://community.asterisk.org/u/greyhound)\
**Post date:** [November 27, 2005, 6:40pm UTC](https://community.asterisk.org/t/tts-engine/2732/3 "2005-11-27T18:40:46Z")

</div>

Cepstral is significantly better quality than festival. $30 to download (includes one voice, $30 for each additional voice).

---

<div class="post-metadata">

**Author:** ![jsgoecke](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jsgoecke/32/585_2.png) [@jsgoecke](https://community.asterisk.org/u/jsgoecke)\
**Post date:** [November 27, 2005, 8:27pm UTC](https://community.asterisk.org/t/tts-engine/2732/4 "2005-11-27T20:27:29Z")

</div>

> [@greyhound](#):
>
> Cepstral is significantly better quality than festival. $30 to download (includes one voice, $30 for each additional voice).

Does Cepstral include the TTS engine? Or how do you install the Cepstral voices with Festival?

---

<div class="post-metadata">

**Author:** ![greyhound](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@greyhound](https://community.asterisk.org/u/greyhound)\
**Post date:** [November 28, 2005, 12:20am UTC](https://community.asterisk.org/t/tts-engine/2732/5 "2005-11-28T00:20:30Z")

</div>

Cepstral includes a TTS engine. It also includes virtually NO documentation, but it’s pretty easy to use.

I use it from a System() command. I think someone may have built an application that allows you to use Cepstral directly, but I find it easy enough to just do it via commands.

---

<div class="post-metadata">

**Author:** ![abdulzu](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@abdulzu](https://community.asterisk.org/u/abdulzu)\
**Post date:** [November 28, 2005, 4:40am UTC](https://community.asterisk.org/t/tts-engine/2732/6 "2005-11-28T04:40:09Z")

</div>

HI,

Is Cepstral supporting Arabic and Asian Language? and is there any demo available?

---

<div class="post-metadata">

**Author:** ![jsgoecke](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jsgoecke/32/585_2.png) [@jsgoecke](https://community.asterisk.org/u/jsgoecke)\
**Post date:** [November 28, 2005, 8:19am UTC](https://community.asterisk.org/t/tts-engine/2732/7 "2005-11-28T08:19:20Z")

</div>

Appears you may be able to test Cepstral with an AGI:

[voip-info.org/wiki/view/Aste … l+www+demo](http://www.voip-info.org/wiki/view/Asterisk+text2cepstral+www+demo)

I will give it a try and let you know how it goes.

---

<div class="post-metadata">

**Author:** ![jsgoecke](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jsgoecke/32/585_2.png) [@jsgoecke](https://community.asterisk.org/u/jsgoecke)\
**Post date:** [November 28, 2005, 1:39pm UTC](https://community.asterisk.org/t/tts-engine/2732/8 "2005-11-28T13:39:27Z")

</div>

Alright, the demo above did not work as that individual’s website appears to be down. I did manage to get it working this way though (almost, see what is not working at the bottom), as it turns out [phpagi.sourceforge.net](http://phpagi.sourceforge.net) has a swift function built-in to the library:

[quote="/etc/asterisk/extensions.ael"]`context cepstral_test {
        s => {
                Answer();
                Set(tts_text='This is a test using this voice');
                Set(tts_lang='en');
                AGI(cepstral_demo.php);
                Hangup();
        };`[/quote]

[quote="/var/lib/asterisk/agi-bin/cepstral\_demo.php"][code]\<?php  
//Script to invoke Cepstral  
require(‘phpagi.php’);  
error\_reporting(E\_ALL);  
$agi = new AGI();

$txt\_array = $agi-\>get\_variable(‘tts\_text’);  
if ($txt\_array != 0) {  
$text = $txt\_array[‘data’];  
$lang\_array = $agi-\>get\_variable(‘tts\_lang’);

```
    if ($lang_array != 0) {
            $lang = $lang_array['data'];
            if ($lang == 'en') {
                    $swift_array = $agi->swift($text, '', 8000, 'Diane');
            } elseif ($lang == 'es') {
                    $swift_array = $agi->swift($text, '', 8000, 'Miguel');
            } else {
                    $swift_array = $agi->swift($text, '', 8000, 'Diane');
            }
    } else {
            $swift_array = $agi->swift($text, '', 8000, 'Diane');
    }

```

}

$agi-\>stream\_file(‘goodbye’);  
?\>[/code][/quote]

Now, it invokes and plays back the correct voice on the first call. But if I change the ‘tts\_lang’ variable in my extensions.ael and unload/load pbx\_ael.so, the system still plays whichever voice was played regardless of what the setting is (I did test, and my logic in the script is correct that it picks up the right language).

It would appear that the function below may be picking up the first wav file to play back each time? Not sure, any ideas?

[quote=“[PHPAGI.sourceforge.net](http://PHPAGI.sourceforge.net)”][code] function swift($text, $escape\_digits=’’, $frequency=8000, $voice=NULL)  
{  
if(!is\_null($voice))  
$voice = “-n $voice”;  
elseif(isset($this-\>config[‘cepstral’][‘voice’]))  
$voice = “-n {$this-\>config[‘cepstral’][‘voice’]}”;

```
  $text = trim($text);
  if($text == '') return true;

  $hash = md5($text);
  $fname = $this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR;
  $fname .= 'swift_' . $hash;

  // create wave file
  if(!file_exists("$fname.wav"))
  {
    // write text file
    if(!file_exists("$fname.txt"))
    {
      $fp = fopen("$fname.txt", 'w');
      fputs($fp, $text);
      fclose($fp);
    }

    shell_exec("{$this->config['cepstral']['swift']} -p audio/channels=1,audio/sampling-rate=$frequency $voice -o $fname.wav -f $fname.txt");
  }

  // stream it
  $ret = $this->stream_file($fname, $escape_digits);

```

// clean up old files  
$delete = time() - 2592000; // 1 month  
foreach(glob($this-\>config[‘phpagi’][‘tempdir’] . DIRECTORY\_SEPARATOR . ‘swift\_\*’) as $file)  
if(filemtime($file) \< $delete)  
unlink($file);

```
  return $ret;
}[/code][/quote]

```

If I delete all of the temp files in /var/spool/asterisk/sounds/tmp then it picks up the right voice without any other changes.

---

<div class="post-metadata">

**Author:** ![jsgoecke](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jsgoecke/32/585_2.png) [@jsgoecke](https://community.asterisk.org/u/jsgoecke)\
**Post date:** [November 28, 2005, 1:52pm UTC](https://community.asterisk.org/t/tts-engine/2732/9 "2005-11-28T13:52:05Z")

</div>

This solves the problem, looks like there might be a bug in PHPAGI for the swift function:

[quote="/var/lib/asterisk/agi-bin/cepstral\_demo.php"][code]\<?php  
//Script to invoke Cepstral  
require(‘phpagi.php’);  
error\_reporting(E\_ALL);  
$agi = new AGI();

$txt\_array = $agi-\>get\_variable(‘tts\_text’);  
if ($txt\_array != 0) {  
$text = $txt\_array[‘data’];  
$lang\_array = $agi-\>get\_variable(‘tts\_lang’);

```
    if ($lang_array != 0) {
            $lang = $lang_array['data'];
            if ($lang == 'en') {
                    [b]$swift_fn = $agi->swift($text, '', 8000, 'Diane');[/b]
            } elseif ($lang == 'es') {
                    [b]$swift_fn = $agi->swift($text, '', 8000, 'Miguel');[/b]
            } else {
                    [b]$swift_fn = $agi->swift($text, '', 8000, 'Diane');[/b]
            }
    } else {
            [b]$swift_fn = $agi->swift($text, '', 8000, 'Diane');[/b]
    }

```

}

System(‘rm ‘.$swift\_fn.’.\*’);  
?\>[/code]

[quote=“PHPAGI”]` // return $ret;
        return $fname;
    }`[/quote][/quote]

By simply returing the filename instead of the original value which was the output of $agi-\>stream\_file.

---

<div class="post-metadata">

**Author:** ![abdulzu](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@abdulzu](https://community.asterisk.org/u/abdulzu)\
**Post date:** [November 29, 2005, 11:54am UTC](https://community.asterisk.org/t/tts-engine/2732/10 "2005-11-29T11:54:52Z")

</div>

Hi MuppetMaster,

I am not using agiphp, i am using the perl. But i am going to apply your method in perl. If anything i will let you know.

Thank you for your kind of help
