Home » Technology » Audio » Siriously: It’s Wolfram Alpha for Asterisk

The Most Versatile VoIP Provider: FREE PORTING

Siriously: It’s Wolfram Alpha for Asterisk

Ever wished your Asterisk® server could harness the power of a 10,000 CPU Supercomputer to answer virtually any question you can dream up about the world we live in? Well, so long as it's for non-commercial use, today's your lucky day. Apple demonstrated with Siri™ just how amazing this technology can be by coupling Wolfram Alpha® to a speech-to-text engine on the iPhone 4S. And, thanks to Google's new speech transcription engine and Wolfram Alpha's API, you can do much the same thing with any Asterisk server. Today, we'll show you how.1

We had such a good name for this project, Iris, which is Siri spelled backwards. You know the backwards sister and all of that. Unfortunately, the new (similar) product for Android phones was named Iris two months ago. And we didn't want to be like Larry on Newhart with two brothers named Darryl. So... we give you 4747. You can figure it out from there.

When people ask what exactly Wolfram Alpha is, our favorite answer was provided by Ed Borasky.

It's an almanac driven by a supercomputer.

That's an understatement. It's a bit like calling Google Search a topic index. Unlike Google which provides links to web sites that can provide answers to queries, Wolfram Alpha provides specific and detailed answers to almost any question. Here are a few examples (with descriptions of the functionality) to help you wrap your head around the breadth of information. For a complete list of what's available, visit Wolfram Alpha's Examples by Topic. Type a sample query here. Or call our demo line2 (1-904-339-8254 or iNum: 883510009043155) and say:

