Java 声学模型路径未设置为右侧CMU Sphinx

Java 声学模型路径未设置为右侧CMU Sphinx,java,java-6,cmusphinx,helios,Java,Java 6,Cmusphinx,Helios,下面编写的代码是使用Java 1.6和Eclipse Helios中的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.s

下面编写的代码是使用Java 1.6和Eclipse Helios中的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)
线程“main”属性异常组件中的异常:'SouadicModelLoader'属性:'location'-错误URL C:/Program Files/eclipse/sphinx4-5prealpha/models/SouadicUnknown协议:C edu.cmu.sphinx.util.props.InternalConfigurationException:错误的URL C:/Program Files/eclipse/sphinx4-5prealpha/models/AudionicUnknown协议:C 位于edu.cmu.sphinx.util.props.ConfigurationManagerUtils.getResource(ConfigurationManagerUtils.java:479) 位于edu.cmu.sphinx.linguist.acoustic.tiedstate.Sphinx3Loader.newProperties(Sphinx3Loader.java:246) 位于edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 位于edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 位于edu.cmu.sphinx.linguist.acoustic.tiedstate.tiedstateAusticModel.newProperties(tiedstateAusticModel.java:102) 位于edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 位于edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 位于edu.cmu.sphinx.linguist.lextree.lextreelineguist.newProperties(lextreelineguist.java:301) 位于edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 位于edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 位于edu.cmu.sphinx.decoder.search.WordPrunningBreadthFirstSearchManager.newProperties(WordPrunningBreadthFirstSearchManager.java:199) 位于edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 位于edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 位于edu.cmu.sphinx.decoder.AbstractDecoder.newProperties(AbstractDecoder.java:71) 位于edu.cmu.sphinx.decoder.decoder.newProperties(decoder.java:37) 位于edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 位于edu.cmu.sphinx.util.props.PropertySheet.getComponent(PropertySheet.java:290) 位于edu.cmu.sphinx.recognizer.recognizer.newProperties(recognizer.java:90) 位于edu.cmu.sphinx.util.props.PropertySheet.getOwner(PropertySheet.java:508) 位于edu.cmu.sphinx.util.props.ConfigurationManager.lookup(ConfigurationManager.java:161) 位于edu.cmu.sphinx.api.Context.(Context.java:77) 位于edu.cmu.sphinx.api.Context.(Context.java:49) 位于edu.cmu.sphinx.api.AbstractSpeechRecognizer.(AbstractSpeechRecognizer.java:37) 位于edu.cmu.sphinx.api.StreamSpeechRecognizer.(StreamSpeechRecognizer.java:33) 位于AudioToText.main(AudioToText.java:21) 原因:java.net.MalformedURLException:未知协议:c 位于java.net.URL。(URL.java:574) 在java.net.URL.(URL.java:464) 在java.net.URL.(URL.java:413) 位于edu.cmu.sphinx.util.props.ConfigurationManagerUtils.resourceToURL(ConfigurationManagerUtils.java:495) 位于edu.cmu.sphinx.util.props.ConfigurationManagerUtils.getResource(ConfigurationManagerUtils.java:472) 我已指定声学文件夹的路径。如何指定正确的路径

private static final String ACOUSTIC_MODEL_PATH = 
        TextAligner.class.getResource("/resources/models/acoustic/wsj").toString();
configuration = new Configuration();
configuration.setAcousticModelPath(ACOUSTIC_MODEL_PATH);
我想如果您已经将声学模型添加到项目文件夹中的资源文件夹中,您可以这样做

更改
configuration.setAcousticModelPath(“C:/Program
文件/eclipse/sphinx4-5prealpha/models/acoustic”)

setAcousticModelPath(“文件:C:\Program 文件\eclips\sphinx4-5prealpha\models\\acoustic”)


它应该可以工作。

在Java on Windows中,文件URL的指定方式如下:file:///C:/path/to/file