IBM®
Skip to main content
    Country/region [select]      Terms of use
 
 
      
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks > Scenarios
developerWorks
How WebSphere Voice SDK can get your enterprise data to speak up for itself
DiscussCode251KBe-mail it!
Contents:
Introduction to the endeavor
Prerequisites
Installing IBM WebSphere Voice Server SDK Version 1.5.0
Setting up and populating the database
Making VisualAge for Java a conversationalist
Making the Test Environment and IBM Voice Server SDK cooperate
Conclusion
Resources
About the authors
Rate this article
Related content:
Introduction to Voice XML
Creating Voice XML applications with IBM WebSphere Studio
Subscriptions:
dW newsletters
dW Subscription
(CDs and downloads)
You talkin' to me?

Level: Introductory

Kulvir Singh Bhogal (kbhogal@us.ibm.com), Software Engineer, IBM Corporation
Joe Puli (joepuli@hotmail.com), Software Engineer

1 Sep 2002

This article teaches you how to retrieve DB2 data using the sound of your voice. The project uses WebSphere Voice SDK 1.5, Visual Age for Java 4.0, and IBM DB2 UDB 7.2. We guide you step-by-step through a project we call "PeopleSearch," where you provide the application with a name and the application uses this name to query a database for data associated with the name.

Introduction to the endeavor
If you've ever worked with a database, you are probably familiar with the SQL select statements used to retrieve data from your data warehouse. It wasn't long after Java emerged that programmers wanted their Java programs to interact with their databases. And so emerged the concept of Java Database Connectivity, what many of us affectionately know as JDBC. So, are the needs of database programmers and of customers satisfied now? Yeah, riiiight.

Fortunately for computer programmers, and for their paychecks, customers want more. Customers want to interact with their database using voice commands. They want to retrieve data housed in their relational database at the sound of their voice.

Why do users want to use voice commands? Maybe they saw too many episodes of the Jetsons as children. Maybe they are too lazy to type. Or, maybe there is a legitimate reason behind this desire. Not only can vision-impaired users more easily interact with their data, but these applications could come in handy for mobile phones and other devices. Imagine being able to pull up a person's phone number by simply saying her name. We might even be able to spare the world from another person driving and dialing. Now that would be impressive.

Guess what? We're here to impress. In this article, we show you how to retrieve voice-initiated enterprise data using IBM WebSphere Voice SDK V1.5, VisualAge for Java 4.0, and IBM DB2 Universal Database together.

A few years ago this feat would have been impossible. Now, with the Voice Technologies infrastructure bundled with IBM VoiceServer SDK, we can reap the benefits of years of research behind IBM's patented voice recognition technologies. As we demonstrate in this article, you won't have to dig through thousands of lines of code to complete the assignment. The infrastructure needed to perform this seemingly complex goal is rather simple. But enough about what we are going to do. Let's do it.

Prerequisites
We completed our project using a machine installed with IBM DB2 UDB Version 7.2 and using Windows NT as the operating system. You will need a microphone and speakers or headphones hooked up to your computer. You also must understand Java servlets, SQL, JDBC, and basic VoiceXML tag definitions.

Our code was developed using IBM VisualAge 4.0 for Java. We will show you how to use this integrated development environment (IDE) to perform the project. We tap into the IDE's WebSphere Test Environment to emulate a WebSphere-like environment. Of course, in a real-world application, you wouldn't use a test environment; you'd use the real McCoy -- WebSphere Application Server. However, the WebSphere Test Environment is ideal for demonstrating our method and debugging the program.

Installing IBM WebSphere Voice Server SDK Version 1.5.0
Sun's Java Runtime Environment (JRE) Version 1.3 or higher must be installed before you install the Voice Server SDK. This software is bundled in the VoiceServer SDK distribution under the install directory. Note that the Voice Server SDK cannot be installed on a machine that has IBM WebSphere Voice Server installed. The Voice Server SDK installation is straightforward and we do not anticipate you running into any problems.

Setting up and populating the database
Our back-end database isn't complex. The user provides the application with a last name. This last name is used as a key value that identifies a unique row to be returned by the application. Our approach is very simplistic. We assume, for example, that no two people will have the same last name. Of course, in a real-world situation, you'd need a more refined criterion.

