不知道哪些类开始测试sphinx4

时间:2016-11-12 14:01:37

标签: eclipse gradle cmusphinx sphinx4

我已经完成了这些步骤

1-从https://sourceforge.net/projects/cmusphinx/files/sphinx4/5prealpha/

下载最新版本的Sphinx4 在Eclipse(Gradle插件)中安装了 Gradle IDE Pack 3.8.x + 1.0.x

3-导入Sphinx4作为Gradle STS项目。

现在我收到错误,如下图所示

enter image description here

为了时间的缘故,我已经评论了这些错误,因为我不知道为什么会出现这些错误。

现在我想运行Sphinx4,但我不知道该怎么运行以及如何运行。 我已经尽力与谷歌并试图做了几天。但没有得到积极的结果。

如果任何人可以帮助我解决问题并指导我如何将sphinx4作为gradle运行,这将是非常好的。正如你所看到的,sphinx有4个项目,所以要运行哪个项目。

这可能是愚蠢的问,“如果我成功运行将输出什么”

PS:我是Gradle和Sphinx4的新手 并且还看了this link

3 个答案:

答案 0 :(得分:1)

教程says

sphinx4源中包含许多示例演示,以便您了解如何运行Sphinx4。你可以从sphinx4-samples jar运行它们:

  • Transcriber - 演示如何转录文件
  • 对话框 - 演示如何与用户进行对话
  • SpeakerID - 演讲者身份识别
  • Aligner - 演示音频到转录时间戳

您只需仔细阅读即可。

答案 1 :(得分:1)

您可以找到教程: - > here< -

虽然我以不同的方式将jar添加到类路径中,但它对您有用。

简单示例代码:

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Port;

import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
import edu.cmu.sphinx.api.SpeechResult;

public class Main {

    // Logger
    private Logger logger = Logger.getLogger(getClass().getName());

    // Variables
    private String result;

    // Threads
    Thread  speechThread;
    Thread  resourcesThread;

    // LiveRecognizer
    private LiveSpeechRecognizer recognizer;

    /**
     * Constructor
     */
    public Main() {

        // Loading Message
        logger.log(Level.INFO, "Loading..\n");

        // Configuration
        Configuration configuration = new Configuration();

        // Load model from the jar
        configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
        configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");

        // if you want to use LanguageModelPath disable the 3 lines after which
        // are setting a custom grammar->

        // configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin")

        // Grammar
        configuration.setGrammarPath("resource:/grammars");
        configuration.setGrammarName("grammar");
        configuration.setUseGrammar(true);

        try {
            recognizer = new LiveSpeechRecognizer(configuration);
        } catch (IOException ex) {
            logger.log(Level.SEVERE, null, ex);
        }

        // Start recognition process pruning previously cached data.
        recognizer.startRecognition(true);

        // Start the Thread
        startSpeechThread();
        startResourcesThread();
    }

    /**
     * Starting the main Thread of speech recognition
     */
    protected void startSpeechThread() {

        // alive?
        if (speechThread != null && speechThread.isAlive())
            return;

        // initialise
        speechThread = new Thread(() -> {
            logger.log(Level.INFO, "You can start to speak...\n");
            try {
                while (true) {
                    /*
                     * This method will return when the end of speech is
                     * reached. Note that the end pointer will determine the end
                     * of speech.
                     */
                    SpeechResult speechResult = recognizer.getResult();
                    if (speechResult != null) {

                        result = speechResult.getHypothesis();
                        System.out.println("You said: [" + result + "]\n");
                        // logger.log(Level.INFO, "You said: " + result + "\n")

                    } else
                        logger.log(Level.INFO, "I can't understand what you said.\n");

                }
            } catch (Exception ex) {
                logger.log(Level.WARNING, null, ex);
            }

            logger.log(Level.INFO, "SpeechThread has exited...");
        });

        // Start
        speechThread.start();

    }

    /**
     * Starting a Thread that checks if the resources needed to the
     * SpeechRecognition library are available
     */
    protected void startResourcesThread() {

        // alive?
        if (resourcesThread != null && resourcesThread.isAlive())
            return;

        resourcesThread = new Thread(() -> {
            try {

                // Detect if the microphone is available
                while (true) {
                    if (AudioSystem.isLineSupported(Port.Info.MICROPHONE)) {
                        // logger.log(Level.INFO, "Microphone is available.\n")
                    } else {
                        // logger.log(Level.INFO, "Microphone is not
                        // available.\n")

                    }

                    // Sleep some period
                    Thread.sleep(350);
                }

            } catch (InterruptedException ex) {
                logger.log(Level.WARNING, null, ex);
                resourcesThread.interrupt();
            }
        });

        // Start
        resourcesThread.start();
    }

    /**
     * Takes a decision based on the given result
     */
    public void makeDesicion(String result) {
        //implemented in the part 2
    }

    /**
     * Java Main Application Method
     * 
     * @param args
     */
    public static void main(String[] args) {

        // // Be sure that the user can't start this application by not giving
        // the
        // // correct entry string
        // if (args.length == 1 && "SPEECH".equalsIgnoreCase(args[0]))
        new Main();
        // else
        // Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Give me
        // the correct entry string..");

    }

}

语法文件:

#JSGF V1.0;

/**
 * JSGF Grammar 
 */

grammar grammar;

public <numbers> = (one | two | three| four| five | six | seven | eight | nine | ten);
public <action>  = (plus | minus | multiply | division);
public <final> = (show result);

答案 2 :(得分:0)

发生这些错误是因为您的编码设置不正确。

在Eclipse中转到Edit -> Set Encoding -> UTF-8