Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

java - Keyword or keyphrase spotting with Sphinx4

I am currently trying to make my java code (using eclipse) perform some function if a certain thing is said. I am using the Sphinx4 libraries and this is what I currently have:

What I would like it to do is at the line where it says:

IF (TRUE) someFunction();

is to run the function if my speech is Hello Computer, Hello Jarvis, Good Morning Computer, or Good Morning Jarvis. Or in other words, run the function if the speech matches the "public < greet >" line of code in the .gram file. Even more specific, return "greet" if my speech corresponds with that grammar rule. I am sorry if this doesnt make sense...

Here is my listener.java file:

package speechRecognition;

import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;

public class Listener {

    public void someFunction(){
        System.out.println("Did Something");
    }

    public static void main(String[] args) {
        ConfigurationManager cm;
        if (args.length > 0) { cm = new ConfigurationManager(args[0]);
        } else { cm = new ConfigurationManager(Listener.class.getResource("configurations.config.xml")); }

        Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
        recognizer.allocate();

        Microphone microphone = (Microphone) cm.lookup("microphone");
        if (!microphone.startRecording()) {
            System.out.println("Cannot start microphone.");
            recognizer.deallocate();
            System.exit(1);
        }

        while (true) {
            Result result = recognizer.recognize();
            if (result != null) {
                String resultText = result.getBestFinalResultNoFiller();
                if (resultText != "" && resultText != null) {
                    IF (TRUE) someFunction();
                }
            } else {
                System.out.println("I can't hear what you said.
");
            }
        }
    }
}

And here is my dictionary.gram:

#JSGF V1.0;
grammar dictionary;

public <greet> = (Hello | Good Morning) (Jarvis | Computer);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do that but the only thing is that you need to enable OOG spotting in sphinx4. Basically take any sphinx4 grammar example and enable OOG according to this wiki page in config file:

<component name="flatLinguist"
           type="edu.cmu.sphinx.linguist.flat.FlatLinguist">
     ....
    <property name="addOutOfGrammarBranch" value="true"/>
    <property name="outOfGrammarProbability" value="1E-20"/>
    <property name="phoneInsertionProbability" value="1E-10"/>
    <property name="phoneLoopAcousticModel" value="wsj"/>
     ...
</component>

After that it will return you <unk> word as a result if just random word is recorded and will return you a key phrase if the word from your grammar is recorded.

You need to tune outOfGrammar probability to get a reliable detection. For more details see

http://cmusphinx.sourceforge.net/wiki/sphinx4:rejectionhandling


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...