Problem when using webservice to call some java application method using resource file

Problem when using webservice to call some java application method using resource file

I created one java application that contains the following directory structure in my src java folder ..

Src/ Transcriber.java config.xml digits.gram transcriber.manifest 

I successfully created a web service for this java application with a .aar file and placed it in the axis2 service folder

I pack it all into a Transcriber.aar file with the following structure

 Transcriber\edu\cmu\sphinx\demo\transcriber 

and that all 4 files are higher than I listed.

I have two methods in the Transcriber.java class. The first method is simply processing without any other use of the file (e.g. config.xml, digits.gram and transcriber.manifest). and its performance, and I can easily call this method on android.

but my second method also uses other files (e.g. config.xml, digits.gram and transcriber.manifest) to process some logic that I want.

But some, how do I get an error when I call the second method, and it gives me an error while I call this second method from the 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 

this gives me an error that some of them cannot find the digits.gram grammar file, which I use to add through the config.xml file with this code in the config.xml file

 <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 do I have such an error? enter code here

My code where I first got CONFIG.XML AND THEN CONFIG.XML WILL RECEIVE ANOTHER RESOURCE FILE .... config.xml successfully finds it, but then the code in config.xml cannot find another 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; } } 
+4
source share
1 answer

Have you ever tried to change

 <property name="grammarLocation" value="resource:/edu/cmu/sphinx/demo/transcriber"/> 

to

 <property name="grammarLocation" value="resource:edu/cmu/sphinx/demo/transcriber"/> 

(which means just removing the leading slash before edu )?

Class.getResource() and ClassLoader.getResource() interpret the provided name differently: while Class.getResource( "/edu/cmu/sphinx/demo/transcriber/transcriber.manifest" ) finds the resource, you should use ClassLoader.getResource() with the argument "edu/cmu/sphinx/demo/transcriber/transcriber.manifest" to find the same resource. Since you do not know which method is used by the library code that you call to load other resources, you should try.

+1
source

Source: https://habr.com/ru/post/1436284/


All Articles