I'm using the SpeechRecognizer component to input two-digit numbers into a set of 15 TextBoxes. The user speaks digits (e.g., “4 5 4 6”), which I clean, pair into numbers like ["45", "46"], and then insert into the next available TextBoxes.
However, I’m facing an issue:
Sometimes, even when the twoDigitNumber list is just ["45", "46"], it fills more than two TextBoxes.
Occasionally, it even repeats the same number in multiple boxes.
I also noticed it sometimes overwrites filled ones.
I’m maintaining a global currentIndex to track which TextBox to fill next. But I suspect the recognizer returns inconsistent results, or my currentIndex isn't syncing correctly.
What I want:
A reliable way to fill only the next empty TextBoxes, without overwriting existing data.
Ensure that each number from the list is inserted only once, and that extra boxes are not filled.
here is my blocks
I find it simpler to skip indices, and instead use temporary lists, adding to them or depleting them as needed.
For your immediate problem, apply Do It to see what arrived in your list of numbers.
If that doesn't help, export and upload your aia file for us to play with.
You need a global list to accumulate the spoken digits, one digit per item.
You also need a global list of components to receive the pairs of digits removed from the first list, two at a time.
You remove two items from the front of a list by removing item 1 twice, because AI2 lists are linked lists
Every speech event, add the incoming digits to the accumulated digits list. If it's got two or more items, take items 1 and 2 to fill the next available component. Then remove the filled component from its list and remove the two digits from their list .
What you need to do is assume things will not always work (inconsistent results) - because that is always the case with speech recognition.
You definitely shouldn't have all of that code in the recogniser block, only use that block to collect the next spoken value. You need a procedure or procedures to process what the recogniser has captured and communicate with the User when recognition has failed and needs to be repeated - you also need to temporarily switch the recogniser off (Only allow User speech when prompted).
Initially, when I spoke numbers like '45 46', multiple textboxes were being filled unexpectedly. However, now it correctly fills only two textboxes. Similarly, saying '39 58' fills the next two boxes as intended.