Page 154 - Asterisk™: The Future of Telephony
P. 154
Asterisk comes with many professionally recorded sound files, which
should be found in the default sounds directory (usual-
ly /var/lib/asterisk/sounds/). When you compile Asterisk, you can choose
to install various sets of sample sounds that have been recorded in a
variety of languages and file formats. We’ll be using these files in many
of our examples. Several of the files in our examples come from the Extra
Sound Package, so please take the time to install it (see Chapter 3). You
can also have your own sound prompts recorded in the same voices as
the stock prompts by visiting http://thevoice.digium.com/.
To use Playback(), specify a filename (without a file extension) as the argument. For
example, Playback(filename) would play the sound file called filename.gsm, assuming
it was located in the default sounds directory. Note that you can include the full path
to the file if you want, like this:
Playback(/home/john/sounds/filename)
The previous example would play filename.gsm from the /home/john/sounds/ directory.
You can also use relative paths from the Asterisk sounds directory as follows:
Playback(custom/filename)
This example would play filename.gsm from the custom/ subdirectory of the default
sounds directory (probably /var/lib/asterisk/sounds/custom/filename.gsm). Note that if
the specified directory contains more than one file with that filename but with different
file extensions, Asterisk automatically plays the best file. §
The Hangup() application does exactly as its name implies: it hangs up the active chan-
nel. You should use this application at the end of a context when you want to end the
current call to ensure that callers don’t continue on in the dialplan in a way you might
not have anticipated. The Hangup() application takes no arguments.
Our First Dialplan
Now that we have designed our extension, let’s put together all the pieces to create our
first dialplan. As is typical in many technology books (especially computer program-
ming books), our first example will be called “Hello World!”
In the first priority of our extension, we’ll answer the call. In the second, we’ll play a
sound file named hello-world.gsm, and in the third we’ll hang up the call. Here’s what
the dialplan looks like:
§ Asterisk selects the best file based on translation cost―that is, it selects the file that is the least CPU-intensive
to convert to its native audio format. When you start Asterisk, it calculates the translation costs between the
different audio formats (they often vary from system to system). You can see these translation costs by typing
show translation many
audio
formats (known as codecs) in Chapter 8.
126 | Chapter 5: Dialplan Basics