gpt4 book ai didi

java - 声学模型路径未正确设置 CMU Sphinx

转载 作者:行者123 更新时间:2023-11-30 06:16:49 26 4
gpt4 key购买 nike

下面写的代码是在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)

我已经指定了声学文件夹的路径。如何指定正确的路径?

最佳答案

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

configuration.setAcousticModelPath("file:C:\Program Files\eclips\sphinx4-5prealpha\models\\acoustic");

它应该可以工作了。

关于java - 声学模型路径未正确设置 CMU Sphinx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26602317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com