BeamerReveal

 view release on metacpan or  search on metacpan

bin/awspolly.pl  view on Meta::CPAN

#!/usr/bin/perl -w
# -*- cperl -*-
# PODNAME: awspollymp3.pl
# ABSTRACT: script converting textfile named $1
#                                  into file $2
#                          with engine:voice $3
#           using AWS Polly
our $VERSION = '20260408.1240'; # VERSION


use v5.32;
use IO::File;
use IPC::Run;

# Check arguments
die( "Usage: $0 <input_text_file> <output_audio_file> <region:engine:voice>\n" )
  unless( 3 == @ARGV );

my ( $textfilename, $audiofilename, $regionenginevoice ) = @ARGV;

# determine format from audiofilename
my $format = $audiofilename;
$format =~ s/.+\.([^\.]+)/$1/;
foreach ( $format ) {
  /^mp3$/ and do {
    $format = 'mp3';
    last;
  };
  /^ogg$/ and do {
    $format = 'ogg_vorbis';
    last;
  };
  die( "Error: could not guess audio format based on output audiofilename\n" );
}

# determine engine and voice
my ( $region, $engine, $voice ) = split( /:/, $regionenginevoice );
    die( "Invalid region, engine or voice format. Use <region:engine:voice>.\n" )
      
  unless( defined $region and defined $engine and defined $voice );

# read text file
my $textfile = IO::File->new();
$textfile->open( "<$textfilename" )
  or die( "Error: cannot open '$textfilename'\n" );
my $text = do { local $/; <$textfile> };

# Run polly, run!
my $command = [
	       'aws',
	       'polly',
	       'synthesize-speech',
	       '--output-format',
	       $format,
	       '--engine',
	       $engine,
	       '--voice-id',
	       $voice,
	       '--text',
	       $text,
	       # '--text-type',
	       # 'ssml',
	       $audiofilename
	      ];
my $out;
IPC::Run::run( $command,
	       '>',  \$out );
exit($?);

__END__

=pod

=encoding UTF-8

=head1 NAME

awspollymp3.pl - script converting textfile named $1

=head1 VERSION

version 20260408.1240

=head1 DESCRIPTION

The script reads the text file, and converts it to a speech audio file using
B<AWS Polly>. You need to setup the correct credentials yourself (in F<.aws/credentials>)
and also the correct region and output format in a configuration file (in F<.aws/config>).

=head1 NAME

awspolly.pl - convert text to speech



( run in 1.794 second using v1.01-cache-2.11-cpan-302cb4679cc )