Code Samples

Telephone
1.360.227.6036

E-Mail
info@ivrforbeginners.com

Get yer sample code, here!

On this page you'll find some code for sample IVR applications. In general, the samples fall into three categories.

  • Introductory Hello-World type applications
  • Weather forecasting by ZIP code entered via keypad
  • Weather forecasting by ZIP code spoken by the caller
The weather samples demonstrate performing all of the tasks common to IVR applications - greeting, prompting, waiting for keypad input, accessing content-serving systems, playing music-on-hold, recognizing speech, synthesizing speech, etc.

Note that we recorded the developer video tutorials using a weather forecasting web service provided by EJSE.com but that the code which we show here uses a different web service. On the upside, we prefer the new one because it does not require that an account be created with them and because in our experience it is always available. On the downside, the URL used to access the service and the XML 'document' it returns and the logic to parse it are somewhat different than what we showed in the videos.

Also note that the samples overlap I/O (the voice user interface) and computation (the delivery of the forecast) in a few different ways.

In the COM (e.g. VB) and Script (e.g. Ruby) samples we access the web service and fetch the content synchronously. We use the loopMessage() method of the call class to play "music on hold" while fetching the content.

In the .Net (e.g. C#) and Java samples, we manage the user interface in the 'main' thread and create a worker thread to perform the content fetch in the background. This offers additional benefits such as the ability to timeout a request as well as a nice separation of the user interface and business logic.

In the C++ example, we handle both the voice user interface and the content fetch using asynchronous functions in a single thread. This is harder to code to be sure, but in high line-density applications the savings in operating system resources may warrant the extra complexity. Of course, you may opt to forego the complexity and instead choose to run on a machine with sufficient memory and processing power.

To be clear, one could use a single threaded approach in a .Net application or a thread pool in a C++ application as one sees fit. 


.Net Language Samples

The voice user interface for an IVR application written in one of the .Net languages is implemented in a method named Answer() in a class derived from our base class named NetClientCall.

To the Common Language Runtime, an IVR application is just another class library which happens to reference the NetClientCall assembly which is located in the .\EEs directory of our installation.

   C#

      HelloWorld       Weather (Keypad)       Weather (Spoken)

   Vb.Net

      HelloWorld       Weather (Keypad)       Weather (Spoken)

   Managed Extensions for C++

      HelloWorld

   J#

      HelloWorld

   C++/CLI

      HelloWorld

   JScript.Net

      HelloWorld

As far as we know, the Visual Studio IDE provides no support for building applications with JScript.Net. We compiled the sample above using this command line

  jsc /reference:NetClientCall.dll /lib:C:\Telephony\EEs
            /target:library /debug HelloWorld.js

   Delphi.Net

Note that we support both the .Net and Win32 versions of Delphi. The samples immediately below were developed with the 2006 version of Delphi and use managed code to create a class library application which is loaded by the .Net platform.

      HelloWorld       Weather (Keypad)       Weather (Spoken)

We also have links to samples that use the Win32 version of Delphi further down this page.


Java Samples

The voice user interface for an IVR application written in Java is a class file derived from one of our base classes - JavaClientCall for applications which run in-process with the server and JavaClientCallRemote for applications which run in a different Java virtually machine, possibly residing on a remote server. In either case, the class must override the method named Answer() where the voice user interface is implemented.

      HelloWorld       Weather (Keypad)        Weather (Spoken)


Delphi Samples

The voice user interface for an IVR application written with the 'native' edition of Delphi is implemented in a function named Answer() which is exported from a DLL which is loaded by the server and simulator. We have such DLL samples immediately below.

      HelloWorld       Weather (Keypad)        Weather (Spoken)

Note that we also support the the .Net version of Delphi. You'll find managed Delphi samples along with other .Net samples above.


COM friendly Samples

The voice user interface for an IVR application written in a language which uses COM for its object model is implemented as in in-process COM server which implements the IDispatch interface. These components are sometimes called ActiveX DLLs. The component must have a method named Answer() in which the voice user interface is implemented.

   Visual Basic

      HelloWorld       Weather (Keypad)        Weather (Spoken)

   Visual FoxPro

      HelloWorld

We are sorry but because we just don't get FoxPro we won't be able to post any more samples in that language.


Native Samples

The voice user interface for an IVR application written in a native language is implemented in a function named Answer() which is exported from a DLL which is loaded by the server and simulator.

   C++

      HelloWorld       Weather (Keypad)        Weather (Spoken)

   C

      HelloWorld       Weather (Keypad)        Weather (Spoken)

Note that C and C++ samples differ from the other samples in the way in which they deal with handling the voice user interface while the content fetch is ongoing.

The samples using the script languages and COM friendly languages perform a synchronous fetch of the content. This is simple but it does not allow an application to detect an early disconnect by the caller.

The samples using the .Net languages and the Java language move the content fetch to a background thread which allows the user interface thread to detect a hangup and recycle the telephone line in a timely fashion on the caller's disconnect.

The C and C++ samples use asynchronous I/O in the user interface thread to communicate with the web service. This allows the application to react to the caller's hangup while not paying the time and space penalty associated with extra threads. In short it is a more scalable approach.

We wrote the sample that way because we expect that scalability is uppermost in the minds of developers who opt to use C++. There is however no reason why a C++ application could not use a background thread or why a .Net or Java or  application could not use asynchronous I/O.


Script Samples

The voice user interface for an IVR application written in a script language is implemented in a publicly accessible procedure named Answer. That procedure receives as its only parameter a reference to a call object.

Note that we don't support a fixed set of script languages. Rather we support the platform's extendible script host. If the script host has an interpreter for a particular script language, and if that language supports COM components (of which our call object is one) then we support it.

You'll find samples below for the script languages we have tested.

   Ruby

      HelloWorld       Weather (Keypad)        Weather (Spoken)

Pierre Pierre, who replica handbag 185cm tall, gucci replica handbags the "Diamond King" in his hermes replica handbags . He has been selected as one of the handbag replica most beautiful 50 people in the "People" magazine. It is also known as replica handbags most elegant and quiet in the world. Unforgettable prince.

   Perl

      HelloWorld      

   Python

      HelloWorld    

   JScript

      HelloWorld   

   VbScript

      HelloWorld    

   Object Rexx

      HelloWorld         


Brother, can you spare a sample?

  • If we don't have what you are looking for check this page again. We are not done until we have at least one sample in each of the languages that we support.
  • If you have a novel sample or one in a novel language that you'd like to contribute  then please drop us a line.
  • Microsoft, Windows, Visual Studio, C#, Visual Basic, Visual FoxPro and JScript are trademarks or registered trademarks of Microsoft Corporation.
  • Borland and Delphi are trademarks or registered trademarks of Borland Software Corporation.
  • Java and JavaScript are trademarks or registered trademarks of Sun Microsystems, Inc.