如何使用CMU Sphinx将音频文件转换为文本

时间:2014-08-21 12:18:23

标签: java cmusphinx audio-converter

我正在尝试转换音频文件,下面是我的代码

public class test {
    public static void main(String[] args) throws Exception {
        System.out.println("Loading models...");

                Configuration configuration = new Configuration();

                // Load model from the jar
                configuration.setAcousticModelPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz");
                configuration.setDictionaryPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/cmudict.0.6d");        
                configuration.setLanguageModelPath("models/language/en-us.lm.dmp");

                StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);


                URL audioUrl = new URL("file:///C:/Sound1.wav");
                recognizer.startRecognition(audioUrl.openStream());

                SpeechResult result;

                while ((result = recognizer.getResult()) != null) {
                    System.out.format("Hypothesis: %s\n",
                                      result.getHypothesis());
                }

                System.out.println("Stop Recognition..");
                recognizer.stopRecognition();
            }
        }

但我在while ((result = recognizer.getResult()) != null)

以下的例外情况
Exception in thread "main" java.lang.NegativeArraySizeException
    at edu.cmu.sphinx.frontend.feature.LiveCMN.initMeansSums(LiveCMN.java:130)
    at edu.cmu.sphinx.frontend.feature.LiveCMN.getData(LiveCMN.java:161)

请建议我如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

此问题已在版本12586中的subversion中修复。