Acquiring a Pick Quantity in the Industrial Browser

The following example script is designed to work with the Wavelink Industrial Browser and allows the user to speak a number 0-9999 (referred to as the pick quantity), ask for help, go back, disconnect the session, or clear the field.

This script requires that text-to-speech, speech-to-text, and a custom grammar file named sapqty_four_digits.bnf is installed. The script also calls a JavaScript function: clearFields. The text of the grammar file and the JavaScript function are included below.

This script calls another Wavelink script in order to repeat the information on the screen. The script sapRepeatPrompts is included in Changing Text-to-Speech Modes.

Acquiring a Pick Quantity Script

Comment: This function acquires the Pick Quantity via voice.
Comment: Ensure Speakeasy support has been installed.
If_Not( Speech_To_Text_Available )
Ask_OK( "Speech-to-Text is not available.", "Error" )
Return
End_If
If_Not( Speech_From_Text_Available )
Ask_OK( "Text-to-Speech is not available.", "Error" )
Return
End_If
Speech_To_Text_Cancel

Comment: The Speech-to-Text and Text-to-Speech languages are
specified.
Speech_Change_Setting( "tts_language_short",
Speech_Find_Setting_Value("tts_language_short","enu",FALSE))
Speech_Change_Setting( "stt_language_short",
Speech_Find_Setting_Value("stt_language_short","enu",FALSE))

Comment: Acquire Pick Quantity via Speech-To-Text.
Comment: Initialize Speech-To-Text variables.
bSpeechStarted = FALSE
bSpeechDone = FALSE

Comment: Initialize confidence value. Speech uttered with
confidence values below this value will be rejected.
Speech_Change_Setting( "stt_threshold", 4500 )

Comment: Start Speech-To-Text if not already started.
Comment: This is needed so we start Speech_To_Text again if
nothing was stated before it times out.
If_Not( bSpeechStarted )
Speech_From_Text( "Enter Quantity:", TRUE )

Comment: With this Speech-To-Text function, the script
waits for voice input until stt_timeout value is reached if nothing is stated sooner.
bSpeechStarted = Speech_To_Text_No_Wait( bSpeechDone,
strSpeechResult, "sapqty_four_digits" )

Comment: Wait_For_Screen_Update waits for speech as well.
Wait_For_Screen_Update

End_If
If( bSpeechDone )
Comment: If sSpeechResult is not empty it signifies that we
received a speech result.
Comment: Command and Control is handled here as well.

If_Not( String_Empty( strSpeechResult ) )

If( String_Equal( strSpeechResult, "repeat", 0, TRUE ) )

Comment: Set bRepeatPrompts so that the script
sapRepeatPrompts will be called.
bRepeatPrompts = TRUE
strSpeechResult = ""
Speech_To_Text_Cancel
Return
End_If
If( String_Equal( strSpeechResult, "back", 0, TRUE ) )

Comment: Press F2 key.
Comment: Keypress_Key("VT220", "F2")
Ask_OK( "F2 Key Pressed", "Back Function" )
bBackFunction = TRUE
strSpeechResult = ""
Speech_To_Text_Cancel
Return
End_If
If( String_Equal( strSpeechResult, "clear", 0, TRUE ) )
Comment: Call clearFields javascript function
Web_Scripting( "javascript:clearFields();" )
strSpeechResult = ""
Return
End_If
If( String_Equal( strSpeechResult, "quit", 0, TRUE ) )
Comment: Disconnect session.
Speech_To_Text_Cancel
Disconnect
Return
End_If
If( String_Equal( strSpeechResult, "help", 0, TRUE ) )
Comment: Annunciate help list.
Speech_To_Text_Cancel
Speech_From_Text("Help list annunciates this list.", TRUE)
Speech_From_Text("Repeat prompts repeats prompts and data.",TRUE)
Speech_From_Text("Go back moves to the previous screen.",TRUE)
Speech_From_Text( "Clear fields clears target bin, material, batch, and pick quantity fields.", TRUE )
Speech_From_Text("Quit SAP disconnects the session.", TRUE)
strSpeechResult = ""
Return
End_If
End_If
End_If

Speech_To_Text_Cancel

Return

Acquiring Pick Quantity Grammar File

The following is an example of a grammar file that will recognize a four-digit number. This grammar file is used with the Acquiring a Pick Quantity script example.

#BNF+AM V1.0;

/**************************************************************

GRAMMAR: sapqty_four_digits.bnf

Description: This is a grammar that recognizes a four-digit number, 0 to 9999. It also recognizes the commands repeat, back, quit, and clear.

What Can I Say? You can say any number from 0 to 9999. You can also speak two, three, or four separate digits.

*************************************************************/

!grammar sapqty_four_digits;
!start <Speech>;

