Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Speech synthesis module

by ady (Deacon)
on Jan 19, 2007 at 18:57 UTC ( [id://595530]=perlquestion: print w/replies, xml ) Need Help??

ady has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks

I'm interested in a simple way of getting a Perl (Nant etc) script to announce the result of it's work using the pc loudspeaker, ie. converting an arbitrary text string to voice (text-to-speech synthesis).As simple as : say "hello world".

I've searched CPAN and other repositories (Active state et al) but there seems to be no high level and easily installable Perl module to achieve this functionality, -- at least not for Windows/Win32.

There are several freeware programs that may be run in "command line/batch" mode to achieve the requested "speak" functionality, buth that's overly clunky.

Anyone had the same issue and resolved it?
best regards
allan dystrup

update

Here's a quick hack for a Perl "SAY" program. Compiled to say.exe I can hand it any text (program arg or pipe), and it will speak it...
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; use Speech::Synthesis; use Getopt::Easy; # Exports: get_options() and %O my $engine = 'SAPI5'; # SAPI5|'SAPI4'|'MSAgent'|'MacSpeech'|'Festival +' my @voices = Speech::Synthesis->InstalledVoices( engine => $engine); my @avatars = Speech::Synthesis->InstalledAvatars(engine => $engine); my $ss; ### =========================================================== ### void test_voices(void) ### =========================================================== sub test_voices { foreach my $voice (@voices) { # Construct new Speech::Synthesis object ($ss) my %params = ( engine => $engine, avatar => undef, language => $voice->{language}, voice => $voice->{id}, async => 0 ); my $ss = Speech::Synthesis->new( %params ); # Print Voice info and speak description print "\n\tId\t=\t" . $voice->{id}, "\n\tName\t=\t" . $voice->{name}, "\n\tVoice\t=\t" . $voice->{description}, "\n\tLang.\t=\t" . $voice->{language}, "\n\tGender\t=\t" . $voice->{gender}, "\n\tAge\t=\t" . $voice->{age}; $ss->speak($voice->{description}|| "test"); } } ### =========================================================== ### ss set_voice(name) ### =========================================================== sub set_voice { my $name = shift || 'Default'; # Build hash of available voices (name->id, cf. test_voices) my $reg = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Toke +ns'; my %voices = ( ATTCrystal => $reg . '\ATT-DT-14-Crystal16', ATTMike => $reg . '\ATT-DT-14-Mike16', CMUKal => $reg . '\CMUKal', MSMary => $reg . '\MSMary', MSMike => $reg . '\MSMike', MSSam => $reg . '\MSSam', Default => $reg . '\ATT-DT-14-Crystal16', ); # lookup name->id, and set $voice_id my $voice_id = $voices{Default}; foreach my $key (sort keys %voices) { if ($key =~ /$name/i) { $voice_id = $voices{$key}; last; } } # Construct new Speech::Synthesis object ($ss) for $voice_id my %params = ( engine => $engine, voice => $voice_id, async => 0 ); $ss = Speech::Synthesis->new( %params ); } ### =========================================================== ### IO ### =========================================================== sub is_interactive { # called from shell (1) or via pipe (0) ? return -t STDIN && -t STDOUT; } sub slurp_STDIN { # return piped stream as string local($/); return <STDIN>; } ### =========================================================== ### unit test ### =========================================================== =cut test_voices(); set_voice('ATTMike'); $ss->speak("hello Mike"); set_voice('ATTCrystal'); $ss->speak("hello Crystal"); =cut ### =========================================================== ### main ### =========================================================== get_options "v-voice=", "usage: say [-v voice] sentence"; # print Dumper(\%O); set_voice($O{voice}); my $sentence = is_interactive() ? shift : slurp_STDIN; $sentence ||= "Please provide a text to speak!"; $ss->speak($sentence);

Replies are listed 'Best First'.
Re: Speech synthesis module
by hesco (Deacon) on Jan 19, 2007 at 19:53 UTC
    I built (and rebuilt) and maintained for a number of years a machine for an officer of an organization where I used to work. He was born blind, but learned to keyboard (both braille and qwerty) in school.

    I installed a Debian based version of the blinux project, which used the Festival software speech synthesizer (saving us hundreds of dollars on a hardware speech synthesis card). As I recall, Festival was only one of two or three choices we had for software text-to-speech synthesis.

    Since he operated completely in plain text, with a speech synthysis process piping it to him, and dealt almost exclusively with email, we were able to build his machine on a used 4gb drive, which he never filled in the time I was at that office.

    Teaching his to use emacs (which streamlined the process for him of handling email through a tts processor), was the only exposure I have had to emacs. I'm a vim kind of guy myself. But the emacspeaks project has rebuilt the emacs code to process most of its user interactions through tts for a blind user. It makes it possible to handle email and web browsing and lots of other functions I never explored.

    Our blind user had to be patient until his machine would sing at him upon presenting him with a login prompt. After that he would log in in silence, but get an auditory cue upon success. Then, again in silence, he would evoke emacspeak. After that every keystroke would be echo'd back both to the terminal and also through the speakers.

    I have no idea what is available for windows boxes. I've barely touched one in years.

    -- Hugh

    if( $lal && $lol ) { $life++; }
Re: Speech synthesis module
by zentara (Archbishop) on Jan 19, 2007 at 20:01 UTC
    I've used Flite , which is an offshoot of the more complex Festival speech engine. It is fast and works pretty well. You could open it in a piped open, and print command to it to say things. Its as simple as "system flite -t 'Wow' ".

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Speech synthesis module
by Albannach (Monsignor) on Jan 19, 2007 at 20:33 UTC
    If you don't really need arbitrary text, you might find Win32::Sound useful. I use it in many of my long-running utilities to alert me of problems. You can easily record messages into .WAV files (I have been known to get my kids to record messages too), or you can assemble a message from individual .WAVs for some flexibility. For instance I have a file that says "unable to open" and then two other files that say "input" and "output". It's simple to keep a directory of such resources and assemble statements as needed, and though it doesn't give you the flexibility of speech synthesis, the sound is probably more understandable and I imagine it uses a lot less CPU.

    --
    I'd like to be able to assign to an luser

Re: Speech synthesis module
by ady (Deacon) on Jan 20, 2007 at 09:30 UTC
    Festival looks interesting, and esp. Flite offers exactly the functionality I'm looking for; The problem is, that Flite according to the documentation only installs on WinCE (and not XP/2K).

    I am currently using pre-recorded WAV-messages (like Albannach suggests), but i'd like to include variable info such as build number in my messages.

    An application like TextSound offers a TTS.exe that accepts a text string on the command line and converts it to .WAV on-the-fly, but you have to pay $30 for a licence.

    So, i've installed Jouke Visser's Speech-Synthesis-0.03 from CPAN. Though I found no ppm for windows, the make instalation went smooth on WinXP and this module will allow me to build a simple perl "SAY"-script that accepts an arbitrary text (including variables) and speaks it aloud. -- I have to find some more natural sounding voices than Mike, Sam & Mary tho'...

    Thank's for the leads!
    allan
Re: Speech synthesis module
by ferreira (Chaplain) on Jan 19, 2007 at 19:12 UTC

    Even though I never tried any kind of speech synthesizer or processor in Perl, I heard about a work by Jouke Visser (for instance, this article on perl.com) on helping disabled people to interact with the computer and whose project included a tool named pVoice. Following the links, you may find out how usable this is by now. And if it is usable, you can discover if it fits your needs.

      Hi ferreira; I checed out the pVoice and it's a full fledged picture based application for "Augmentative and Alternative Communication (AAC)".
      I'm on the outlook for a very simple "say" wrapper module for speaking aloud simple text strings, so that would be overkill.
      best regards/ allan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://595530]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found