Skip to content. | Skip to navigation

Sections
Personal tools
You are here: Home Accelerate Articles Connect WebSphere Voice Server SDK to U2 using RedBack JavaBeans

Connect WebSphere Voice Server SDK to U2 Using U2 Web DE JavaBeans

Learn how to retrieve data from a U2 database management system using the voice technology of WebSphere® Voice Server SDK.

Provide voice access to your U2 database

Level: Introductory

Louis Tur ( ltur@rs.com), U2 Sales Engineer, Rocket Software

14 Jul 2005


Introduction

Are you a U2 Web Development Environment (U2 Web DE) programmer who wants to offer access to U2 data from phone and other devices? Would you like to demonstrate that feature on your laptop? This article will show you how. Using the IBM WebSphere® Voice Server Software Developers Kit, you can submit voice requests that use existing RedBack business objects.

The project

This project prompts the caller for a name and retrieves the contact information that matches. The sample code illustrates how you can create an external grammar file, validate the spoken name, and fetch the records that match. This project is based on an article written by Kulvir Singh Bhogal and Joe Pull titled "How WebSphere Voice SDK can get your enterprise data to speak up for itself." Code examples from their article were modified to meet the needs of the RedBack developer. See Resources.

Software used

The application uses VoiceXML (VXML), Java Server Pages (JSP) and RedBack's Java Beans to access U2 data. WebSphere Voice Server SDK is the engine for the VXML execution, and WebSphere Application Server is the engine for the JSP and Java Beans execution. On the back end, RedBack Scheduler handles the requests to the database.

The project uses the following software:

  • IBM WebSphere Voice Server SDK 3.1
  • IBM WebSphere Application Server 5.0
  • UniVerse 10.1 for Windows
  • U2 Web DE 4.4.3

 

Setting up the application

After you have installed the necessary software, you need to do the following before you can run your application:

  • Create a rgw.ini configuration file for RedBack Gateway for WebSphere Application Server. Save the file to the Windows system directory. The contents of the file should be:
    rbexamples localhost:8401
    

  • Copy rgw.exe from the U2 Web DE product CD to the cgi-bin directory on the IBM HTTP server.
  • Install the rbexamples.war package on WebSphere Application Server. RedBack provides a Web Archive (war) file for demonstration purposes. This file is a self-contained package containing examples and the RedBack Java Beans. To install the file in WebSphere Application Server 5.0:
    1. At the WebSphere Application Server, start the Administrative Console by pointing your Web browser to: http://localhost:9090/admin
    2. In the left side of the console, expand Applications.
    3. Select Install New Application.
    4. Click the Browse button in the right pane.
    5. Navigate to your rbexamples.war file (under the RedBeans directory on the product CD), select it and click Open.
    6. In Context Root, enter rbexamples. Click Next.
    7. Set Virtual Host to default_host. Click Next.
    8. In Application Name, enter rbexamples. Click Next.
    9. Click Finish.
    10. Save the configuration by clicking the Save to Master Configuration link.
    11. In the left side of the console, select Enterprise Applications.
    12. Select rbexamples and click Start.
    13. Connect to this URL: http://locahost:9080/rbexamples/jspindex.htm

After installing the rbexamples.war package on WebSphere Application Server, you need to set up the database for this project. This application uses the EMPLOYEES table in the RBEXAMPLES UniVerse account. This database was created during the installation of the RedBack Scheduler.

The following UniVerse BASIC program builds a grammar file that the VoiceXML application will use to validate the spoken name. Cut and paste the code into a text editor. Modify the variable WDIR to match your WebSphere directory path. Save the edited program code to the BP directory under the rbexamples UniVerse directory. Compile and run the program BUILDGRAMFILE from the REBEXAMPLES UniVerse account. The BUILDGRAMFILE program will build the grammar file name.gram, which contains the list of last names from the EMPLOYEES table in a format that the Voice Server SDK can process.

