I'm trying to use Sphinx4 in Java with an input from an InputStream over the network. Currently my program is setup to read an arbitrary number of packets incoming from the network into an array called all_data. From that I create a ByteArrayInputStream. What I'm hoping to be able to do is pass that to Sphinx to be recognized.
The code I have so far is:
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;
}
This same code works if I use the microphone as an input. I am basing everything I am doing off the following sample: http://roila.org/wp-content/uploads/2010/04/roila_java.txt. That code does work, and all I've done is changed the Microphone to StreamDataSource and tried to get it to work.
Unfortunately whatever I try, result always returns null, but when I use a microphone input (see above sample on roila.org) it works great!
I added the following to my roila.confg.xml file:
<component name="streamDataSource" type="edu.cmu.sphinx.frontend.util.StreamDataSource">
<property name="sampleRate" value="16000" />
<property name="bigendianData" value="false" />
</component>
Before I added it I was getting a null pointer exception but afterwards streamDataSource is being picked up.
Any help is appreciated - what I ultimately would like to be able to do is recognized as data is coming in continuously in the event doing that makes it easier to process this.