Loquendo TTS
Created by: RPR_RPR,Last modification on Mon 01 of Dec, 2008 [15:14 UTC]
Loquendo TTS is a commercial Speech software, including English, French, German, Spanish, Italian, Dutch, Portuguese, Greek, Catalan and Swedish voices
The current version of Loquendo TTS as of this page update is 7.
There are a few ways to Setup Loquendo TTS with Asterisk:
* The first one is to use an AGI script and a loquendo application developed by new-phone - Abantos Networks.
* The second one is to use a dialplan application written by Manuel Guesdon
Step 1: Install Loquendo TTS using the instructions from the package. (Usually installs in /opt/Loquendo/LTTS7/)
Step 2: Install Asterisk with AGi support.
Step 3: Install Asterisk::AGI support in perl using cpan:
First update CPAN
perl -MCPAN -e shell
cpan> install MD5
cpan> install CPAN
cpan> reload cpan
Then install Asterisk::AGI module
cpan> install Asterisk::AGI
Step 4: Create the script loquendo.agi with the following code in the asterisk agi directory . (Usually /var/lib/asterisk/agi-bin/)
#!/usr/bin/perl
use Asterisk::AGI;
use File::Basename;
use Digest::MD5 qw(md5_hex);
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my ($text)=@ARGV;
my $hash = md5_hex($text);
my $voice= "Leonor";
my $sounddir = "/var/lib/asterisk/sounds/tts";
my $wavefile = "$sounddir/"."tts-$hash-$voice.sln";
my $loquendoDir= "/opt/Loquendo/LTTS7/bin/";
unless (-f $wavefile) {
open(fileOUT, ">$sounddir"."/say-text-$hash.txt");
print fileOUT "$text";
close(fileOUT);
my $execf=$loquendoDir."txt2audio $sounddir/say-text-$hash.txt $wavefile $voice";
system($execf);
unlink($sounddir."/say-text-$hash.txt");
}
$AGI->stream_file('tts/'.basename($wavefile,'.sln'));
Step 5: Compile application txt2audio from new-phone based in simple loquendo sample.
To compile, create directory /opt/Loquendo/LTTS7/samples/c/txt2audio with this two files and execute make.
txt2audio.c
#include <stdio.h>
#include "loqtts.h" /* Loquendo TTS include file */
int main(int argc, char *argv[])
{
ttsHandleType hSession, hReader; /* Reader handle */
ttsResultType r; /* Error code returned by TTS APIs */
const char* p = "Ludoviko";
if(argc == 4) {
p = argv[3];
} else if(argc !=3) {
fprintf(stderr, "Run '%s <textFile> <wavFile> [<voiceName>] '\n", argv[0]);
return -1;
}
fprintf(stderr, "Using voice %s\n", p);
/* Initializes a LoquendoTTS Reader using the implicit session */
r = ttsNewSession(&hSession,"/opt/Loquendo/LTTS7/bin/default.session");
if (r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
ttsDeleteSession(NULL); /* deallocates all tts resources */
return r;
}
r = ttsNewReader(&hReader, hSession);
if (r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
ttsDeleteSession(NULL); /* deallocates all tts resources */
return r;
}
/* Sets the persona parameters using mother tongue and default style */
r = ttsLoadPersona(hReader, p, NULL, NULL);
if(r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
ttsDeleteSession(NULL); /* deallocates all tts resources */
return r;
}
/* Sends samples directly to the audio board */
r = ttsSetAudio(hReader, "LTTS7AudioFile", argv[2], 8000, tts_LINEAR, tts_MONO, 0);
if(r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
ttsDeleteSession(NULL); /* deallocates all tts resources */
return r;
}
/* Converts text to speech */
r = ttsRead( hReader, argv[1], ttsFALSE, ttsTRUE, NULL); /* ttsRead keeps control until the end */
if (r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
}
ttsDeleteSession(NULL); /* deallocates all tts resources */
return 0;
}
makefile
CC = gcc
CFLAGS = -O -Wall
PROG_NAME = txt2audio
../../../bin/$(PROG_NAME): $(PROG_NAME).c
cd ../../../bin && $(CC) $(CFLAGS) -I ../include libLoqTTS7.so ../samples/c/$(PROG_NAME)/$^ -Wl,--rpath,. -o $(PROG_NAME)
clean :
rm -f ../../../bin/$(PROG_NAME)
Finally: Use in dialplan to say the 'Hello world' text on the channel like this:
AGI(loquendo, 'Hello world')
Notes:
1. txt2audio.c needs to be patched if your Loquendo installation is in different location than the default of /opt/... you can either change the path on line 20 to the correct path or set it to NULL and do an export LTTS7_DEFAULTSESSION before using it. If anyone has a better suggestion, please add it.
2. the makefile needs a tab character in front of lines 6 and 9 else making will fail with 'missing separator'
Download the application source file from http://free.oxymium.net/Asterisk/app_loquendo.c.
I've been reported that this code doesn't work with asterisk 1.4 nor with Loquendo TTS 7.
You must compile and install the code, but there are no instructions in the Manuel's page.
Looking the code, I've collected information about config file _loquendo-tts.conf (usually in /etc/asterisk)
[general]
configurationPath=/opt/Loquendo/LTTS/default.session
cacheDir=/tmp/LoquendoCache
cacheDirLevels=4
[defaults]
streamIt=
coding=ulaw
sampleRate=8000
pitch=55
voice=Jorge
speed=55
volume=50
textCoding=ansi
* Asterisk tips and tricks
* Spanish version
How to integrate with asterisk.
The current version of Loquendo TTS as of this page update is 7.
There are a few ways to Setup Loquendo TTS with Asterisk:
* The first one is to use an AGI script and a loquendo application developed by new-phone - Abantos Networks.
* The second one is to use a dialplan application written by Manuel Guesdon
Method 1 : To Use an AGI script
Step 1: Install Loquendo TTS using the instructions from the package. (Usually installs in /opt/Loquendo/LTTS7/)
Step 2: Install Asterisk with AGi support.
Step 3: Install Asterisk::AGI support in perl using cpan:
First update CPAN
perl -MCPAN -e shell
cpan> install MD5
cpan> install CPAN
cpan> reload cpan
Then install Asterisk::AGI module
cpan> install Asterisk::AGI
Step 4: Create the script loquendo.agi with the following code in the asterisk agi directory . (Usually /var/lib/asterisk/agi-bin/)
#!/usr/bin/perl
use Asterisk::AGI;
use File::Basename;
use Digest::MD5 qw(md5_hex);
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my ($text)=@ARGV;
my $hash = md5_hex($text);
my $voice= "Leonor";
my $sounddir = "/var/lib/asterisk/sounds/tts";
my $wavefile = "$sounddir/"."tts-$hash-$voice.sln";
my $loquendoDir= "/opt/Loquendo/LTTS7/bin/";
unless (-f $wavefile) {
open(fileOUT, ">$sounddir"."/say-text-$hash.txt");
print fileOUT "$text";
close(fileOUT);
my $execf=$loquendoDir."txt2audio $sounddir/say-text-$hash.txt $wavefile $voice";
system($execf);
unlink($sounddir."/say-text-$hash.txt");
}
$AGI->stream_file('tts/'.basename($wavefile,'.sln'));
Step 5: Compile application txt2audio from new-phone based in simple loquendo sample.
To compile, create directory /opt/Loquendo/LTTS7/samples/c/txt2audio with this two files and execute make.
txt2audio.c
#include <stdio.h>
#include "loqtts.h" /* Loquendo TTS include file */
int main(int argc, char *argv[])
{
ttsHandleType hSession, hReader; /* Reader handle */
ttsResultType r; /* Error code returned by TTS APIs */
const char* p = "Ludoviko";
if(argc == 4) {
p = argv[3];
} else if(argc !=3) {
fprintf(stderr, "Run '%s <textFile> <wavFile> [<voiceName>] '\n", argv[0]);
return -1;
}
fprintf(stderr, "Using voice %s\n", p);
/* Initializes a LoquendoTTS Reader using the implicit session */
r = ttsNewSession(&hSession,"/opt/Loquendo/LTTS7/bin/default.session");
if (r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
ttsDeleteSession(NULL); /* deallocates all tts resources */
return r;
}
r = ttsNewReader(&hReader, hSession);
if (r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
ttsDeleteSession(NULL); /* deallocates all tts resources */
return r;
}
/* Sets the persona parameters using mother tongue and default style */
r = ttsLoadPersona(hReader, p, NULL, NULL);
if(r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
ttsDeleteSession(NULL); /* deallocates all tts resources */
return r;
}
/* Sends samples directly to the audio board */
r = ttsSetAudio(hReader, "LTTS7AudioFile", argv[2], 8000, tts_LINEAR, tts_MONO, 0);
if(r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
ttsDeleteSession(NULL); /* deallocates all tts resources */
return r;
}
/* Converts text to speech */
r = ttsRead( hReader, argv[1], ttsFALSE, ttsTRUE, NULL); /* ttsRead keeps control until the end */
if (r != tts_OK) {
fprintf(stderr, "%s\n", ttsGetErrorMessage(r));
}
ttsDeleteSession(NULL); /* deallocates all tts resources */
return 0;
}
makefile
CC = gcc
CFLAGS = -O -Wall
PROG_NAME = txt2audio
../../../bin/$(PROG_NAME): $(PROG_NAME).c
cd ../../../bin && $(CC) $(CFLAGS) -I ../include libLoqTTS7.so ../samples/c/$(PROG_NAME)/$^ -Wl,--rpath,. -o $(PROG_NAME)
clean :
rm -f ../../../bin/$(PROG_NAME)
Finally: Use in dialplan to say the 'Hello world' text on the channel like this:
AGI(loquendo, 'Hello world')
Notes:
1. txt2audio.c needs to be patched if your Loquendo installation is in different location than the default of /opt/... you can either change the path on line 20 to the correct path or set it to NULL and do an export LTTS7_DEFAULTSESSION before using it. If anyone has a better suggestion, please add it.
2. the makefile needs a tab character in front of lines 6 and 9 else making will fail with 'missing separator'
Method 2 : To use a dialplan application.
Download the application source file from http://free.oxymium.net/Asterisk/app_loquendo.c.
I've been reported that this code doesn't work with asterisk 1.4 nor with Loquendo TTS 7.
You must compile and install the code, but there are no instructions in the Manuel's page.
Looking the code, I've collected information about config file _loquendo-tts.conf (usually in /etc/asterisk)
[general]
configurationPath=/opt/Loquendo/LTTS/default.session
cacheDir=/tmp/LoquendoCache
cacheDirLevels=4
[defaults]
streamIt=
coding=ulaw
sampleRate=8000
pitch=55
voice=Jorge
speed=55
volume=50
textCoding=ansi
See also
* TTS: Text-toSpeech solutions* Asterisk tips and tricks
* Spanish version

Comments