You've done a bit of research on how to create your own custom prompts for Asterisk, and you know that Digium will sell you nice, professionally recorded custom prompts for a reasonable fee. You know that you can go nuts with recording gear and do it yourself. Both sound like nice options, but for now, you just want quick and cheap.
You can have quick and cheap. You'll need sound support on your Asterisk server. This can be a sound card plus a microphone and speakers, or a sound card and headset, or a USB headset. (A USB headset replaces a sound card, microphone, and speakers.) Or, call into your server from a client's phone. Then you'll create a context in Asterisk just for recording custom prompts.
First, create two new directories:
# mkdir /var/lib/asterisk/sounds/local
# mkdir /var/lib/asterisk/sounds/tmp
Then, create this context for recording your custom prompts in /etc/asterisk/extensions.conf:
[record-prompts] ;record new voice files exten => s,1,Wait(2) exten => s,2,Record(tmp/newrecord:gsm) exten => s,3,Wait(2) exten => s,4,Playback(tmp/newrecord) exten => s,5,wait(2) exten => s,6,Hangup ;record new messages exten => 350,1,Goto(record-prompts,s,1)
Reload the dialplan:
asterisk1*CLI> dialplan reload
Now, dial 350. You will hear only a beep—start talking after the beep, then hit the pound key when you're finished. It will replay your new message, then hang up. The first file you're going to record should be an instructional file that says something like, "Wait for the beep to begin recording a new message, then press pound when you are finished."
Next, move the file from the tmp/ folder to local/, and rename it to whatever you want. In this example, it is called r-make-new-recording:
# mv /var/lib/asterisk/sounds/tmp/newrecord.gsm \
/var/lib/asterisk/sounds/local/r-make-new-recording.gsm
Now, record a second message that says, "If you are satisfied with your new recording, press 1. If you wish to record it again, press 2," and rename it r-keep-or-record.gsm.
Record a third message that says, "Thank you, your new recording has been saved. Press 2 to record another message, or 3 to exit." Call this one r-thank-you-message-saved.gsm.
Then, revise your dialplan to use the new soundfiles:
[record-prompts] ;record new voice files exten => s,1,Wait(1) exten => s,2,Playback(local/r-make-new-recording) exten => s,3,Wait(1) exten => s,4,Record(tmp/znewrecord:gsm) exten => s,5,Wait(1) exten => s,6,Playback(tmp/znewrecord) exten => s,7,Wait(1) exten => s,8,Background(local/r-keep-or-record) ;copy file to local/ directory and give unique filename exten => 1,1,System(/bin/mv /var/lib/asterisk/sounds/tmp/znewrecord.gsm /var/lib/ asterisk/sounds/local/${UNIQUEID}.gsm) exten => 1,2,Background(local/r-thank-you-message-saved) exten => 2,1,Goto(record-prompts,s,2) exten => 3,1,Playback(goodbye) exten => 3,2,Hangup
Add this to the [local-users]
context:
;record new messages exten => 350,1,Goto(record-prompts,s,1)
Reload the dialplan:
asterisk1*CLI> dialplan reload
Now, give it a try by dialing extension 350. This lets you listen to and rerecord your new soundfile until you are satisfied with it, and to record several new soundfiles in a single session without redialing.
If you record soundfiles at the Asterisk console instead of from an IP phone on a client PC, you need to specify the context like this:
asterisk1*CLI> dial 350@record-prompts
Let's take a quick walk through the new [record-prompts]
context. The s
(start) extension is a special extension
that kicks in when a specific destination is not named. I think of it
as Asterisk answering the call personally, instead of handing it off
to a user.
The soundfile names can be anything you want. I prefix them with
r
- to indicate that they are used
for recording. znewrecord.gsm puts the
temporary sound file last alphabetically in case I get confused and
want to find it in a hurry. Asterisk has hundreds of soundfiles, so
it's helpful to have a naming convention that keeps them somewhat
sorted.
The Goto application jumps to different parts of the dialplan, and to different contexts. If you're an ace programmer, you probably don't think much of Goto, but for Asterisk, it's a simple way to reuse contexts. Without it, dialplans would be unmanageable.
Goto syntax takes a number of options:
exten => 100,1,Goto(context,extension,priority)
At a minimum, you need a priority. The default is to go to the extension and priority in the current context. I like to make it explicit and spell out everything.
The Playback application plays a soundfile. The default Asterisk soundfile directory is /var/lib/asterisk/sounds/. So, Asterisk assumes that tmp/ and local/ are subdirectories of /var/lib/asterisk/sounds/.
The Background application plays soundfiles that can be interrupted by keypresses, so this is where you use the "press 1, press 2" instruction soundfiles.
Playback and Background don't need the soundfile extension specified because Asterisk will automatically select the most efficient file available.
Using the colon with the Record command, as in znewrecord:gsm
, means record a new sound
file named znewrecord in the GSM
format. You may also use the formats g723,
g729, gsm, h263, ulaw, alaw, vox, wav
, or WAV. WAV
is wav49
, which is a GSM-compressed WAVE
format. wav49 and GSM files are about one-tenth the size of WAVE
files. For recording voice prompts, gsm
or wav49
work fine, and save a lot of disk
space. GSM is the format for the free prompts that come with
Asterisk.
This recipe should help make clear why the different parts of a dialplan are called contexts. The numbers that you dial operate according to context. The familiar "press 1, press 2" dance works because pressing 1 and 2 work differently in different contexts, so you can use the same numbers over and over for different jobs.
The Wait values are in seconds, and can be adjusted to suit. You can leave them out if you like; they give you a chance to take a breath and get ready to talk.
When you hit 1 to tell Asterisk you are satisfied with your
recording, it will be copied to
/var/lib/asterisk/sounds/local/ and given a
unique filename based on the UNIQUEID
variable. You'll want to rename the
files something descriptive.
Asterisk commands:
http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands |
Asterisk variables:
http://www.voip-info.org/wiki-Asterisk+variables |