Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl use strict; use warnings; use Festival::Client; use LWP::Simple; use XML::Simple; $| = 1; # Information for Festival server to connect to # (undef as port value to use default port) my %festival_server = ( host => q{localhost}, port => undef, ); # The following values are in seconds. # $delay - approximate delay between CB XML Ticker retrievals # $speech_delay - approximate delay between spoken lines my $delay = 90; my $speech_delay = 7; # $seen - holds the message_id of last message seen # $max_retrievals - number of times to retrieve CB content # before exiting (as I did not want to allow the process # to run forever). This is computed as time to run divided # by the retrieval delay (both in seconds). my $seen = 0; my ($max_retrievals); { # Time period to run for. (0d 0h 30m 0s, for testing) my %to_run = ( days => 0, hours => 0, minutes => 30, seconds => 0, ); $max_retrievals = int( ( ( ( $to_run{days} * 24 + $to_run{hours} ) * 60 + $to_run{minutes} ) * 60 + $to_run{seconds} ) / $delay ); } # Display CB content and number of messages spoken during # retrieval period (set true to display) my $display_messages = 0; # Setup my $xs = new XML::Simple; my $cb_xml_url = q{http://www.perlmonks.org/index.pl?node_id=207304}; my $fs = Festival::Client->new( $festival_server{host}, $festival_server{port} ) or die ( qq{Could not connect to Festival server at } . join ( ':', $festival_server{host}, ( defined( $festival_server{port} ? $festival_server{port} : 1314 ) ) ) . qq{: $!\n} ); my $format = sprintf( qq{(%%0%dd) %%s - %%s: %%s\n}, length($max_retrievals) ); print length($max_retrievals), " ", $max_retrievals, "\n"; while ($max_retrievals) { my $said = 0; my $cb_xml = get($cb_xml_url) or die (qq{Could not retrieve CB XML ticker: $!\n}); my $ref = $xs->XMLin( $cb_xml, ForceArray => [q{message}] ) or die (qq{Could not parse CB XML: $!\n}); # print Data::Dumper->Dump( [ \$ref ], [qw(*ref)] ), "\n"; # Check to see if there are message entries if ( exists( $ref->{message} ) ) { # print ref( $ref->{message} ), "\n"; foreach my $message ( @{ $ref->{message} } ) { if ( $message->{message_id} > $seen ) { $seen = $message->{message_id}; $fs->say( join ( qq{\t}, $message->{author}, $message->{text} ) . qq{\n} ); $said++; printf $format, $max_retrievals, scalar localtime $message->{epoch}, $message->{author}, $message->{text} if ($display_messages); # I experienced a problem with the content being # spoken being "lost" if I did not delay between # sending lines of content. Thus, the delay here. sleep($speech_delay); } } print qq{Said: $said\n} if ($display_messages); } $max_retrievals--; sleep( $speech_delay * $said < $delay ? $delay - ( $speech_delay * $said ) : 1 ); }

In reply to Chatterbox to Festival Server (TTS output) by atcroft

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (7)
    As of 2014-09-03 03:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (35 votes), past polls