【问题标题】:Keyword or keyphrase spotting with Sphinx4使用 Sphinx4 发现关键字或关键词
【发布时间】:2013-06-08 01:05:09
【问题描述】:

我目前正在尝试让我的 java 代码(使用 eclipse)在说某件事时执行某些功能。我正在使用 Sphinx4 库,这是我目前拥有的:

我想要它做的是在它说的那一行:

IF (TRUE) someFunction();

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

这是我的 listener.java 文件:

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:

#JSGF V1.0;
grammar dictionary;

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

【问题讨论】:

    标签: java grammar speech-recognition cmusphinx sphinx4


    【解决方案1】:

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

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

    之后,如果仅记录随机单词,它将返回&lt;unk&gt; 作为结果,如果记录了语法中的单词,它将返回关键短语。

    您需要调整 outOfGrammar 概率以获得可​​靠的检测。更多详情见

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

    【讨论】:

    • 是否可以只为语法的一部分设置 OutOfGrammarBranch,这将是关键字?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多