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
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 220.127.116.11.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:
chmod +x 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!
wget --no-check-certificate http://nerd.bz/w8HCDF
tar zxvf asterisk-speech*
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:
wget --no-check-certificate http://nerd.bz/zA4fCB
tar zxvf asterisk-speech*
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:
tar zxvf 4747.tgz
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:
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:
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 PBX in a Flash Forum.
Or Try the New, Free PBX in a Flash Conference Bridge.
whos.amung.us If you're wondering what your fellow man is reading on Nerd Vittles these days, wonder no more. Visit our new whos.amung.us statistical web site and check out what's happening. It's a terrific resource both for us and for you.
Special Thanks to Our Generous Sponsors
Awesome Vitelity Special. Vitelity has generously offered a terrific discount for Nerd Vittles readers. You now can get an almost half-price DID from our special Vitelity sign-up link. If you're seeking the best flexibility in choosing an area code and phone number plus the lowest entry level pricing plus high quality calls, then Vitelity is the hands-down winner. Vitelity provides Tier A DID inbound service in over 3,000 rate centers throughout the US and Canada. When you use our special link to sign up, Nerd Vittles gets a few shekels down the road to support our open source development efforts while you get an incredible signup deal as well. The going rate for Vitelity's DID service is $7.95 a month which includes up to 4,000 incoming minutes on two simultaneous channels with terminations priced at 1.45¢ per minute. Not any more! For our users, here's a deal you can't (and shouldn't) refuse! Sign up now, and you can purchase a Tier A DID with unlimited incoming calls and four simultaneous channels for just $3.99 a month. To check availability of local numbers and tiers of service from Vitelity, click here. NOTE: You can only use the Nerd Vittles sign-up link to order your DIDs, or you won't get the special pricing! Vitelity's rate is just 1.44¢ per minute for outbound calls in the U.S. There is a $35 prepay when you sign up. This covers future usage. Any balance is refundable if you decide to discontinue service with Vitelity.
Some Recent Nerd Vittles Articles of Interest...
- 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. [↩]
- 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. [↩]
- Version 0.5 also includes some sample Wolfram Alpha perl code that is certainly worth a look. [↩]