VoiceXML: Events, Errors, and ECMAScript - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

VoiceXML: Events, Errors, and ECMAScript

Description:

ECMAScript code ... vxml that elicits the selling price of a property and then calculates the ... Prof. Mctear, Natural Language Processing, ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 36
Provided by: Michael3454
Category:

less

Transcript and Presenter's Notes

Title: VoiceXML: Events, Errors, and ECMAScript


1
VoiceXMLEvents, Errors, and ECMAScript
2
Acknowledgements
  • Prof. Mctear, Natural Language Processing,
    http//www.infj.ulst.ac.uk/nlp/index.html,
    University of Ulster.

3
Events
  1. Plain events happen normally, involve special
    event handler
  2. Error events - unexpected situations, may cause
    application to terminate

Plain events Error events
cancel, help, exit (user) error.badfetch
noinput, nomatch (user input) error.semantic
connection.disconnect.hangup error.noauthorization
maxspeechtimeout error.unsupported.builtin
Note how events are handled is platform-dependent
4
Default catch handlers
Event Type Action
cancel dont reprompt
error exit interpreter
exit exit interpreter
help reprompt
noinput reprompt
nomatch reprompt
maxspeechtimeout reprompt
connection.disconnect exit interpreter
all others exit interpreter
5
noinput, nomatch
  • ltnoinputgt
  • System does not detect any speech.
  • This event is thrown when the timeout interval is
    exceeded (in IBM WebSphere Voice Toolkit the
    default timeout interval is 500 milliseconds).
  • ltnomatchgt
  • The users input does not match the recognition
    grammar.
  • The default behaviour in the IBM WebSphere Voice
    Toolkit for this event is to output a message and
    then re-prompt.
  • These (and other) default event handlers can be
    modified.
  • Properties such as timeout can also be modified.

6
ltcatchgt
  • ltcatch event "nomatch"gt           ltpromptgt  I
    did not understand what you said. Please answer
    the question again. lt/promptgtlt/catchgt
  • ltcatch event "nomatch noinput help"gt         
      ltpromptgt  I did not understand what you said.
    Please answer the question again. lt/promptgt 
    ltreprompt/gt  lt!--  Present the original prompt
    message again to the user   --gtlt/catchgt
  • ltcatch event "nomatch" count "2"gt
  •   lt!--  count different occurrences of an event
      --gt

7
Shorthand ltcatchgt elements
  • Some common events, such as noinput, nomatch,
    help, and error have shorthand versions, e.g.
  • ltnomatchgt     I did not understand, please try
    again.lt/nomatchgt
  • ltnoinputgt
  • I didnt hear anything. Please speak a little
    louder.
  • ltnoinputgt
  • With counters ltnomatch count 1gt

8
ltthrowgt
  • Used to define application-specific events e.g.
    user has failed 3 times to enter valid id
  • ltcatch event nomatch" count "1gt
  • That is not a valid i d   lt/catchgt
  • ltcatch event "nomatch" count "4gt
  • ltthrow event "error.invalid_password"/gt
    lt/catchgt
  • ltcatch event "error.invalid_password" gt
  • ltpromptgt Please check your i d. Goodbye lt/promptgt
  • ltexit/gt
  • lt/catchgt    

9
Event handlers and scope
  • Event handlers can be defined at different scope
    levels
  • Scope levels form a hierarchy.  
  • Event handlers defined in a higher scope level
    are inherited at lower scope levels within the
    hierarchy. 
  • A local event handler overrides or replaces an
    inherited event handler.  If a local event
    handler has the same name as an inherited event
    handler, then the local event handler replaces
    the inherited event handler.
  • The VoiceXML interpreter examines the following
    containers in the order listed to select an event
    handler
  • Field
  • Dialog
  • Document
  • Application
  • Session

10
Tutorial Exercises Error handling
  • Aim to explore events such as ltnoinputgt and
    ltnomatchgt and modify their default behaviours
  • Run the file studentsystem1b.vxml and test how
    it behaves when a) You do not say anything b)
    You say something that is not in the specified
    recognition vocabulary.
  • Modify the default behaviours for ltnoinputgt and
    ltnomatchgt using counters for alternative
    behaviours.
  • Define an application specific event using
    ltthrowgt that causes the application to terminate
    with some form of explanation following an event
    such as repeated failure to elicit valid input.
  • The event could be a third failure to elicit the
    users spoken input, with an event thrown such as
    error.no_input. This event can be caught,
    causing the system to transfer to a human
    operator. Include a prompt that explains what is
    happening. If transfer is not possible, then use
    ltexit /gt or ltdisconnect/gt to cause the
    application to terminate.

