gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:58:02 25 4
gpt4 key购买 nike

我正在尝试使用 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/

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