Part I: Developing Inbound Applications: Voice Command | Gateway Tutorial

Voice command is the main method to develop an interactive telephony application. It has many advantages over traditional DTMF tone based applications.

Suppose we want to enable user to get the time of day of a specific time zone, we can change the timeofday.jsp file to the following.

<?xml version="1.0"?>
                <vxml version="1.0">

                    <%@ page import="java.util.Date" %>
                    <%@ page import="java.text.SimpleDateFormat" %>
                    <%@ page import="java.util.TimeZone" %>
                    <%
                    response.setHeader("Cache-Control","no-cache");

                    Date d = new Date(System.currentTimeMillis());

                    String tz = request.getParameter("tz");
                    TimeZone timez = null;
                    if ("pacific time".equals(tz))
                    timez = TimeZone.getTimeZone("America/Los_Angeles");
                    else if ("mountain time".equals(tz))
                    timez = TimeZone.getTimeZone("America/Denver");
                    else if ("central time".equals(tz))
                    timez = TimeZone.getTimeZone("America/Chicago");
                    else if ("eastern time".equals(tz))
                    timez = TimeZone.getTimeZone("America/New_York");

                    SimpleDateFormat f;
                    if (timez != null) {
                    f = new SimpleDateFormat("hh:mm a, zzzz");
                    f.setTimeZone(timez);
                    }
                    else {
                    f = new SimpleDateFormat("hh:mm a");
                    }
                    %>

                    <form id="td">
                        <field name="tz">
                            <prompt timeout="10s">
                                <block>
                                    <audio src="audio/welcome.wav"/>
                                    <%= f.format(d) %>
                                    <audio src="audio/which_timezone.wav"/>
                                </block>
                            </prompt>
                            <grammar>
                                pacific time | mountain time | central time | eastern time
                            </grammar>
                            <filled>
                <submit next="/td/timeofday.jsp" namelist="tz"/>
                            </filled>
                        </field>
                    </form>
                </vxml>

Compile the file using jspc and javac.

Also, record additional voice prompt "To get time of day again, please tell me the time zone" and save it as <tddir>/webapps/audio/which_timezone.wav.

Restart the gateway. Call in and test the service.

An example of the service interaction is shown below:

User: dial the service number
                    Service: ..., Hello, this is the time of day service. The current time is ... To get time of day again, please tell me the time zone
                    User: pacific time
                    Service: ... The current time is ... Pacific standard time. ...

As you can see in this example, combining JSP and VXML is flexible and quite powerful.

Download the sample code: timeofday_step4.zip.