Two-Way Telephone Interaction - Mother of Perl | WebReference

Two-Way Telephone Interaction - Mother of Perl

Two-Way Telephone Interaction

Responding to DTMF tones

Revisiting Tutorial 14

In our last tutorial, we learned a bit about how to use the Modem::Vgetty Perl module in conjunction with vgetty, a voice-enabled version of mgetty. We also learned how to write a short script that dials out and plays a recorded message. I wanted to provide a few hints about vgetty and then give a little more information about how it interacts with Perl. First, the last tutorial was an outbound-only script. That is, we were only making outbound calls with the modem. While it's true that you will need the programs that are distributed with vgetty to record and convert files to the modem format, we really haven't used vgetty.

You see, when you install vgetty, you usually set it up to start with the system by editing the /etc/inittab to start vgetty on the tty that your voice modem is connected to. Again, I will defer to the vgetty documentation that I linked to in the last article. I wish it were a bit easier for non-sysadmins to setup, however, it seems that consumer voice technology is virtually nonexistent for Unix and Linux right now. By the way, if you haven't figured it out, I'm a heavy Linux advocate, though I do use Windows 2000 as well with a program called vmware, which allows me to run Windows inside Linux.

In any case, I've found it difficult to work with vgetty. As you write programs to interface with your voice modem, you may find out like I did that you can't rely on the modem to always do what you tell it to do. For example, sometimes when I'm dialing out and waiting for Modem::Vgetty to fire off an event, the event never comes; sometimes the modem simply hangs up while it's waiting for an event. So I've concluded that you cannot trust the modem to perform properly. Keep this in mind when you're writing programs to gather input over the phone. You might not get it right the first time and will have to dial back.

Modem::Vgetty Handlers

In Tutorial 14, we did register an event for a busy signal, but I didn't fully explain what was going on there. Let's take another look.

#!/usr/bin/perl
 
use Modem::Vgetty;
 
my $phone   = "12403517873";
my $message = "message.rmd";
my $voice   = new Modem::Vgetty;
$voice->device('DIALUP_LINE');
$voice->add_handler('BUSY_TONE', 'finish',
                sub { $v->stop; exit 0; });
$voice->enable_events;
$voice->dial($phone);
$voice->waitfor('READY');
$voice->wait(5);
$voice->waitfor('READY');
$voice->play_and_wait($message);      

The Modem::Vgetty module allows us to capture certain events that the modem generates as things happen. The add_handler method is used to register these events in our program and tie them to a function. In the case above, we're embedding a dynamic callback subroutine inside the method call. Under normal circumstances, you'd usually pass a reference to your handlers subroutine located somewhere else in the program. We'll see an example of this next.


https://www.internet.com

Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: October 26, 2000
Revised: October 27, 2000

URL: https://www.webreference.com/perl/tutorial/15/index.html