Two-Way Telephone Interaction - Mother of Perl | 3 | WebReference

Two-Way Telephone Interaction - Mother of Perl | 3

Two-Way Telephone Interaction

Recognizing DTMF Tones

Handling DTMF tones

Now we can take a look at the actual subroutine that handles the DTMF tones.

1  sub read_dtfm {
2    my ($self,$input,$mydtmf) = @_;
3      print "Reading DTFM...$mydtmf\n";
4      $dtmf = $mydtmf;
5      $self->stop;
6      $self->expect('READY');
7      if ($dtmf == 1) {
8  	$voice->play_and_wait($pressed1);
9  	print "$number is confirmed.\n";
10     } else {
11 	$voice->play_and_wait($no_pressed1);
12 	print "$friend cannot attend\n";
13     }
14     $self->stop;
15     $self->shutdown;
16 }

The subroutine above gets called each time the modem recognizes a DTMF tone on the line. In this case, the third parameter that is passed is the number that was recognized. Lines 5 and 6 stop the event and waits for the modem to report that it's ready to perform another function. As you write vgetty scripts, you'll frequently use this combination between actions and events. Lines 7 through 13 play different messages based on the key the user pressed. This is how you can effectively implement a user menu. This particular example is only one level deep, but you could program multiple levels.

Let's look at the other subroutine in the script; the one that plays the menu.

sub play_menu {
    my $self = shift;
    print "Playing menu...\n";
    $self->play_and_wait($menu1);
}

Simply, the application calls this function after it has dialed a phone number and plays it until the user presses a number on the keypad.


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/3.html