in reply to Creating random sentences from a dictionary

Hi, a bit of an upgrade to tybalt89's script...... added audio output with the flite speech synthesizer. It could almost be used to generate political speeches. :-) The padsp program is PulseAudio's utility to allow access to /dev/dsp. If your system dosn't use PulseAudio, you don't need it.
#!/usr/bin/perl # adapted from https://perlmonks.org/?node_id=1221711 use strict; use warnings; # padsp is the PulseAudio /dev/dsp utility, # you may not need it on your system my $cmd = "padsp flite"; my $pid = open( OH, "| $cmd 2>&1"); my $pattern = "art adj{0,2} noun adverb{0,1} verb art adj{0,2} noun.\n +"; my %words; while( <DATA> ) { my ($word, $part) = /(\S+)\s+(\S+)/ or next; push $words{$part}->@*, $word; } for (1 .. 3 + rand 10) { print OH ucfirst $pattern =~ s/(\w+)(?:\{(\d+),(\d+)\})?/ my @avail = $words{$1}->@*; join ' ', map { $avail[rand @avail] } $2 ? 1 .. $2 + int $3 - $2 +: 1 /ger } __DATA__ abnormal adj blah adj crazy adj dolt noun dolthead noun doltish adj doltishly adverb doltishness adj eccentric adj fallacious adj galling adj hapless adj illogical adj jabber verb kooky adj lame adj misguided adj nuisance noun officious adj pretense noun questionable adj resentful adj shaky adj tenuous adj the art a art untenable adj vague adj warp verb yawn verb zombie noun

I'm not really a human, but I play one on earth. ..... an animated JAPH

Replies are listed 'Best First'.
Re^2: Creating random sentences from a dictionary
by bliako (Abbot) on Sep 05, 2018 at 13:52 UTC

    this is what i call opening a door, cool!

Re^2: Creating random sentences from a dictionary
by tybalt89 (Monsignor) on Sep 05, 2018 at 19:41 UTC

    Cool...