PERL Text-to-Speech using Cepstral voices (libswift)

I’ve released two new PERL modules:

Speech::Swift – a PERL interface to the Cepstral text-to-speech engine, Swift.

and

Speech::Swift::Simple – a simplified interface to Speech::Swift

The libswift shared library is required to support this code, which is included with every voice downloaded from Cepstral.

The reason for two releases, is that the Speech::Swift module exports all (well, almost all) the underlying functions of the libswift.so library, while Speech::Swift::Simple has a simplified interface to generate speech in a just a few function calls.

For example:

#!/usr/bin/perl

use Speech::Swift::Simple;

#
# create a new Speech::Swift::Simple with one channel audio, and 16bit encoding.
#
my $s = new Speech::Swift::Simple(
         channels => 1,
         encoding => Speech::Swift::AUDIO_ENCODING_PCM16
);

#
# set the voice to use by name
#
$s->set_voice("Allison");

#
# synthesize the text, and return it as a Speech::Swift::Simple::Wav object
#
my $wav = $s->generate("My name is allison");

#
# write the wav object to a file.
#
$wav->write("test.wav");

Or use the Speech::Swift library directly, for a more low-level interface.

The audio output is always as a WAV file; you can use one of the many audio modules available from CPAN, likeĀ Audio::GSM or Audio::MPEG, to re-encode the audio as needed.

Both PERL modules are available for download from CPAN now.

2 thoughts on “PERL Text-to-Speech using Cepstral voices (libswift)

  1. speech to text

    That is exactly what I was looking for. Please approve my appreciate for this site. Thanks!

  2. mike

    Problem installing on OSX

    pro-5:Speech-Swift-1.0 mike$ perl Makefile.PL
    Warning (mostly harmless): No library found for -lswift
    Warning (mostly harmless): No library found for -lceplang_en
    Warning (mostly harmless): No library found for -lceplex_us
    Writing Makefile for Speech::Swift
    Writing MYMETA.yml and MYMETA.json
    pro-5:Speech-Swift-1.0 mike$ make
    Skip blib/lib/Speech/Swift.pm (unchanged)
    cc -c -I. -I/opt/swift/include -arch i386 -arch x86_64 -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector -Os -DVERSION=\”1.0\” -DXS_VERSION=\”1.0\” “-I/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE” Swift.c
    Swift.xs:51:10: fatal error: ‘swift.h’ file not found
    #include “swift.h”
    ^
    1 error generated.
    make: *** [Swift.o] Error 1

Leave a Reply

Your email address will not be published. Required fields are marked *