Hack74.Make a Quick-and-Dirty Prompter


Hack 74. Make a Quick-and-Dirty Prompter

Use Perl CGI scripts to create a prompter that makes it easy to read from a script.

A prompter is a program that puts up the text of a script in large type and scrolls it on a timer. This makes it easy to concentrate on reading the script, instead of scrolling through pages of small type. In this hack I'll explain how to create a prompter that makes it easy to read from a script.

11.3.1. The Code

Save this code as prompter.pl:

 #!/usr/bin/perl use FileHandle; use CGI; use strict; my $q = new CGI(); my $text = $q->param( "text" ); print "Content-type: text/html\n\n"; if ( $text ) { my $template = ""; my $fh = new FileHandle( "prompter.html" ); while( <$fh> ) { $template .= $_; } $fh->close(); my @textitems = split /[\n+]/, $text; my $jsarray = join( ",", map { s/\n|\r//g; "\"$_\"" } @textitems ); $template =~ s/\%\%lines\%\%/$jsarray/; print $template; } else { my $fh = new FileHandle( "prompter_form.html" ); while( <$fh> ) { print; } $fh->close(); } 

Save this code as prompter.html:

 <html> <head><title>Podcast Prompter</title> <script language="Javascript"> var lines = [ %%lines%% ]; </script> <script language="JavaScript"> var wordDelay = 300; // The average time per word in milliseconds function getwordcount( str ) { words = str.split( /\s+/ ); return words.length; } var currentPrompt = 0; var timeoutId = 0; function prompt( index ) { if ( index >= lines.length ) index = lines.length - 1; currentPrompt = index; if ( index > 0 ) line0.innerHTML = lines[ index - 1 ]; else line0.innerHTML = "<br/>"; line1.innerHTML = lines[ index ]; if ( index < lines.length - 1 ) line2.innerHTML = lines[ index + 1 ]; else line2.innerHTML = "<br/>"; clearTimeout( timeoutId ); timeoutId = setTimeout( "prompt( "+(index+1)+" )", getwordcount( lines[index] ) * wordDelay ); } function next() { clearTimeout( timeoutId ); prompt( currentPrompt + 1 ); } </script> <style type="text/css"> .dim,.current { font-size: 48pt; font-weight: bold; padding: 20px; } .dim { color: #ccc; } </style> </head> <body onload="prompt(0)" onkeydown="next()"> <div  ></div> <div  ></div> <div  ></div> </body> </html> 

Save this file as prompter_form.html:

 <html> <head><title>Prompter Form</title> </head> <body> <form method="post"> Text for the prompter:<br/> <textarea name="text" rows="20" cols="80"> </textarea> <br/> <input type="submit" /> </form> </body> </html> 

Install all of these files in the cgi-bin directory of your web server, either on your hosted server or on your local machine [Hack #7].

11.3.2. Running the Hack

After the scripts are installed on your server, use your browser to navigate to http://localhost/cgi-bin/prompter.pl (if you're running on a remote server, replace localhost with the hostname). Once there, you will get the form shown in Figure 11-4.

Figure 11-4. Entering the text for the prompter


This is the form from the prompter_form.html file. Put the text of your speech in the big text box and hit Submit.

Figure 11-5 shows the prompter in action. The text of the speech, now split into lines, is shown in three rows. The center row is what you are reading. Above it is the previous line, and below it is the next line.

11.3.3. Hacking the Hack

The text will scroll by at a rate of 300 milliseconds per word. If you tend to speak faster than that, alter the prompter.html file to use a smaller value. If you speak more slowly, use a larger value. To jump to the next line before the time delay does it for you, just press the spacebar.

You can change the font size or font family of the display by adjusting the CSS values in the prompter.html file.

11.3.4. See Also

  • "Build a Teleprompter" [Hack #75]

Figure 11-5. The prompter in action




    Podcasting Hacks
    Podcasting Hacks: Tips and Tools for Blogging Out Loud
    ISBN: 0596100663
    EAN: 2147483647
    Year: 2003
    Pages: 144

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net