Skip to content

Commit f98d931

Browse files
committed
Fixed issue with lost words during speech recognition.
1 parent 9cb8e71 commit f98d931

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

comp_listener/src/main/java/edu/cmu/xprize/listener/SpeechRecognizer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,7 @@ private void publishStableHypothesis(Hypothesis hypothesis) {
625625

626626
for (int i1 = 0; i1 < maxScan; i1++) {
627627
// If the word has changed - update its last changed time.
628-
if (!asrWords[i1].equals(prevAsrWords[i1]) // && !("START_" + asrWords[i1]).equals(prevAsrWords[i1])
629-
) {
628+
if (!asrWords[i1].equals(prevAsrWords[i1]) && !("START_" + asrWords[i1]).equals(prevAsrWords[i1])) {
630629
wordLastChanged.set(i1, currTime);
631630

632631
Log.d("ASR", "Word Changed: " + asrWords[i1] + " from: " + prevAsrWords[i1]);

comp_reading/src/main/java/cmu/xprize/rt_component/CRt_ViewManagerASB.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public class CRt_ViewManagerASB implements ICRt_ViewManager, ILoadableObject {
102102
private int attemptNum = 0;
103103
private boolean skippedWord = false;
104104
private boolean storyBooting;
105+
private boolean restartListener;
105106

106107
private String[] wordsToDisplay; // current sentence words to display - contain punctuation
107108
private String[] wordsToSpeak; // current sentence words to hear
@@ -691,7 +692,6 @@ private void trackSegment() {
691692

692693
if (!endOfSentence) {
693694
// Tell the script to speak the new utterance
694-
//
695695
mParent.applyBehavior(TCONST.SPEAK_UTTERANCE);
696696
postDelayedTracker();
697697
} else {
@@ -744,7 +744,6 @@ private void publishStateValues() {
744744

745745
String cumulativeState = TCONST.RTC_CLEAR;
746746

747-
// ensure echo state has a valid value.
748747
mParent.publishValue(TCONST.RTC_VAR_ECHOSTATE, TCONST.FALSE);
749748
mParent.publishValue(TCONST.RTC_VAR_PARROTSTATE, TCONST.FALSE);
750749

@@ -1010,6 +1009,7 @@ private void setTutorFeatures(int currPage, int currPara, int currLine) {
10101009
mParent.setTutorFeatures(mCurrEffectiveVariant);
10111010

10121011
if (storyBooting) mParent.setFeature(TCONST.FTR_STORY_STARTING, TCONST.ADD_FEATURE);
1012+
restartListener = true;
10131013

10141014
pagePrompt = data[currPage].prompt;
10151015
mPrevPrompt = mCurrPrompt;
@@ -1050,10 +1050,12 @@ private String computeEffectiveVariant(int currPage, int currPara, int currLine)
10501050
*/
10511051
public void continueListening() {
10521052
if (hearRead.equals(TCONST.FTR_USER_HEAR)) mParent.applyBehavior(TCONST.NARRATE_STORY);
1053-
if (hearRead.equals(TCONST.FTR_USER_READ)) startListening();
1053+
if (hearRead.equals(TCONST.FTR_USER_READ) && restartListener) startListening();
10541054
}
10551055

10561056
private void startListening() {
1057+
Log.d(TAG, "startListening");
1058+
10571059
// We allow the user to say any of the onscreen words but set the priority order of how we
10581060
// would like them matched Note that if the listener is not explicitly listening for a word
10591061
// it will just ignore it if spoken.
@@ -1082,6 +1084,7 @@ private void startListening() {
10821084

10831085
mListener.listenFor(wordsToListenFor.toArray(new String[wordsToListenFor.size()]), 0);
10841086
mListener.setPauseListener(false);
1087+
restartListener = false;
10851088
}
10861089
}
10871090

@@ -1249,8 +1252,7 @@ public void onUpdate(ListenerBase.HeardWord[] heardWords, boolean finalResult) {
12491252
}
12501253

12511254
while ((mCurrWord < wordsToSpeak.length) && (mHeardWord < heardWords.length)) {
1252-
if (wordsToSpeak[mCurrWord].equals(heardWords[mHeardWord].hypWord) // || ("START_" + wordsToSpeak[mCurrWord]).equals(heardWords[mHeardWord].hypWord)
1253-
) {
1255+
if (wordsToSpeak[mCurrWord].equals(heardWords[mHeardWord].hypWord) || ("START_" + wordsToSpeak[mCurrWord]).equals(heardWords[mHeardWord].hypWord)) {
12541256
Log.i("ASR", "RIGHT");
12551257

12561258
skippedWord = false;
@@ -1260,8 +1262,7 @@ public void onUpdate(ListenerBase.HeardWord[] heardWords, boolean finalResult) {
12601262
attemptNum = 0;
12611263
result = true;
12621264
mParent.updateContext(rawSentence, mCurrLine, wordsToSpeak, mCurrWord - 1, heardWords[mHeardWord - 1].hypWord, attemptNum, heardWords[mHeardWord - 1].utteranceId == "", true);
1263-
} else if (skippingWords && !skippedWord && attemptNum == 0 && mCurrWord + 1 < wordsToSpeak.length && (wordsToSpeak[mCurrWord + 1].equals(heardWords[mHeardWord].hypWord) // || ("START_" + wordsToSpeak[mCurrWord]).equals(heardWords[mHeardWord].hypWord)
1264-
)) {
1265+
} else if (skippingWords && !skippedWord && attemptNum == 0 && mCurrWord + 1 < wordsToSpeak.length && (wordsToSpeak[mCurrWord + 1].equals(heardWords[mHeardWord].hypWord) || ("START_" + wordsToSpeak[mCurrWord + 1]).equals(heardWords[mHeardWord].hypWord))) {
12651266
Log.i("ASR", "SKIPPED");
12661267

12671268
skippedWord = true;
@@ -1284,6 +1285,7 @@ public void onUpdate(ListenerBase.HeardWord[] heardWords, boolean finalResult) {
12841285

12851286
skippedWord = false;
12861287
mListener.setPauseListener(true);
1288+
restartListener = true;
12871289
attemptNum++;
12881290
result = false;
12891291
mParent.updateContext(rawSentence, mCurrLine, wordsToSpeak, mCurrWord, heardWords[mHeardWord].hypWord, attemptNum, heardWords[mHeardWord].utteranceId == "", false);

0 commit comments

Comments
 (0)