如何添加用户在Sphinx 4(语音识别)中选择的关键字?

时间:2012-10-03 02:44:28

标签: java speech-recognition sphinx4

我想知道如何使用GRAM文件在Java中使用sphinx 4为语音识别添加自定义关键字?

喜欢:public =(设置歌曲);

如果在“设定歌曲”后用户可以说出他想要的任何内容并且仍然可以解析它,我将如何做到这一点?

        URL url = LulzSpeech.class.getResource("lulzspeech.config.xml");;

        System.out.println("Loading input...");

        ConfigurationManager cm = new ConfigurationManager(url);

        Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
        Microphone microphone = (Microphone) cm.lookup("microphone");

        recognizer.allocate();

        if (microphone.startRecording()) {

            System.out.println("Loading input completed, mic working, ready!");

            try{
            while (true) {
                Thread.sleep(50);

                Result result = recognizer.recognize();

                if (result != null)
                    if(result.getBestFinalResultNoFiller().toLowerCase().contains(MainLulz.programName.toLowerCase()))
                        MainLulz.mainVoiceHandler.handleInput(result.getBestFinalResultNoFiller());
            }
            }catch(Exception e){
                e.printStackTrace();
            }
        } else {
            System.out.println("Cannot start microphone.");
            recognizer.deallocate();
            System.exit(1);
        }
    } catch (IOException e) {
        System.err.println("Problem when loading LulzSpeech input: " + e);
        e.printStackTrace();
    } catch (PropertyException e) {
        System.err.println("Problem configuring LulzSpeech input: " + e);
        e.printStackTrace();
    } catch (InstantiationException e) {
        System.err.println("Problem creating LulzSpeech input: " + e);
        e.printStackTrace();
    }

1 个答案:

答案 0 :(得分:0)

当前版本的Sphinx-4中未实现关键字检测功能。您无法轻松检测到关键字。