Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for piper speech engine #920

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/Voice_Text.pm
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,35 @@ sub speak_text {
}
}
}
elsif ( $speak_engine =~ /piper/ ) {

#There is a recursion to web_file. if a web_file is defined, then this runs once with the file defined
#and then a second time without the output file. This prevents the duplication?
return if ($parms{web_file} eq "web_file");

print "*** PIPER ***\n\n" if $main::Debug{voice};
print "to_file=$parms{to_file} text=$parms{text} async=$parms{async} play=$parms{play};\n" if $main::Debug{voice};
my $cmd = 'echo "' . $parms{text} . '" |';
$cmd .= $main::config_parms{piper_path} . "/piper -q";
$cmd .= " --model " . $main::config_parms{piper_model_path} . "/" . $main::config_parms{piper_model};
$cmd .= " --speaker " . $main::config_parms{piper_speaker} if (defined $main::config_parms{piper_speaker});

if (defined $parms{to_file}) {
# create a file for mh to play
#figure out how to fork this to prevent pauses?
$cmd .= " --output_file " . $parms{to_file};
print "cmd=$cmd\n" if $main::Debug{voice};
$cmd .= " > /dev/null 2>&1";
my $r = system $cmd;
&main::print_log("Voice_Text.pm: piper: ERROR running command: $cmd") if $r != 0;

&web_hook_callback(%parms);

} else {
&main::print_log("Voice_Text.pm: piper: Warning, no to_file found. Local play not supported");
# just play the audio directly
}
}
elsif ( $speak_engine =~ /google/ ) {

# Speak to tile using the Google TTS Engine
Expand Down Expand Up @@ -1072,6 +1101,7 @@ sub read_parms {
next if /^\#/;
( $word, $phonemes ) = $_ =~ /^(\S+)\s+(.+)\s*$/;
next unless $word;
print "word=$word phonemes=$phonemes\n" if $main::Debug{voice};
$cnt++;
$pronouncable{$word} = $phonemes;
}
Expand Down
Loading