【问题标题】:Don't know which classes to start to test sphinx4不知道从哪些类开始测试 sphinx4
【发布时间】:2017-01-12 18:50:50
【问题描述】:

我已经完成了这些步骤

1- 从https://sourceforge.net/projects/cmusphinx/files/sphinx4/5prealpha/下载最新版本的Sphinx4

2- 在 Eclipse(Gradle 插件)中安装 Gradle IDE Pack 3.8.x + 1.0.x

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

现在我得到了如下图所示的错误

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

现在我想运行 Sphinx4,但我不知道要运行什么以及如何运行。 我在谷歌上尽了最大的努力,并尝试了好几天。但没有得到积极的结果。

如果有人可以帮助我解决问题并指导我如何将 sphinx4 作为 gradle 运行,那就太好了。如您所见,sphinx 有 4 个项目,所以要运行哪个项目。

问“如果我成功运行会输出什么”可能很愚蠢

PS:我是 Gradle 和 Sphinx4 的新手 也看过this link

【问题讨论】:

    标签: eclipse gradle cmusphinx sphinx4


    【解决方案1】:

    教程says

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

    • Transcriber - 演示如何转录文件
    • Dialog - 演示如何与用户进行对话
    • SpeakerID - 说话人识别
    • Aligner - 音频到转录时间戳的演示

    您只需要仔细阅读即可。

    【讨论】:

    【解决方案2】:

    您可以找到教程:-> here

    虽然我将 jars 添加到类路径中的方式不同,但它会为你工作。


    简单示例代码:

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

    【讨论】:

    • 帮助已满。我会探索它并让你知道
    • @Adnan Ali 这是 LiveSpeechRecognition 的完整工作示例。它用于实际的应用程序代码;)
    • @AdnanAli 你探索了吗?当您到达您的应用程序时告诉我们
    【解决方案3】:

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

    在 Eclipse 中转到 Edit -&gt; Set Encoding -&gt; UTF-8

    【讨论】:

    猜你喜欢
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2011-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多