Skip to content

Commit

Permalink
Merge pull request #447 from JaredF/Voice_Text_Google_Fix
Browse files Browse the repository at this point in the history
Ubuntu Fixes for Google TTS Support
  • Loading branch information
JaredF committed Jul 27, 2014
2 parents 8beac58 + 2061313 commit 8f27b65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bin/mh.ini
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ organizer_email = fred => [email protected], bambi => bambi => flinstone.com
sound_program=play
@ Set this to the program used to convert sound files from mp3 to wav. Currently
@ only used by the Google TTS engine. The default is ffmpeg, but this is unavailable
@ on some platforms, Ubuntu for example, which requires the use of avconv instead.
sound_converter=
@ Set this to 1 to use fork, rather than system calls, when calling sound_program
sound_fork=
Expand Down
8 changes: 5 additions & 3 deletions lib/Voice_Text.pm
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ sub speak_text {
my $google_file = "$main::config_parms{data_dir}/mh_temp.google-$random.mp3";

# Make the request, store the result in the google temp file
my $ua_request = HTTP::Request->new('GET' => "http://translate.google.com/translate_tts?tl=en&q=".qq[ $parms{text} ]);
my $language = ($main::config_parms{language}) ? lc($main::config_parms{language}) : "en";
my $ua_request = HTTP::Request->new('GET' => "http://translate.google.com/translate_tts?tl=$language&q=".qq[ $parms{text} ]);
my $ua_response = $ua->request($ua_request, $google_file);

# Log the failure
Expand All @@ -461,11 +462,12 @@ sub speak_text {
}

# Convert the returned mp3 file to a wav, and clean up the temp file
system("ffmpeg", "-loglevel", "panic", "-i", "$google_file", "$out_file");
my $sound_converter = ($main::config_parms{sound_converter}) ? $main::config_parms{sound_converter} : "ffmpeg";
system($sound_converter, '-v', 'panic', '-i', $google_file, $out_file);
unlink($google_file);

# Play the wav file, clean up only if we are not being forced to file
system($main::config_parms{sound_program}, $out_file) unless $parms{to_file};
system("$main::config_parms{sound_program} $out_file") unless $parms{to_file};
unlink($out_file) unless $parms{to_file};
}
elsif ($speak_pgm) {
Expand Down

0 comments on commit 8f27b65

Please sign in to comment.