IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Modules Perl Discussion :

Probleme d'utilisation du module Speech::Google::TTS


Sujet :

Modules Perl

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2014
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2014
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Probleme d'utilisation du module Speech::Google::TTS
    Bonjour a tous les perliens de ce forum !
    J'aurais besoin de votre aide s'il vous plait car j'aimerais faire parler mes applications en utilisant le module TTS de Google que j'ai telechargé et installé sans encombre via la commande "cpan Speech::Google::TTS"
    J'ai essayé le code test fourni sur le site
    http://search.cpan.org/~nielsd/Speec.../Google/TTS.pm
    Mais sans succès le message d'erreur que je recupere est
    "le chemin d'accés specifié est introuvable.
    mpg123 failled to progress sound file to WAV

    Qu'est ce que ça veut dire et que puis je faire pour que ça fonctionne?
    J'espere que vous pourrez m'aider au mieux

  2. #2
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Bonjour,

    si tu colles le code entre balise ## on pourra plus facilement t'aider.

    "le chemin d'accés specifié est introuvable.
    En général il s'agit de pb de gestion de simples quottes et/ou doubles quottes.

    Fait un print du chemin d'accès que tu as construit, ça aidera aussi

  3. #3
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    C'est vrai qu'il est avare d'information.

    En grattant j'ai trouvé ICI :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    Speech::Google::TTS
                     v0.7 (21.11.2013)
    
    
    This Module allows to use the Google TTS service behind the
    Google Translation service from Perl and is the core of the
    following Speech::Google Text to Speech Module set.
    
    SOFTWARE REQUIREMENTS:
    ======================
     * mpg123 or mpg321
    
    SOFTWARE OPTIONS:
    =================
     * sox
    
    
    USAGE:
    ======
    A simple example:
    
            use Speech::Google::TTS
    
            $a = new Speech::Google::TTS();
    
            $a->say_text("speak this text!");
            $a->as_filename();
    
            $a->{'lang'} = 'de';
            $a->say_text("sprich diesen Text");
            $a->as_filename();
    
    
    MORE OPTIONS/CONFIGURATION:
    ===========================
    $a->{'samplerate'}      sample rate in kHz (16000)
    $a->{'lang'}            language ('en')
    $a->{'speed'}           speed of speech (1.2)
    $a->{'tmpdir'}          temp directory (/var/tmp)
    $a->{'timeout'}         timeout google connect in s (10)
    $a->{'googleurl'}       google url
    $a->{'mpg123'}          mpg123 path ('/usr/bin/mpg123')
    $a->{'sox'}             sox path ('/usr/bin/sox')
    $a->{'soxargs'}         sox args ('')
    Je n'ai ni mpg123 ni mpg321, je n'ai pu rien tester !
    Désolé


    Si tu les as il te faut ajouter au minimum, je pense :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    $a->{'tmpdir'} = 'E:\\_DEV\\SpeechGoogle\\';  # Enfin tes répertoires et fichiers perso mp3 ou wav
    $a->{'mpg123'} = 'E:\\_DEV\\SpeechGoogle\\file.mp3';
    NB à cet URL tu peux faire jouer un son :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    http://translate.google.com/translate_tts?ie=UTF-8&tl=fr&q=COUCOU
    Quelque chose du genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    use Speech::Google::TTS;
     
    my $a = Speech::Google::TTS->new();
     
    $a = new Speech::Google::TTS();
    $a->{'lang'}   = 'fr';
    $a->{'tmpdir'} = 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'} = 'E:\\_DEV\\SpeechGoogle\\file.mp3';
     
    $a->say_text("google parle français");
    $a->as_filename();
     
     
    =pod
     
    #$a->say_text("google parle français");
    #$a->as_filename();
     
    MORE OPTIONS/CONFIGURATION:
    ===========================
    $a->{'samplerate'}      sample rate in kHz (16000)
    $a->{'lang'}            language ('en')
    $a->{'speed'}           speed of speech (1.2)
    $a->{'tmpdir'}          temp directory (/var/tmp)
    $a->{'timeout'}         timeout google connect in s (10)
    $a->{'googleurl'}       google url
    $a->{'mpg123'}          mpg123 path ('/usr/bin/mpg123')
    $a->{'sox'}             sox path ('/usr/bin/sox')
    $a->{'soxargs'}         sox args ('')
     
     
    use Speech::Google::TTS;
    my $a = Speech::Google::TTS->new();
     
    $a = new Speech::Google::TTS();
     
    $a->say_text("speak this text!");
    $a->as_filename();
     
    $a->{'lang'} = 'de';
    $a->say_text("sprich diesen Text");
    $a->as_filename();
     
     
     
     
    1 #!/usr/local/bin/perl -w
        2 use strict;
        3 use Speech::Google::TTS;
        4 
        5 my $tts = Speech::Google::TTS->new();
        6 
        7 $tts->{'lang'} = 'de';
        8 $tts->say_text( "Ja was ist denn da los!");
        9 system "mplayer", $tts->as_filename();
    Sans aucune garantie

  4. #4
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Comme je suis curieux, j'ai téléchargé mpg123 ICI
    J'ai pris mpg123-1.20.1-x86-64.zip

    J'ai extrait le .zip dans le répertoire E:\_DEV\SpeechGoogle
    J'ai copié le contenu du répertoire dézippé mpg123-1.20.1-x86-64 dans E:\_DEV\SpeechGoogle soit le répertoire courant qui contient également speech.pl

    Ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    use Speech::Google::TTS;
     
    my $a = Speech::Google::TTS->new();
     
    $a = new Speech::Google::TTS();
    $a->{'lang'}   = 'fr';
    $a->{'speed'}  = '1';
    $a->{'timeout'} = '2';
    $a->{'tmpdir'} = 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'} = 'E:\\_DEV\\SpeechGoogle\\mpg123.exe';
     
    $a->say_text("google parle français");
    $a->as_filename();
     
    system "mpg123.exe ". $a->as_filename();
    Crée bien à chaque lancement 2 fichiers 1.mp3 et 1.wav avec des noms construits de toutes pièces

    Mais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    system "mpg123.exe ". $a->as_filename();
    sleep (5);
    Ne fait que produire un son bizarre.

    Cela vient du fait qu'il essai de jouer le son à partir du fichier .wav et non du .mp3

    mpg123.exe tts_CpGkVD.mp3 fonctionne très bien

    Je n'ai pas le temps de chercher ce soir, peut-être demain

  5. #5
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    En attendant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    use Speech::Google::TTS;
    
    my $a = Speech::Google::TTS->new();
    
    $a = new Speech::Google::TTS();
    $a->{'lang'}   = 'fr';
    $a->{'speed'}  = '1';
    $a->{'tmpdir'} = 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'} = 'E:\\_DEV\\SpeechGoogle\\mpg123.exe';
    
    $a->say_text("google parle français");
    $a->as_filename();
    
    # En attendant je récupère le fichier.mp3 dans le répertoire courant
    # je le détruis après l'avoir joué
    # ATTENTION il reste les .wav tu en fais ce que tu veux 
    
    opendir my $FhRep, 'E:\\_DEV\\SpeechGoogle\\' or die "impossible d'ouvrir le répertoire\n $!";
    my @Contenu = grep { /\.mp3/ } readdir($FhRep);
    print "\nFICHIER= $Contenu[0]\n\n";
    system "mpg123.exe ". $Contenu[0];
    unlink $Contenu[0];

  6. #6
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Bonjour,
    Voilà ma dernière mouture :

    [EDIT 05:59]ATTENTION Modif du source pour m'apercevoir que les paramètres speed & samplerate, n'ont rien d'efficace
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    use Speech::Google::TTS;
     
    my $a = Speech::Google::TTS->new();
     
    $a = new Speech::Google::TTS();
    $a->{'lang'}				= 'fr';
    $a->{'speed'}				= 1.2;
    $a->{'samplerate'}	= 16000;
    $a->{'tmpdir'}			= 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'}			= 'E:\\_DEV\\SpeechGoogle\\mpg123.exe';
    $a->{'auformat'}		= "mp3";
     
    $a->say_text("google parle français");
    $a->as_filename();
     
    opendir my $FhRep, 'E:\\_DEV\\SpeechGoogle\\' or die "impossible d'ouvrir le répertoire\n $!";
    my @MP3 = grep { /\.mp3$/ } readdir($FhRep);
    print "\nMP3= $MP3[0]\n";
     
    #system "mpg123.exe ". $MP3[0]; # Pour éventuellement rejouer le fichier .mp3 MAIS NON .wav !
     
    unlink $MP3[0];           # Suppression du .mp3
    unlink $a->as_filename(); # Suppression du .wav
     
    =pod
     
    EXEMPLE OPTIONS
            $self->{'samplerate'}     = 16000;
            $self->{'speed'}          = 1.2;
            $self->{'lang'}           = "en";
            $self->{'tmpdir'}        	= tempdir( CLEANUP =>  0 );
            $self->{'timeout'}    		= "10";
            $self->{'googleurl'} 		  = "http://translate.google.com/translate_tts";
            $self->{'languages'}		  = languages();
    				$self->{'auformat'}		    = "wav";
            $self->{'mpg123'}         = "/usr/bin/mpg123";
            $self->{'sox'}            = "/usr/bin/sox";
    				$self->{'soxargs'}		    = '';
            return($self);
     
    EXEMPLES
    $a->say_text("google parle français");
    $a->as_filename();
     
    my $tts = Speech::Google::TTS->new();
     
    $tts->{'lang'} = 'de';
    $tts->say_text( "Ja was ist denn da los!");
    system "mplayer", $tts->as_filename();
    [EDIT 05:26] Ajout :
    Perso pour jouer des sons sur windows j'utilise Balabolka
    associé à la voix de Virginie, perso j'ai dû l'ajouter dans Win7.

    Éventuellement, si c'est pour une utilisation perso, tu peux modifier le module .pm
    Il n'y a pas de difficulté apparente :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    package Speech::Google::TTS;
     
    #
    # Module that uses Google Translate for text to speech synthesis.
    #
    # Copyright (C) 2013, by Niels Dettenbach <nd@syndicat.com> 
    # with contributes of Lefteris Zafiris <zaf.000@gmail.com>
    #
    # This program is free software, distributed under the terms of
    # the GNU General Public License Version 2.
    #
     
    =head1 NAME
     
    Speech::Google::TTS - Module that uses Google Translate for text to speech synthesis.!
     
    =head1 VERSION
     
    Version 0.74
     
    =cut
     
    our $VERSION = '0.74';
     
     
    =head1 SYNOPSIS
     
    This Module uses Googles Translate Service for text to multilingual
    text to speech synthesis.
     
    This Module allows to use the Google TTS service behind the
    Google Translation service from Perl and is the core of the
    following Speech::Google Text to Speech Module set.
     
    Perhaps a little code snippet.
     
        	use Speech::Google::TTS;
     
        	my $a = Speech::Google::TTS->new();
     
            $a = new Speech::Google::TTS();
     
            $a->say_text("speak this text!");
            $a->as_filename();
     
            $a->{'lang'} = 'de';
            $a->say_text("sprich diesen Text");
            $a->as_filename();
        	...
     
    =head1 FUNCTIONS
     
    =head2 new
     
    Create a new Speech::Google::TTS object and initialize configuration.
     
    =head2 say_text
     
    Generates a WAV or MP3 from text, stored in the temp directory.
     
    =head2 as_filename
     
    Gives back the filename of the last generated WAV or MP3 from i.e. "say_text".
     
    =head2 languages
     
    The list of currently supported languages.
     
    =cut
     
     
     
    use warnings;
    use strict;
    use File::Temp qw(tempfile tempdir);
    use CGI::Util qw(escape);
    use LWP::UserAgent;
    use LWP::ConnCache;
     
    my @text;
     
    # init
    sub new {
            my ($class) = @_;
            my $self = {};
            bless $self, $class;
     
            $self->{'samplerate'}     = 16000;
            $self->{'speed'}          = 1.2;
            $self->{'lang'}           = "en";
            $self->{'tmpdir'}        	= tempdir( CLEANUP =>  0 );
            $self->{'timeout'}    		= "10";
            $self->{'googleurl'} 		  = "http://translate.google.com/translate_tts";
            $self->{'languages'}		  = languages();
    				$self->{'auformat'}		    = "wav";
            $self->{'mpg123'}         = "/usr/bin/mpg123";
            $self->{'sox'}            = "/usr/bin/sox";
    				$self->{'soxargs'}		    = '';
            return($self);
    }
     
     
    sub say_text {
    	my ($self, @text) = @_;
    	my @mp3list;
    	my @soxargs;
    	my $samplerate		= $self->{'samplerate'};
    	my $filename			= '';
    	my $wav_name;
    	my $lang					= $self->{'lang'};
    	my $speed       	= $self->{'speed'};
      my $tmpdir				= $self->{'tmpdir'};
      my $timeout				= $self->{'timeout'};
      my $url						= $self->{'googleurl'};
    	my $mpg123				= $self->{'mpg123'};
    	my $sox						= $self->{'sox'};
    	my $soxargs				= $self->{'soxargs'};
     
    	for (@text) {
    		# Split input text to comply with google tts requirements #
    		s/[\\|*~<>^\n\(\)\[\]\{\}[:cntrl:]]/ /g;
    		s/\s+/ /g;
    		s/^\s|\s$//g;
    		if (!length) {
    			print "No text passed for synthesis.";
    			return;
    		}
    		$_ .= "." unless (/^.+[.,?!:;]$/);
    		@text = /.{1,100}[.,?!:;]|.{1,100}\s/g;
     
    		my $ua = LWP::UserAgent->new;
    		$ua->agent("Mozilla/5.0 (X11; Linux; rv:8.0) Gecko/20100101");
    		$ua->env_proxy;
    		$ua->conn_cache(LWP::ConnCache->new());
    		$ua->timeout($timeout);
     
    		foreach my $line (@text) {
    			# Get speech data from google and save them in temp files #
    			$line =~ s/^\s+|\s+$//g;
    			next if (length($line) == 0);
    			$line = escape($line);
     
    			my ($mp3_fh, $mp3_name) = tempfile(
    				"tts_XXXXXX",
    				DIR    => $tmpdir,
    				SUFFIX => ".mp3",
    				UNLINK => 0
    			);
    			my $request = HTTP::Request->new('GET' => "$url?tl=$lang&q=$line");
    			my $response = $ua->request($request, $mp3_name);
    			if (!$response->is_success) {
    				print "Failed to fetch speech data.";
    				return $self;
    			} else {
    				push(@mp3list, $mp3_name);
    			}
    		}
     
     
    		# decode mp3s and concatenate #
    		my ($wav_fh, $wav_name) = tempfile(
    			"tts_XXXXXX",
    			DIR    => $tmpdir,
    			SUFFIX => ".wav",
    			UNLINK => 0
    		);
    		$self->{'filename'} = $wav_name;
     
     
    		# as WAV
    		if ($self->{'auformat'} eq 'wav') {
    			if (system($mpg123, "-q", "-w", $wav_name, @mp3list)) {
    				print "mpg123 failed to process sound file to WAV.";
    				return;
    			}
    		}
     
    		# as MP3
    		elsif ($self->{'auformat'} eq 'mp3') {
                            if (system($mpg123, "-q", $wav_name, @mp3list)) {
                                    print "mpg123 failed to process sound file to WAV.";
                                    return;
    			}
                    }
     
     
    		elsif ($self->{'auformat'} eq 'sox') {
    	#		# Set sox args and process wav file 
    	#		@soxargs = ($sox, "-q", $wav_name);
    	#		push(@soxargs, ("tempo", "-s", $speed)) if ($speed != 1);
    	#		push(@soxargs, ("rate", $samplerate)) if ($samplerate);
    	#		if (system(@soxargs)) {
    	#			print "sox failed to process sound file.";
    	#			return;
    	#		}
    		}
    	}
    	return($self);
    }
     
    sub as_filename {
            my ($self) = @_;
    	my $filename = $self->{'filename'};
    	return $filename;
    }
     
    sub languages {
    	my ($self) = @_;
    	# the list of currently supported languages to the user or return it as a hash #
    	my %sup_lang = (
    		"Afrikaans",             "af",         "Albanian",             "sq",
    		"Amharic",               "am",         "Arabic",               "ar",
    		"Armenian",              "hy",         "Azerbaijani",          "az",
    		"Basque",                "eu",         "Belarusian",           "be",
    		"Bengali",               "bn",         "Bihari",               "bh",
    		"Bosnian",               "bs",         "Breton",               "br",
    		"Bulgarian",             "bg",         "Cambodian",            "km",
    		"Catalan",               "ca",         "Chinese (Simplified)", "zh-CN",
    		"Chinese (Traditional)", "zh-TW",      "Corsican",             "co",
    		"Croatian",              "hr",         "Czech",                "cs",
    		"Danish",                "da",         "Dutch",                "nl",
    		"English",               "en",         "Esperanto",            "eo",
    		"Estonian",              "et",         "Faroese",              "fo",
    		"Filipino",              "tl",         "Finnish",              "fi",
    		"French",                "fr",         "Frisian",              "fy",
    		"Galician",              "gl",         "Georgian",             "ka",
    		"German",                "de",         "Greek",                "el",
    		"Guarani",               "gn",         "Gujarati",             "gu",
    		"Hacker",                "xx-hacker",  "Hausa",                "ha",
    		"Hebrew",                "iw",         "Hindi",                "hi",
    		"Hungarian",             "hu",         "Icelandic",            "is",
    		"Indonesian",            "id",         "Interlingua",          "ia",
    		"Irish",                 "ga",         "Italian",              "it",
    		"Japanese",              "ja",         "Javanese",             "jw",
    		"Kannada",               "kn",         "Kazakh",               "kk",
    		"Kinyarwanda",           "rw",         "Kirundi",              "rn",
    		"Klingon",               "xx-klingon", "Korean",               "ko",
    		"Kurdish",               "ku",         "Kyrgyz",               "ky",
    		"Laothian",              "lo",         "Latin",                "la",
    		"Latvian",               "lv",         "Lingala",              "ln",
    		"Lithuanian",            "lt",         "Macedonian",           "mk",
    		"Malagasy",              "mg",         "Malay",                "ms",
    		"Malayalam",             "ml",         "Maltese",              "mt",
    		"Maori",                 "mi",         "Marathi",              "mr",
    		"Moldavian",             "mo",         "Mongolian",            "mn",
    		"Montenegrin",           "sr-ME",      "Nepali",               "ne",
    		"Norwegian",             "no",         "Norwegian (Nynorsk)",  "nn",
    		"Occitan",               "oc",         "Oriya",                "or",
    		"Oromo",                 "om",         "Pashto",               "ps",
    		"Persian",               "fa",         "Pirate",               "xx-pirate",
    		"Polish",                "pl",         "Portuguese (Brazil)",  "pt-BR",
    		"Portuguese (Portugal)", "pt-PT",      "Portuguese",           "pt",
    		"Punjabi",               "pa",         "Quechua",              "qu",
    		"Romanian",              "ro",         "Romansh",              "rm",
    		"Russian",               "ru",         "Scots Gaelic",         "gd",
    		"Serbian",               "sr",         "Serbo-Croatian",       "sh",
    		"Sesotho",               "st",         "Shona",                "sn",
    		"Sindhi",                "sd",         "Sinhalese",            "si",
    		"Slovak",                "sk",         "Slovenian",            "sl",
    		"Somali",                "so",         "Spanish",              "es",
    		"Sundanese",             "su",         "Swahili",              "sw",
    		"Swedish",               "sv",         "Tajik",                "tg",
    		"Tamil",                 "ta",         "Tatar",                "tt",
    		"Telugu",                "te",         "Thai",                 "th",
    		"Tigrinya",              "ti",         "Tonga",                "to",
    		"Turkish",               "tr",         "Turkmen",              "tk",
    		"Twi",                   "tw",         "Uighur",               "ug",
    		"Ukrainian",             "uk",         "Urdu",                 "ur",
    		"Uzbek",                 "uz",         "Vietnamese",           "vi",
    		"Welsh",                 "cy",         "Xhosa",                "xh",
    		"Yiddish",               "yi",         "Yoruba",               "yo",
    		"Zulu",                  "zu"
    	);
    	return %sup_lang;
    }
     
     
    =head1 AUTHOR
     
    Niels Dettenbach, <nd@syndicat.com> http://www.syndicat.com
     
    =head1 BUGS
     
    Please report any bugs or feature requests to C<bug-speech-google-tts at rt.cpan.org>, or through
    the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Speech::Google::TTS>.  I will be notified, and then you'll
    automatically be notified of progress on your bug as I make changes.
     
    Feel free to visit the project website http://www.syndicat.com/open_source/google/perl/googletts/
     
    or write to googletts@syndicat.com
     
     
    =head1 SUPPORT
     
    You can find documentation for this module with the perldoc command.
     
        perldoc Speech::Google::TTS
     
     
    Feel free to visit the project website http://www.syndicat.com/open_source/google/perl/googletts/
     
    You can also look for information at:
     
    =over 4
     
    =item * RT: CPAN's request tracker
     
    L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Speech::Google::TTS>
     
    =item * AnnoCPAN: Annotated CPAN documentation
     
    L<http://annocpan.org/dist/Speech::Google::TTS>
     
    =item * CPAN Ratings
     
    L<http://cpanratings.perl.org/d/Speech::Google::TTS>
     
    =item * Search CPAN
     
    L<http://search.cpan.org/dist/Speech::Google::TTS>
     
    =back
     
     
    =head1 ACKNOWLEDGEMENTS
     
     
    =head1 COPYRIGHT & LICENSE
     
    Copyright 2012/2013 Niels Dettenbach <nd@syndicat.com>, 
    with contributes of Lefteris Zafiris <zaf.000@gmail.com>
    all rights reserved.
     
    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.
     
     
    =cut
     
    1; # End of Speech::Google::TTS

  7. #7
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Si non installe Win32::SAPI5 il semble beaucoup plus complet

  8. #8
    Membre chevronné Avatar de dmganges
    Homme Profil pro
    Retraité. Ne recherche pas un emploi.
    Inscrit en
    Septembre 2011
    Messages
    1 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Retraité. Ne recherche pas un emploi.
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2011
    Messages : 1 392
    Points : 2 044
    Points
    2 044
    Par défaut
    Voici un petit essai ÉPOUSTOUFLANT avec Speech::Google::TTS

    speech.pl :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
     
    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    use Speech::Google::TTS;
     
    my $a = Speech::Google::TTS->new();
    $a = new Speech::Google::TTS();
     
    my ( $FhRep, @MP3 ) = ();
     
    ############################################### Français
    $a->{'lang'}				= 'fr';
    $a->{'speed'}				= 1.2;
    $a->{'samplerate'}	= 16000;
    $a->{'tmpdir'}			= 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'}			= 'E:\\_DEV\\SpeechGoogle\\mpg123.exe';
    $a->{'auformat'}		= "mp3";
     
    $a->say_text("google parle français");
    $a->as_filename();
     
    opendir $FhRep, 'E:\\_DEV\\SpeechGoogle\\' or die "impossible d'ouvrir le répertoire\n $!";
    @MP3 = grep { /\.mp3$/ } readdir($FhRep);
    print "\nMP3= $MP3[0]\n";
     
    #system "mpg123.exe ". $MP3[0]; # Pour éventuellement rejouer le fichier .mp3 MAIS NON .wav !
     
    unlink $MP3[0];           # Suppression du .mp3
    unlink $a->as_filename(); # Suppression du .wav
     
    ############################################### Anglais
    $a->{'lang'}				= 'en';
    $a->{'speed'}				= 1.2;
    $a->{'samplerate'}	= 16000;
    $a->{'tmpdir'}			= 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'}			= 'E:\\_DEV\\SpeechGoogle\\mpg123.exe';
    $a->{'auformat'}		= "mp3";
     
    $a->say_text("google speak English");
    $a->as_filename();
     
    opendir $FhRep, 'E:\\_DEV\\SpeechGoogle\\' or die "impossible d'ouvrir le répertoire\n $!";
    @MP3 = grep { /\.mp3$/ } readdir($FhRep);
    print "\nMP3= $MP3[0]\n";
     
    #system "mpg123.exe ". $MP3[0]; # Pour éventuellement rejouer le fichier .mp3 MAIS NON .wav !
     
    unlink $MP3[0];           # Suppression du .mp3
    unlink $a->as_filename(); # Suppression du .wav
     
    ############################################### Arabe
    $a->{'lang'}				= 'ar';
    $a->{'speed'}				= 1.2;
    $a->{'samplerate'}	= 16000;
    $a->{'tmpdir'}			= 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'}			= 'E:\\_DEV\\SpeechGoogle\\mpg123.exe';
    $a->{'auformat'}		= "mp3";
     
    $a->say_text("جوجل يتحدث العربية");
    $a->as_filename();
     
    opendir $FhRep, 'E:\\_DEV\\SpeechGoogle\\' or die "impossible d'ouvrir le répertoire\n $!";
    @MP3 = grep { /\.mp3$/ } readdir($FhRep);
    print "\nMP3= $MP3[0]\n";
     
    #system "mpg123.exe ". $MP3[0]; # Pour éventuellement rejouer le fichier .mp3 MAIS NON .wav !
     
    unlink $MP3[0];           # Suppression du .mp3
    unlink $a->as_filename(); # Suppression du .wav
     
    ############################################### Allemand
    $a->{'lang'}				= 'de';
    $a->{'speed'}				= 1.2;
    $a->{'samplerate'}	= 16000;
    $a->{'tmpdir'}			= 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'}			= 'E:\\_DEV\\SpeechGoogle\\mpg123.exe';
    $a->{'auformat'}		= "mp3";
     
    $a->say_text("Google spricht Deutsch");
    $a->as_filename();
     
    opendir $FhRep, 'E:\\_DEV\\SpeechGoogle\\' or die "impossible d'ouvrir le répertoire\n $!";
    @MP3 = grep { /\.mp3$/ } readdir($FhRep);
    print "\nMP3= $MP3[0]\n";
     
    #system "mpg123.exe ". $MP3[0]; # Pour éventuellement rejouer le fichier .mp3 MAIS NON .wav !
     
    unlink $MP3[0];           # Suppression du .mp3
    unlink $a->as_filename(); # Suppression du .wav
     
    ############################################### Italien
    $a->{'lang'}				= 'it';
    $a->{'speed'}				= 1.2;
    $a->{'samplerate'}	= 16000;
    $a->{'tmpdir'}			= 'E:\\_DEV\\SpeechGoogle\\';
    $a->{'mpg123'}			= 'E:\\_DEV\\SpeechGoogle\\mpg123.exe';
    $a->{'auformat'}		= "mp3";
     
    $a->say_text("Google parla italiano");
    $a->as_filename();
     
    opendir $FhRep, 'E:\\_DEV\\SpeechGoogle\\' or die "impossible d'ouvrir le répertoire\n $!";
    @MP3 = grep { /\.mp3$/ } readdir($FhRep);
    print "\nMP3= $MP3[0]\n";
     
    #system "mpg123.exe ". $MP3[0]; # Pour éventuellement rejouer le fichier .mp3 MAIS NON .wav !
     
    unlink $MP3[0];           # Suppression du .mp3
    unlink $a->as_filename(); # Suppression du .wav
     
    =pod
    EXEMPLE OPTIONS
            $self->{'samplerate'}     = 16000;
            $self->{'speed'}          = 1.2;
            $self->{'lang'}           = "en";
            $self->{'tmpdir'}        	= tempdir( CLEANUP =>  0 );
            $self->{'timeout'}    		= "10";
            $self->{'googleurl'} 		  = "http://translate.google.com/translate_tts";
            $self->{'languages'}		  = languages();
    				$self->{'auformat'}		    = "wav";
            $self->{'mpg123'}         = "/usr/bin/mpg123";
            $self->{'sox'}            = "/usr/bin/sox";
    				$self->{'soxargs'}		    = '';
            return($self);
    En arabe les balises CODE transforment le code en hexa, en réalité comme speech.pl est sauvegardé utf-8 NO BOM il contient :
    $a->say_text("جوجل يتحدث العربية");


    Inspiré par hackoofr en vbs

Discussions similaires

  1. [ZF 1.9] probleme de routeur avec utilisation des modules
    Par SergeF dans le forum MVC
    Réponses: 7
    Dernier message: 01/02/2010, 16h06
  2. Réponses: 3
    Dernier message: 08/08/2009, 21h33
  3. Probleme utilisation du module DBIx::XML_RDB
    Par jesuscrie dans le forum Web
    Réponses: 1
    Dernier message: 28/05/2007, 09h08
  4. [web] Probleme de passe de variable qd j utilise un module TK
    Par Slippers dans le forum Interfaces Graphiques
    Réponses: 5
    Dernier message: 19/04/2005, 17h48
  5. [Debutant] probleme pour utiliser les classes d'un .jar
    Par pissek dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 12/05/2004, 18h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo