diff options
-rwxr-xr-x | tools/voice.pl | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/tools/voice.pl b/tools/voice.pl index a07accaf22..98f67337d4 100755 --- a/tools/voice.pl +++ b/tools/voice.pl | |||
@@ -24,6 +24,7 @@ use vars qw($V $C $t $l $e $E $s $S $i $v); | |||
24 | use IPC::Open2; | 24 | use IPC::Open2; |
25 | use IPC::Open3; | 25 | use IPC::Open3; |
26 | use Digest::MD5 qw(md5_hex); | 26 | use Digest::MD5 qw(md5_hex); |
27 | use DirHandle; | ||
27 | 28 | ||
28 | sub printusage { | 29 | sub printusage { |
29 | print <<USAGE | 30 | print <<USAGE |
@@ -234,7 +235,7 @@ sub voicestring { | |||
234 | print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n"); | 235 | print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n"); |
235 | } | 236 | } |
236 | case "swift" { | 237 | case "swift" { |
237 | $cmd = "swift $tts_engine_opts -o $output \"$string\""; | 238 | $cmd = "swift $tts_engine_opts -o \"$output\" \"$string\""; |
238 | print("> $cmd\n") if $verbose; | 239 | print("> $cmd\n") if $verbose; |
239 | system($cmd); | 240 | system($cmd); |
240 | } | 241 | } |
@@ -251,7 +252,7 @@ sub wavtrim { | |||
251 | print({$$tts_object{"stdin"}} "EXEC\t$cmd\r\n"); | 252 | print({$$tts_object{"stdin"}} "EXEC\t$cmd\r\n"); |
252 | } | 253 | } |
253 | else { | 254 | else { |
254 | my $cmd = dirname($0) . "/wavtrim $file $threshold"; | 255 | my $cmd = dirname($0) . "/wavtrim \"$file\" $threshold"; |
255 | print("> $cmd\n") if $verbose; | 256 | print("> $cmd\n") if $verbose; |
256 | `$cmd`; | 257 | `$cmd`; |
257 | } | 258 | } |
@@ -402,6 +403,49 @@ sub panic_cleanup { | |||
402 | die "moo"; | 403 | die "moo"; |
403 | } | 404 | } |
404 | 405 | ||
406 | # Generate .talk clips | ||
407 | sub gentalkclips { | ||
408 | our $verbose; | ||
409 | my ($dir, $tts_object, $encoder, $encoder_opts, $tts_engine_opts, $i) = @_; | ||
410 | my $d = new DirHandle $dir; | ||
411 | while (my $file = $d->read) { | ||
412 | my ($voice, $wav, $mp3); | ||
413 | $voice = $file; | ||
414 | $wav = sprintf("%s.talk.wav", $path); | ||
415 | |||
416 | # Print some progress information | ||
417 | if (++$i % 10 == 0 and !$verbose) { | ||
418 | print("."); | ||
419 | } | ||
420 | |||
421 | # Convert to a complete path | ||
422 | my $path = sprintf("%s/%s", $dir, $file); | ||
423 | # Ignore dot-dirs and talk files | ||
424 | if ($file eq '.' || $file eq '..' || $file =~ /\.talk$/) { | ||
425 | next; | ||
426 | } | ||
427 | # Element is a dir | ||
428 | if ( -d $path) { | ||
429 | gentalkclips($path, $tts_object, $encoder, $encoder_opts, $i); | ||
430 | $mp3 = sprintf("%s/_dirname.talk", $path); | ||
431 | } | ||
432 | # Element is a file | ||
433 | else { | ||
434 | $mp3 = sprintf("%s.talk", $path); | ||
435 | $voice =~ s/\.[^\.]*$//; # Trim extension | ||
436 | } | ||
437 | |||
438 | printf("Talkclip %s: %s", $mp3, $voice) if $verbose; | ||
439 | |||
440 | voicestring($voice, $wav, $tts_engine_opts, $tts_object); | ||
441 | wavtrim($wav, 500, $tts_object); | ||
442 | # 500 seems to be a reasonable default for now | ||
443 | encodewav($wav, $mp3, $encoder, $encoder_opts, $tts_object); | ||
444 | unlink($wav); | ||
445 | } | ||
446 | } | ||
447 | |||
448 | |||
405 | # Check parameters | 449 | # Check parameters |
406 | my $printusage = 0; | 450 | my $printusage = 0; |
407 | unless (defined($V) or defined($C)) { print("Missing either -V or -C\n"); $printusage = 1; } | 451 | unless (defined($V) or defined($C)) { print("Missing either -V or -C\n"); $printusage = 1; } |
@@ -419,9 +463,6 @@ unless (defined($s)) { print("Missing -s argument\n"); $printusage = 1; } | |||
419 | unless (defined($S)) { print("Missing -S argument\n"); $printusage = 1; } | 463 | unless (defined($S)) { print("Missing -S argument\n"); $printusage = 1; } |
420 | if ($printusage == 1) { printusage(); exit 1; } | 464 | if ($printusage == 1) { printusage(); exit 1; } |
421 | 465 | ||
422 | $SIG{INT} = \&panic_cleanup; | ||
423 | $SIG{KILL} = \&panic_cleanup; | ||
424 | |||
425 | if (defined($v) or defined($ENV{'V'})) { | 466 | if (defined($v) or defined($ENV{'V'})) { |
426 | our $verbose = 1; | 467 | our $verbose = 1; |
427 | } | 468 | } |
@@ -429,6 +470,10 @@ if (defined($v) or defined($ENV{'V'})) { | |||
429 | 470 | ||
430 | # Do what we're told | 471 | # Do what we're told |
431 | if ($V == 1) { | 472 | if ($V == 1) { |
473 | # Only do the panic cleanup for voicefiles | ||
474 | $SIG{INT} = \&panic_cleanup; | ||
475 | $SIG{KILL} = \&panic_cleanup; | ||
476 | |||
432 | printf("Generating voice\n Target: %s\n Language: %s\n Encoder (options): %s (%s)\n TTS Engine (options): %s (%s)\n", | 477 | printf("Generating voice\n Target: %s\n Language: %s\n Encoder (options): %s (%s)\n TTS Engine (options): %s (%s)\n", |
433 | $t, $l, $e, $E, $s, $S); | 478 | $t, $l, $e, $E, $s, $S); |
434 | generateclips($l, $t, $e, $E, $s, $S); | 479 | generateclips($l, $t, $e, $E, $s, $S); |
@@ -436,7 +481,10 @@ if ($V == 1) { | |||
436 | deletemp3s(); | 481 | deletemp3s(); |
437 | } | 482 | } |
438 | elsif ($C) { | 483 | elsif ($C) { |
439 | # xxx: Implement .talk clip generation | 484 | 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); |
485 | my $tts_object = init_tts($s, $S, $l); | ||
486 | gentalkclips($ARGV[0], $tts_object, $e, $E, 0); | ||
487 | shutdown_tts($tts_object); | ||
440 | } | 488 | } |
441 | else { | 489 | else { |
442 | printusage(); | 490 | printusage(); |