2012-09-26 14 views
4

問題,而使用Web服務調用這是使用問題,而使用Web服務調用它

我創建了包含在以下目錄結構中的一個Java應用程序的資源文件中的一些Java應用程序方法使用的資源文件中的一些Java應用程序的方法,我與.aar文件這個Java應用程序的Java的的src文件夾..

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

我已經成功地創建Web服務和投入Axis2服務的文件夾

我在擷取音訊包裝這整個具有以下結構的r.ar文件

Transcriber\edu\cmu\sphinx\demo\transcriber 

並且在上面列出的所有4個文件中。

我在上面的Transcriber.java類中有兩種方法..第一種方法只是處理沒有任何其他文件使用像(如config.xml,digits.gram和transcriber.manifest)。它的工作正常,我可以很容易地從Android調用該方法。

但我的第二種方法還使用其他文件(例如config.xml,digits.gram和transcriber.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 

它給我的錯誤,一些它如何定位不能語法文件digits.gram這是我使用通過config.xml文件與此代碼在配置增加.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和THEN CONFIG.XML得到另一個資源文件....它成功地找到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; 


    } 




} 
+3

您以前已經問過這個問題(http://stackoverflow.com/questions/12436173/webservice-giving-error-like-cant-locate-resources-when-using-some-dependet-file),但是您刪除了它(包括我對這個問題的回答)。你爲什麼這麼做? –

+0

我現在不常使用該帳戶..因爲我想在這個問題上給予賞金,所以這就是爲什麼。對於那個 –

+0

@AndreasVeithen你提到你已經回答了這個問題?你的答案是否解決了巴赫維克問題? –

回答

1

你有沒有試過改變

<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"找到相同的資源。由於您不知道您調用的加載其他資源的庫代碼使用了哪種方法,因此您應該嘗試一下。

+0

好吧...將嘗試讓üknw ... –