Skip to EDIT1 for updated info
What I am trying to achieve: - I have two classes in my project, a Communicator which communicates with the third party API and the main class that I use to translate the info I receive from the communicator.
- My question is: What do I need to do to get my "ds.config" file, which I'm passing as a string, to get loaded? That is if that is even the problem here.
Another Question is: How could I debug this to figure out what is going wrong?
First step is I "initialize my communicator" in the Main.java file:
try{ mDSC = Communicator.createDSCommunicator("ds.config", gRecordDevice, gPlaybackDevice); } catch (IOException e1) { // Failed }
Inside of Communicator this looks like:
public static Communicator createDSCommunicator(String dsConfigFile, String captureMixerName, String playerMixerName) throws IOException { DSRecognizer dsRecognizer = new DSRecognizer(); dsRecognizer.setInitInfo(dsConfigFile); //THIS LINE CAUSES PROBLEM // Only applies if setting a filter dsRecognizer.setLanguage(Language.ENGLISH); DLog.setLogger(new DLogInterface() { @Override public void w(String s, String s2) { System.out.println("DS log Warning s:" + s + " s2:" + s2); } @Override public void v(String s, String s2) { System.out.println("DS log Verbose s:" + s + " s2:" + s2); } @Override public void e(String s, String s2) { System.out.println("DS log Error s:" + s + " s2:" + s2); } @Override public void i(String s, String s2) { System.out.println("DS log Info s:" + s + " s2:" + s2); } @Override public void d(String s, String s2) { System.out.println("DS log Debug s:" + s + " s2:" + s2); } }); return new Communicator(dsRecognizer, captureMixerName, playerMixerName); }
Now is where it kinda gets out of my hands, dsRecognizer is a C++ file from the API. This is the code:
public void setInitInfo(String infoFile) throws FileNotFoundException, IOException { if(this.isInitialized()) { SLog.v("DSRecognizer", "setInitInfo returning; can only be called prior to init()"); } else { SLog.v("DSRecognizer", "Info file " + infoFile); Properties p = new Properties(); FileInputStream fin = null; try { fin = new FileInputStream(infoFile); //It doesn't get past this line p.load(fin); } finally { if(fin != null) { try { fin.close(); } catch (IOException var13) { ; } } } File f = new File(infoFile); File parent = f.getParentFile(); String path = "."; if(parent != null) { path = parent.getAbsolutePath(); } SLog.v("DSRecognizer", "Setting base directory: " + path); this.mBaseDirectory = path; if(!p.containsKey("SamplingRate")) { p.setProperty("SamplingRate", Integer.toString(16000)); } this.mSamplingRate = Integer.parseInt(p.getProperty("SamplingRate")); this.mUrlAudio = new URLAudio(this.mSamplingRate); if(p.containsKey("Parameters")) { this.mParameters = p.getProperty("Parameters"); } else { if(!p.containsKey("parameters")) { throw new FileNotFoundException("parameters file not specified in info file"); } this.mParameters = p.getProperty("parameters"); p.remove("parameters"); p.setProperty("Parameters", this.mParameters); } SLog.v("DSRecognizer", "parameters file set to: " + this.mParameters); this.mGrammar = null; if(p.containsKey("Grammar")) { this.mGrammar = p.getProperty("Grammar"); } else if(p.containsKey("grammarentry")) { this.mGrammar = p.getProperty("grammarentry"); p.remove("grammarentry"); p.setProperty("Grammar", this.mGrammar); } SLog.v("DSRecognizer", "default grammar entry set to: " + this.mGrammar); if(!p.containsKey("RecognizerType")) { boolean rescore = false; if(p.containsKey("Rescore")) { rescore = Boolean.parseBoolean(p.getProperty("Rescore")); } else if(p.containsKey("rescore")) { rescore = Boolean.parseBoolean(p.getProperty("rescore")); } if(rescore) { p.setProperty("RecognizerType", "rescore"); } else { p.setProperty("RecognizerType", "plain"); } } p.remove("Rescore"); p.remove("rescore"); this.mRecognizerType = p.getProperty("RecognizerType"); SLog.v("DSRecognizer", "recognizer type (plain|rescore|dnn) set to: " + this.mRecognizerType); this.mEpParameters = ""; if(p.containsKey("EPParameters")) { this.mEpParameters = p.getProperty("EPParameters"); } else if(p.containsKey("epparameters")) { this.mEpParameters = p.getProperty("epparameters", ""); p.remove("epparameters"); p.setProperty("EPParameters", this.mEpParameters); } this.mEpGrammar = ""; if(p.containsKey("EPGrammar")) { this.mEpGrammar = p.getProperty("EPGrammar"); } else if(p.containsKey("epgrammarentry")) { this.mEpGrammar = p.getProperty("epgrammarentry", ""); p.remove("epgrammarentry"); p.setProperty("EPGrammar", this.mEpGrammar); } StringBuffer sb = new StringBuffer(); Enumeration en = p.keys(); while(en.hasMoreElements()) { String key = (String)en.nextElement(); sb.append(key); sb.append(" "); sb.append(p.getProperty(key)); sb.append("\n"); } this.mInitString = sb.toString(); SLog.v("DSRecognizer", "DS initialization config: " + this.mInitString); } }
Somewhere my "ds.config" file, which is in the assets folder of my android studio project, is not being recognized.
Communicator.createDSCommunicator exits after the line marked with the comment "This line causes problem"
- I tried loading the file the same way it's done in dsRecognizer in my main java file, tried loading it using just plain File a = new File().
- My question is: What do I need to do to get my "ds.config" file, which I'm passing as a string, to get loaded? That is if that is even the problem here.
- Another Question is: How could I debug this to figure out what is going wrong?
EDIT1
Figured out what the problem is: My "ds.config" file is not being located and is giving the error "android.system.ErrnoException: open failed: ENOENT (No such file or directory)".
The file "ds.config" is located in the assets folder of my Android Studio project and any path I provide as a string input to my initializeDS() method causes this error. I need to pass a string to the API file to load the config file but what string do I pass?
Also interested in finding out if there is any other way I can acheive this?