使用Sphinx4进行关键字或关键短语识别 [英] Keyword or keyphrase spotting with Sphinx4

查看:603
本文介绍了使用Sphinx4进行关键字或关键短语识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的java代码(使用eclipse)执行某些功能,如果说某件事。我正在使用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:

我希望它能做的是:

IF (TRUE) someFunction();

如果我的演讲是Hello Computer,Hello Jarvis,Good Morning Computer或Good,则运行该函数早上贾维斯。或者换句话说,如果语音与.gram文件中的public< greet>代码行匹配,则运行该函数。更具体的是,如果我的演讲符合该语法规则,则返回问候。如果这没有意义,我很抱歉...

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...

这是我的listener.java文件:

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.\n");
            }
        }
    }
}

这是我的dictionary.gram:

And here is my dictionary.gram:

#JSGF V1.0;
grammar dictionary;

public <greet> = (Hello | Good Morning) (Jarvis | Computer);


推荐答案

你可以这样做,但唯一的事就是你需要在sphinx4中启用OOG定位。基本上采用任何sphinx4语法示例并根据配置文件中的此Wiki页面启用OOG:

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>

之后它将返回< unk> 如果只记录随机单词,则会输入单词,如果记录了你的语法中的单词,它将返回一个关键短语。

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.

你需要将outOfGrammar概率调到获得可靠的检测。有关详细信息,请参阅

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

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

这篇关于使用Sphinx4进行关键字或关键短语识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