java - 使用 cmu sphinx 进行语音识别 - 无法正常工作

标签 java speech-recognition cmusphinx

我正在尝试使用 CMU Sphinx 在 Java 中进行语音识别,但我得到的结果不正确,我不知道为什么。

我有一个 .wav 文件,是用我的声音用英语说一些句子录制的。

这是我的java代码:

            Configuration configuration = new Configuration();

        // Set path to acoustic model.
        configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
        // Set path to dictionary.
        configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
        // Set language model.
        configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.dmp");
        StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);

        recognizer.startRecognition(new FileInputStream("assets/voice/some_wav_file.wav"));
        SpeechResult result = null;

        while ((result = recognizer.getResult()) != null) {
            System.out.println("~~ RESULTS: " + result.getHypothesis());
        }

        recognizer.stopRecognition();

    }
    catch(Exception e){
        System.out.println("ERROR: " + e.getMessage());
    }

我在 Android 中还有另一个代码,但效果不佳:

Assets assets = new Assets(context);
                File assetDir = assets.syncAssets();
                String prefix = assetDir.getPath();

                Config c = Decoder.defaultConfig();
                c.setString("-hmm", prefix + "/en-us-ptm");
                c.setString("-lm", prefix + "/en-us.lm");
                c.setString("-dict", prefix + "/cmudict-en-us.dict");
                Decoder d = new Decoder(c);
                InputStream stream = context.getResources().openRawResource(R.raw.some_wav_file);


                d.startUtt();
                byte[] b = new byte[4096];
                try {
                    int nbytes;
                    while ((nbytes = stream.read(b)) >= 0) {
                        ByteBuffer bb = ByteBuffer.wrap(b, 0, nbytes);
                        short[] s = new short[nbytes/2];
                        bb.asShortBuffer().get(s);
                        d.processRaw(s, nbytes/2, false, false);
                    }
                } catch (IOException e) {
                    Log.d("ERROR: ", "Error when reading file" + e.getMessage());
                }
                d.endUtt();
                Log.d("TOTAL RESULT: ", d.hyp().getHypstr());
                for (Segment seg : d.seg()) {
                    Log.d("RESULT: ", seg.getWord());
                }

我用了this网站将wav文件转换为16bit、16khz、mono和little-endian(尝试了它的所有选项)。

任何想法为什么不起作用。我使用内置词典和 Accustic 模型,而且我的英语口音并不完美(不知道这是否重要)。

编辑:

This is my file 。我记录下自己说:“我的宝宝很可爱”,这就是我期望的输出。 在纯java代码中我得到:“i've amy's Youth”,在android代码中我得到:“it

Here is file containing the logs .

最佳答案

您的音频因转换而有些损坏。您应该将其原始录制为 wav 或其他无损格式。你的发音也与美国英语相差甚远。对于格式之间的转换,您可以使用 sox 而不是外部网站。你的 android 示例看起来是正确的,但感觉就像你用 android 解码不同的文件。您可以检查资源中是否有真正正确的文件。

关于java - 使用 cmu sphinx 进行语音识别 - 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29619986/

相关文章:

java - 如何将 Wowza Stream 发送到 Google Cloud Speech API?

python - 在 MAC OS X 上安装 PocketSphinx

ios - TLSphinx cmusphinx pocketsphinx 假设结果文本 空字符串 得分 负 (-) 数字

java: "final"System.out、System.in 和 System.err?

java - 无法使用 oauth2 添加 spring security 的自定义配置

Java修改csv行

c# - Windows Phone 上的语音识别 - 语音到文本

ios - Speech Framework 只能识别英语吗?

android - CMUSphinx PocketSphinx - 识别所有(或大量)单词

c# - 通过.net访问openfire Java API?