I will be using Festival for the speech synthesis part, although my work is cut out slightly thanks to the Festival component at http://www.cepstral.com/source/POE-Component-Festival/
Do you know if I can use the POE::Wheel::Curses on Windows as well? (I'm supposed to be supporting both platforms).
Thanks again,
James.
Sam Vilain wrote:
On Wed, 31 Dec 2003 00:36, James Brown wrote;
> I'm relatively new to Perl and POE in particular, but I have a > University final year project to develop a small web browser for > the blind. The browser only needs to retrieve very simple web > pages (similar to a WAP browser on a mobile phone) and have a > simple keyboard input (only a couple of buttons with no GUI - > we're going to use a speech synthesiser instead).
Nice. Are you using festival, or something better? Going to make a nice, re-usable POE component for it and release it to CPAN ? ;-)
> I've successfully used POE::Component::Client::UserAgent to > retrieve the web pages, but I would really appreciate some advice > on getting keyboard input. Which module should I use? Does anyone > have experience in taking keyboard input for a POE app?
See the attached, it's probably just enough to set you moving. From my early POE days :)
------------------------------------------------------------------------
#!/usr/bin/perl -w # # This script is mainly a test of POE::Wheel::Curses
use strict;
use POE; use Curses; # for unctrl, etc use POE::Wheel::Curses;
my $LOG; sub logger { $LOG .= (shift @_)."\n" }; sub flushlog { print $LOG; $LOG="" };
sub _start { my $heap = $_[HEAP];
logger ("_start(". join (", ", map { "\"$_\"" } @_[ARG0..$#_]).")"); $heap->{console} = POE::Wheel::Curses->new ( InputEvent => 'keystroke_handler', ); }
# Generate events from console input. Sets up Curses, too.
# A keystroke handler. This is the body of the program's main input # loop. sub keystroke_handler { my ($keystroke, $wheel_id, $heap) = @_[ARG0, ARG1, HEAP];
logger ("keystroke_handler(". join (", ", map { "\"$_\"" } @_[ARG0..$#_]).")");
$|=1; # Control characters. Change them into something printable via # Curses' unctrl function.
if ($keystroke lt ' ') { $keystroke = '<' . uc(unctrl($keystroke)) . '>'; }
# Extended keys get translated into their names via Curses' # keyname function.
elsif ($keystroke =~ /^\d{2,}$/) { $keystroke = '<' . uc(keyname($keystroke)) . '>'; }
# Just display it. #addstr( $heap->{console}, $keystroke ); addstr( 0, 0, "You pressed $keystroke" ); #noutrefresh( $heap->{console} );
refresh();
# this won't block unless we hit pipe buffers (user presses # Ctrl+S, etc) #doupdate; if ( $keystroke eq "q" ) { $_[KERNEL]->yield("_stop"); } }
sub _stop {
logger ("keystroke_handler(". join (", ", map { "\"$_\"" } @_[ARG0..$#_]).")");
my ($heap) = $_[HEAP]; # This will close the console delete $heap->{console}; }
flushlog();
my $session = POE::Session->create ( inline_states => { _start => \&_start, "keystroke_handler" => \&keystroke_handler, _stop => \&_stop, }, );
$poe_kernel->run();
flushlog();
