本文介绍了CMU-Sphinx:recognizer.allocate() 处的 NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在我的 PC 上设置 CMU-Sphinx4,以便使用语音识别制作应用程序.我能够设置大部分部件和配置并尝试运行 Sphinx 提供的 HelloWorld 应用程序,但在 recognizer.allocate(); 处遇到了 NullPointerExcetption.>

完整的堆栈跟踪:

12:34:45.501 WARNING 字典缺少词:<sil>12:34:45.517 警告 jsgfGrammar 找不到 <sil> 的发音12:34:45.517 警告字典缺少单词:<sil>12:34:45.517 警告 jsgfGrammar 找不到 <sil> 的发音线程main"中的异常 java.lang.NullPointerException在 edu.cmu.sphinx.linguist.flat.SentenceHMMState.collectStates(SentenceHMMState.java:635)在 edu.cmu.sphinx.linguist.flat.FlatLinguist.compileGrammar(FlatLinguist.java:452)在 edu.cmu.sphinx.linguist.flat.FlatLinguist.allocate(FlatLinguist.java:304)在 edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.allocate(SimpleBreadthFirstSearchManager.java:646)在 edu.cmu.sphinx.decoder.AbstractDecoder.allocate(AbstractDecoder.java:87)在 edu.cmu.sphinx.recognizer.Recognizer.allocate(Recognizer.java:168)在 com.cmu.sphinx.HelloWorld.main(HelloWorld.java:42)

