diff options
author | Jens Arnold <amiconn@rockbox.org> | 2008-08-19 21:23:00 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2008-08-19 21:23:00 +0000 |
commit | 425d0ef22e37831f650773dbaec818057bc9afcb (patch) | |
tree | 9ea387d349d3382338df67743504ef74dff156d5 /tools | |
parent | a4e72dddcbb5b29596ea3930901c90fa0f21d232 (diff) | |
download | rockbox-425d0ef22e37831f650773dbaec818057bc9afcb.tar.gz rockbox-425d0ef22e37831f650773dbaec818057bc9afcb.zip |
Character set handling refinements:
- Default to UTF-8 for all I/O, including STDIO, removing the need to explicitly select UTF-8 in several places
- Let PerlIO check for valid UTF-8
- Cygwin/SAPI: Perl 5.8.8 breaks when asked to handle both UTF-16 and CRLF in PerlIO ('unexpected non-continuation byte'). Work around this by going back to manual CRLF handling.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18321 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/voice.pl | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/tools/voice.pl b/tools/voice.pl index 358b575b9c..db480dd0e6 100755 --- a/tools/voice.pl +++ b/tools/voice.pl | |||
@@ -25,7 +25,8 @@ 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 | use DirHandle; |
28 | use open IN => ':utf8'; | 28 | use open ':encoding(utf8)'; |
29 | use open ':std'; | ||
29 | 30 | ||
30 | sub printusage { | 31 | sub printusage { |
31 | print <<USAGE | 32 | print <<USAGE |
@@ -91,13 +92,13 @@ sub init_tts { | |||
91 | $cmd =~ s/\\/\\\\/g; | 92 | $cmd =~ s/\\/\\\\/g; |
92 | print("> cscript //nologo $cmd\n") if $verbose; | 93 | print("> cscript //nologo $cmd\n") if $verbose; |
93 | my $pid = open2(*CMD_OUT, *CMD_IN, "cscript //nologo $cmd"); | 94 | my $pid = open2(*CMD_OUT, *CMD_IN, "cscript //nologo $cmd"); |
94 | binmode(*CMD_IN, ':encoding(utf16le):crlf'); | 95 | binmode(*CMD_IN, ':encoding(utf16le)'); |
95 | binmode(*CMD_OUT, ':encoding(utf16le):crlf'); | 96 | binmode(*CMD_OUT, ':encoding(utf16le)'); |
96 | $SIG{INT} = sub { print(CMD_IN "QUIT\n"); panic_cleanup(); }; | 97 | $SIG{INT} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); }; |
97 | $SIG{KILL} = sub { print(CMD_IN "QUIT\n"); panic_cleanup(); }; | 98 | $SIG{KILL} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); }; |
98 | print(CMD_IN "QUERY\tVENDOR\n"); | 99 | print(CMD_IN "QUERY\tVENDOR\r\n"); |
99 | my $vendor = readline(*CMD_OUT); | 100 | my $vendor = readline(*CMD_OUT); |
100 | chomp($vendor); | 101 | $vendor =~ s/\r\n//; |
101 | %ret = (%ret, | 102 | %ret = (%ret, |
102 | "stdin" => *CMD_IN, | 103 | "stdin" => *CMD_IN, |
103 | "stdout" => *CMD_OUT, | 104 | "stdout" => *CMD_OUT, |
@@ -116,7 +117,7 @@ sub shutdown_tts { | |||
116 | kill TERM => $$tts_object{"pid"}; | 117 | kill TERM => $$tts_object{"pid"}; |
117 | } | 118 | } |
118 | case "sapi" { | 119 | case "sapi" { |
119 | print({$$tts_object{"stdin"}} "QUIT\n"); | 120 | print({$$tts_object{"stdin"}} "QUIT\r\n"); |
120 | close($$tts_object{"stdin"}); | 121 | close($$tts_object{"stdin"}); |
121 | } | 122 | } |
122 | } | 123 | } |
@@ -237,7 +238,6 @@ sub voicestring { | |||
237 | our $verbose; | 238 | our $verbose; |
238 | my ($string, $output, $tts_engine_opts, $tts_object) = @_; | 239 | my ($string, $output, $tts_engine_opts, $tts_object) = @_; |
239 | my $cmd; | 240 | my $cmd; |
240 | binmode(STDOUT, ':encoding(UTF-8)'); | ||
241 | printf("Generate \"%s\" with %s in file %s\n", $string, $$tts_object{"name"}, $output) if $verbose; | 241 | printf("Generate \"%s\" with %s in file %s\n", $string, $$tts_object{"name"}, $output) if $verbose; |
242 | switch($$tts_object{"name"}) { | 242 | switch($$tts_object{"name"}) { |
243 | case "festival" { | 243 | case "festival" { |
@@ -248,7 +248,6 @@ sub voicestring { | |||
248 | # Open command, and filehandles for STDIN, STDOUT, STDERR | 248 | # Open command, and filehandles for STDIN, STDOUT, STDERR |
249 | my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd); | 249 | my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd); |
250 | # Put the string to speak into STDIN and close it | 250 | # Put the string to speak into STDIN and close it |
251 | binmode(CMD_IN, ':encoding(utf8)'); | ||
252 | print(CMD_IN $string); | 251 | print(CMD_IN $string); |
253 | close(CMD_IN); | 252 | close(CMD_IN); |
254 | # Read all output from festival_client (because it LIES TO US) | 253 | # Read all output from festival_client (because it LIES TO US) |
@@ -265,12 +264,12 @@ sub voicestring { | |||
265 | case "espeak" { | 264 | case "espeak" { |
266 | $cmd = "espeak $tts_engine_opts -w \"$output\""; | 265 | $cmd = "espeak $tts_engine_opts -w \"$output\""; |
267 | print("> $cmd\n") if $verbose; | 266 | print("> $cmd\n") if $verbose; |
268 | open(ESPEAK, "|-:encoding(utf8)", $cmd); | 267 | open(ESPEAK, "| $cmd"); |
269 | print ESPEAK $string . "\n"; | 268 | print ESPEAK $string . "\n"; |
270 | close(ESPEAK); | 269 | close(ESPEAK); |
271 | } | 270 | } |
272 | case "sapi" { | 271 | case "sapi" { |
273 | print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\n"); | 272 | print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n"); |
274 | } | 273 | } |
275 | case "swift" { | 274 | case "swift" { |
276 | $cmd = "swift $tts_engine_opts -o \"$output\" \"$string\""; | 275 | $cmd = "swift $tts_engine_opts -o \"$output\" \"$string\""; |
@@ -287,7 +286,7 @@ sub wavtrim { | |||
287 | printf("Trim \"%s\"\n", $file) if $verbose; | 286 | printf("Trim \"%s\"\n", $file) if $verbose; |
288 | my $cmd = "wavtrim \"$file\" $threshold"; | 287 | my $cmd = "wavtrim \"$file\" $threshold"; |
289 | if ($$tts_object{"name"} eq "sapi") { | 288 | if ($$tts_object{"name"} eq "sapi") { |
290 | print({$$tts_object{"stdin"}} "EXEC\t$cmd\n"); | 289 | print({$$tts_object{"stdin"}} "EXEC\t$cmd\r\n"); |
291 | } | 290 | } |
292 | else { | 291 | else { |
293 | print("> $cmd\n") if $verbose; | 292 | print("> $cmd\n") if $verbose; |
@@ -302,7 +301,7 @@ sub encodewav { | |||
302 | printf("Encode \"%s\" with %s in file %s\n", $input, $encoder, $output) if $verbose; | 301 | printf("Encode \"%s\" with %s in file %s\n", $input, $encoder, $output) if $verbose; |
303 | my $cmd = "$encoder $encoder_opts \"$input\" \"$output\""; | 302 | my $cmd = "$encoder $encoder_opts \"$input\" \"$output\""; |
304 | if ($$tts_object{"name"} eq "sapi") { | 303 | if ($$tts_object{"name"} eq "sapi") { |
305 | print({$$tts_object{"stdin"}} "EXEC\t$cmd\n"); | 304 | print({$$tts_object{"stdin"}} "EXEC\t$cmd\r\n"); |
306 | } | 305 | } |
307 | else { | 306 | else { |
308 | print("> $cmd\n") if $verbose; | 307 | print("> $cmd\n") if $verbose; |
@@ -314,7 +313,7 @@ sub encodewav { | |||
314 | sub synchronize { | 313 | sub synchronize { |
315 | my ($tts_object) = @_; | 314 | my ($tts_object) = @_; |
316 | if ($$tts_object{"name"} eq "sapi") { | 315 | if ($$tts_object{"name"} eq "sapi") { |
317 | print({$$tts_object{"stdin"}} "SYNC\t42\n"); | 316 | print({$$tts_object{"stdin"}} "SYNC\t42\r\n"); |
318 | my $wait = readline($$tts_object{"stdout"}); | 317 | my $wait = readline($$tts_object{"stdout"}); |
319 | #ignore what's actually returned | 318 | #ignore what's actually returned |
320 | } | 319 | } |
@@ -330,7 +329,7 @@ sub generateclips { | |||
330 | my $voice = ''; | 329 | my $voice = ''; |
331 | my $cmd = "genlang -o -t=$target -e=$english $langfile 2>/dev/null"; | 330 | my $cmd = "genlang -o -t=$target -e=$english $langfile 2>/dev/null"; |
332 | my $pool_file; | 331 | my $pool_file; |
333 | open(VOICEFONTIDS, ">:utf8", "voicefontids"); | 332 | open(VOICEFONTIDS, "> voicefontids"); |
334 | my $i = 0; | 333 | my $i = 0; |
335 | local $| = 1; # make progress indicator work reliably | 334 | local $| = 1; # make progress indicator work reliably |
336 | 335 | ||