Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

My interest in the chatterbox, as well as my interest in VoiceXML, as well as my boredom, have made me create a very simple VoiceXML application that reads the contents of the public chatterbox to any listeners. You connect to the application and it simply enters an inifinite loop, checking the public chatterbox for new messages. New messages are read out loud using text-to-speech. I even included the use of 2 simple sound files to spruce things up a bit.

To tune in to the chatterbox from anywhere in the United States or Canada, call 1-800-289-5570 and enter 9991420869 as the application PIN. If you download the software available on http://www.freeworlddialup.com, you can also access the application using a broadband connection rather than a phone line. The freeworlddialup 'phone #' you call to directly access the VoiceXML chatterbox listener at is **86919991420869. Code follows readmore below.

update: As per request, the perl script that produces the VoiceXML document is below. I was having problems using a .pl extension (even though I output a text/xml content-type header), so I finally gave up and renamed it to /chat.xml and tweaked Apache to make .xml a perl script in the root directory of my virtual host. The code:

update: Fixed typo s!baregin!bargein! in one of the prompts. Thanks to herveus for that one.

#!c:/perl/bin/perl -w $| = 1; use strict; use CGI; use LWP::Simple; use XML::Simple (); my $q = CGI->new(); print $q->header( { Cache_control => 'no-cache', Expires => '-1y', Content_type => 'text/xml' } ), qq{ <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.0" > <var name="skipintro" expr="0" /> <var name="last_id" expr="0" /> <var name="doc_count" expr="0" /> <form id="main"> }; my $xml = XML::Simple->new(); my $chatter = get( 'http://www.perlmonks.org/index.pl?node_id=207304' +); my $chat = $xml->XMLin( $chatter, ForceArray => [ 'message' ] ); my $last_id = $q->param('last_id') || 0; my $doc_count = $q->param('doc_count') || 0; ++$doc_count; unless ( $q->param('skipintro') ) { print qq{ <block> <prompt bargein="false"> Welcome to the purl-munks voice XML chatterbox listene +r. Whenever you hear the <audio src="/audio/ding.wav" /> sound, it means that new messages are about to be read + out loud. The <audio src="/audio/buzzer.wav" /> sound mean +s that no new messages are available on the public chatt +erbox. Note that this phone call runs in an infinite loop to +make sure you catch all the chatter! \\!p2000 </prompt> </block> }; } if ( $doc_count == 19 ) { print qq{ <field name="keepgoing" type="boolean"> <prompt bargein="true"> User input required. Press <emphasis>one</emphasis> to continue listening. </prompt> <filled> <prompt>Thank you. \\!p1000 </prompt> <assign name="skipintro" expr="1" /> <assign name="doc_count" expr="0" /> </filled> </field> }; } else { print qq{ <block> <assign name="doc_count" expr="'$doc_count'" /> </block> }; } if ( grep { $_->{message_id} > $last_id } @{ $chat->{message} } ) { print qq{ <block> <prompt><audio src="/audio/ding.wav" /> \\!p2500 </prompt> </block> }; } else { print qq{ <block> <prompt><audio src="/audio/buzzer.wav" /></prompt> </block> }; } for my $msg ( @{ $chat->{message} } ) { next if ( $msg->{message_id} <= $last_id ); my $txt = $msg->{text}; # Fix up output to sound better in oral speech. # This could use a _heck_ of a lot of work. # strip out links $txt =~ s!\[[^\|]+\|([^\]]+)\]!$1!g; $txt =~ s!\[([^\]]+)\]!$1!g; # remove html tags. 1 while $txt =~ s!<[^>]+>!!g; # remove smileys :) $txt =~ s![:;]\-?[\(\)\|]!!g; # remove [tye]-type smileys (: $txt =~ s![\(\)\|]\-?[:;]!!g; if ( $txt =~ s!\A/me!! ) { print qq{ <block> <prompt> <emphasis>$msg->{author}</emphasis> <![CDATA[ $txt ]]> \\!p2000 </prompt> </block> }; } else { print qq{ <block> <prompt> <emphasis>$msg->{author}</emphasis> says: \\!p500 <![CDATA[ $txt ]]> \\!p2000 </prompt> </block> }; } $last_id = $msg->{message_id}; } print qq{ <block> <prompt> \\!p35000 </prompt> <assign name="last_id" expr="'$last_id'" /> <assign name="skipintro" expr="1" /> <submit next="/chat.xml" fetchhint="safe" method="get" namelist="last_id skipintro doc_count" /> </block> </form> </vxml> };

In reply to VoiceXML Chatterbox Listener by saskaqueer

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 avoiding work at the Monastery: (7)
    As of 2014-04-23 21:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (555 votes), past polls