代码:

 包 com.cmu.sphinx;导入 edu.cmu.sphinx.frontend.util.Microphone;导入 edu.cmu.sphinx.recognizer.Recognizer;导入 edu.cmu.sphinx.result.Result;导入 edu.cmu.sphinx.util.props.ConfigurationManager;公共类 HelloWorld {公共静态无效主(字符串 [] args){配置管理器厘米;如果 (args.length > 0) {cm = new ConfigurationManager(args[0]);} 别的 {cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.

配置文件:

<配置><!-- *********************************************************** --><!-- 经常调整的属性--><!-- *********************************************************** --><property name="logLevel" value="WARNING"/><property name="absoluteBeamWidth" value="-1"/><property name="relativeBeamWidth" value="1E-80"/><property name="wordInsertionProbability" value="1E-36"/><property name="languageWeight" value="8"/><property name="frontend" value="epFrontEnd"/><property name="recognizer" value="recognizer"/><property name="showCreations" value="false"/><!-- *********************************************************** --><!-- 单词识别器配置--><!-- *********************************************************** --><组件名称="recognizer" type="edu.cmu.sphinx.recognizer.Recognizer"><属性名称=解码器"值=解码器"/><propertylist name="monitors"><item>accuracyTracker </item><item>speedTracker </item><item>memoryTracker</item></propertylist></组件><!-- *********************************************************** --><!-- 解码器配置--><!-- *********************************************************** --><组件名称=解码器"类型=edu.cmu.sphinx.decoder.Decoder"><property name="searchManager" value="searchManager"/></组件><组件名称="searchManager"type="edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager"><property name="logMath" value="logMath"/><property name="linguist" value="flatLinguist"/><property name="pruner" value="trivialPruner"/><property name="scorer" value="threadedScorer"/><property name="activeListFactory" value="activeList"/></组件><组件名称="activeList"type="edu.cmu.sphinx.decoder.search.PartitionActiveListFactory"><property name="logMath" value="logMath"/><property name="absoluteBeamWidth" value="${absoluteBeamWidth}"/><property name="relativeBeamWidth" value="${relativeBeamWidth}"/></组件><组件名称="trivialPruner"type="edu.cmu.sphinx.decoder.pruner.SimplePruner"/><组件名称="threadedScorer"type="edu.cmu.sphinx.decoder.scorer.ThreadedAcousticScorer"><property name="frontend" value="${frontend}"/></组件><!-- *********************************************************** --><!-- 语言学家配置--><!-- *********************************************************** --><组件名称="flatLinguist"type="edu.cmu.sphinx.linguist.flat.FlatLinguist"><property name="logMath" value="logMath"/><property name="grammar" value="jsgfGrammar"/><property name="acousticModel" value="wsj"/><属性名称="wordInsertionProbability"value="${wordInsertionProbability}"/><property name="languageWeight" value="${languageWeight}"/><property name="unitManager" value="unitManager"/></组件><!-- *********************************************************** --><!-- 语法配置--><!-- *********************************************************** --><组件名称="jsgfGrammar" type="edu.cmu.sphinx.jsgf.JSGFGrammar"><property name="dictionary" value="dictionary"/><属性名称=语法位置"value="资源:/com/cmu/sphinx/"/><property name="grammarName" value="hello"/><property name="logMath" value="logMath"/></组件><!-- *********************************************************** --><!-- 字典配置--><!-- *********************************************************** --><组件名称="字典"type="edu.cmu.sphinx.linguist.dictionary.FastDictionary"><属性名称="dictionaryPath"value="resource:/edu/cmu/sphinx/model/acoustic/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/cmudict.0.6d"/><属性名称=fillerPath"value="resource:/edu/cmu/sphinx/model/acoustic/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict"/><property name="addSilEndingPronunciation" value="false"/><property name="allowMissingWords" value="false"/><property name="unitManager" value="unitManager"/></组件><!-- *********************************************************** --><!-- 声学模型配置--><!-- *********************************************************** --><组件名称="wsj"type="edu.cmu.sphinx.linguist.acoustic.tiedstate.TiedStateAcousticModel"><property name="loader" value="wsjLoader"/><property name="unitManager" value="unitManager"/></组件><组件名称="wsjLoader" type="edu.cmu.sphinx.linguist.acoustic.tiedstate.Sphinx3Loader"><property name="logMath" value="logMath"/><property name="unitManager" value="unitManager"/><property name="location" value="resource:/edu/cmu/sphinx/model/acoustic/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz"/><property name="modelDefinition" value="etc/WSJ_clean_13dCep_16k_40mel_130Hz_6800Hz.4000.mdef"/><property name="dataLocation" value="cd_continuous_8gau/"/></组件><!-- *********************************************************** --><!-- 单元管理器配置--><!-- *********************************************************** --><组件名称="unitManager"type="edu.cmu.sphinx.linguist.acoustic.UnitManager"/><!-- *********************************************************** --><!-- 前端配置--><!-- *********************************************************** --><组件名称="frontEnd" type="edu.cmu.sphinx.frontend.FrontEnd"><propertylist name="pipeline"><item>麦克风</item><item>预加重器</item><item>窗口窗口</item><item>fft</item><item>melFilterBank </item><item>dct</item><item>liveCMN </item><item>特征提取</item></propertylist></组件><!-- *********************************************************** --><!-- 实时前端配置--><!-- *********************************************************** --><组件名称="epFrontEnd" type="edu.cmu.sphinx.frontend.FrontEnd"><propertylist name="pipeline"><item>麦克风</item><item>dataBlocker </item><item>speechClassifier </item><item>speechMarker </item><item>nonSpeechDataFilter </item><item>预加重器</item><item>窗口窗口</item><item>fft</item><item>melFilterBank </item><item>dct</item><item>liveCMN </item><item>特征提取</item></propertylist></组件><!-- *********************************************************** --><!-- 前端管道--><!-- *********************************************************** --><组件名称="dataBlocker" type="edu.cmu.sphinx.frontend.DataBlocker"><!--<property name="blockSizeMs" value="10"/>--></组件><组件名称="语音分类器"type="edu.cmu.sphinx.frontend.endpoint.SpeechClassifier"><property name="threshold" value="13"/></组件><组件名称="nonSpeechDataFilter"type="edu.cmu.sphinx.frontend.endpoint.NonSpeechDataFilter"/><组件名称="speechMarker"type="edu.cmu.sphinx.frontend.endpoint.SpeechMarker" ><property name="speechTrailer" value="50"/></组件><组件名称="预加重器"type="edu.cmu.sphinx.frontend.filter.Preemphasizer"/><组件名称=窗口"type="edu.cmu.sphinx.frontend.window.RaisedCosineWindower"></组件><组件名称="fft"type="edu.cmu.sphinx.frontend.transform.DiscreteFourierTransform"></组件><组件名称="melFilterBank"type="edu.cmu.sphinx.frontend.frequencywarp.MelFrequencyFilterBank"></组件><组件名称="dct"type="edu.cmu.sphinx.frontend.transform.DiscreteCosineTransform"/><组件名称=liveCMN"type="edu.cmu.sphinx.frontend.feature.LiveCMN"/><组件名称=特征提取"type="edu.cmu.sphinx.frontend.feature.DeltasFeatureExtractor"/><组件名称=麦克风"type="edu.cmu.sphinx.frontend.util.Microphone"><property name="closeBetweenUtterances" value="false"/></组件><!-- ********************************************************** --><!-- 监视器--><!-- ********************************************************** --><组件名称="accuracyTracker"type="edu.cmu.sphinx.instrumentation.BestPathAccuracyTracker"><property name="recognizer" value="${recognizer}"/><property name="showAlignedResults" value="false"/><property name="showRawResults" value="false"/></组件><组件名称="memoryTracker"type="edu.cmu.sphinx.instrumentation.MemoryTracker"><property name="recognizer" value="${recognizer}"/><property name="showSummary" value="false"/><property name="showDetails" value="false"/></组件><组件名称="speedTracker"type="edu.cmu.sphinx.instrumentation.SpeedTracker"><property name="recognizer" value="${recognizer}"/><property name="frontend" value="${frontend}"/><property name="showSummary" value="true"/><property name="showDetails" value="false"/></组件><!-- ********************************************************** --><!-- 其他组件--><!-- ********************************************************** --><组件名称="logMath" type="edu.cmu.sphinx.util.LogMath"><property name="logBase" value="1.0001"/><property name="useAddTable" value="true"/></组件></config>

语法

#JSGF V1.0;/*** Hello World 示例的 JSGF 语法*/语法你好;公开<问候>= (早上好 | 你好) ( Bhiksha | Evandro | Paul | Philip | Rita | Will );
解决方案

终于可以运行 Sphinx4 的HelloWorld"应用了.对于上面提到的问题,我不得不更改配置文件.

之前的 fillerPath 属性是:

我刚刚添加了 fillerdict 并且它起作用了:

I've been trying to set up CMU-Sphinx4 on my PC in order to make an application using speech Recognition. I was able to setup most of the parts and configuration and trying to run the HelloWorld application provided by Sphinx, but stuck with NullPointerExcetption at recognizer.allocate();.

Complete Stack Trace :

12:34:45.501 WARNING dictionary        Missing word: <sil>
12:34:45.517 WARNING jsgfGrammar       Can't find pronunciation for <sil>
12:34:45.517 WARNING dictionary        Missing word: <sil>
12:34:45.517 WARNING jsgfGrammar       Can't find pronunciation for <sil>
Exception in thread "main" java.lang.NullPointerException
    at edu.cmu.sphinx.linguist.flat.SentenceHMMState.collectStates(SentenceHMMState.java:635)
    at edu.cmu.sphinx.linguist.flat.FlatLinguist.compileGrammar(FlatLinguist.java:452)
    at edu.cmu.sphinx.linguist.flat.FlatLinguist.allocate(FlatLinguist.java:304)
    at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.allocate(SimpleBreadthFirstSearchManager.java:646)
    at edu.cmu.sphinx.decoder.AbstractDecoder.allocate(AbstractDecoder.java:87)
    at edu.cmu.sphinx.recognizer.Recognizer.allocate(Recognizer.java:168)
    at com.cmu.sphinx.HelloWorld.main(HelloWorld.java:42)

Code:

 package com.cmu.sphinx;

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

public static void main(String[] args) {
    ConfigurationManager cm;

    if (args.length > 0) {
        cm = new ConfigurationManager(args[0]);
    } else {
        cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.

Config File :

<?

Grammar

#JSGF V1.0;

/**
 * JSGF Grammar for Hello World example
 */

grammar hello;

public <greet> = (Good morning | Hello) ( Bhiksha | Evandro | Paul | Philip | Rita | Will );
解决方案

Finally able to run "HelloWorld" application of Sphinx4. For the above mentioned problem, I had to change the config file.

Earlier the fillerPath property was:

<property name="fillerPath"
 value="resource:/edu/cmu/sphinx/model/acoustic/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict"/>

I just added the fillerdict and it worked:

<property name="fillerPath"
     value="resource:/edu/cmu/sphinx/model/acoustic/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/fillerdict"/>

这篇关于CMU-Sphinx:recognizer.allocate() 处的 NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 21:52