Speech_To_Text_No_Wait

Listens to the user speak and returns the text equivalent of what the user said. The Boolean variable is set to TRUE when the speech is recognized or times out. If a grammar is specified, the grammar file with that name is used for the speech recognition. Otherwise, the previous grammar file is reused.

Parameters

Done

Indicates when the speech is recognized or times out.

Text

The string variable into which the converted speech is placed.

Grammar

The grammar file to use.

Format

Speech_To_Text_No_Wait (Done, Text, Grammar)

Return Value

Returns the text equivalent of a user’s speech in the string variable. Returns a Boolean value of either TRUE or FALSE. It returns TRUE if the speech-to-text started successfully, or FALSE otherwise.

Example

Script( Speech_Demo )

Profile( Speech_Demo_Profile )

String( sSpeechResult )

Boolean( bSpeechStarted )

Boolean( bSpeechDone )

Number( nCurrentGrammar )

Number( nDesiredGrammar )

Number( nCurrentScreen )

Activate( Connection )

Comment: Is Speech available?

If_Not( Speech_To_Text_Available )

Message( "Speech To Text Not available", 3 )

Return

End_If

If_Not( Speech_From_Text_Available )

Message( "Speech From Text Not Available", 3 )

Return

End_If

 

Comment: We are using English.

Speech_Change_Setting( "stt_language_long", Speech_Find_Setting_Value( "stt_language_long", "English", FALSE ))

Speech_Change_Setting( "tts_language_long", Speech_Find_Setting_Value("tts_language_long", "English", FALSE ))

 

While( TRUE )

 

Comment: Perform Speech-to-Text with the desired grammar.

If( Number_Not_Equal( nCurrentGrammar, nDesiredGrammar ) )

Speech_To_Text_Cancel

bSpeechStarted = FALSE

bSpeechDone = FALSE

sSpeechResult = ""

End_If

If( Boolean_And( bSpeechDone, String_Empty( sSpeechResult ) ) )

Comment: The string was cleared because the result was used. Reset for the next use.

bSpeechStarted = FALSE

bSpeechDone = FALSE

End_If

If_Not( bSpeechStarted )

If( Number_Equal( nDesiredGrammar, 1 ) )

Comment: Set the threshold for this grammar.

Comment: Lower values are more likely to get results, but they are more likely to be wrong.

Speech_Change_Setting( "stt_threshold", 4500 )

 

Comment: Use the digit.bnf grammar file.

bSpeechStarted = Speech_To_Text_No_Wait( bSpeechDone, sSpeechResult, "digit" )

End_If

 

Comment: Can add support for other grammars here.

 

nCurrentGrammar = nDesiredGrammar

End_If

 

Comment: Look for screens where we include speech support.

If( Boolean_And( String_Equal( Get_Screen_Text_Length( 1, 1, 6 ), "Pick ", 0, FALSE ), String_Equal( Get_Screen_Text_Length( 7, 1, 4 ), "Pick", 0, FALSE ) ) )

Comment: The first time we see this screen, tell the user what we want.

If( Number_Not_Equal( nCurrentScreen, 101 ) )

nCurrentScreen = 101

Speech_From_Text( "Pick a menu item from 1 to 5.", FALSE )

End_If

 

Comment: Prepare to get the user's response.

nDesiredGrammar = 1

If( Number_Not_Equal( nDesiredGrammar, nCurrentGrammar ) )

Continue

End_If

 

Comment: Handle any user responses.

If_Not( String_Empty( sSpeechResult ) )

If( Boolean_And( Number_Greater_Than_Or_Equal( String_To_Number_Decimal( sSpeechResult ), 1 ), Number_Less_Than_Or_Equal( String_To_Number_Decimal( sSpeechResult ), 5 ) ) )

Comment: Type the response the user supplied.

Keypress_String( sSpeechResult )

Keypress_Key( "VT220", "Enter" )

Wait_For_Screen_Update

nDesiredGrammar = 0

sSpeechResult = ""

Continue

End_If

 

Speech_From_Text( "Unexpected result. Please try again.", FALSE )

sSpeechResult = ""

Continue

End_If

 

Comment: Wait for the user to respond.

Wait_For_Screen_Update

Continue

End_If

 

Comment: Can add support for other screens here.

 

Comment: If we reach this point, we don't recognize the current screen.

Comment: Wait for a screen we recognize.

nCurrentScreen = 0

nDesiredGrammar = 0

Wait_For_Screen_Update

End_While

 

Return

See Also

Speech_From_Text_Available, Speech_From_Text, Speech_To_Text_Available, Speech_To_Text, Speech_To_Text_Cancel, Speech_Setting_Available, Speech_Change_Setting, Speech_Get_Setting, Speech_Get_Setting_Max, Speech_Find_Setting_Value, Speech_Get_Setting_Value_Desc, Speech_To_Text_Get_User_Name, Speech_To_Text_Change_User_Name, Speech_From_Text_Error_Desc, Speech_To_Text_Error_Desc, Speech_From_Text_Cancel

 


Was this article useful?    

The topic was:

Inaccurate

Incomplete

Not what I expected

Other

Privacy and Legal