waitForSpeechRange

Audio.waitForSpeechRange(timeout, start, end, [increment])

Parameters

timeout Time to wait in seconds before stopping waiting for speech.
start numeric start value of the range
end numeric end value of the range
increment the increment of the range (optional)

Returns

The value within the range as a number or the word "timeout" if timeout is reached.

Description

Suspends execution of the script until one of the numbers within the range (start, end) is detected in the microphone by speech, or a timeout occurs after timeout seconds. If a timeout occurs, the method will return "timeout." The returned value is a number (i.e., 23, 10, 5) and not a string (i.e., twenty-three, ten, five).

Each option will be displayed if the number of options within the range is less than 10. For example, if the start is 10 and the end is 20, there will be 10 options for each option to be displayed.


If there are more than ten options, the range will be displayed.


Large Number Ranges

This style of speech recognition populates the pre-defined responses it expects to hear. In this case, a range of numbers. This dramatically increases the accuracy of the speech recognition system by limiting the detected phrase/words to the list. By providing the list, the speech recognition system will generate definitions of the sound waveforms it is looking for.

While this method dramatically improves detection accuracy, it also can consume a lot of PC resources if an extensive number range is used. For example, a range higher than 100 is considered an extensive range. You may notice a significant delay every time this function is called, and that is due to the vast range.

A recommended solution is to use the waitForAnyNumberSpeech() command.

An additional solution is to prompt for multiple digits that will generate a more significant number when added together with simple math. For example, if you require 1000 positions, consider prompting for each digit.

Example

// Get a number from the user within the range between 10 and 20
response = Audio.waitForSpeechRange(10, 10, 20);
Audio.say("You selected " + response);

// Get a number from the user within the range between 10 and 20 incremented by 2 (every even number)
response = Audio.waitForSpeechRange(10, 10, 20, 2);
Audio.say("You selected " + response);