Speech recognition 将StreamDataSource与Sphinx4一起使用

Speech recognition 将StreamDataSource与Sphinx4一起使用,speech-recognition,sphinx4,Speech Recognition,Sphinx4,我试图在Java中使用Sphinx4,通过网络从InputStream输入。目前,我的程序被设置为将从网络传入的任意数量的数据包读取到一个名为all_data的数组中。由此,我创建了一个ByteArrayInputStream。我希望能做的就是把它传给斯芬克斯,让他认出来 到目前为止,我掌握的代码是: InputStream audioToPlay = new ByteArrayInputStream(all_data); ConfigurationManager cm; cm = new Co

我试图在Java中使用
Sphinx4
,通过网络从
InputStream
输入。目前,我的程序被设置为将从网络传入的任意数量的数据包读取到一个名为
all_data
的数组中。由此,我创建了一个
ByteArrayInputStream
。我希望能做的就是把它传给斯芬克斯,让他认出来

到目前为止,我掌握的代码是:

InputStream audioToPlay = new ByteArrayInputStream(all_data);
ConfigurationManager cm;
cm = new ConfigurationManager(BTsend.class.getResource("roila.config.xml"));
System.out.println("Loading Recognizer...");
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();

StreamDataSource streamDataSource = (StreamDataSource) cm.lookup("streamDataSource");
streamDataSource.setInputStream(audioToPlay, "Main Stream");

System.out.println("Start speaking.\n");
Result result = recognizer.recognize();
if (result != null)
{
    String resultText = result.getBestResultNoFiller();
    System.out.println("You said: " + resultText + "\n");
}
else
{
    System.out.println("I can't hear what you said.\n");
    //break;
}
如果我使用麦克风作为输入,同样的代码也会起作用。我所做的一切都基于以下示例:。该代码确实有效,我所做的只是将麦克风更改为
StreamDataSource
,并尝试使其正常工作

不幸的是,无论我尝试什么,结果总是返回空值,但当我使用麦克风输入时(参见上面roila.org上的示例),它工作得非常好

我在roila.confg.xml文件中添加了以下内容:

<component name="streamDataSource" type="edu.cmu.sphinx.frontend.util.StreamDataSource">
    <property name="sampleRate" value="16000" />
    <property name="bigendianData" value="false" />
</component>

在我添加它之前,我得到了一个空指针异常,但之后
streamDataSource
被拾取


非常感谢您提供的任何帮助-我最终希望能够做到的是,在这样做的情况下,数据会不断输入,从而使处理变得更容易。

除了将组件添加到xml文件中,您还需要将其添加到前端管道中的组件列表中,而不是麦克风组件:

<component name="epFrontEnd" type="edu.cmu.sphinx.frontend.FrontEnd">
    <propertylist name="pipeline">
        <item>streamDataSource </item>
        <item>dataBlocker</item>
        <item>....</item>
        <item>featureExtraction </item>
    </propertylist>
</component>

流数据源
数据锁
....
特征提取

我怀疑您忘记了更改。

当您遇到NullPointerException问题时,请学习从NullPointerException提供stacktrace。有关您的问题的所有重要信息都包含在stacktrace中,您只需阅读即可。