[英]How to detect out of vocabulary word in CMU Sphinx
I am having a problem with the Sphinx voice recognition library for Java. 我在使用Sphinx Java语音识别库时遇到了问题。 I am using it to get input and handle it.
我正在使用它来获取输入并处理它。 In the grammar file , I wrote like this:
在语法文件中,我这样写:
#JSGF V1.0;
grammar hello;
public <sentence> = (play | pause | next | previous);
My grammar is simple , just includes 4 words : "play" , "pause" , "next" , "previous". 我的语法很简单,仅包含四个词:“播放”,“暂停”,“下一个”,“上一个”。 I have used Sphinx to detect them sucessfully .
我已经用Sphinx成功地检测了它们。 But I want my app to show a message like : "Unrecognized word" when I speak some words that do not belong to the grammar.
但是当我说一些不属于语法的单词时,我希望我的应用程序显示类似“无法识别的单词”的消息。 Currently, For example, if I speak to the microphone a not belong to the grammar like :"stop" , it still show up the word that it detects that it is the nearest result.
当前,例如,如果我对麦克风说a不属于语法,例如:“ stop”,它仍然显示检测到它是最接近结果的词。
My code is like this : 我的代码是这样的:
public class SphinxDemo {
static int i = 1;
static String resultText;
public static void main(String[] args) {
try {
URL url;
if (args.length > 0) {
url = new File(args[0]).toURI().toURL();
} else {
url = SphinxDemo.class.getResource("helloworld.config.xml");
}
System.out.println("Loading...");
ConfigurationManager cm = new ConfigurationManager(url);
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
Microphone microphone = (Microphone) cm.lookup("microphone");
/* allocate the resource necessary for the recognizer */
recognizer.allocate();
/* the microphone will keep recording until the program exits */
if (microphone.startRecording()) {
System.out
.println("Say: play|pause|previous|next");
while (true) {
System.out
.println("Start speaking. Press Ctrl-C to quit.\n");
Result result = recognizer.recognize();
if (result != null) {
System.out.println("Enter your choise" + "\n");
resultText = result.getBestFinalResultNoFiller();
System.out.println("You said: " + resultText + "\n");
}
if(!(resultText.equalsIgnoreCase("play") || resultText.equalsIgnoreCase("previous") || resultText.equalsIgnoreCase("pause")||resultText.equalsIgnoreCase("next"))){
System.out.println("Unrecognized word\n");
}
}
} else {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
} catch (IOException e) {
System.err.println("Problem when loading SphinxDemo: " + e);
e.printStackTrace();
} catch (PropertyException e) {
System.err.println("Problem configuring SphinxDemo: " + e);
e.printStackTrace();
} catch (InstantiationException e) {
System.err.println("Problem creating SphinxDemo: " + e);
e.printStackTrace();
}
}
}
I have tried to add something like this to detect unrecognized word but it does not work: 我试图添加类似这样的东西来检测无法识别的单词,但是它不起作用:
if(!(resultText.equalsIgnoreCase("play") || resultText.equalsIgnoreCase("previous") || resultText.equalsIgnoreCase("pause")||resultText.equalsIgnoreCase("next"))){
System.out.println("Unrecognized word\n");
}
如果你使用最新的cmusphinx,它将返回<unk>
当字不在语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.