<Speech>: (edit | change quantity) <FourDigits> {@ = #2;} | <Command>;

<NonZeroDigit>: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;

<Digit>:
0 {@ = "0";} |
OH {@ = "0";} |

<NonZeroDigit>;

<Teens>: 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19;

<Tens>:
TEN {@ = "10";} |
TWENTY {@ = "20";} |
TWENY {@ = "20";} |
THIRTY {@ = "30";} |
THIRDY {@ = "30";} |
FORTY {@ = "40";} |
FORDY {@ = "40";} |
FIFTY {@ = "50";} |
FIFDY {@ = "50";} |
SIXTY {@ = "60";} |
SIXDY {@ = "60";} |
SEVENTY {@ = "70";} |
SEVENDY {@ = "70";} |
EIGHTY {@ = "80";} |
EIGHDY {@ = "80";} |
NINETY {@ = "90";} |
NINEDY {@ = "90";};

<CombinedTens>:
TWENTY {@ = "2";} |
TWENY {@ = "2";} |
THIRTY {@ = "3";} |
THIRDY {@ = "3";} |
FORTY {@ = "4";} |
FORDY {@ = "4";} |
FIFTY {@ = "5";} |
FIFDY {@ = "5";} |
SIXTY {@ = "6";} |
SIXDY {@ = "6";} |
SEVENTY {@ = "7";} |
SEVENDY {@ = "7";} |
EIGHTY {@ = "8";} |
EIGHDY {@ = "8";} |
NINETY {@ = "9";} |
NINEDY {@ = "9";};

<ExactThreeDigits>:

<NonZeroDigit> HUNDRED [AND] ( <Teens> | <CombinedTens> <NonZeroDigit> {@ = #1+#2;} | <Tens> | <NonZeroDigit> {@ = "0"+#1;} ) {@ = #1+#4;} |

<NonZeroDigit> HUNDRED {@ = #1+"00";} |

<NonZeroDigit> ( <Teens> | <CombinedTens> <NonZeroDigit> {@ = #1+#2;} | <Tens> ) {@ = #1+#2;} |

<Teens> {@ = "0"+#1;} | <CombinedTens> <NonZeroDigit> {@ = "0"+#1+#2;} | <Tens> {@ = "0"+#1;} |

<Digit> {@ = "00"+#1;};

<FourDigits>:

<NonZeroDigit> THOUSAND [AND] <ExactThreeDigits> {@ = #1+#4;} |

<NonZeroDigit> THOUSAND {@ = #1+"000";} |

<NonZeroDigit> HUNDRED [AND] ( <Teens> | <CombinedTens> <NonZeroDigit> {@ = #1+#2;} | <Tens> | <NonZeroDigit> {@ = "0"+#1;} ) {@ = #1+#4;} |

<NonZeroDigit> HUNDRED {@ = #1+"00";} |

<NonZeroDigit> ( <Teens> | <CombinedTens> <NonZeroDigit> {@ = #1+#2;} | <Tens> ) {@ = #1+#2;} |

<Teens> |<CombinedTens> <NonZeroDigit> {@ = #1+#2;} | <Tens> |

!repeat(<Digit> {@ = previous.@ + #1;},1,4);

<Command>: repeat prompts {@ = "repeat";} |

go back {@ = "back";} | quit sap {@ = "quit";} |

clear fields {@ = "clear";} | help list {@ = "help";};

JavaScript Function clearFields

The following JavaScript function is an example of a function that will clear the fields in the Wavelink Industrial Browser. This is used with the Acquiring a Pick Quantity script example.

/**************************************************
This function is called to clear the fields when the clear command and control command is spoken.

There are no inputs provided when this function is called.
***************************************************/

function clearFields()
{
//Clear target Bin field
var strFieldNameClear = "s4000_binp[1]";
var strFieldValueClear = "";
document.getElementsByName(strFieldNameClear).value = strFieldValueClear;
var arrayFieldNameClear = document.getElementsByName(strFieldNameClear);
arrayFieldNameClear[0].value=strFieldValueClear;

//Clear target Material field
var strFieldNameClear = "s4000_matnrp[1]";
var strFieldValueClear = "";
document.getElementsByName(strFieldNameClear).value = strFieldValueClear;
var arrayFieldNameClear = document.getElementsByName(strFieldNameClear);
arrayFieldNameClear[0].value=strFieldValueClear;

//Clear target Batch field
var strFieldNameClear = "s4000_chargp[1]";
var strFieldValueClear = "";
document.getElementsByName(strFieldNameClear).value = strFieldValueClear;
var arrayFieldNameClear = document.getElementsByName(strFieldNameClear);
arrayFieldNameClear[0].value=strFieldValueClear;

//Clear Pick qty field
var strFieldNameClear = "s4000_qty[1]";
var strFieldValueClear = "";
document.getElementsByName(strFieldNameClear).value = strFieldValueClear;
var arrayFieldNameClear = document.getElementsByName(strFieldNameClear);
arrayFieldNameClear[0].value=strFieldValueClear;

}

 

 


Was this article useful?    

The topic was:

Inaccurate

Incomplete

Not what I expected

Other

Privacy and Legal