使用webservice调用某个正在使用资源文件的java应用程序方法时出现问题



使用webservice调用某些使用资源文件的java应用程序方法时出现问题

我已经创建了一个java应用程序,它在我的java src文件夹中包含以下目录结构。。

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

我已经成功地用.aar文件创建了这个java应用程序的web服务,并将其放入axis2服务文件夹中

我正在用以下结构将整个文件打包在Transcripter.aar文件中

Transcribereducmusphinxdemotranscriber

在我列出的所有4个文件中。

我在上面的Transcripter.java类中有两个方法。。第一种方法只是在没有任何其他文件使用的情况下进行处理(例如config.xml、digitals.gram和transcripter.manifest)。它运行良好,我可以很容易地从android调用该方法。

但我的第二种方法也使用其他文件(例如config.xml、digitals.gram和transcripter.manifest)来处理我想要的一些逻辑。

但是当我从android设备调用第二个方法时,它会给我错误。

我的错误如下:

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

它给我的错误是,它无法定位语法文件digitals.gram,我使用它通过config.xml文件在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>

为什么我会犯这种错误?enter code here

我的代码首先获取CONFIG.XML,然后CONFIG.XXML获取另一个资源文件。。。。它成功地找到了config.xml,但config.xml中的代码找不到其他资源文件

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;

}


}

您是否尝试过更改

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

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

(意思是只删除edu之前的前导斜杠)?

Class.getResource()ClassLoader.getResource()对所提供的名称的解释不同:虽然Class.getResource( "/edu/cmu/sphinx/demo/transcriber/transcriber.manifest" )可以查找资源,但必须将ClassLoader.getResource()与参数"edu/cmu/sphinx/demo/transcriber/transcriber.manifest"一起使用才能查找相同的资源。由于您不知道您调用的库代码使用哪种方法来加载其他资源,因此应该尝试一下。

相关内容

最新更新