Weather in Charleston South Carolina
Weather forecast for Washington D.C.
Next solar eclipse
Otis Redding
Define politician
Who won the 1969 Superbowl? (Broadway Joe)
What planes are flying overhead? (flying over your server's location)
Ham and cheese sandwich (nutritional information)
Holidays 2012 (summary of all holidays for 2012 with dates and DOW)
Medical University of South Carolina (history of MUSC)
Star Trek (show history, air dates, number of episodes, and more)
Apollo 11 (everything you ever wanted to know)
Cheapest Toaster (brand and price)
Battle of Gettysburg (sad day 🙂 )
Daylight Savings Time 2012 (date ranges and how to set your clocks)
Tablets by Motorola (pricing, models, and specs from Best Buy)
Doughnut (you don't wanna know)
Snickers bar (ditto)
Weather (local weather at your server's location)

Best Question of the Day Award: "How much wood could a woodchuck chuck if a woodchuck could chuck wood?" And the answer: "A woodchuck would chuck all the wood he could chuck if a woodchuck could chuck wood. According to the tongue twister, although the paper 'The Ability of Woodchucks to Chuck Cellulose Fibers' by P.A. Paskevich and T.B. Shea in Annals of Improbable Research vol. 1, no. 4, pp. 4-9, July/August 1995, concluded that a woodchuck can chuck 361.9237001 cubic centimeters of wood per day."

Implementation Overview. Today what we're going to demonstrate is how to configure your Asterisk server so that you can pick up any phone on your system, dial 4-7-4-7, speak a question, and we'll show you how to send it to Google to convert your spoken words into text. Then we'll pass that text translation to Wolfram Alpha which will provide a plain text answer to your question. Finally, we'll take that plain text and use Flite or Cepstral to deliver the results to you.

For openers, you'll need a free Wolfram Alpha account. We'll be using PBX in a Flash 2.0.6.2.1™ to demonstrate the setup because its reliance on CentOS 6.2 provides the most complete collection of Linux utilities available. And, of course, you get unlimited, free calling within the U.S. and Canada with Google Voice as part of any PBX in a Flash install. It's certainly possible to do what we're demonstrating on other Asterisk server platforms once you get all of the dependencies resolved. But we'll leave that for the pioneers.

Using PIAF2™, you'll need to download a new AGI script to take advantage of Google's speech transcription engine. No registration is (yet) required. Then we'll provide a simple piece of dialplan code to handle the phone conversation. Finally, we'll provide a couple of AGI scripts to tame the Wolfram Alpha interface for you. Plug in your Wolfram Alpha APP-ID, and you'll be off to the races. It's about a 15-minute project using an existing PIAF2 server. So let's get started.

Legal Disclaimer. What we're demonstrating today is how to use two publicly accessible web resources to harness the power of a supercomputer to respond to your queries using a phone connected to an Asterisk server. We're assuming that both Google and Wolfram Alpha have their legal bases covered and have a right to provide the public services they are offering. We are not vouching for them or the services they are offering in any way. By using our scripts, YOU AGREE TO ASSUME ALL RISKS, LEGAL AND OTHERWISE, ASSOCIATED WITH USE OF THESE FREELY ACCESSIBLE WEB TOOLS. NO WARRANTY EXPRESS OR IMPLIED IS BEING PROVIDED BY US INCLUDING ANY IMPLIED WARRANTY OF FITNESS FOR USE OR MERCHANTABILITY. You, of course, have an absolute right not to use our code if you have reservations of any kind or are unwilling to assume all risks associated with such use. Sorry for legalese, but it's the time in which we live I'm afraid. Plain English: "Don't Shoot the Messenger!"

Getting a Wolfram Alpha Account. As you can imagine, there have to be some rules when you're using someone else's supercomputer for free. So here's the deal. It's free for non-commercial, personal use once you sign up for an account. But you're limited to 2,000 queries a month which works out to almost 70 queries a day. Every query requires your personal application ID, and that's how Wolfram Alpha keeps track of your queries. Considering the price, we think you'll find the query limitation pretty generous compared to other web resources.

To get started, sign up for a free Wolfram Alpha API account. Just provide your email address and set up a password. It takes less than a minute. Log into your account and click on Get An App ID. Make up a name for your application and write down (and keep secret) your APP-ID code. That's all there is to getting set up with Wolfram Alpha. If you want to explore costs for commercial use, there are links to let you get more information.

One-Click Installer. If you don't care about how things work, you can skip all of the steps below and use the new one-click installer. Or you can keep reading to see what's going on. Here are the steps to use the one-click installer. Log into your server as root and issue the following commands:

cd /root
wget http://nerd.bz/xhUpJr
chmod +x wolframalpha-oneclick.sh
./wolframalpha-oneclick.sh

You now can skip the next four sections and dial 4-7-4-7 to try things out.

Installing the Google Transcription AGI Script. Log into your PIAF2 server as root and issue the following commands to download and install Lefteris Zaferis' AGI script from GitHub. It's a terrific piece of code!

cd /root
wget --no-check-certificate http://nerd.bz/w8HCDF
tar zxvf asterisk-speech*
cd asterisk-speech-recog-0.4
cp speech-recog.agi /var/lib/asterisk/agi-bin/.

If you prefer living on the Bleeding Edge, you can download Lefteris' very latest (untested by us!) release3:

cd /root
wget --no-check-certificate http://nerd.bz/zA4fCB
tar zxvf asterisk-speech*
cd asterisk-speech-recog-0.5
cp speech-recog.agi /var/lib/asterisk/agi-bin/.

Installing the Wolfram Alpha Scripts. Now log into your PIAF2 server as root using SSH and issue the following commands to install the Wolfram Alpha transportation layer:

cd /
wget http://nerd.bz/A7umMK
tar zxvf 4747.tgz
cd /tmp
cat 4747.txt

Adding the Asterisk Dialplan Module. What is displayed on your screen at the end of the steps above will be the dialplan code that needs to be added to extensions_custom.conf in the /etc/asterisk directory. Just cut-and-paste the code and drop it into the [from-internal-custom] context. If you use nano, be sure to open the file with nano -w extensions_custom.conf to avoid problems with long lines being truncated. You'll notice that there are commented lines 3, 6, 16, and 17 to support Cepstral. If you use this commercial TTS app which now can be installed in PIAF2 with install-cepstral, then you can comment out the Flite entries and uncomment the Swift (Cepstral) entries in the dialplan code. Here's the SED alternative rather than manually updating the file with cut-and-paste:

cd /etc/asterisk
cp /tmp/4747.txt .
sed -i '/\[from-internal-custom\]/r 4747.txt' extensions_custom.conf
asterisk -rx "dialplan reload"

If you manually edit, don't forget: asterisk -rx "dialplan reload".

Adding Wolfram Alpha APP-ID. The final configuration step is adding your Wolfram Alpha APP-ID credentials. Issue the following commands to access the AGI script:

cd /var/lib/asterisk/agi-bin
nano -w 4747

When the file opens, replace yourID between the quotes with the APP-ID that was provided to you on the Wolfram Alpha web site. Then save the file: Ctrl-X, Y, then Enter. You're done!

Tweaking the Abbreviations List. Translating abbreviations into speech is a tricky business, and Flite and Cepstral do a pretty lousy job on some of them. We've started the beginnings of an abbreviation list which you will find in the function section of 4747.php which is stored in /var/lib/asterisk/agi-bin. It's easy to add additional entries. Just clone one of the entries that's already there. For example, here's the line that translates Jr. into Junior. HINT: Be careful to surround most unpunctuated abbreviations with spaces, or you may get unexpected results when a word actually begins or ends with the same letters.

$response = str_replace("Jr.","junior",$response);

Taking Wolfram Alpha for a Spin. Some sample commands have been documented above to get you started. Just pick up a phone on your PIAF2 server and dial 4747. When prompted, say one of the commands and press the pound key. Your command will be sent to Google for translation, and then the text result will be played back using Flite or Cepstral. If it says what you meant to say, press 1 to launch the Wolfram Alpha connection and get the answer to your question. If not, press * and try again.

You also can watch the progress of your calls on the Asterisk CLI. We've found the Google speech-to-text transcription to be extremely accurate in quiet rooms. One of the variables returned in the [4747@from-internal:5] entry on the Asterisk CLI includes a transcription accuracy measurement which is shown as a decimal number less than 1. This gives you an idea of how well Google is understanding your accent. If the number consistently falls below .9, you may want to move out of the Deep South for a bit. 😉

Originally published: Monday, January 16, 2012



Need help with Asterisk? Visit the VoIP-info Forum.


 

Special Thanks to Our Generous Sponsors


FULL DISCLOSURE: ClearlyIP, Skyetel, Vitelity, DigitalOcean, Vultr, VoIP.ms, 3CX, Sangoma, TelecomsXchange and VitalPBX have provided financial support to Nerd Vittles and our open source projects through advertising, referral revenue, and/or merchandise. As an Amazon Associate and Best Buy Affiliate, we also earn from qualifying purchases. We’ve chosen these providers not the other way around. Our decisions are based upon their corporate reputation and the quality of their offerings and pricing. Our recommendations regarding technology are reached without regard to financial compensation except in situations in which comparable products at comparable pricing are available from multiple sources. In this limited case, we support our sponsors because our sponsors support us.

BOGO Bonaza: Enjoy state-of-the-art VoIP service with a $10 credit and half-price SIP service on up to $500 of Skyetel trunking with free number porting when you fund your Skyetel account. No limits on number of simultaneous calls. Quadruple data center redundancy. $25 monthly minimum spend required. Tutorial and sign up details are here.

The lynchpin of Incredible PBX 2020 and beyond is ClearlyIP components which bring management of FreePBX modules and SIP phone integration to a level never before available with any other Asterisk distribution. And now you can configure and reconfigure your new Incredible PBX phones from the convenience of the Incredible PBX GUI.

VitalPBX is perhaps the fastest-growing PBX offering based upon Asterisk with an installed presence in more than 100 countries worldwide. VitalPBX has generously provided a customized White Label version of Incredible PBX tailored for use with all Incredible PBX and VitalPBX custom applications. Follow this link for a free test drive!
 

Special Thanks to Vitelity. Vitelity is now Voyant Communications and has halted new registrations for the time being. Our special thanks to Vitelity for their unwavering financial support over many years and to the many Nerd Vittles readers who continue to enjoy the benefits of their service offerings. We will keep everyone posted on further developments.
 



  1. We want to extend a special welcome to our Hack A Day and Reddit visitors. We have new tips and tricks on VoIP technology every week. And almost half of our traffic is from returning visitors. We hope you'll join the club. Thanks for visiting. []
  2. Because of a few "special people" we've had to limit calls to one per person. You still can beat the system by calling back from a different phone. 😉 For those that are curious, this demo line is supported by Google Voice so you can check out the call quality for yourself. We alternate hosting the trunk on either an Aspire Revo or one of 10 PBX in a Flash servers running as virtual machines under Proxmox on a $500 Dell PowerEdge T310 server behind a secure, hardware-based firewall with no Internet port exposure and no ports forwarded from the firewall to the server. Dell servers go on sale about once every couple of weeks. []
  3. Version 0.5 also includes some sample Wolfram Alpha perl code that is certainly worth a look. []

2 Comments

Comments are closed.