11
What is ECMAScript?
  • Used as the scripting language of VoiceXML for
    client-side processing, e.g. to validate user
    input (without requiring access to the server),
    or to dynamically generate values.
  • VoiceXML variables are completely equivalent to
    ECMAScript variables.
  • The expr and the cond attributes reference
    ECMAScript expressions.
  • Escaping characters to conform to the rules of
    XML e.g.ltif cond age gt 21 gt
  • Or use the ltscriptgt element e.g.
  • ltSCRIPTgt
  • lt!CDATA
  • ... ECMAScript code ... gt
  • lt/SCRIPTgt

http//www.ecma-international.org/publications/sta
ndards/Ecma-262.htm
12
ECMAScript Example
  • ltform id"form"gt
  • ltblockgt
  • ltvar name"hours"/gt
  • ltvar name"minutes"/gt
  • ltvar name"seconds"/gt
  • ltscriptgt
  • lt!CDATA
  • var nownew Date()
  • hoursnow.getHours()
  • minutesnow.getMinutes()
  • secondsnow.getSeconds()
  • gt
  • lt/scriptgt

ltpromptgt The current time is ltvalue
expr"hours"/gt hours, ltvalue expr "minutes"/gt
minutes, and ltvalue expr "seconds"/gt
seconds. lt/promptgt lt/blockgt lt/formgt
13
More on the date object
  • The Date object stores a year, month, day, date,
    hour, minute, and second.   
  • Methods of the Date object include
  • getSeconds( ) returns the seconds in Date
  • get Minutes( ) returns the minutes in Date
  • getHours( ) returns the hours in Date
  • getDay( ) returns the day of the week in Date
    beginning at 0
  • getDate( ) returns the day of the month in Date
  • getMonth( ) returns the month in Date beginning
    at 0
  • getFullYear( ) returns the year as a 4 digit
    string

14
Example with ltifgt Calculating variable interest
  • ltform id"calculate_interest"gt
  • ltvar name interest"/gt
  • ltvar name"interest_calculated" /gt
  • ltfield name"amount typenumbergt
  • ltpromptgtWhat is the amount in your account?
    lt/promptgt
  • ltfilledgt
  • ltscriptgt
  • lt!CDATA
  • if (amount lt 1000) interest 0.02
  • if (amount gt 1000 amount lt 10000)
    interest 0.03
  • if (amount gt 10000) interest 0.04
  • interest_calculated interest amount
  • gt
  • lt/scriptgt
  • ltpromptgt the interest on your balance is ltvalue
    expr"interest_calculated"/gt lt/promptgt
  • lt/filledgt
  • lt/fieldgt
  • lt/formgt

15
Tutorial Exercise ECMAScript
  • Using the file interest.vxml as a basis, create
    a file called commission.vxml that elicits the
    selling price of a property and then calculates
    the commission fee based on the following rules
  • if (amount lt 90000) fee 0.05
  • if (amount gt 90000 amount lt 200000) fee
    0.04
  • if (amount gt 200000) fee 0.03

16
Universal Commands and Navigation
17
Overview
  • Using a root document for global commands and
    storing information
  • Navigation within and between documents
  • The ltsubdialoggt element
  • Exercises
  • Using a root document
  • Creating a subdialog

18
Root document
  • Simple applications may consist of one document.
  • Larger applications may consist of several
    documents, one of which is the root document, and
    the others are child documents of the root
    document.
  • The root document can contain event handlers,
    grammars, variables, scripts and other constructs
    in the scope of the application which are
    inherited by the child documents.
  • These elements are active throughout the entire
    application, unless otherwise specified.
  • The child documents must reference the root
    document using the application attribute of the
    ltvxmlgt element, e.g.ltvxml version2.0" applicati
    on"root.vxml"gt
  • (assuming root document is called root.vxml
    Note the root document can have any arbitrary
    name)

19
root.vxml
  • lt!-- header information --gt
  • ltvar nameuser_pin"/gt
  • ltlink next"main.vxml" gt
  • ltgrammar type"application/srgsxml" root"main"
    version"1.0" mode"voice"gt
  • ltrule id"main" scope"public"gt
  • ltone-ofgt
  • ltitemgt main menu lt/itemgt
  • ltitemgt start over lt/itemgt
  • lt/one-ofgt
  • lt/rulegt
  • lt/grammargt
  • lt/linkgt
  • lt/vxmlgt

20
logon.vxml
  • ltfield name"pin" type"digits" gt
  • ltpromptgtwhat is your four digit pinlt/promptgt
  • lt/fieldgt
  • ltblockgt
  • ltassign name"application.user_pin" expr"pin" /gt
  • ltgoto next"main.vxml" /gt
  • lt/blockgt
  • lt/formgt
  • lt/vxmlgt

