VoIP with FreeSWITCH
Talk Soft
![© Mateusz Radek, Fotolia © Mateusz Radek, Fotolia](/var/linux_magazin/storage/images/linux-magazine.com/issues/2009/106/talk-soft/fo_11738558_pst_mateusz-radek.png/423124-1-eng-US/fo_11738558_pst_Mateusz-Radek.png_medium.png)
© Mateusz Radek, Fotolia
FreeSWITCH is a powerful and versatile telephony platform that can scale from a softphone to a PBX and even to a carrier-class softswitch.
Open source projects have lowered the barrier to entry into telephony for hobbyists and businesses alike. The popular Asterisk PBX tool, for instance, is a high-functioning and low-budget telephony alternative that has proven disruptive in the world of business telephone systems [1]. Perhaps the most disruptive software of all, however, comes in the form of the scalable softswitch library called FreeSWITCH.
The FreeSWITCH website [2] says that it can be used as a "simple switching engine, a PBX, a media gateway, or a media server to host IVR applications."
True to that chameleon-like description, FreeSWITCH has appeared in production environments as a telco switch, in numerous business scenarios as a PBX, as a softphone for laptop users, and even as a voice routing engine for the OpenSim project.
Additionally, you can deploy FreeSWITCH as an application or use it as a library (libfreeswitch) that can be embedded in third-party software. This double identity is similar to the relationship between cURL (application) and libcurl (library).
FreeSWITCH has been used in some exotic scenarios; however, those new to telephony applications are best served starting out with FreeSWITCH in its default configuration as a SOHO PBX. Although you might find the numerous FreeSWITCH configuration files and settings overwhelming, in a short time, you will appreciate the power and flexibility of this versatile telephony tool.
Installing FreeSWITCH
As of this writing, the current, stable version of FreeSWITCH is 1.0.4, which can be downloaded from the project website [3], or you can use the Subversion repository to install the latest version. Unlike many projects, the SVN trunk is extremely stable, so it might be convenient for you simply to use the latest trunk.
In any case, the FreeSWITCH developers have made it very easy to update to the latest trunk, even if you have installed from the latest stable version. Some pre-compiled binaries are known to exist; however, I recommend compiling from source.
First, unpack and install the source. In this example, I will download into /usr/src and install from there:
tar zxvf freeswitch-1.0.4.tar.gz cd freeswitch-1.0.4 ./configure make install
I recommend getting the sound files:
make cd-sounds-install make cd-moh-install
FreeSWITCH comes with and can handle sound files at 8, 16, 32, and 48kHz sampling rates. Few, if any, telephony systems – open source or proprietary – can do the kinds of things FreeSWITCH can do with calls at multiple sampling rates.
The installation will take some time, so feel free to chain the commands together with the && operator.
When the process is complete, you will have a basic FreeSWITCH installation. Because it is handy to have the two main FreeSWITCH executable files available in the bin path, I use symlinks:
ln -s /usr/local/freeswitch/bin/freeswitch /usr/local/bin/freeswitch ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/fs_cli
To launch the application, enter freeswitch, and use the fs_cli utility to access the command line of any FreeSWITCH server to which you have access, even if it is on another server. At first, you'll see quite a bit of debug/log information, but don't worry about errors or warnings at this point.
Your New Softswitch
The first basic command is version, which displays the version of Free-SWITCH you are running, including the SVN revision. The status command shows information about your instance of FreeSWITCH, including uptime and the number of currently active sessions. Another basic command is the self-descriptive help.
To exit FreeSWITCH, type fsctl shutdown or use the shortcut command … (three periods).
If you have a sound card or headset on your system then try this:
load mod_portaudio
After several debug lines, you'll see +OK when the module is loaded. Now list the PortAudio devices available on your system:
pa devlist API CALL [pa(devlist)] output: 0;Built-in Microphone;2;0;i 1;Built-in Input;2;0; 2;Built-in Output;0;2;r,o 3;Logitech USB Headset;0;2; 4;Logitech USB Headset;1;0;
The i and o are next to the currently selected input and output devices. To change the input device, use the pa indev command with the device number,
pa indev #x
where x is the number of the input device. The output device can be changed with the pa outdev command. In my setup, I'll use device 4 as output and device 5 as input.
If you have the MOH (music on hold) files installed, this command will make a call to the MOH extension and send the MOH to the PortAudio output device:
pa call 9999
If you hear music, it was a successful call. If not, make sure the MOH files were installed properly. Hang up with the pa hangup command.
To make sure both input and output devices are working, do an echo test:
pa call 9996
Now when you speak into the input device, your voice should be echoed to the output device. The pa hangup command disconnects.
As you can see, it is possible to use Free-SWITCH and PortAudio to create a simple softphone. In this way, you will be able to use any codec that your FreeSWITCH installation supports – and there are some very high quality codecs available – without installing a softphone client.
Connecting a SIP Phone
The most common way to use Free-SWITCH is with a SIP phone. A physical handset is often called a hard phone, whereas a software-based phone is appropriately called a softphone. Numerous types of hard phones are available from manufacturers. Softphones come in both proprietary and FLOSS varieties. A popular free – but not open source – softphone is X-Lite from CounterPath [4], which is available for Linux, Mac OS X, and Windows. Even if your FreeSWITCH server runs on Linux, your softphones can run on any operating system, as long as they are SIP compliant.
Session Initiation Protocol
SIP is a TCP/IP-based Application Layer protocol used for multimedia sessions over the Internet. The text-based protocol is similar to HTTP, with requests and responses, header fields, encoding rules, and status codes. In addition to VoIP, SIP is used in instant messaging, online gaming, and distribution of streaming multimedia.
To begin, download X-Lite for your desktop or laptop operating system and perform a default install. (Installing a softphone on the same system that is running FreeSWITCH is not recommended; however, in many cases, it will work for the sake of testing.)
Now launch X-Lite and open the SIP Account Settings menu by clicking the Show Menu button. (The button is the small down-arrow at the top of the phone, just left of center.)
Only one SIP account is available in X-Lite, so click on it then click the Properties button. As shown in Figure 1, fill in the fields and use 1234 as the password for extension 1000.
Next, clear out the Dialing plan field because it is not needed with FreeSWITCH. Now click OK then Close, and the phone will attempt to register. Figure 2 shows a successful registration.
To make a test call, dial 9999 and click the green button to send. In a few moments you should hear music on hold. Figure 3 shows a call in progress to extension 9999.
To shut down FreeSWITCH, use the fsctl shutdown (…) command.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.
-
Nitrux 3.6.0 (“ie”) Available for Download and Install
The latest version of the systemd-free Linux distribution, Nitrux, has been released for general usage and includes the beta of the upcoming NVIDIA 560 graphics driver.
-
Vanilla OS 2 Orchid Available for Download
The latest iteration of Vanilla OS (Orchid) has been released and uses a hybrid Debian base.