Issue while using webservice to call some java application method which is using resource file
I have created one java application which contains following directory structure in my src folder of java..
Src/
Transcriber.java
config.xml
digits.gram
transcriber.manifest
I have successfully created web-service of this java application with .aar file and putting into axis2 service folder
I am packaging this whole in Transcriber.aar file with the following structure
Transcriber\edu\cmu\sphinx\demo\transcriber
and in that all 4 file above I listed.
I have two method in above Transcriber.java class.. 1st method is just processing without any of other file use like (e.g. config.xml,digits.gram and transcriber.manifest). and its working fine and I can call easily that method from android.
but my second method uses the other files also(e.g. config.xml,digits.gram and transcriber.manifest) to process some logic I want.
But some how I'm getting error when I call the second method and its give me error while I'm calling this 2nd method from android device .
My Error is as follows:
at java.lang.Thread.run(Thread.java:662)
Caused by: Property exception component:'jsgfGrammar' property:'grammarLocation'
- Can't locate resource:/edu/cmu/sphinx/demo/transcriber
edu.cmu.sphinx.util.props.InternalConfigurationException: Can't locate resource:
/edu/cmu/sphinx/demo/transcriber
its give me error that some how it cant locate the grammar file digits.gram which is i use to add via the config.xml file with this code in config.xml
<component name="jsgfGrammar" type="edu.cmu.sphinx.jsgf.JSGFGrammar">
<property name="dictionary" value="dictionary"/>
<property name="grammarLocation"
value="resource:/edu/cmu/sphinx/demo/transcriber"/>
<property name="grammarName" value="digits"/>
<property name="logMath" value="logMath"/>
</component>
Why I'm Having this kind of error?enter code here
My CODE WHERE I HAVE FIRST GET THE CONFIG.XML AND THEN CONFIG.XML GET ANOTHER RESOURCE FILE....its successfully finds the config.xml but then the code in config.xml cant locate other resource file
package edu.cmu.sphinx.demo.transcriber;
import edu.cmu.sphinx.frontend.util.AudioFileDataSource;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
/** A simple example that shows how to transcribe a continuous audio file that has multiple utterances in it. */
public class TranscribeSimpleGrammar {
private static final String PATH = "file:///D:\\Sound\\";
@SuppressWarnings({ "null", "null" })
public String recognize_wave(String wavePath) throws MalformedURLException{
URL audioURL;
// if (args.length > 0) {
// audioURL = new File(args[0]).toURI().toURL();
// } else {
//audioURL = TranscribeSimpleGrammar.class.getResource("hello.wav");
//audioURL = new URL(PATH + "turn-on-light-kitchen-male.wav");
//audioURL = new URL(PATH + "turn-down-tv-volume-female.wav");
// audioURL = new URL(PATH + wavePath);
audioURL = new URL(wavePath);
//audioURL = new URL(PATH + "turn-down-dining-room-music-player-volume-male.wav");
// }
URL configURL = TranscribeSimpleGrammar.class.getResource("config.xml");
ConfigurationManager cm = new ConfigurationManager(configURL);
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
/* allocate the resource necessary for the recognizer */
recognizer.allocate();
// configure the audio input for the recognizer
AudioFileDataSource dataSource = (AudioFileDataSource) cm.lookup("audioFileDataSource");
dataSource.setAudioFile(audioURL, null);
// Loop until last utterance in the audio file has been decoded, in which case the recognizer will return null.
Result result;
while ((result = recognizer.recognize())!= null) {
String resultText = result.getBestResultNoFiller();
System.out.println(resultText);
}
return result.getBestResultNoFiller();
}
public String get_wav_byte(byte[] wavbite,String path){
String result1="null";
try
{
File dstFile = new File(path);
FileOutputStream out = new FileOutputStream(dstFile);
out.write(wavbite, 0, wavbite.length);
out.close();
}
catch (IOException e)
{
System.out.println("IOException : " + e);
}
try {
result1=recognize_wave(path);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result1;
}
}