21
Retrieving the value
  • The value stored as an application level variable
    can be retrieved as follows
  • ltprompt version"1.0"gt
  • Your pin is
  • ltsay-as interpret-as"vxmldigits"gt
  • ltvalue expr"application.user_pin"/gt lt/say-asgt
  • The prompt demonstrates that the value of
    user-pin is available to each leaf document
    that references root.vxml

22
More on Navigation
  • Transition to other forms etc when the FIA has
    processed a form (dialog)
  • ltchoicegt - Used within the ltmenugt element to
    select and transition to another dialog.
  • ltgotogt - Used within ltblockgt, ltcatchgt, lterrorgt,
    ltfilledgt, ltforeachgt, lthelpgt, ltifgt, ltnoinputgt,
    ltnomatchgt, and ltpromptgt
  • ltlinkgt - Used within ltfieldgt, ltformgt, ltinitialgt,
    and ltvxmlgt
  • ltsubmitgt Used within ltblockgt, ltcatchgt, lterrorgt,
    ltfilledgt, ltforeachgt, lthelpgt, ltifgt, ltnoinputgt,
    ltnomatchgt, and ltpromptgt 

23
Attributes for navigation
  • Specifying the target item
  • next - A URI reference e.g.
  • next"http//myexamples.com/student_system
    (absolute reference)
  • nextstudents.vxml (relative e.g. in same
    directory)
  • nextstudents.vxml first_query" (specifies
    dialog within the document)
  • nextitem - The name of an input item within the
    same form e.g. nextitem student_name
  • expr - A URI reference that is dynamically
    determined by evaluating the ECMAScript
    expression e.g.
  • exprstudent_system' '' first_query'
  • expritem - The name of an input item within the
    same form

24
ltgotogt ltsubmitgt
  • ltgotogt
  • transition to another form item within current
    form, another form within current document, or
    another document
  • transitioning to another dialog or document using
    ltgotogt will cause the old dialogs variables to
    be lost. If the variables are to persist across
    multiple documents, they should be stored with
    application scope
  • ltsubmitgt
  • used to submit values to the document server via
    an HTTP GET or POST request
  • namelist attribute specifies which values are
    being submitted e.g. ltsubmit nexthttpwww.myser
    ver.com/getstudentdetails.jsp namelist
    studentname coursename /gt
  • Control will not necessarily return to the
    calling document. For example, the script
    specified in the next attribute might generate
    a VoiceXML document dynamically and execution
    will continue with this document.

25
ltexitgt
  • ltexitgt
  • terminates all loaded documents and returns
    control to the voice browser which determines
    what to do next
  • Attributes
  • exprECMAScript expression that is evaluated as
    the return value
  • namelistList of variable names to be returned
  • ltexitgt example
  • ltfilledgtltsubmit namelist source target
    amount" /gt ltexit/gt lt/filledgt   

26
ltdisconnectgt
  • Causes the voice browser to disconnect
  • ltdisconnectgt example
  • ltfilledgtltsubmit namelist source target
    amount" /gt ltdisconnect/gt lt/filledgt   
  • Note Before ending the session, developers can
    catch the ltdisconnectgt event to perform some
    post-disconnect processing such as submitting any
    remaining data to a Web server.

27
lttransfergt (1)
  • Enables the user to connect via the telephone to
    another voice application on another speech
    server.
  • Also enables the user to connect to a person's
    telephone. Frequently this will be an operator or
    help agent that assists a user having trouble.
  • blind transfer
  • the caller can converse only with the party on
    the other end of the connection.
  • bridge transfer
  • the caller may converse with another party and
    also hear prompts and respond by speaking or
    pressing the keys on a touchtone telephone.  This
    enables the caller to proactively end the
    transferred call.  

