Skip to content

Commit

Permalink
fix for #123 (until fixed in Sphinx itself)
Browse files Browse the repository at this point in the history
the main fix is in sphinx.frontend.feature.LiveCMN : avoid to keep
stale Data objects around in the queue. Other changes:
(a) avoid re-running recognition after cancellation (Sphinx.java)
(b) Java-9 adaptations in many places
  • Loading branch information
timobaumann committed Dec 7, 2018
1 parent 3843e16 commit d35fc30
Show file tree
Hide file tree
Showing 12 changed files with 445 additions and 194 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Reordered tabs in node properties windows: useful tabs are now on the left (see #122).
- GUI language can now be changed from the Help menu (#95).
- fix issue when discarding TTS node property window without ever using it first (#128).

- fix issue with ASR becoming unresponsive if aborted on the very first run (#123).

**Version 2.0.3, 21 November 2018**

Expand Down
303 changes: 140 additions & 163 deletions Diamant/src/main/java/com/clt/diamant/graph/nodes/AbstractInputNode.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,11 @@ public final RecognitionResult startLiveRecognition() throws SpeechException {
}

public final RecognitionResult startLiveRecognition(final Object lock) throws SpeechException {
RecognitionResult result = null;
RecognizerListener startupListener = new RecognizerListener() {

public void recognizerStateChanged(RecognizerEvent evt) {

synchronized (lock) {
if (evt.getType() == RecognizerEvent.RECOGNIZER_ACTIVATED) {
lock.notifyAll();
}
RecognitionResult result;
RecognizerListener startupListener = evt -> {
synchronized (lock) {
if (evt.getType() == RecognizerEvent.RECOGNIZER_ACTIVATED) {
lock.notifyAll();
}
}
};
Expand Down Expand Up @@ -164,15 +160,11 @@ public final RecognitionResult startOfflineRecognition(File file)
public final RecognitionResult startOfflineRecognition(final Object lock,
File file)
throws SpeechException, IOException, UnsupportedAudioFileException {
RecognitionResult result = null;
RecognizerListener startupListener = new RecognizerListener() {

public void recognizerStateChanged(RecognizerEvent evt) {

synchronized (lock) {
if (evt.getType() == RecognizerEvent.RECOGNIZER_ACTIVATED) {
lock.notifyAll();
}
RecognitionResult result;
RecognizerListener startupListener = evt -> {
synchronized (lock) {
if (evt.getType() == RecognizerEvent.RECOGNIZER_ACTIVATED) {
lock.notifyAll();
}
}
};
Expand Down Expand Up @@ -217,6 +209,7 @@ public synchronized final void stopRecognition()
this.wait();
}
} catch (InterruptedException ignore) {
throw new SpeechException(ignore);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public MlfNode getTree() {

@Override
public String toString() {
return "DummyRecognizerUtterance{"
return "SimpleRecognizerUtterance{"
+ "words=" + words
+ ", logConfidence=" + logConfidence
+ ", confidence=" + getConfidence()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
IONode = Sprache
RecognizerLoading = Spracherkennung l\u00e4dt...
RecognizerActivated = Spracherkennung aktiviert
RecognizerDeactived = Spracherkennung deaktiviert
RecognizerDeactivated = Spracherkennung deaktiviert
RecognizerEndOfSpeech = Ende des Sprachsignals
RecognizerPartialResult = Zwischenergebnis der Spracherkennung verf\u00fcgbar
RecognizerInvalidResult = Erkennungsergebnis konnte nicht interpretiert werden
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
IONode = Speech
RecognizerLoading = Recognizer loading...
RecognizerActivated = Recognizer activated
RecognizerDeactived = Recognizer deactivated
RecognizerDeactivated = Recognizer deactivated
RecognizerEndOfSpeech = End of speech detected
RecognizerPartialResult = Partial recognition result available
RecognizerInvalidResult = Recognition result cannot be interpreted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ConfigurableSpeechRecognizer(Context context, InputStream audioSource) th

/*recognizer.addStateListener(new StateListener() {
@Override public void statusChanged(edu.cmu.sphinx.recognizer.Recognizer.State status) {
System.err.println("listener defined in configurable speech recognizer: " + status);
System.err.println("Sphinx recognition listener defined in ConfigurableSpeechRecognizer.java: " + status);
}
@Override public void newProperties(PropertySheet ps) throws PropertyException { }
});*/
Expand All @@ -44,7 +44,7 @@ public ConfigurableSpeechRecognizer(Context context, InputStream audioSource) th
public synchronized void startRecognition() {
if (recognizer.getState() == Recognizer.State.DEALLOCATED)
recognizer.allocate();
if (microphone != null)
if (microphone != null)
microphone.startRecording();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
*
* List of TODOs:
* handle multiple languages (configurable for more than DE/EN?),
* exhibit a "default" language through Plugin
*
*/
public class Sphinx extends SphinxBaseRecognizer {
private Map<Language, SphinxLanguageSettings> languageSettings;
private SphinxContext context;
ConfigurableSpeechRecognizer csr;
private boolean vadInSpeech = false;
private boolean stopping = false;

public Sphinx() {
languageSettings = SphinxLanguageSettings.createDefault();
/* addRecognizerListener(evt -> {
System.err.println("DialogOS recognizer listener defined in Sphinx.java: " + evt.toString());
}); */
}

public SphinxLanguageSettings getLanguageSettings(Language l) {
Expand All @@ -42,18 +45,19 @@ public SphinxLanguageSettings getLanguageSettings(Language l) {
vadInSpeech = false;
SpeechResult speechResult;
boolean isMatch;
stopping = false;
csr.startRecognition();
do {
csr.startRecognition();
fireRecognizerEvent(RecognizerEvent.RECOGNIZER_READY);
speechResult = csr.getResult();
if (speechResult == null)
break;
isMatch = isMatch(speechResult);
if (!isMatch)
fireRecognizerEvent(new RecognizerEvent(this, RecognizerEvent.INVALID_RESULT, sphinx2DOSResult(speechResult)));
} while (!isMatch);
} while (!isMatch && !stopping && isActive());
csr.stopRecognition();
if (speechResult != null) {
if (speechResult != null && !stopping) {
RecognitionResult sphinxResult = sphinx2DOSResult(speechResult);
fireRecognizerEvent(sphinxResult);
return sphinxResult;
Expand All @@ -73,6 +77,7 @@ private RecognitionResult sphinx2DOSResult(SpeechResult sphinx) {
}

@Override protected void stopImpl() {
stopping = true;
if (csr != null)
csr.stopRecognition();
vadInSpeech = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
* - default language (if nothing is specified by the node)
* - pronunciation exception dictionary
*
* SOME HINTS ON DEBUGGING THIS BEAST:
* - take a look at the DialogOS Wiki for the overall (intended) structure of the code
* - there are two listeners for DialogOS recognition events and Sphinx recognition events in
* ConfigurableSpeechRecognizer.java and Sphinx.java. Do consider uncommenting them.
*
*/
package edu.cmu.lti.dialogos.sphinx;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public MatchResult start(final Grammar grammar, final Pattern[] patterns, long t
if (stateListener != null) {
recognizer.addRecognizerListener(stateListener);
}
RecognitionResult recognitionResult = null;
RecognitionResult recognitionResult;
try {
recognitionResult = recognizer.startLiveRecognition();
if (recognitionResult == null) {
Expand All @@ -54,7 +54,6 @@ public MatchResult start(final Grammar grammar, final Pattern[] patterns, long t
// TODO unlocalized string
if (mr == null)
throw new RecognizerException("No match for recognition result '" + utterance.getWords() + "'");
// throw new RecognizerException(Resources.format("NoMatchFor", r));
return mr;
});

Expand Down
Loading

0 comments on commit d35fc30

Please sign in to comment.