首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不知道应该开始测试sphinx4的哪些类

不知道应该开始测试sphinx4的哪些类
EN

Stack Overflow用户
提问于 2016-11-12 14:01:37
回答 3查看 217关注 0票数 1

我已经完成了这些步骤

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

2-在Eclipse3.8.x+ 1.0.x (Gradle插件)中安装了Gradle IDE包。

3-进口Sphinx4作为分级STS项目。

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

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

现在我想运行Sphinx4,但是我不知道该运行什么和如何运行。我已经尽我最大的努力在谷歌,并试图做了几天。但没有取得积极的结果。

如果有人能帮助我解决这个问题,并指导我如何将sphinx4作为gradle运行,那就太好了。如你所见,有4个项目,斯芬克斯,所以哪一个要运行。

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

PS:我是Gradle和Sphinx4的新手,我也看过此链接

EN

回答 3

Stack Overflow用户

发布于 2016-11-13 08:02:44

教程他说

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

  • 转录器 -演示如何转录文件
  • 对话框-演示如何与用户一起引导对话框。
  • SpeakerID -说话人识别
  • 校准器.音频到转录时间戳的演示

你只要仔细阅读就行了。

票数 1
EN

Stack Overflow用户

发布于 2016-11-19 13:16:23

您可以找到教程:-> 这里 <-

虽然我把罐子添加到类路径中,但是它对你会有不同的效果。

简单示例代码:

代码语言:javascript
复制
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..");

    }

}

语法文件:

代码语言:javascript
复制
#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);
票数 1
EN

Stack Overflow用户

发布于 2016-11-14 08:54:21

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

在Eclipse中去Edit -> Set Encoding -> UTF-8

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40563612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档