java - 在 CMU Sphinx 4 中禁用控制台消息

标签 java cmusphinx sphinx4

我正在尝试 CMUSphinx,但遇到了困难。我已将 coredata jar 包含到我从 here 下载的 Eclipse 项目中。

我尝试按照提到的方式进行实时语音识别 in the tutorial但是当我尝试运行它时,控制台充满了一些错误,例如 The dictionary is missing a phonetic transcription for the word '....' 等等。

代码:

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

public class Hello {       

   public static void main(String[] args) throws Exception {
    Configuration configuration = new Configuration();


    configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");

    configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");

    configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
    LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);

    while(true)
    {
    System.out.println("Start speaking...");
    recognizer.startRecognition(true);
    SpeechResult result = recognizer.getResult();
    System.out.println("result: "+result.getHypothesis());

    recognizer.stopRecognition();
    }

}
}

控制台:

23:15:07.552 INFO unitManager          CI Unit: *+NSN+
23:15:07.556 INFO unitManager          CI Unit: *+SPN+
23:15:07.556 INFO unitManager          CI Unit: AA
23:15:07.556 INFO unitManager          CI Unit: AE
23:15:07.556 INFO unitManager          CI Unit: AH
23:15:07.556 INFO unitManager          CI Unit: AO
...
...     /* Similar to above messages */
...
...
23:15:08.447 INFO autoCepstrum         Cepstrum component auto-configured as follows: autoCepstrum {MelFrequencyFilterBank, Denoise, DiscreteCosineTransform2, Lifter}
2016-02-22 23:15:08.649 java[68475:2340128] 23:15:08.649 WARNING:  140: This application, or a library it uses, is using the deprecated Carbon Component Manager for hosting Audio Units. Support for this will be removed in a future release. Also, this makes the host incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h.
Start speaking... /* My Output */
23:15:08.653 INFO dictionary           Loading dictionary from: jar:file:/Users/sriharish/Java/sphinx4-data-5prealpha-20151218.160017-5.jar!/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict
23:15:08.786 INFO dictionary           Loading filler dictionary from: jar:file:/Users/sriharish/Java/sphinx4-data-5prealpha-20151218.160017-5.jar!/edu/cmu/sphinx/models/en-us/en-us/noisedict
23:15:08.786 INFO acousticModelLoader  Loading tied-state acoustic model from: jar:file:/Users/sriharish/Java/sphinx4-data-5prealpha-20151218.160017-5.jar!/edu/cmu/sphinx/models/en-us/en-us
23:15:08.787 INFO acousticModelLoader  Pool means Entries: 16128
23:15:08.787 INFO acousticModelLoader  Pool variances Entries: 16128
23:15:08.787 INFO acousticModelLoader  Pool transition_matrices Entries: 42
23:15:08.787 INFO acousticModelLoader  Pool senones Entries: 5126
23:15:08.787 INFO acousticModelLoader  Gaussian weights: mixture_weights. Entries: 15378
23:15:08.787 INFO acousticModelLoader  Pool senones Entries: 5126
23:15:08.787 INFO acousticModelLoader  Context Independent Unit Entries: 42
23:15:08.788 INFO acousticModelLoader  HMM Manager: 137095 hmms
23:15:08.788 INFO acousticModel        CompositeSenoneSequences: 0
23:15:08.789 INFO trieNgramModel       Loading n-gram language model from: jar:file:/Users/sriharish/Java/sphinx4-data-5prealpha-20151218.160017-5.jar!/edu/cmu/sphinx/models/en-us/en-us.lm.bin
23:15:09.821 INFO dictionary           The dictionary is missing a phonetic transcription for the word '3-d'
23:15:09.821 WARNING trieNgramModel    The dictionary is missing a phonetic transcription for the word '3-d'
23:15:09.830 INFO dictionary           The dictionary is missing a phonetic transcription for the word 'adjustors'
23:15:09.830 WARNING trieNgramModel    The dictionary is missing a phonetic transcription for the word 'adjustors'
...
...    /* Similar to above messages */
...

23:15:11.231 INFO lexTreeLinguist      Max CI Units 43
23:15:11.232 INFO lexTreeLinguist      Unit table size 79507
23:15:11.234 INFO speedTracker         # -----------------------------         Timers----------------------------------------
23:15:11.235 INFO speedTracker         # Name               Count   CurTime   MinTime   MaxTime   AvgTime   TotTime   
23:15:11.237 INFO speedTracker         Compile              1       1.1360s   1.1360s   1.1360s   1.1360s   1.1360s   
23:15:11.238 INFO speedTracker         Load Dictionary      1       0.1330s   0.1330s   0.1330s   0.1330s   0.1330s   
23:15:11.238 INFO speedTracker         Load AM              1       2.0880s   2.0880s   2.0880s   2.0880s   2.0880s   
23:15:11.238 INFO speedTracker         Load LM              1       1.3080s   1.3080s   1.3080s   1.3080s   1.3080s   
23:15:16.674 INFO speedTracker            This  Time Audio: 0.37s  Proc: 4.12s  Speed: 11.14 X real time
23:15:16.676 INFO speedTracker            Total Time Audio: 0.37s  Proc: 4.12s 11.14 X real time
23:15:16.676 INFO memoryTracker           Mem  Total: 738.00 Mb  Free: 378.28 Mb
23:15:16.676 INFO memoryTracker           Used: This: 359.72 Mb  Avg: 359.72 Mb  Max: 359.72 Mb
23:15:16.676 INFO trieNgramModel       LM Cache Size: 870 Hits: 153862 Misses: 870
result: none /* My Output */

我已经下载了推荐的jar并包含在项目中。那它有什么问题呢?他们没有提供字典吗?我可以添加缺少的拼音吗?如果是,请提供链接。最后,我怎样才能禁用所有控制台警告等,并且只有我提供的输出。

最佳答案

我有同样的问题,我使用的唯一类是 StreamSpeechRecognizer 和 Configuration。在查看了 ConfigurationManagerUtils 的 sphinx 源代码后,我设法在自己的类中获取了以下代码,以禁用 edu.cmu.sphinx 包中的所有控制台日志记录。在实例化识别器之前放置此代码。

  Logger cmRootLogger = Logger.getLogger("default.config");
  cmRootLogger.setLevel(java.util.logging.Level.OFF);
  String conFile = System.getProperty("java.util.logging.config.file");
  if (conFile == null) {
        System.setProperty("java.util.logging.config.file", "ignoreAllSphinx4LoggingOutput");
  }

算不上优雅,但对我有用,除非有人有更简洁的方法通过 sphinx 配置/上下文类在运行时禁用日志记录。

对于我需要在我自己的项目中使用的任何第三方包,我有充分的理由直接在代码中执行此操作,因为 1/我不关心公开任何第三方日志记录和 2/我不希望为第三方代码提供定制的日志记录配置文件。

关于java - 在 CMU Sphinx 4 中禁用控制台消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35560969/

相关文章:

java - 如何在java spring websocket中实现ping pong

java - 奇怪的口袋狮身人面像精度下降

java - 如何使用 AudioInputStream 的中间录制 x 秒的文件,并继续流式传输?

Java排序和HashMap

java - 如何从 hibernate 关系中的实体选择属性

Python 无法识别 pocketsphinx 的解码器

java - 接收 JSGF Gramma 规则名称

java - Sphinx4 演示应用程序无法运行

java - Jackson 中的自定义 JSON 数组反序列化

java - 提高 CMUSphinx 5 速度和准确性