gpt4 book ai didi

java - java sphinx程序中的错误

转载 作者:行者123 更新时间:2023-11-29 03:49:13 25 4
gpt4 key购买 nike

您好,我正在用 Java 开发一个软件,我想在其中开发一个语音软件...我正在用 Java 运行“Hello”sphinx 代码。

import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;

public class HelloWorld {

public static void main(String[] args) {
ConfigurationManager cm;

if (args.length > 0) {
cm = new ConfigurationManager(args[0]);
} else {
cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));
}

Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();

// start the microphone or exit if the programm if this is not possible
Microphone microphone = (Microphone) cm.lookup("microphone");
if (!microphone.startRecording()) {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}

System.out.println("Say: (Good morning | Hello) ( Bhiksha | Evandro | Paul | Philip | Rita | Will )");

// loop the recognition until the programm exits.
while (true) {
System.out.println("Start speaking. Press Ctrl-C to quit.\n");

Result result = recognizer.recognize();

if (result != null) {
String resultText = result.getBestFinalResultNoFiller();
System.out.println("You said: " + resultText + '\n');
} else {
System.out.println("I can't hear what you said.\n");
}
}
}
}

当我尝试运行这个程序时,我遇到了这个错误...

Exception in thread "main" java.lang.NullPointerException
at edu.cmu.sphinx.util.props.SaxLoader.load(SaxLoader.java:74)
at edu.cmu.sphinx.util.props.ConfigurationManager.<init>(ConfigurationManager.java:58)
at HelloWorld.main(HelloWorld.java:22)

请建议...

谢谢

最佳答案

我有同样的错误并修复了它。您只需在 sphinx bin 文件夹中找到一个 HelloWord.jar 文件,只需将 jar 文件包含到您的项目中,它就会正常运行


jar 文件的路径:sphinx4-1.0beta6-bin\sphinx4-1.0beta6\bin\HelloWorld.jar

关于java - java sphinx程序中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9532455/

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