Issue the following commands using the command-line processor to set up your environment:

db2 => create database empldb

db2 => connect to empldb

Next, create a database table to accommodate your records (we've split the command onto several lines here, but you should type it all on one line):


db2 => create table employee (FirstName varchar(20), lastname varchar(20) not null, 
department varchar(30), designation varchar(30), city varchar(30), state varchar(30), 
country varchar(30), phone varchar(30), email varchar(30))

Then, populate the database table with the following records:

db2 =>insert into employee values ('Mike','Jordan','IBM Global Services','Manager','Dallas','Texas','USA','123-456-7890','mike@somewhere.com')

db2 =>insert into employee values ('Dan','Smith','IBM ThinkPad Sales','Technician','Hollywood','California','USA','123-456-7120','smith@somewhere.com')

Making VisualAge for Java a conversationalist
Download the project zip file included in this article. In it you will find a JAR file. Create a project on your VisualAge for Java Workbench. (We called our project "peopleSearch.") Import the JAR file from the project zip file. Doing so will allow you to see a package called "com.ibm.peoplesearch." This package will act as a messenger, collecting data from the database as you need it.

You will need to edit the classpath of the Servlet Engine using the WebSphere Test Environment Control Center. Be sure to select the peopleSearch project you created in the "Select the projects to include the classpath" section. Also, provide the path to the IBM DB2 JDBC driver (db2java.zip) in the "Enter the class path" section. When you have done these two things, you should have something similar to what is shown in Figure 1.

Figure 1. Setting the Servlet Engine Class Path
Setting the Classpath

In the project zip file, you will also notice two other files; a file named "welcome.vxml" and a file named "peoplesearch.jsp." Copy these two files to your WebSphere test environment directory. By default, the following would be the pertinent location:

C:\Program Files\IBM\VisualAge for Java\ide\project_resources\IBM WebSphere Test Environment\hosts\default_host\default_app\web

Next, you need to start the Servlet Engine. You'll know that things are up and running when you see a message that states "***Servlet Engine is started***" in your console.

Making the Test Environment and IBM Voice Server SDK cooperate
Now that you have your servlet engine up and running, let's get your SDK working in tandem with the WebSphere Test Environment.

Using the DOS prompt, go to the directory where the Voice Server SDK was installed. Under the install directory is a directory called "bin". We used the default installation settings, which means that our bin directory is located at C:\Program Files\VoiceServerSDK\bin\ .

In this bin directory is a batch file that you will run. Issue the following DOS command:

vsaudio_en_US "http://localhost:8080/welcome.vxml"

When you do this for the first time, the Voice Server SDK invokes the Audio Setup Wizard (see Figure 2).

Figure 2. The Audio Setup Wizard
The Audio Setup Wizard

Take a few moments to set up your microphone and speakers. The questions asked are easy to answer, but your answers will depend on your particular audio setup. The setup wizard will guide you through the process (see Figure 3).

Figure 3. The Audio Setup Wizard gets you up and running
The Audio Setup Wizard will guide you

Be sure to adjust your microphone to get the optimal recording environment (see Figure 4).

Figure 4. Adjust the headset as suggested by the wizard
Adjust the headset as suggested by the wizard

The wizard next guides you through a series of steps to determine your recording environment. These steps are straightforward and will take you only a few minutes to complete.

When everything is set up using the wizard, you will be presented with a dialogue as follows:

System: Hello and Welcome to IBM's Address Book Application. Please say the last name of the person whose address you want to search.

User: [says the last name of the person]

At this point the system verifies the last name against the grammar file that is written inline for this application.


<grammar>
<![CDATA[[      Jordan | Smith | Peters | Jackson| Biggs      ]]]>
</grammar>>

In a real-world application the grammar file would be created dynamically following the Java Speech Grammar Format (JSGF) and linked to the VoiceXML document. A complete discussion on grammar is beyond the scope of this article; but you can find more information on grammar in Resources.

After the grammar validation, the system collects the input and executes the <filled> element in the people.vxml file if the user input is valid .

System: I heard you say $userInput, would you like to continue?

User: Yes

At this point the system forwards the request to a JavaServer Pages page, peoplesearch.jsp, using the VoiceXML tag <submit>. The last name of the person is sent to the JSP page in the Query String.

In this JSP, we first state that our file is of the form "<vxml version="1.0">". This will let the VoiceSDK interpret the Voice tags in the JSP page. To grab the name that the user provides verbally from the request object, use the following syntax:

String name = request.getParameter("name");

Note that our JSP is left oblivious to the form and fashion in which the information was provided. Using VXML, we did a one-to-one linking of the spoken last name to a last name we specified in the grammar. This last name was then concatenated to the query string from which we retrieve the parameter using the getParameter method.

After grabbing the request parameter, we send the newly obtained information to the constructor of the com.ibm.peoplesearch.EmployeeInfo class, which is nothing more than a Database Access Object for the Employee table.

The code for the constructor is shown below.

Code for the com.ibm.peoplesearch.EmployeeInfo constructor

/**
 * EmployeeInfo constructor comment.
 */
public EmployeeInfo(String empName) 
{
 super();
 
 try

 {

  //load the IBM DB2 driver
  
  Class.forName("COM.ibm.db2.jdbc.app.DB2Driver"); 
  // Get Connection object to query the EMPDB database 
     conn = DriverManager.getConnection(URL);
     // get the employee record from the employee 
     // and populate the Class Attributes.
     // empName is the Employee LastName value 
     // we get from Application EndUser.
     if(empName !=null){

      String strSQL = "select * from employee where LASTNAME='"+empName+"'";
      
      stm = conn.createStatement();
      
      rs = stm.executeQuery(strSQL);

      int i =1;
      
      while(rs.next()){

       recordFound = true;
       strFirstName = rs.getString(i);
       strLastName = rs.getString(++i);
       strDept = rs.getString(++i);
       strDesignation = rs.getString(++i);
       strCity = rs.getString(++i);
       strState = rs.getString(++i);
       strCountry = rs.getString(++i);
       strPhone = rs.getString(++i);
       strEmail = rs.getString(++i);       
      }


       }
     
     }
 catch(Exception e){

  System.out.println("Error in the EmployeeInfo Object constructor");
  System.out.println("Error is :"+e.getMessage());
  try{
   if(rs!=null){rs.close();}
   if(stm!=null){stm.close();}
   if(conn!=null){conn.close();}
  }
  catch(Exception sqe){
   System.out.println("Error is :"+sqe.getMessage());
  }
   
  
  
  }
}

As you can see from the code, we first establish a connection to our DB2 database. Next, we create an SQL query using the last name inputted by the user. If a record is found that meets our criterion, then we populate our instantiated object's properties with the data.

This data is then relayed to the VoiceSDK, which understand the tags and spells it out to the user using the computerized voice which sounds remarkably like those Speak-and-Spells that were the craze in the 80s. While the application presented here is rather rudimentary, you can expand on our little application, using it as a foundation for your enterprise solution.

Conclusion
Have you ever had a cubicle next to someone that you swear was trying to have a real conversation with their computer screen? If you are that "someone" then at least you can do something productive with your voice ... like retrieving enterprise data. In this article, we tapped into an exciting technology which just a few years ago would have been considered science fiction -- voice recognition. IBM has been in the forefront of developing voice recognition with its award-winning products, including IBM ViaVoice and IBM's Voice Server SDK. This article gives you a glimpse of some of the amazing things that you can do with the mere sound of your voice.

Resources

About the authors
author name Kulvir Singh Bhogal works as an IBM consultant, devising and implementing Java-centric solutions at customer sites across the nation. You can contact Kulvir at kbhogal@us.ibm.com.


author name Joe Puli is an independent Software Engineer working in the Bay Area. He has worked for a number of industries and specializes in Java-centric projects. You can contact Joe at joepuli@hotmail.com.



DiscussCode251KBe-mail it!

What do you think of this document?
Killer! (5)Good stuff (4)So-so; not bad (3)Needs work (2)Lame! (1)

Send us your comments or click Discuss to share your comments with others.



developerWorks > Scenarios
developerWorks
  About IBM  |  Privacy  |  Terms of use  |  Contact