2014-10-28 3 views
2

아래 코드는 Java 1.6 및 Eclipse Helios의 CMU Sphinx를 사용하여 오디오를 텍스트로 변환하는 코드입니다.어쿠스틱 모델 경로가 올바르게 설정되지 않았습니다. CMU Sphinx

import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.FileNotFoundException; 

import edu.cmu.sphinx.api.Configuration; 
import edu.cmu.sphinx.api.SpeechResult; 
import edu.cmu.sphinx.api.StreamSpeechRecognizer; 

public class AudioToText { 
    public static void main(String [] args) throws FileNotFoundException,IOException{ 
     Configuration configuration = new Configuration(); 

     // Set path to acoustic model. 
     configuration.setAcousticModelPath("C:/Program Files/eclipse/sphinx4-5prealpha/models/acoustic"); 
     // Set path to dictionary. 
     configuration.setDictionaryPath("C:/Program Files/eclipse/sphinx4-5prealpha/models/acoustic/wsj/dict/cmudict.0.6d"); 
     // Set language model. 
     configuration.setLanguageModelPath("C:/Program Files/eclipse/sphinx4-5prealpha/models/language/en-us.lm.dmp"); 

     StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration); 
     //recognizer.startRecognition(new File("D:/audio.mp3").toURI().toURL()); 
     recognizer.startRecognition(new FileInputStream("D:/audio.mp3")); 
     SpeechResult result; 
     while ((result = recognizer.getResult()) != null) { 
      System.out.println(result.getHypothesis()); 
     } 
     recognizer.stopRecognition(); 
    } 
} 

예외가 있기 때문에 아래에 언급 한 바와 같이 올바르게 음향 모델의 경로를 설정하지의 발생된다 음향 폴더에

Exception in thread "main" Property exception component:'acousticModelLoader' property:'location' - Bad URL C:/Program Files/eclipse/sphinx4-5prealpha/models/acousticunknown protocol: c 
edu.cmu.sphinx.util.props.InternalConfigurationException: Bad URL C:/Program Files/eclipse/sphinx4-5prealpha/models/acousticunknown protocol: c 
    at edu.cmu.sphinx.util.props.ConfigurationManagerUtils.getResource(ConfigurationManagerUtils.java:479) 
    at edu.cmu.sphinx.linguist.acoustic.tiedstate.Sphinx3Loader.newProperties(Sphinx3Loader.java:246) 
    at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 
    at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 
    at edu.cmu.sphinx.linguist.acoustic.tiedstate.TiedStateAcousticModel.newProperties(TiedStateAcousticModel.java:102) 
    at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 
    at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 
    at edu.cmu.sphinx.linguist.lextree.LexTreeLinguist.newProperties(LexTreeLinguist.java:301) 
    at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 
    at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 
    at edu.cmu.sphinx.decoder.search.WordPruningBreadthFirstSearchManager.newProperties(WordPruningBreadthFirstSearchManager.java:199) 
    at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 
    at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 
    at edu.cmu.sphinx.decoder.AbstractDecoder.newProperties(AbstractDecoder.java:71) 
    at edu.cmu.sphinx.decoder.Decoder.newProperties(Decoder.java:37) 
    at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 
    at edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 
    at edu.cmu.sphinx.recognizer.Recognizer.newProperties(Recognizer.java:90) 
    at edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 
    at edu.cmu.sphinx.util.props.ConfigurationManager.lookup(ConfigurationManager.java:161) 
    at edu.cmu.sphinx.api.Context.<init>(Context.java:77) 
    at edu.cmu.sphinx.api.Context.<init>(Context.java:49) 
    at edu.cmu.sphinx.api.AbstractSpeechRecognizer.<init>(AbstractSpeechRecognizer.java:37) 
    at edu.cmu.sphinx.api.StreamSpeechRecognizer.<init>(StreamSpeechRecognizer.java:33) 
    at AudioToText.main(AudioToText.java:21) 
Caused by: java.net.MalformedURLException: unknown protocol: c 
    at java.net.URL.<init>(URL.java:574) 
    at java.net.URL.<init>(URL.java:464) 
    at java.net.URL.<init>(URL.java:413) 
    at edu.cmu.sphinx.util.props.ConfigurationManagerUtils.resourceToURL(ConfigurationManagerUtils.java:495) 
    at edu.cmu.sphinx.util.props.ConfigurationManagerUtils.getResource(ConfigurationManagerUtils.java:472) 

내가 지정한 경로를. 올바른 경로를 지정하는 방법은 무엇입니까?

+0

Windows의 Java 파일에서 URL은 다음과 같이 지정됩니다. file : /// C :/path/to/file –

답변

2
private static final String ACOUSTIC_MODEL_PATH = 
     TextAligner.class.getResource("/resources/models/acoustic/wsj").toString(); 
configuration = new Configuration(); 
configuration.setAcousticModelPath(ACOUSTIC_MODEL_PATH); 

프로젝트 폴더의 리소스 폴더에 음향 모델을 추가 한 경우 이렇게 할 수 있습니다.

3

변경 configuration.setAcousticModelPath("C:/Program Files/eclipse/sphinx4-5prealpha/models/acoustic");

configuration.setAcousticModelPath에 ("C : 파일 \ 프로그램 파일 \ ECLIPS \ sphinx4-5prealpha \ 모델 \\ 음향");

그러면 작동합니다.