1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.asterisk.fastagi.command;
18
19 /***
20 * Record to a file until a given dtmf digit in the sequence is received.<br>
21 * Returns -1 on hangup or error.<br>
22 * The format will specify what kind of file will be recorded. The timeout is
23 * the maximum record time in milliseconds, or -1 for no timeout. Offset samples
24 * is optional, and if provided will seek to the offset without exceeding the
25 * end of the file. "maxSilence" is the number of seconds of maxSilence allowed
26 * before the function returns despite the lack of dtmf digits or reaching
27 * timeout.
28 *
29 * @author srt
30 * @version $Id: RecordFileCommand.java,v 1.2 2005/03/08 16:48:34 srt Exp $
31 */
32 public class RecordFileCommand extends AGICommand
33 {
34 /***
35 * Serial version identifier.
36 */
37 private static final long serialVersionUID = 3978141041352128820L;
38
39 /***
40 * The name of the file to record.
41 */
42 private String file;
43
44 /***
45 * The format of the file to be recorded, for example "wav".
46 */
47 private String format;
48
49 /***
50 * The these digits a user can press to end the recording.
51 */
52 private String escapeDigits;
53
54 /***
55 * The maximum record time in milliseconds, or -1 for no timeout.
56 */
57 private int timeout;
58
59 /***
60 * The offset samples to skip.
61 */
62 private int offset;
63
64 /***
65 * Wheather a beep should be played before recording.
66 */
67 private boolean beep;
68
69 /***
70 * The amount of silence (in seconds) to allow before returning despite the
71 * lack of dtmf digits or reaching timeout.
72 */
73 private int maxSilence;
74
75 /***
76 * Creates a new RecordFileCommand.
77 *
78 * @param file the name of the file to stream, must not include extension.
79 * @param format the format of the file to be recorded, for example "wav".
80 * @param escapeDigits contains the digits that allow the user to end
81 * recording.
82 * @param timeout the maximum record time in milliseconds, or -1 for no
83 * timeout.
84 */
85 public RecordFileCommand(String file, String format, String escapeDigits,
86 int timeout)
87 {
88 this.file = file;
89 this.format = format;
90 this.escapeDigits = escapeDigits;
91 this.timeout = timeout;
92 this.offset = 0;
93 this.beep = false;
94 this.maxSilence = 0;
95 }
96
97 /***
98 * Creates a new RecordFileCommand.
99 *
100 * @param file the name of the file to stream, must not include extension.
101 * @param format the format of the file to be recorded, for example "wav".
102 * @param escapeDigits contains the digits that allow the user to end
103 * recording.
104 * @param timeout the maximum record time in milliseconds, or -1 for no
105 * timeout.
106 * @param offset the offset samples to skip.
107 * @param beep <code>true</code> if a beep should be played before
108 * recording.
109 * @param maxSilence The amount of silence (in seconds) to allow before
110 * returning despite the lack of dtmf digits or reaching timeout.
111 */
112 public RecordFileCommand(String file, String format, String escapeDigits,
113 int timeout, int offset, boolean beep, int maxSilence)
114 {
115 this.file = file;
116 this.format = format;
117 this.escapeDigits = escapeDigits;
118 this.timeout = timeout;
119 this.offset = offset;
120 this.beep = beep;
121 this.maxSilence = maxSilence;
122 }
123
124 /***
125 * Returns the name of the file to stream.
126 *
127 * @return the name of the file to stream.
128 */
129 public String getFile()
130 {
131 return file;
132 }
133
134 /***
135 * Sets the name of the file to stream.
136 *
137 * @param file the name of the file to stream, must not include extension.
138 */
139 public void setFile(String file)
140 {
141 this.file = file;
142 }
143
144 /***
145 * Returns the format of the file to be recorded, for example "wav".
146 *
147 * @return the format of the file to be recorded, for example "wav".
148 */
149 public String getFormat()
150 {
151 return format;
152 }
153
154 /***
155 * Sets the format of the file to be recorded, for example "wav".
156 *
157 * @param format the format of the file to be recorded, for example "wav".
158 */
159 public void setFormat(String format)
160 {
161 this.format = format;
162 }
163
164 /***
165 * Returns the digits that allow the user to end recording.
166 *
167 * @return the digits that allow the user to end recording.
168 */
169 public String getEscapeDigits()
170 {
171 return escapeDigits;
172 }
173
174 /***
175 * Sets the digits that allow the user to end recording.
176 *
177 * @param escapeDigits the digits that allow the user to end recording or
178 * <code>null</code> for none.
179 */
180 public void setEscapeDigits(String escapeDigits)
181 {
182 this.escapeDigits = escapeDigits;
183 }
184
185 /***
186 * Returns the maximum record time in milliseconds.
187 *
188 * @return the maximum record time in milliseconds.
189 */
190 public int getTimeout()
191 {
192 return timeout;
193 }
194
195 /***
196 * Sets the maximum record time in milliseconds.
197 *
198 * @param timeout the maximum record time in milliseconds, or -1 for no
199 * timeout.
200 */
201 public void setTimeout(int timeout)
202 {
203 this.timeout = timeout;
204 }
205
206 /***
207 * Returns the offset samples to skip.
208 *
209 * @return the offset samples to skip.
210 */
211 public int getOffset()
212 {
213 return offset;
214 }
215
216 /***
217 * Sets the offset samples to skip.
218 *
219 * @param offset the offset samples to skip.
220 */
221 public void setOffset(int offset)
222 {
223 this.offset = offset;
224 }
225
226 /***
227 * Returns <code>true</code> if a beep should be played before recording.
228 *
229 * @return <code>true</code> if a beep should be played before recording,
230 * <code>false</code> if not.
231 */
232 public boolean getBeep()
233 {
234 return beep;
235 }
236
237 /***
238 * Set to <code>true</code> to play a beep before recording.
239 *
240 * @param beep <code>true</code> if a beep should be played before
241 * recording, <code>false</code> if not.
242 */
243 public void setBeep(boolean beep)
244 {
245 this.beep = beep;
246 }
247
248 public String buildCommand()
249 {
250 return "RECORD FILE " + escapeAndQuote(file) + " "
251 + escapeAndQuote(format) + " " + escapeAndQuote(escapeDigits)
252 + " " + timeout + " " + offset + (beep == true ? " BEEP" : "")
253 + " s=" + maxSilence;
254 }
255 }