28
lttransfergt (2)
  • When the transfer is complete, the connection is
    broken. 
  • Once the transfer disconnects, the instructions
    in the ltfilledgt element associated with the
    lttransfergt element are interpreted.   
  • The input-form-item variable may contain values
    including the following which indicate why the
    transfer was not successful
  • busy - The other person was busy.
  • noanswer - The other person did not answer.
  • network_busy - An intermediate network was not
    able to transfer the call.
  • Various shadow variables contain information
    about a successful transfer e.g..
  • duration of the call transfer in seconds. 
  • mode used by the caller to terminate the
    transferred call (voice or DTMF

29
ltsubdialoggt
  • Enables frequently used code to be saved in a
    library and re-used in several applications
  • When invoked, a subdialog executes in a new
    execution environment it does not inherit any
    parameters from the calling dialog.  The
    subdialog proceeds until it encounters  
  • ltreturngt elementEnds the execution of a
    subdialog and returns control and data to the
    calling dialog.  Data is returned to the calling
    dialog as a namelist.  When the subdialog
    returns, its execution environment is deleted.
  • ltexitgt elementExecution stops
  • No form items remain eligible for the FIA to
    select - Execution stops

30
Go to subdialog to elicit name which is
returned to main dialog for greeting
ltsubdialoggt 1
  • 3. ltform id"main_menu"gt
  • 4. ltblockgt
  • 5. Welcome to the Student System Main Menu
  • 6 lt/blockgt
  • 7 ltsubdialog name"result" src"validation"gt
  • 8 lt/subdialoggt
  • 9 ltblockgt
  • 10 ltpromptgt
  • 11 hello ltvalue expr "result.username" /gt
  • 12 lt/promptgt
  • 13 lt/blockgt
  • 14 lt/formgt
  • 15 lt!-- subdialog --gt
  • 16 ltform id"validation"gt
  • 17 ltfield name"username"gt
  • 18 ltgrammargt
  • 19 liz margaret mike guest
  • 20 lt/grammargt
  • 21 ltpromptgt Please say your user name. lt/promptgt
  • 22 lt/fieldgt
  • 23 ltfilledgt
  • 24 ltreturn namelist"username" /gt
  • 25 lt/filledgt
  • 26 lt/formgt

studentsystem3a.vxml
31
Pass value into subdialog for validation
ltsubdialoggt 2
ltform id"main_menu"gt ltblockgtWelcome
lt/blockgt ltfield namestudentnamegt ltgrammargt
john david rosemary jennifer
lt/grammargt ltpromptgt Please say your user name
lt/prompt lt/fieldgt ltsubdialog name"result"
src"validation"gt ltparam name username" expr
studentname" /gt lt/subdialoggt lt/formgt
lt!-- subdialog --gt ltform id"validation"gt ltvar
name username" /gt ltblockgt ltpromptgt hello
ltvalue expr username" /gt lt/promptgt ltreturn
/gt lt/blockgt lt/formgt
studentsystem3b.vxml
32
Pass values in both directions elicit value and
pass to subdialog for validation, return to main
dialog with result
ltsubdialoggt 3
ltform id"main_menu"gt ltblockgtWelcome
lt/blockgt ltfield namestudentnamegt elicit name
lt/fieldgt ltsubdialog name"result"
src"validation"gt ltparam name studentname"
expr username" /gt lt/subdialoggt ltblockgt ltprompt
gt hello ltvalue expr "result.studentname" /gt the
student number is ltvalue expr
"result.studentid" /gt lt/promptgtlt/blockgt lt/formgt
lt!-- subdialog --gt ltform id"validation"gt ltvar
name studentname" /gt ltvar name "studentid"
expr" /gt ltblockgt ltif cond "name'john'"gt lta
ssign name "studentid" expr "'96050918'"
/gt lt/ifgt ltreturn namelist "studentid"
/gt lt/blockgt lt/formgt
studentsystem3c.vxml
33
Tutorial Exercises Using a root document
  1. Assuming that you have separate documents for the
    main elements of the Student System - student
    details, course details, view student details,
    reports, and a main menu document - create a root
    document with links to these documents. Provide a
    link in the root document that will enable the
    user to navigate to the main menu document from
    any other document in the application.
  2. Create a variable with application scope in the
    root document to hold the user's pin. Elicit a
    value for the user's pin in a file such as
    logon.vxml, store the value in the root document
    and access it from some other child document.

34
Tutorial Exercises Subdialog (1)
  • Passing values back from a subdialog following
    some computation within the subdialog
  • Load and run the file studentsystem3a.vxml. You
    can say one of the student names (john, david,
    rosemary or jennifer) in response to the system
    prompt.
  • Passing values into a subdialog to be referenced
    in that subdialog
  • Load and run the file studentsystem3b.vxml. As
    before, you can say one of the student names
    (John, David, Rosemary, Jennifer) in response to
    the system prompt.

35
Tutorial Exercises Subdialog (1)
  • Passing values in both directions
  • Load and run the file studentsystem3c.vxml. This
    time you have to say the student name 'John' for
    the conditional statement in the subdialog to
    evaluate correctly.
  • 6. Add further conditions in the subdialog for
    the names 'David' and 'Rosemary'.
  • Amend the code in the main dialog so that if the
    user says the name 'Jennifer', the system
    responds 'Sorry that student is not listed in the
    database'.
  • Note Names that are not in the database will
    still have to be included in the recognition
    vocabulary to be recognised and passed on to the
    subdialog.
Write a Comment
User Comments (0)
About PowerShow.com