Skip to content

Commit a416a83

Browse files
committed
Fixed issue with lost words during speech recognition.
1 parent f143ac1 commit a416a83

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
@@ -103,6 +103,7 @@ public class CRt_ViewManagerASB implements ICRt_ViewManager, ILoadableObject {
103103
private int attemptNum = 0;
104104
private boolean skippedWord = false;
105105
private boolean storyBooting;
106+
private boolean restartListener;
106107

107108
private String[] wordsToDisplay; // current sentence words to display - contain punctuation
108109
private String[] wordsToSpeak; // current sentence words to hear
@@ -697,7 +698,6 @@ private void trackSegment() {
697698

698699
if (!endOfSentence) {
699700
// Tell the script to speak the new utterance
700-
//
701701
mParent.applyBehavior(TCONST.SPEAK_UTTERANCE);
702702
postDelayedTracker();
703703
} else {
@@ -750,7 +750,6 @@ private void publishStateValues() {
750750

751751
String cumulativeState = TCONST.RTC_CLEAR;
752752

753-
// ensure echo state has a valid value.
754753
mParent.publishValue(TCONST.RTC_VAR_ECHOSTATE, TCONST.FALSE);
755754
mParent.publishValue(TCONST.RTC_VAR_PARROTSTATE, TCONST.FALSE);
756755

@@ -1016,6 +1015,7 @@ private void setTutorFeatures(int currPage, int currPara, int currLine) {
10161015
mParent.setTutorFeatures(mCurrEffectiveVariant);
10171016

10181017
if (storyBooting) mParent.setFeature(TCONST.FTR_STORY_STARTING, TCONST.ADD_FEATURE);
1018+
restartListener = true;
10191019

10201020
pagePrompt = data[currPage].prompt;
10211021
mPrevPrompt = mCurrPrompt;
@@ -1056,10 +1056,12 @@ private String computeEffectiveVariant(int currPage, int currPara, int currLine)
10561056
*/
10571057
public void continueListening() {
10581058
if (hearRead.equals(TCONST.FTR_USER_HEAR)) mParent.applyBehavior(TCONST.NARRATE_STORY);
1059-
if (hearRead.equals(TCONST.FTR_USER_READ)) startListening();
1059+
if (hearRead.equals(TCONST.FTR_USER_READ) && restartListener) startListening();
10601060
}
10611061

10621062
private void startListening() {
1063+
Log.d(TAG, "startListening");
1064+
10631065
// We allow the user to say any of the onscreen words but set the priority order of how we
10641066
// would like them matched Note that if the listener is not explicitly listening for a word
10651067
// it will just ignore it if spoken.
@@ -1088,6 +1090,7 @@ private void startListening() {
10881090

10891091
mListener.listenFor(wordsToListenFor.toArray(new String[wordsToListenFor.size()]), 0);
10901092
mListener.setPauseListener(false);
1093+
restartListener = false;
10911094
}
10921095
}
10931096

@@ -1255,8 +1258,7 @@ public void onUpdate(ListenerBase.HeardWord[] heardWords, boolean finalResult) {
12551258
}
12561259

12571260
while ((mCurrWord < wordsToSpeak.length) && (mHeardWord < heardWords.length)) {
1258-
if (wordsToSpeak[mCurrWord].equals(heardWords[mHeardWord].hypWord) // || ("START_" + wordsToSpeak[mCurrWord]).equals(heardWords[mHeardWord].hypWord)
1259-
) {
1261+
if (wordsToSpeak[mCurrWord].equals(heardWords[mHeardWord].hypWord) || ("START_" + wordsToSpeak[mCurrWord]).equals(heardWords[mHeardWord].hypWord)) {
12601262
Log.i("ASR", "RIGHT");
12611263

12621264
skippedWord = false;
@@ -1266,8 +1268,7 @@ public void onUpdate(ListenerBase.HeardWord[] heardWords, boolean finalResult) {
12661268
attemptNum = 0;
12671269
result = true;
12681270
mParent.updateContext(rawSentence, mCurrLine, wordsToSpeak, mCurrWord - 1, heardWords[mHeardWord - 1].hypWord, attemptNum, heardWords[mHeardWord - 1].utteranceId == "", true);
1269-
} else if (skippingWords && !skippedWord && attemptNum == 0 && mCurrWord + 1 < wordsToSpeak.length && (wordsToSpeak[mCurrWord + 1].equals(heardWords[mHeardWord].hypWord) // || ("START_" + wordsToSpeak[mCurrWord]).equals(heardWords[mHeardWord].hypWord)
1270-
)) {
1271+
} 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))) {
12711272
Log.i("ASR", "SKIPPED");
12721273

12731274
skippedWord = true;
@@ -1290,6 +1291,7 @@ public void onUpdate(ListenerBase.HeardWord[] heardWords, boolean finalResult) {
12901291

12911292
skippedWord = false;
12921293
mListener.setPauseListener(true);
1294+
restartListener = true;
12931295
attemptNum++;
12941296
result = false;
12951297
mParent.updateContext(rawSentence, mCurrLine, wordsToSpeak, mCurrWord, heardWords[mHeardWord].hypWord, attemptNum, heardWords[mHeardWord].utteranceId == "", false);

0 commit comments

Comments
 (0)