2007-08-25 22:00:13 +00:00
|
|
|
#!/usr/bin/perl -s
|
|
|
|
# __________ __ ___.
|
|
|
|
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
# \/ \/ \/ \/ \/
|
2008-08-07 20:04:36 +00:00
|
|
|
# $Id$
|
2007-08-25 22:00:13 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Jonas Häggqvist
|
|
|
|
#
|
|
|
|
# All files in this archive are subject to the GNU General Public License.
|
|
|
|
# See the file COPYING in the source tree root for full license agreement.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use File::Basename;
|
|
|
|
use File::Copy;
|
|
|
|
use Switch;
|
|
|
|
use vars qw($V $C $t $l $e $E $s $S $i $v);
|
2007-09-01 08:38:10 +00:00
|
|
|
use IPC::Open2;
|
2007-08-25 22:00:13 +00:00
|
|
|
use IPC::Open3;
|
|
|
|
use Digest::MD5 qw(md5_hex);
|
2007-11-16 19:59:09 +00:00
|
|
|
use DirHandle;
|
2008-08-19 21:23:00 +00:00
|
|
|
use open ':encoding(utf8)';
|
|
|
|
use open ':std';
|
2007-08-25 22:00:13 +00:00
|
|
|
|
|
|
|
sub printusage {
|
|
|
|
print <<USAGE
|
|
|
|
|
|
|
|
Usage: voice.pl [options] [path to dir]
|
|
|
|
-V
|
|
|
|
Create voice file. You must also specify -t and -l.
|
|
|
|
|
|
|
|
-C
|
|
|
|
Create .talk clips.
|
|
|
|
|
|
|
|
-t=<target>
|
|
|
|
Specify which target you want to build voicefile for. Must include
|
|
|
|
any features that target supports.
|
|
|
|
|
|
|
|
-i=<target_id>
|
|
|
|
Numeric target id. Needed for voice building.
|
|
|
|
|
|
|
|
-l=<language>
|
|
|
|
Specify which language you want to build. Without .lang extension.
|
|
|
|
|
|
|
|
-e=<encoder>
|
|
|
|
Which encoder to use for voice strings
|
|
|
|
|
|
|
|
-E=<encoder options>
|
|
|
|
Which encoder options to use when compressing voice strings. Enclose
|
|
|
|
in double quotes if the options include spaces.
|
|
|
|
|
|
|
|
-s=<TTS engine>
|
|
|
|
Which TTS engine to use.
|
|
|
|
|
|
|
|
-S=<TTS engine options>
|
|
|
|
Options to pass to the TTS engine. Enclose in double quotes if the
|
|
|
|
options include spaces.
|
|
|
|
|
|
|
|
-v
|
|
|
|
Be verbose
|
|
|
|
USAGE
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialize TTS engine. May return an object or value which will be passed
|
|
|
|
# to voicestring and shutdown_tts
|
|
|
|
sub init_tts {
|
|
|
|
our $verbose;
|
|
|
|
my ($tts_engine, $tts_engine_opts, $language) = @_;
|
2007-09-01 08:38:10 +00:00
|
|
|
my %ret = ("name" => $tts_engine);
|
2007-08-25 22:00:13 +00:00
|
|
|
switch($tts_engine) {
|
|
|
|
case "festival" {
|
|
|
|
print("> festival $tts_engine_opts --server\n") if $verbose;
|
|
|
|
my $pid = open(FESTIVAL_SERVER, "| festival $tts_engine_opts --server > /dev/null 2>&1");
|
2007-09-01 08:38:10 +00:00
|
|
|
my $dummy = *FESTIVAL_SERVER; #suppress warning
|
2007-08-25 22:00:13 +00:00
|
|
|
$SIG{INT} = sub { kill TERM => $pid; print("foo"); panic_cleanup(); };
|
|
|
|
$SIG{KILL} = sub { kill TERM => $pid; print("boo"); panic_cleanup(); };
|
2007-09-01 08:38:10 +00:00
|
|
|
$ret{"pid"} = $pid;
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
2007-09-02 22:32:34 +00:00
|
|
|
case "sapi" {
|
2007-08-25 22:00:13 +00:00
|
|
|
my $toolsdir = dirname($0);
|
|
|
|
my $path = `cygpath $toolsdir -a -w`;
|
2007-11-18 18:44:45 +00:00
|
|
|
chomp($path);
|
2007-09-01 08:38:10 +00:00
|
|
|
$path = $path . '\\';
|
2007-09-02 22:32:34 +00:00
|
|
|
my $cmd = $path . "sapi_voice.vbs /language:$language $tts_engine_opts";
|
2007-09-01 08:38:10 +00:00
|
|
|
$cmd =~ s/\\/\\\\/g;
|
|
|
|
print("> cscript //nologo $cmd\n") if $verbose;
|
|
|
|
my $pid = open2(*CMD_OUT, *CMD_IN, "cscript //nologo $cmd");
|
2008-08-19 21:23:00 +00:00
|
|
|
binmode(*CMD_IN, ':encoding(utf16le)');
|
|
|
|
binmode(*CMD_OUT, ':encoding(utf16le)');
|
|
|
|
$SIG{INT} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); };
|
|
|
|
$SIG{KILL} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); };
|
|
|
|
print(CMD_IN "QUERY\tVENDOR\r\n");
|
2008-07-20 13:55:04 +00:00
|
|
|
my $vendor = readline(*CMD_OUT);
|
2008-08-19 21:23:00 +00:00
|
|
|
$vendor =~ s/\r\n//;
|
2007-09-04 22:13:52 +00:00
|
|
|
%ret = (%ret,
|
2007-09-04 22:03:05 +00:00
|
|
|
"stdin" => *CMD_IN,
|
|
|
|
"stdout" => *CMD_OUT,
|
|
|
|
"vendor" => $vendor);
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-01 08:38:10 +00:00
|
|
|
return \%ret;
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Shutdown TTS engine if necessary.
|
|
|
|
sub shutdown_tts {
|
2007-09-01 08:38:10 +00:00
|
|
|
my ($tts_object) = @_;
|
|
|
|
switch($$tts_object{"name"}) {
|
2007-08-25 22:00:13 +00:00
|
|
|
case "festival" {
|
|
|
|
# Send SIGTERM to festival server
|
2007-09-01 08:38:10 +00:00
|
|
|
kill TERM => $$tts_object{"pid"};
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
2007-09-02 22:32:34 +00:00
|
|
|
case "sapi" {
|
2008-08-19 21:23:00 +00:00
|
|
|
print({$$tts_object{"stdin"}} "QUIT\r\n");
|
2007-09-01 08:38:10 +00:00
|
|
|
close($$tts_object{"stdin"});
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Apply corrections to a voice-string to make it sound better
|
|
|
|
sub correct_string {
|
|
|
|
our $verbose;
|
2007-09-01 08:38:10 +00:00
|
|
|
my ($string, $language, $tts_object) = @_;
|
2007-08-25 22:00:13 +00:00
|
|
|
my $orig = $string;
|
|
|
|
switch($language) {
|
2007-09-04 22:03:05 +00:00
|
|
|
# General for all engines and languages
|
2007-09-04 22:13:52 +00:00
|
|
|
$string =~ s/USB/U S B/g;
|
|
|
|
$string =~ s/ID3/I D 3/g;
|
2007-08-25 22:00:13 +00:00
|
|
|
|
2007-09-04 22:03:05 +00:00
|
|
|
case "english" {
|
2007-10-02 16:34:06 +00:00
|
|
|
switch($$tts_object{"name"}) {
|
2007-10-02 17:32:30 +00:00
|
|
|
case ["sapi","festival"] {
|
2008-04-28 18:12:14 +00:00
|
|
|
$string =~ s/plugin(s?)/plug-in$1/ig; next
|
|
|
|
}
|
|
|
|
case "festival" {
|
|
|
|
$string =~ s/\ba\b/ay/ig;
|
2007-10-02 16:34:06 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-04 22:03:05 +00:00
|
|
|
}
|
|
|
|
case "deutsch" {
|
|
|
|
# for all german engines (e.g. for english words)
|
|
|
|
$string =~ s/alkaline/alkalein/ig;
|
|
|
|
$string =~ s/byte(s?)/beit$1/ig;
|
|
|
|
$string =~ s/clip(s?)/klipp$1/ig;
|
2008-11-03 07:45:45 +00:00
|
|
|
$string =~ s/\bcover/kawwer/ig;
|
2007-09-04 22:03:05 +00:00
|
|
|
$string =~ s/cuesheet/kjuschiet/ig;
|
|
|
|
$string =~ s/dither/didder/ig;
|
|
|
|
$string =~ s/equalizer/iquileiser/ig;
|
|
|
|
$string =~ s/\bflash\b/fläsh/ig;
|
|
|
|
$string =~ s/\bfirmware(s?)\b/firmwer$1/ig;
|
|
|
|
$string =~ s/\bI D 3 tag\b/I D 3 täg/ig; # can't just use "tag" here
|
|
|
|
$string =~ s/\bloudness\b/laudness/ig;
|
|
|
|
$string =~ s/\bunicode\b/unikod/ig;
|
|
|
|
switch($$tts_object{"name"}) {
|
|
|
|
case "sapi" { # just for SAPI
|
|
|
|
switch($$tts_object{"vendor"}) {
|
|
|
|
case "AT&T Labs" {
|
|
|
|
$string =~ s/alphabet/alfabet/ig;
|
|
|
|
$string =~ s/ampere/amper/ig;
|
|
|
|
$string =~ s/\bdezibel\b/de-zibell/ig;
|
|
|
|
$string =~ s/diddering/didde-ring/ig;
|
|
|
|
$string =~ s/energie\b/ener-gie/ig;
|
2007-11-19 21:21:45 +00:00
|
|
|
$string =~ s/\Blauf\b/-lauf/ig;
|
2007-09-04 22:03:05 +00:00
|
|
|
$string =~ s/\bnumerisch\b/numehrisch/ig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-14 17:48:18 +00:00
|
|
|
case "svenska" {
|
|
|
|
# for all swedish engines (e.g. for english words)
|
|
|
|
$string =~ s/kilobyte/kilobajt/ig;
|
|
|
|
$string =~ s/megabyte/megabajt/ig;
|
|
|
|
$string =~ s/gigabyte/gigabajt/ig;
|
|
|
|
$string =~ s/\bloudness\b/laudness/ig;
|
|
|
|
|
|
|
|
switch($$tts_object{"name"}) {
|
|
|
|
case "espeak" { # just for eSpeak
|
|
|
|
$string =~ s/ampere/ampär/ig;
|
|
|
|
$string =~ s/bokmärken/bok-märken/ig;
|
|
|
|
$string =~ s/generella/schenerella/ig;
|
|
|
|
$string =~ s/dithering/diddering/ig;
|
|
|
|
$string =~ s/\bunicode\b/jynikod/ig;
|
|
|
|
$string =~ s/uttoning/utoning/ig;
|
|
|
|
$string =~ s/procent/pro-cent/ig;
|
|
|
|
$string =~ s/spellistor/spelistor/ig;
|
|
|
|
$string =~ s/cuesheet/qjyschiit/ig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-19 17:44:15 +00:00
|
|
|
case "italiano" {
|
|
|
|
# for all italian engines (e.g. for english words)
|
|
|
|
$string =~ s/Replaygain/Ripleyghein/ig;
|
|
|
|
$string =~ s/Crossfade/Crossfeid/ig;
|
|
|
|
$string =~ s/beep/Bip/ig;
|
|
|
|
$string =~ s/cuesheet/chiushit/ig;
|
|
|
|
$string =~ s/fade/feid/ig;
|
|
|
|
$string =~ s/Crossfeed/crossfid/ig;
|
|
|
|
$string =~ s/Cache/chash/ig;
|
|
|
|
$string =~ s/\bfirmware(s?)\b/firmuer$1/ig;
|
|
|
|
$string =~ s/\bFile(s?)\b/fail$1/ig;
|
|
|
|
$string =~ s/\bloudness\b/laudness/ig;
|
|
|
|
$string =~ s/\bunicode\b/unikod/ig;
|
|
|
|
$string =~ s/Playlist/pleylist/ig;
|
|
|
|
$string =~ s/WavPack/wave pak/ig;
|
|
|
|
$string =~ s/BITRATE/bit reit/ig;
|
|
|
|
$string =~ s/Codepage/cod page/ig;
|
2008-03-27 21:26:19 +00:00
|
|
|
$string =~ s/PCM Wave/pcm Ue'iv/ig;
|
2007-11-19 17:44:15 +00:00
|
|
|
switch($$tts_object{"name"}) {
|
|
|
|
case "sapi" { # just for SAPI
|
|
|
|
switch($$tts_object{"vendor"}) {
|
|
|
|
case "Loquendo" {
|
|
|
|
$string =~ s/Inizializza/inizializa/ig;
|
|
|
|
}
|
|
|
|
case "ScanSoft, Inc" {
|
|
|
|
$string =~ s/V/v/ig;
|
|
|
|
$string =~ s/X/x/ig;
|
|
|
|
$string =~ s/stop/stohp/ig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
if ($orig ne $string) {
|
|
|
|
printf("%s -> %s\n", $orig, $string) if $verbose;
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Produce a wav file of the text given
|
|
|
|
sub voicestring {
|
|
|
|
our $verbose;
|
2007-09-01 08:38:10 +00:00
|
|
|
my ($string, $output, $tts_engine_opts, $tts_object) = @_;
|
2007-08-25 22:00:13 +00:00
|
|
|
my $cmd;
|
2007-09-01 08:38:10 +00:00
|
|
|
printf("Generate \"%s\" with %s in file %s\n", $string, $$tts_object{"name"}, $output) if $verbose;
|
|
|
|
switch($$tts_object{"name"}) {
|
2007-08-25 22:00:13 +00:00
|
|
|
case "festival" {
|
|
|
|
# festival_client lies to us, so we have to do awful soul-eating
|
|
|
|
# work with IPC::open3()
|
|
|
|
$cmd = "festival_client --server localhost --otype riff --ttw --output \"$output\"";
|
|
|
|
print("> $cmd\n") if $verbose;
|
|
|
|
# Open command, and filehandles for STDIN, STDOUT, STDERR
|
|
|
|
my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd);
|
|
|
|
# Put the string to speak into STDIN and close it
|
|
|
|
print(CMD_IN $string);
|
|
|
|
close(CMD_IN);
|
|
|
|
# Read all output from festival_client (because it LIES TO US)
|
|
|
|
while (<CMD_ERR>) {
|
|
|
|
}
|
|
|
|
close(CMD_OUT);
|
|
|
|
close(CMD_ERR);
|
|
|
|
}
|
|
|
|
case "flite" {
|
|
|
|
$cmd = "flite $tts_engine_opts -t \"$string\" \"$output\"";
|
|
|
|
print("> $cmd\n") if $verbose;
|
|
|
|
`$cmd`;
|
|
|
|
}
|
|
|
|
case "espeak" {
|
2007-11-16 21:33:24 +00:00
|
|
|
$cmd = "espeak $tts_engine_opts -w \"$output\"";
|
2007-08-25 22:00:13 +00:00
|
|
|
print("> $cmd\n") if $verbose;
|
2008-08-19 21:23:00 +00:00
|
|
|
open(ESPEAK, "| $cmd");
|
2007-08-25 22:00:13 +00:00
|
|
|
print ESPEAK $string . "\n";
|
|
|
|
close(ESPEAK);
|
|
|
|
}
|
2007-09-02 22:32:34 +00:00
|
|
|
case "sapi" {
|
2008-08-19 21:23:00 +00:00
|
|
|
print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n");
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
2007-09-01 20:03:20 +00:00
|
|
|
case "swift" {
|
2007-11-16 19:59:09 +00:00
|
|
|
$cmd = "swift $tts_engine_opts -o \"$output\" \"$string\"";
|
2007-09-01 20:03:20 +00:00
|
|
|
print("> $cmd\n") if $verbose;
|
|
|
|
system($cmd);
|
|
|
|
}
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-01 08:38:10 +00:00
|
|
|
# trim leading / trailing silence from the clip
|
|
|
|
sub wavtrim {
|
|
|
|
our $verbose;
|
|
|
|
my ($file, $threshold, $tts_object) = @_;
|
|
|
|
printf("Trim \"%s\"\n", $file) if $verbose;
|
2007-11-18 18:44:45 +00:00
|
|
|
my $cmd = "wavtrim \"$file\" $threshold";
|
2007-09-02 22:32:34 +00:00
|
|
|
if ($$tts_object{"name"} eq "sapi") {
|
2008-08-19 21:23:00 +00:00
|
|
|
print({$$tts_object{"stdin"}} "EXEC\t$cmd\r\n");
|
2007-09-01 08:38:10 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
print("> $cmd\n") if $verbose;
|
|
|
|
`$cmd`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-25 22:00:13 +00:00
|
|
|
# Encode a wav file into the given destination file
|
|
|
|
sub encodewav {
|
|
|
|
our $verbose;
|
2007-09-01 08:38:10 +00:00
|
|
|
my ($input, $output, $encoder, $encoder_opts, $tts_object) = @_;
|
2007-08-25 22:00:13 +00:00
|
|
|
printf("Encode \"%s\" with %s in file %s\n", $input, $encoder, $output) if $verbose;
|
2007-11-18 18:44:45 +00:00
|
|
|
my $cmd = "$encoder $encoder_opts \"$input\" \"$output\"";
|
2007-09-02 22:32:34 +00:00
|
|
|
if ($$tts_object{"name"} eq "sapi") {
|
2008-08-19 21:23:00 +00:00
|
|
|
print({$$tts_object{"stdin"}} "EXEC\t$cmd\r\n");
|
2007-09-01 08:38:10 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
print("> $cmd\n") if $verbose;
|
|
|
|
`$cmd`;
|
|
|
|
}
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
|
2007-09-01 08:38:10 +00:00
|
|
|
# synchronize the clip generation / processing if it's running in another process
|
|
|
|
sub synchronize {
|
|
|
|
my ($tts_object) = @_;
|
2007-09-02 22:32:34 +00:00
|
|
|
if ($$tts_object{"name"} eq "sapi") {
|
2008-08-19 21:23:00 +00:00
|
|
|
print({$$tts_object{"stdin"}} "SYNC\t42\r\n");
|
2007-09-01 08:38:10 +00:00
|
|
|
my $wait = readline($$tts_object{"stdout"});
|
|
|
|
#ignore what's actually returned
|
|
|
|
}
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Run genlang and create voice clips for each string
|
|
|
|
sub generateclips {
|
|
|
|
our $verbose;
|
|
|
|
my ($language, $target, $encoder, $encoder_opts, $tts_engine, $tts_engine_opts) = @_;
|
|
|
|
my $english = dirname($0) . '/../apps/lang/english.lang';
|
|
|
|
my $langfile = dirname($0) . '/../apps/lang/' . $language . '.lang';
|
|
|
|
my $id = '';
|
|
|
|
my $voice = '';
|
2007-11-18 18:44:45 +00:00
|
|
|
my $cmd = "genlang -o -t=$target -e=$english $langfile 2>/dev/null";
|
2007-08-25 22:00:13 +00:00
|
|
|
my $pool_file;
|
2008-08-19 21:23:00 +00:00
|
|
|
open(VOICEFONTIDS, "> voicefontids");
|
2007-08-25 22:00:13 +00:00
|
|
|
my $i = 0;
|
2007-09-02 00:50:08 +00:00
|
|
|
local $| = 1; # make progress indicator work reliably
|
2007-08-25 22:00:13 +00:00
|
|
|
|
|
|
|
my $tts_object = init_tts($tts_engine, $tts_engine_opts, $language);
|
|
|
|
print("Generating voice clips");
|
|
|
|
print("\n") if $verbose;
|
|
|
|
for (`$cmd`) {
|
|
|
|
my $line = $_;
|
|
|
|
print(VOICEFONTIDS $line);
|
|
|
|
if ($line =~ /^id: (.*)$/) {
|
|
|
|
$id = $1;
|
|
|
|
}
|
|
|
|
elsif ($line =~ /^voice: "(.*)"$/) {
|
|
|
|
$voice = $1;
|
|
|
|
if ($id !~ /^NOT_USED_.*$/ && $voice ne "") {
|
|
|
|
my $wav = $id . '.wav';
|
|
|
|
my $mp3 = $id . '.mp3';
|
|
|
|
|
|
|
|
# Print some progress information
|
|
|
|
if (++$i % 10 == 0 and !$verbose) {
|
|
|
|
print(".");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Apply corrections to the string
|
2007-09-04 22:03:05 +00:00
|
|
|
$voice = correct_string($voice, $language, $tts_object);
|
2007-08-25 22:00:13 +00:00
|
|
|
|
2007-09-04 22:03:05 +00:00
|
|
|
# If we have a pool of snippets, see if the string exists there first
|
2007-08-25 22:00:13 +00:00
|
|
|
if (defined($ENV{'POOL'})) {
|
2007-09-04 22:03:05 +00:00
|
|
|
$pool_file = sprintf("%s/%s-%s.mp3", $ENV{'POOL'},
|
|
|
|
md5_hex("$voice $tts_engine $tts_engine_opts $encoder_opts"),
|
|
|
|
$language);
|
2007-08-25 22:00:13 +00:00
|
|
|
if (-f $pool_file) {
|
|
|
|
printf("Re-using %s (%s) from pool\n", $id, $voice) if $verbose;
|
|
|
|
copy($pool_file, $mp3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Don't generate MP3 if it already exists (probably from the POOL)
|
|
|
|
if (! -f $mp3) {
|
|
|
|
if ($id eq "VOICE_PAUSE") {
|
|
|
|
print("Use distributed $wav\n") if $verbose;
|
|
|
|
copy(dirname($0)."/VOICE_PAUSE.wav", $wav);
|
|
|
|
}
|
|
|
|
else {
|
2007-09-01 08:38:10 +00:00
|
|
|
voicestring($voice, $wav, $tts_engine_opts, $tts_object);
|
|
|
|
wavtrim($wav, 500, $tts_object);
|
|
|
|
# 500 seems to be a reasonable default for now
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
|
2007-09-01 08:38:10 +00:00
|
|
|
encodewav($wav, $mp3, $encoder, $encoder_opts, $tts_object);
|
|
|
|
synchronize($tts_object);
|
2007-08-25 22:00:13 +00:00
|
|
|
if (defined($ENV{'POOL'})) {
|
|
|
|
copy($mp3, $pool_file);
|
|
|
|
}
|
|
|
|
unlink($wav);
|
|
|
|
}
|
|
|
|
$voice = "";
|
|
|
|
$id = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print("\n");
|
|
|
|
close(VOICEFONTIDS);
|
2007-09-01 08:38:10 +00:00
|
|
|
shutdown_tts($tts_object);
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Assemble the voicefile
|
|
|
|
sub createvoice {
|
|
|
|
our $verbose;
|
|
|
|
my ($language, $target_id) = @_;
|
|
|
|
my $outfile = "";
|
2007-11-27 13:47:52 +00:00
|
|
|
$outfile = sprintf("%s.voice", $language);
|
2007-08-25 22:00:13 +00:00
|
|
|
printf("Saving voice file to %s\n", $outfile) if $verbose;
|
2007-11-18 18:44:45 +00:00
|
|
|
my $cmd = "voicefont 'voicefontids' $target_id ./ $outfile";
|
2007-08-25 22:00:13 +00:00
|
|
|
print("> $cmd\n") if $verbose;
|
|
|
|
my $output = `$cmd`;
|
|
|
|
print($output) if $verbose;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub deletemp3s() {
|
|
|
|
for (glob('*.mp3')) {
|
|
|
|
unlink($_);
|
|
|
|
}
|
|
|
|
for (glob('*.wav')) {
|
|
|
|
unlink($_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub panic_cleanup {
|
|
|
|
deletemp3s();
|
|
|
|
die "moo";
|
|
|
|
}
|
|
|
|
|
2007-11-16 19:59:09 +00:00
|
|
|
# Generate .talk clips
|
|
|
|
sub gentalkclips {
|
|
|
|
our $verbose;
|
|
|
|
my ($dir, $tts_object, $encoder, $encoder_opts, $tts_engine_opts, $i) = @_;
|
|
|
|
my $d = new DirHandle $dir;
|
|
|
|
while (my $file = $d->read) {
|
|
|
|
my ($voice, $wav, $mp3);
|
|
|
|
# Print some progress information
|
|
|
|
if (++$i % 10 == 0 and !$verbose) {
|
|
|
|
print(".");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Convert to a complete path
|
|
|
|
my $path = sprintf("%s/%s", $dir, $file);
|
2007-11-16 20:02:02 +00:00
|
|
|
|
|
|
|
$voice = $file;
|
|
|
|
$wav = sprintf("%s.talk.wav", $path);
|
|
|
|
|
2007-11-16 19:59:09 +00:00
|
|
|
# Ignore dot-dirs and talk files
|
|
|
|
if ($file eq '.' || $file eq '..' || $file =~ /\.talk$/) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
# Element is a dir
|
|
|
|
if ( -d $path) {
|
2007-11-16 23:42:18 +00:00
|
|
|
gentalkclips($path, $tts_object, $encoder, $encoder_opts, $tts_engine_opts, $i);
|
2007-11-16 19:59:09 +00:00
|
|
|
$mp3 = sprintf("%s/_dirname.talk", $path);
|
|
|
|
}
|
|
|
|
# Element is a file
|
|
|
|
else {
|
|
|
|
$mp3 = sprintf("%s.talk", $path);
|
|
|
|
$voice =~ s/\.[^\.]*$//; # Trim extension
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Talkclip %s: %s", $mp3, $voice) if $verbose;
|
|
|
|
|
|
|
|
voicestring($voice, $wav, $tts_engine_opts, $tts_object);
|
|
|
|
wavtrim($wav, 500, $tts_object);
|
|
|
|
# 500 seems to be a reasonable default for now
|
|
|
|
encodewav($wav, $mp3, $encoder, $encoder_opts, $tts_object);
|
2007-11-19 23:24:27 +00:00
|
|
|
synchronize($tts_object);
|
2007-11-16 19:59:09 +00:00
|
|
|
unlink($wav);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-25 22:00:13 +00:00
|
|
|
# Check parameters
|
|
|
|
my $printusage = 0;
|
|
|
|
unless (defined($V) or defined($C)) { print("Missing either -V or -C\n"); $printusage = 1; }
|
|
|
|
if (defined($V)) {
|
|
|
|
unless (defined($t)) { print("Missing -t argument\n"); $printusage = 1; }
|
|
|
|
unless (defined($l)) { print("Missing -l argument\n"); $printusage = 1; }
|
|
|
|
unless (defined($i)) { print("Missing -i argument\n"); $printusage = 1; }
|
|
|
|
}
|
|
|
|
elsif (defined($C)) {
|
|
|
|
unless (defined($ARGV[0])) { print "Missing path argument\n"; $printusage = 1; }
|
|
|
|
}
|
|
|
|
unless (defined($e)) { print("Missing -e argument\n"); $printusage = 1; }
|
|
|
|
unless (defined($E)) { print("Missing -E argument\n"); $printusage = 1; }
|
|
|
|
unless (defined($s)) { print("Missing -s argument\n"); $printusage = 1; }
|
|
|
|
unless (defined($S)) { print("Missing -S argument\n"); $printusage = 1; }
|
|
|
|
if ($printusage == 1) { printusage(); exit 1; }
|
|
|
|
|
|
|
|
if (defined($v) or defined($ENV{'V'})) {
|
|
|
|
our $verbose = 1;
|
|
|
|
}
|
|
|
|
|
2007-11-18 18:44:45 +00:00
|
|
|
# add the tools dir to the path temporarily, for calling various tools
|
|
|
|
$ENV{'PATH'} = dirname($0) . ':' . $ENV{'PATH'};
|
|
|
|
|
2007-08-25 22:00:13 +00:00
|
|
|
|
|
|
|
# Do what we're told
|
|
|
|
if ($V == 1) {
|
2007-11-16 19:59:09 +00:00
|
|
|
# Only do the panic cleanup for voicefiles
|
|
|
|
$SIG{INT} = \&panic_cleanup;
|
|
|
|
$SIG{KILL} = \&panic_cleanup;
|
|
|
|
|
2007-08-25 22:00:13 +00:00
|
|
|
printf("Generating voice\n Target: %s\n Language: %s\n Encoder (options): %s (%s)\n TTS Engine (options): %s (%s)\n",
|
|
|
|
$t, $l, $e, $E, $s, $S);
|
|
|
|
generateclips($l, $t, $e, $E, $s, $S);
|
|
|
|
createvoice($l, $i);
|
|
|
|
deletemp3s();
|
|
|
|
}
|
|
|
|
elsif ($C) {
|
2007-11-16 19:59:09 +00:00
|
|
|
printf("Generating .talk clips\n Path: %s\n Language: %s\n Encoder (options): %s (%s)\n TTS Engine (options): %s (%s)\n", $ARGV[0], $l, $e, $E, $s, $S);
|
|
|
|
my $tts_object = init_tts($s, $S, $l);
|
2007-11-18 17:10:50 +00:00
|
|
|
gentalkclips($ARGV[0], $tts_object, $e, $E, $S, 0);
|
2007-11-16 19:59:09 +00:00
|
|
|
shutdown_tts($tts_object);
|
2007-08-25 22:00:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printusage();
|
|
|
|
exit 1;
|
|
|
|
}
|