BUILDGRAMFILE
10 PRINT "THIS PROGRAM WILL CREATE THE name.gram FILE FOR VOICE ACCESS"
PRINT "INPUT Y/N TO CONTINUE :":;INPUT X
IF X = "N" THEN STOP
IF X # "Y" THEN GOTO 10
* The path for WebSphere rbexamples directory may be different on your pc so change it accordingly
WDIR="C:\WEBSPHERE\APPSERVER\INSTALLEDAPPS\LOCALHOST\RBEXAMPLES.EAR\RBEXAMPLES.WAR"
* Remove the old name.gram file from the and create a empty file
CMD = "DOS /c rm ":WDIR"\name.gram"
EXECUTE CMD
CMD = "DOS /c touch ":WDIR:"\name.gram"
EXECUTE CMD
**********
* Grammar string needed
*********
CR=CHAR(13)
GRAM="#JSGF V1.0 ;":CR
GRAM=GRAM:"grammar name ;":CR
GRAM=GRAM:'public <rule1>= ':CR
* Now open name.gram file
OPENSEQ WDIR:"/name.gram" TO NAME
ELSE PRINT "PROBLEM OPENING name.gram";STOP
* Now open the EMPLOYEES table and select all records
OPEN "","EMPLOYEES" TO EMP
ELSE PRINT "PROBLEM OPENING EMPLOYEES FILE";STOP
SELECT EMP
FIRST=1
* Now loop and read each employee record and build array containing LAST.NAME
100 READNEXT ID ELSE GOTO 200
READV LAST.NAME FROM EMP,ID,2 ELSE GOTO 100
IF FIRST THEN
FIRST=0
GRAM=GRAM:LAST.NAME:CR
END ELSE
GRAM=GRAM:"|":LAST.NAME:CR
END
GOTO 100
200 *
GRAM=GRAM:";"
* Now write the array to the name.gram file
WRITESEQ GRAM ON NAME THEN PRINT "OK" 
ELSE PRINT "PROBLEM WRITING name.gram"
CLOSESEQ NAME
PRINT "DONE WRITE"
STOP


Listing EMPLOYEES Table by  LAST.NAME
EMPLOYEES. Last Name..

1012       Berry
1015       Byrne
1014       Caddick
1007       Chazan
1009       Delas
1019       Drury
1013       Fox
1023       Gassis
1024       Green
1020       Jenkins
1005       Joarder
1017       Kaynor
1006       Kennedy
1011       Kesic
1008       Kontorovich
1010       La
1022       MacKenzie
1004       Prinz
1016       Rabinovitch
1002       Reyburn
1018       Smith
1003       Teo
1001       Wedewer
23 records listed
 

Next, you need to create the files rbwelcome.vxml and u2peoplesearch.jsp. Copy the sample code shown below, paste it into a text editor, and save each file to the rbexamples.war directory (for example, c:\WebSphere\AppServer\installedApps\localhost\rbexamples.ear\rbexamples.war). This directory was created when you installed rbexamples.war in WebSphere Application Server. This is also where the UniVerse BASIC program BUILDGRAMFILE will write the name.gram file.

<vxml version="1.0">
<var name="name">
<var name="decide">
 <form id="rbwelcome" >
  <-- welcome Message -->
   <block>
      HELLO AND WELCOME TO ROCKET'S  U2 PEOPLE SEARCH APPLICATION. 
     <block>
   <field name="LASTNAME">
    <grammar src = "name.gram" />
<!-- Prompt user for input -->
      <prompt>
         Please say the last name of the person you want to search for.
     <prompt>
      <noinput>        
         <prompt>
          I did not hear you. Please say the last name of the person you want to search for.
     <prompt>
      </noinput>
      <help>
        Please say the last name of the person you want to search for.
      </help>
      <!-- If input received reconfirm with user -->
      <filled>
      <assign name="name" expr="LASTNAME"/>
      <prompt>
         I heard you say <value expr="name"/>
    
     </prompt>            
       <goto next="#confirm"/>
         </filled>
   </field>
  </form>
  <-- Reconfirm form which sends the request back to server if the user confirms the last name -->
  <form id="confirm" >  
    <field name="test" type="boolean">
    <prompt>
         Would you like to continue.
      <prompt>
      <noinput>    
         <reprompt/>
      </noinput>
      <help>
        Please say yes to confirm or No to search again.
      <help>
      <filled>      
        <if cond="test == true">
     <prompt>
         Please wait as I process your request.
     </prompt>
         <submit next= "http://localhost/rbexamples/u2peoplesearch.jsp" namelist="name"/>
