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

In reply to Re: Creating random sentences from a dictionary by zentara
in thread Creating random sentences from a dictionary by Lotus1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.