Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-26 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found