2014-10-28 5 views
2

Код, представленный ниже, предназначен для преобразования аудио в текст с использованием CMU Sphinx в Java 1.6 и Eclipse Helios.Путь к акустической модели не установлена ​​Right 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

В Java на Windows файлы 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: \ Program Files \ ECLIPS \ sphinx4-5prealpha \ модели \\ акустическое");

Тогда он должен работать.