File: demo.pl

package info (click to toggle)
mgetty 1.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,880 kB
  • sloc: ansic: 42,728; sh: 6,487; perl: 6,262; makefile: 1,457; tcl: 756; lisp: 283
file content (229 lines) | stat: -rw-r--r-- 4,257 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#! /usr/local/bin/vm shell
exec /usr/local/bin/perl -x $0
#! /usr/local/bin/perl

#
# This is a demo script for the new interface between shell scripts and
# the voice library
#
# WARNING: you MUST use the "#!" lines as shown, otherwise perl/vm get into
#          a recursive loop until your system runs out of file descriptors
#
# $Id: demo.pl,v 1.1 1998/04/18 17:49:14 gert Exp $
#

require 5.004;
use IO::Handle;

# debugging?
$opt_d = 1;

#
# Define the function to receive an answer from the voice library
#
sub voice_receive
{
    my $line = <$voice_rfd>;
    chomp $line;
    print "VR: <$line>\n"  if $opt_d;
    return $line;
}

#
# Define the function to send a command to the voice library
#

sub voice_send
{
    print "VS: <$_[0]>\n"  if $opt_d;
    print $voice_wfd $_[0] . "\n";
    $voice_wfd->flush();
    kill PIPE => $voice_pid;
}

#
# Define the function to initialize the file descriptors and 
# check whether the voice library is talking to us.
#

sub voice_init
{
    if ( ! defined( $ENV{VOICE_INPUT} ) )
	{ die "$0: environment variable 'VOICE_INPUT' not set!\n"; }
    if ( ! defined( $ENV{VOICE_OUTPUT} ) )
	{ die "$0: environment variable 'VOICE_OUTPUT' not set!\n"; }
    if ( ! defined( $ENV{VOICE_PID} ) )
	{ die "$0: environment variable 'VOICE_PID' not set!\n"; }

    print "VI: input:  " . $ENV{VOICE_INPUT} . "\n";
    print "VI: output: " . $ENV{VOICE_OUTPUT} . "\n";

    $voice_rfd = new IO::Handle;
    unless( $voice_rfd->fdopen( $ENV{VOICE_INPUT}, "r" ) )
	{ die "$0: can't reopen VOICE_INPUT for reading"; }

    $voice_wfd = new IO::Handle;
    unless( $voice_wfd->fdopen( $ENV{VOICE_OUTPUT}, "w" ) )
	{ die "$0: can't reopen VOICE_OUTPUT for writing"; }

    $voice_pid = $ENV{VOICE_PID};

    my $text = &voice_receive;
    if ( $text ne 'HELLO SHELL' )
	{ die "$0: voice library not answering ($text)"; }
}

#
# Let's see if the voice library is talking to us
#
&voice_init;

#
# Let's answer the message
#

&voice_send("HELLO VOICE PROGRAM");

#
# Let's see if it worked
#

$answer=&voice_receive;
if ( $answer ne 'READY' )
{
    die "$0: initialization failed ($answer)\n";
}

#
# Set the device
#

if ( $ARGV[0] eq 'dialup' )
     { &voice_send('DEVICE DIALUP_LINE'); }
else
     { &voice_send('DEVICE INTERNAL_SPEAKER'); }

#
# Let's see if it worked
#

$answer=&voice_receive;
if ( $answer ne 'READY' )
{
    die "$0: could not set output device ($answer)\n";
}

#
# Let's send demo.rmd if it exists
#

if ( -f 'demo.rmd' )
{
     &voice_send('PLAY demo.rmd');

     #
     # Let's see if it works
     #

     $answer=&voice_receive;
     if ( $answer ne 'PLAYING' )
     {
          die "$0: could not start playing ($answer)";
     }

     $answer=&voice_receive;
     if ( $answer ne 'READY' )
     {
          die "$0: something went wrong on playing ($answer)";
     }
}

#
# Let's record a new demo.rmd if we are connected to the dialup
# line
#

if ( $ARGV[0] eq 'dialup' )
{
    #
    # Let's send a beep
    #

    &voice_send('BEEP');

    #
    # Let's see if it works
    #

    $answer=&voice_receive;
    if ( $answer ne 'BEEPING' )
    {
	die "$0: could not send a beep ($answer)";
    }

    $answer=&voice_receive;
    if ( $answer ne 'READY' )
    {
        die "$0: could not send a beep ($answer)";
    }

    #
    # Let's start the recording
    #

    &voice_send('RECORD demo.rmd');

    #
    # Let's see if it works
    #

    $answer=&voice_receive;
    if ( $answer ne 'RECORDING' )
    {
        die "$0: could not start recording ($answer)" >&2
    }

    $answer=&voice_receive;
    if ( $answer ne 'READY' )
    {
        die "$0: something went wrong on recording ($answer)" >&2
    }

    #
    # Let's send a final beep
    #
    &voice_send('BEEP');

    #
    # Let's see if it works
    #

    $answer=&voice_receive;
    if ( $answer ne 'BEEPING' )
    {
	die "$0: could not send a beep ($answer)";
    }

    $answer=&voice_receive;
    if ( $answer ne 'READY' )
    {
        die "$0: could not send a beep ($answer)";
    }
}
#
# Let's say goodbye
#

&voice_send('GOODBYE');

#
# Let's see if the voice library got it
#

$answer=&voice_receive;
if ( $answer ne 'GOODBYE SHELL' )
{
     die "$0: could not say goodbye to the voice library ($answer)";
}

exit 0;