<else/>
         <goto next="#rbwelcome"/>
      <if>        
      </filled>
   </field>  
  </form>
</vxml>
<vxml version="1.0">
<%@ page import = "com.ibm.redback.redbeans.*" %>
<jsp:useBean id="connection" class="com.ibm.redback.redbeans.Connection" scope="session"/>
<jsp:setProperty name="connection" property="connectionURL" value="rbexamples"/>
<%@ page isThreadSafe="false" import="java.util.*"
            errorPage="error.jsp" %>
<%
// Get the user last name and instantiate the EmployeeList object.

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

com.ibm.redback.redbeans.RedObject obj = null; // handle to this page's redobject
com.ibm.redback.redbeans.RecordSet rs = null;
 obj = new com.ibm.redback.redbeans.RedObject();
    obj.setActiveConnection(connection);
    obj.setRBOClass("EXMOD:EmployeeList");
    obj.open();
    obj.setProperty("select_criteria", "LAST.NAME = \""+ name + "\"");
  // Now do selection
  rs = obj.callMethod("Select");
String maxr = obj.getProperty("MaxRows");
 <form id="results">
  <block>
  // output  number of records found
Records found = <%= obj.getProperty("MaxRows")%>
   
     The person you searched for 
     <% 
if(rs.isEOF()){
out.println("could not be found. Good Bye");    
     }
     else{
// script for each employee row

     rs.moveFirst();
       out.println(rs.getProperty("FIRST.NAME") +"  "+rs.getProperty("LAST.NAME")+".");

// if more than one employee  match  output  each - 
     for (int i = 2; i  <= rs.getPageSize() ; i++){
     rs.moveNext();
     out.println(rs.getProperty("FIRST.NAME") +"  "+rs.getProperty("LAST.NAME") + ".");
         }  
     }
     %>
         </block>
         </form>

 </vxml>
</code </vxml>

Running the application

  • At the DOS prompt, go to the directory where the Voice Server SDK was installed. The default is C:\Program Files\VoiceServerSDK\bin\.
  • In the bin directory, enter the following DOS command:
    vsaudio_en_US "http://localhost:9080/rbexamples/rbwelcome.vxml"
  • The first time you run the program, a wizard helps you set up your microphone. After that you will be presented with a dialogue as follows:
    System: Hello and welcome to Rocket's U2 People Search Application. Please say the last name of the person who you want to search for.
    User: [says the last name of the person]
  • At this point, the system verifies the name against the external grammar file name.gram.
  • After the grammar validation, the system executes the <filled> element in the rbwelcome.vxml file.
    System: I heard you say $userInput, would you like to continue?
    User: Yes
  • The system sends the request to u2peoplesearch.jsp, using the VoiceXML tag <submit>. The last name of the person is sent to the JSP page in the namelist attribute.
  • To enable the VoiceServer SDK to execute the Voice tags in the JSP page, the first line of code is <vxml version="1.0">. To get the name that the user provides verbally from the request object, use the following syntax:
    String name = request.getParameter("name");
  • This example instantiates the existing RedBack Business Object in the rbexamples U2 account called EmployeeList using the com.ibm.redback.redbeans.RedObject class and call the method Select passing the criteria LAST.NAME = name
  • The Voice Server SDK processes the result set from the query, and tells the user the first and last name of the employees selected.

Conclusion

IBM's Voice Server SDK and RedBack products make it simple to integrate voice recognition into a U2 database management system. With a little customization of the examples provided here, you can provide your users with voice access to your data.


Resources

Learn
  • The article How WebSphere Voice SDK can get your enterprise data to speak up for itself (developerWorks, September 2002) 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 V7.2.

  • About the authors

    Louis Tur photo

    Louis Tur is responsible for the technical enablement of  assigned partners and customers of Rocket's U2 Database and Tools business. Louis  joined Unidata, Inc. in 1993. He has over 30 years experience  in MultiValue database development and deployment. Louis has a Bachelor of Science degree in Economics from Queens College, NY.



 

Document Actions