#!/usr/local/bin/perl5 # # BeVocal Sample Code # (C) Copyright BeVocal, Inc. 2003, All rights reserved. # # This Sample Code is provided for your reference purposes, # and carries no warranty whatsoever. Use of this code is # restricted to use in connection with the BeVocal Cafe # developer's program. # # BeVocal disclaims and excludes any and all warranties of # merchantability, title and fitness for a particular # purpose. BeVocal does not warrant that the software will # satisfy your requirements, or that the software is without # defect or error. You are using the software at your own # risk. # use CGI; # # This is a sample Perl-based CGI to demonstrate a server-side technique # for disambiguating the multiple results or multiple interpretations # from a speech recognition. # # Note: If you want to change this script in any way and use it with your # Cafe application, you'll need to host the new Perl script on your # own web server. You cannot upload a Perl script to your Cafe account. # # This script assumes the recognition was from a grammar that filled # two slots: "city" and "state". # # The expected HTTP request parameters are: # results.length - The number of results from the recognition. # # For i from 0 to results.length - 1: # results[i].confidence - The confidence of this result, 0 to 1 # results[i].interpretation.city - The city recognized for this result # results[i].interpretation.state - The state recognized for this result # # # Print out the XML and VoiceXML headers, plus the beginning of the # disambiguation dialog # print "\n"; print "Content-type:application/voicexml+xml\n\n"; print "\n"; print "\n"; print "
\n"; print " \n"; print " I didn't quite get that.\n"; print " Please say 'that one' when you hear the city you want.\n"; print " \n"; # Create two variables to store the disambiguation results print " \n"; print " \n"; # Figure out how many results we have to deal with $length = CGI::param("results.length"); # Save the maximum confidence of any result $maxConfidence = CGI::param("results[0].confidence"); for ($i = 0; $i < $length; $i++) { my ($fname) = ( "f$i" ); # field name my ($city) = ( CGI::param("results[$i].interpretation.city") ); my ($state) = ( CGI::param("results[$i].interpretation.state") ); my ($conf) = ( CGI::param("results[$i].confidence") ); # # If the confidence of this result is close enough to the maximum # one (which we know is always the first one) then use it in # the disambiguation # if (($maxConfidence - $conf) < 0.05) { # # Generate a field that prompts out this city/state name # and then pauses briefly to let the user say "that one". # If the user remains silent, our custom handler # simply goes to the next field. # print " \n"; print " [ ( yes ) ( that one ) ]\n"; print " \n"; print " $city, $state\n"; print " \n"; # # If they said "that one", fill in the result variables. # The form-level block below will then return them. # print " \n"; print " \n"; print " \n"; print " \n"; # # They didn't say anything. Tell the interpreter to go to the # next field by setting this field's form item variable to true. # print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; } }; # # If we get here, it means they didn't say "that one" on any of the fields. # Clear them all out and try again. # print " \n"; print " \n"; print " \n"; # # This form-level filled block returns the city and state variables # as soon as any of the fields are filled by the user saying "that one" # It will be executed after the field-level filled, since filled blocks # are always executed in document order. # print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "\n"; exit 0;